:root {
  --ink: #17212b;
  --muted: #617083;
  --paper: #f7f9fc;
  --surface: #ffffff;
  --line: #d8e0ea;
  --teal: #0f8c8c;
  --teal-dark: #0b6468;
  --coral: #e15d4f;
  --gold: #e3a525;
  --green: #2f9b65;
  --blue: #3b6fb6;
  --shadow: 0 18px 45px rgba(42, 54, 71, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(15, 140, 140, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(225, 93, 79, 0.1), transparent 34%),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  touch-action: manipulation;
}

.app-shell {
  margin: 0 auto;
  max-width: 1240px;
  padding: 24px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 20px;
  justify-content: space-between;
  margin-bottom: 20px;
}

.eyebrow {
  color: var(--teal-dark);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 5px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 3.4rem;
  line-height: 0.98;
  margin-bottom: 0;
}

h2 {
  font-size: 1.05rem;
  margin-bottom: 12px;
}

.layout {
  align-items: start;
  display: grid;
  gap: 20px;
  grid-template-columns: 290px 1fr;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 18px;
}

.sidebar,
.play-area {
  display: grid;
  gap: 16px;
}

.panel,
.mission-bar,
.game-card,
.word-bank {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.button-stack {
  display: grid;
  gap: 9px;
}

.unit-button,
.mode-button,
.action-button,
.choice-button,
.letter-button,
.word-chip,
.definition-button,
.cell-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, color 140ms ease;
}

.unit-button,
.mode-button {
  background: #fff;
  color: var(--ink);
  min-height: 52px;
  padding: 11px 12px;
  text-align: left;
}

.unit-button strong,
.mode-button strong {
  display: block;
  font-size: 0.98rem;
}

.unit-button span,
.mode-button span {
  color: var(--muted);
  display: block;
  font-size: 0.83rem;
  margin-top: 2px;
}

.unit-button.active,
.mode-button.active {
  background: #e7f6f4;
  border-color: var(--teal);
  color: var(--teal-dark);
}

.unit-button:hover,
.mode-button:hover,
.action-button:hover,
.choice-button:hover,
.letter-button:hover,
.word-chip:hover,
.definition-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.meter {
  background: #edf1f5;
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
}

.meter span {
  background: linear-gradient(90deg, var(--green), var(--gold));
  display: block;
  height: 100%;
  width: 0;
}

.stats-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 14px;
}

.stats-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 8px;
  text-align: center;
}

.stats-grid strong,
.stats-grid span {
  display: block;
}

.stats-grid span {
  color: var(--muted);
  font-size: 0.78rem;
}

.mission-bar {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 18px 20px;
}

.mission-bar h2 {
  font-size: 1.65rem;
  line-height: 1.05;
  margin: 0;
}

.score-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: end;
}

.score-strip span,
.status-pill {
  background: #f0f4f8;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  padding: 7px 10px;
  white-space: nowrap;
}

.game-root {
  min-height: 420px;
}

.game-card {
  min-height: 420px;
  padding: 22px;
}

.prompt-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.prompt-card {
  border-left: 5px solid var(--teal);
  margin-bottom: 18px;
  padding: 4px 0 2px 14px;
}

.definition {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.18;
  margin-bottom: 10px;
}

.example {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
  margin-bottom: 0;
}

.answer-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 20px 0;
  min-height: 48px;
}

.slot {
  align-items: center;
  background: #f4f7fb;
  border: 2px solid #c9d5e2;
  border-radius: 8px;
  display: inline-flex;
  font-size: 1.25rem;
  font-weight: 800;
  height: 46px;
  justify-content: center;
  min-width: 38px;
  padding: 0 8px;
}

.slot.fixed {
  background: #e7f6f4;
  border-color: #93c9c5;
  color: var(--teal-dark);
}

.slot.space {
  background: transparent;
  border-color: transparent;
  min-width: 14px;
}

.letters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.letter-button {
  background: #fff;
  color: var(--ink);
  font-size: 1.1rem;
  font-weight: 800;
  height: 50px;
  min-width: 50px;
  padding: 0 12px;
  text-transform: uppercase;
}

.letter-button:disabled {
  background: #eef3f8;
  color: #a5b2bf;
  cursor: default;
  transform: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.action-button,
.icon-button {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  font-weight: 800;
  min-height: 48px;
  padding: 10px 14px;
}

.action-button {
  flex: 0 1 auto;
}

.action-button.secondary,
.icon-button {
  background: #fff;
  color: var(--ink);
}

.feedback {
  border-radius: 8px;
  font-weight: 800;
  margin-top: 16px;
  min-height: 45px;
  padding: 12px 14px;
}

.feedback.good {
  background: #e8f7ef;
  color: #19623f;
}

.feedback.bad {
  background: #fdecea;
  color: #9b3128;
}

.feedback.neutral {
  background: #f1f5fa;
  color: var(--muted);
}

.choice-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-button {
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  min-height: 60px;
  padding: 14px;
  text-align: left;
}

.choice-button.correct {
  background: #e8f7ef;
  border-color: var(--green);
  color: #19623f;
}

.choice-button.wrong {
  background: #fdecea;
  border-color: var(--coral);
  color: #9b3128;
}

.match-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 220px 1fr;
}

.match-column {
  display: grid;
  gap: 9px;
}

.word-chip,
.definition-button {
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  min-height: 52px;
  padding: 11px;
  text-align: left;
}

.definition-button {
  font-weight: 700;
  line-height: 1.35;
}

.word-chip.selected,
.definition-button.selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59, 111, 182, 0.16);
}

.word-chip.done,
.definition-button.done {
  background: #e8f7ef;
  border-color: var(--green);
  color: #19623f;
}

.search-layout {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(280px, 460px) 1fr;
}

.letter-grid {
  display: grid;
  gap: 5px;
  max-width: 460px;
  touch-action: manipulation;
  width: 100%;
}

.cell-button {
  align-items: center;
  aspect-ratio: 1;
  background: #fff;
  color: var(--ink);
  display: inline-flex;
  font-weight: 900;
  justify-content: center;
  min-width: 0;
  padding: 0;
  text-transform: uppercase;
}

.cell-button.active {
  background: #fff3cf;
  border-color: var(--gold);
}

.cell-button.found {
  background: #dff4eb;
  border-color: var(--green);
  color: #19623f;
}

.target-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.target-list span {
  background: #f0f4f8;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 800;
  padding: 7px 10px;
}

.target-list span.found {
  background: #e8f7ef;
  color: #19623f;
  text-decoration: line-through;
}

.section-heading {
  align-items: baseline;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 16px 16px 0;
}

.section-heading h2 {
  margin-bottom: 0;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.9rem;
}

.word-bank {
  padding-bottom: 16px;
}

.word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px 0;
}

.bank-word {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  padding: 8px 11px;
}

.bank-word.mastered {
  background: #e8f7ef;
  color: #19623f;
}

.bank-word.review {
  background: #fdecea;
  color: #9b3128;
}

.empty-state {
  align-items: center;
  display: grid;
  min-height: 320px;
  place-items: center;
  text-align: center;
}

.empty-state h3 {
  font-size: 1.8rem;
  margin-bottom: 8px;
}

.empty-state p {
  color: var(--muted);
  line-height: 1.5;
  max-width: 520px;
}

@media (max-width: 900px) {
  .app-shell {
    padding: 16px;
  }

  h1 {
    font-size: 2.7rem;
  }

  .layout,
  .search-layout,
  .match-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .panel {
    padding: 14px;
  }

  .button-stack {
    gap: 8px;
  }

  .mission-bar {
    align-items: start;
    flex-direction: column;
  }

  .score-strip {
    justify-content: start;
  }

  .choice-grid {
    grid-template-columns: 1fr;
  }

  .letter-grid {
    max-width: 520px;
  }
}

@media (max-width: 560px) {
  body {
    background: var(--paper);
  }

  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
  }

  h1 {
    font-size: 2.15rem;
  }

  h2 {
    font-size: 1rem;
    margin-bottom: 10px;
  }

  .sidebar {
    display: block;
  }

  .panel {
    margin-bottom: 10px;
    padding: 12px;
  }

  .progress-panel {
    display: none;
  }

  .button-stack {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 1px 1px 8px;
    scroll-snap-type: x proximity;
  }

  .unit-button,
  .mode-button {
    flex: 0 0 72%;
    min-height: 58px;
    scroll-snap-align: start;
  }

  .mode-button {
    flex-basis: 62%;
  }

  .mission-bar {
    padding: 14px;
  }

  .mission-bar h2 {
    font-size: 1.35rem;
  }

  .score-strip span,
  .status-pill {
    font-size: 0.82rem;
    padding: 6px 9px;
  }

  .game-card {
    min-height: auto;
    padding: 16px;
  }

  .definition {
    font-size: 1.32rem;
  }

  .example {
    font-size: 0.96rem;
  }

  .answer-slots {
    gap: 5px;
    margin: 16px 0;
  }

  .slot {
    border-width: 1px;
    font-size: 1.05rem;
    height: 34px;
    min-width: 28px;
    padding: 0 6px;
  }

  .letters {
    gap: 7px;
  }

  .letter-button {
    flex: 1 1 42px;
    height: 48px;
    min-width: 42px;
    padding: 0 8px;
  }

  .action-button {
    flex: 1 1 calc(50% - 10px);
    min-height: 50px;
  }

  .choice-button,
  .word-chip,
  .definition-button {
    min-height: 54px;
  }

  .letter-grid {
    gap: 4px;
    max-width: 390px;
  }

  .cell-button {
    border-radius: 6px;
    font-size: 0.92rem;
  }

  .section-heading {
    align-items: start;
    flex-direction: column;
    gap: 4px;
  }

  .word-list {
    max-height: 142px;
    overflow: auto;
  }
}

@media (max-width: 380px) {
  .unit-button {
    flex-basis: 84%;
  }

  .mode-button {
    flex-basis: 76%;
  }

  .slot {
    min-width: 26px;
  }

  .cell-button {
    font-size: 0.86rem;
  }
}
