:root {
  --ink: #17202a;
  --muted: #65727d;
  --line: #dce4e8;
  --paper: #fbfcfd;
  --panel: #ffffff;
  --teal: #007f7a;
  --teal-dark: #005f5b;
  --berry: #b7355b;
  --amber: #d7971f;
  --mint: #e7f6f2;
  --rose: #faeef2;
  --blue: #eaf2fb;
  --success: #207a42;
  --danger: #b93030;
  --shadow: 0 18px 45px rgba(23, 32, 42, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(231, 246, 242, 0.9), rgba(251, 252, 253, 0.5) 34rem),
    var(--paper);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 180px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(234, 242, 251, 0.9)),
    var(--panel);
  box-shadow: var(--shadow);
}

.brand-logo {
  width: 100%;
  max-height: 86px;
  object-fit: contain;
  justify-self: center;
}

.eyebrow,
.subtitle,
.panel-heading p,
.exercise-title p,
.result,
.score-label {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0;
}

h1 {
  margin-top: 8px;
  font-size: clamp(2.5rem, 9vw, 5.4rem);
}

.subtitle {
  margin-top: 8px;
  font-size: clamp(1rem, 2.5vw, 1.35rem);
}

.score-panel {
  display: grid;
  place-items: center;
  width: 118px;
  height: 118px;
  border: 1px solid rgba(0, 127, 122, 0.24);
  border-radius: 8px;
  background: var(--mint);
}

.score-panel strong {
  font-size: 2rem;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.tab-button,
.segment,
.primary-button,
.secondary-button,
.ghost-button,
.mark-card-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.tab-button.is-active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.panel-heading {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  margin: 22px 0 16px;
}

.panel-heading h2 {
  font-size: clamp(1.45rem, 4vw, 2.25rem);
}

.exercise-block,
.reference-section,
.flashcard-area {
  margin-top: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 30px rgba(23, 32, 42, 0.05);
}

.exercise-title {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.number-badge {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--rose);
  color: var(--berry);
  font-weight: 800;
}

.grid {
  display: grid;
  gap: 12px;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.answer-row,
.letter-box,
.matching-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.answer-row {
  display: grid;
  grid-template-columns: minmax(0, 0.62fr) minmax(170px, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 12px;
}

.prompt {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.nowrap-label {
  white-space: nowrap;
}

.answer-row input,
.letter-box input,
.number-find-grid input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
}

.answer-row input:focus,
.letter-box input:focus,
.number-find-grid input:focus,
.tab-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.ghost-button:focus-visible,
.mark-card-button:focus-visible,
.char-button:focus-visible,
.segment:focus-visible,
.flashcard:focus-visible,
.drop-zone:focus-visible,
.drag-chip:focus-visible,
.chain-letter:focus-visible,
.search-cell:focus-visible {
  outline: 3px solid rgba(215, 151, 31, 0.45);
  outline-offset: 2px;
}

.is-correct {
  border-color: rgba(32, 122, 66, 0.5);
  background: #f0fbf3;
}

.is-wrong {
  border-color: rgba(185, 48, 48, 0.45);
  background: #fff3f3;
}

.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 16px;
}

.drag-chip,
.word-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid rgba(0, 127, 122, 0.25);
  border-radius: 8px;
  background: var(--mint);
  color: var(--teal-dark);
  font-weight: 800;
  box-shadow: 0 5px 14px rgba(0, 95, 91, 0.08);
  cursor: pointer;
}

.drag-chip:hover {
  border-color: var(--teal);
  background: #d8f0ec;
}

.drag-chip.is-selected {
  border-color: var(--teal-dark);
  background: var(--teal-dark);
  color: #fff;
  box-shadow: 0 10px 22px rgba(0, 95, 91, 0.22);
}

.drop-zone {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 9ch;
  min-height: 36px;
  margin: 0 1px;
  padding: 3px 6px;
  border: 1px dashed rgba(0, 127, 122, 0.45);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  vertical-align: middle;
}

.drop-zone:empty::before {
  content: "";
  display: block;
  width: 6.5ch;
  height: 1.2em;
}

.drop-zone.is-filled {
  border-style: solid;
}

.drop-zone .drag-chip {
  min-height: 30px;
  padding: 4px 8px;
  box-shadow: none;
}

.solution-text {
  color: var(--success);
  font-weight: 800;
}

.char-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: -2px 0 16px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.char-button {
  min-width: 34px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
}

.char-button:hover {
  border-color: var(--teal);
  background: var(--mint);
}

.letter-chain {
  display: block;
  margin: 0 0 14px;
  padding: 14px;
  border: 1px solid rgba(0, 127, 122, 0.24);
  border-radius: 8px;
  background: var(--mint);
  font-size: clamp(1rem, 3vw, 1.45rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
  user-select: none;
}

.chain-letter {
  display: inline;
  min-height: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  margin: 0;
  padding: 0;
  touch-action: none;
}

.chain-letter:hover,
.chain-letter.is-marked {
  background: #fff36b;
  box-shadow: 0 0 0 1px #d8bf00 inset;
}

.example-line,
.exercise-example {
  margin: 0 0 16px;
  color: var(--ink);
}

.exercise-example {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.example-heading {
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.example-heading span {
  font-weight: 800;
  text-decoration: underline;
}

.example-heading em {
  color: var(--muted);
}

.answer-line {
  display: inline-block;
  min-width: 22ch;
  border-bottom: 1px solid var(--ink);
}

.number-find-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

#exercise1 .number-find-grid {
  grid-template-columns: repeat(7, minmax(78px, max-content));
  gap: 8px;
}

#exercise1 .answer-row {
  grid-template-columns: max-content 5.5ch;
  gap: 6px;
  width: max-content;
  min-height: 44px;
  padding: 8px;
}

#exercise1 .answer-row input {
  width: 5.5ch;
  min-width: 0;
  padding: 8px 4px;
  text-align: center;
}

.inline-task {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  align-items: center;
  min-height: 48px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 700;
}

#exercise3 .inline-task {
  font-weight: 400;
}

#exercise3 .drop-zone .drag-chip,
#exercise3 .solution-text {
  font-weight: 700;
}

.clue-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.clue {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--mint);
  font-weight: 800;
}

.letter-solution {
  display: grid;
  grid-template-columns: repeat(5, minmax(80px, 1fr));
  gap: 10px;
}

.letter-box {
  display: grid;
  gap: 8px;
  justify-items: center;
  padding: 12px;
}

.letter-box span {
  color: var(--muted);
  font-weight: 800;
}

.letter-box input,
.prefilled-letter {
  width: 54px;
  min-height: 46px;
  text-align: center;
  font-size: 1.35rem;
  font-weight: 800;
  text-transform: uppercase;
}

.prefilled-letter {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f8f9;
}

.solution-word {
  grid-column: 1 / -1;
  margin: 4px 0 0;
  color: var(--teal-dark);
  font-weight: 900;
  text-align: center;
}

.search-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(26px, 1fr));
  gap: 4px;
  max-width: 520px;
  margin-bottom: 16px;
}

.search-cell {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

.search-cell.is-user-marked {
  background: #bdeedb;
  border-color: rgba(0, 127, 122, 0.65);
}

.search-cell.is-selection-start {
  outline: 3px solid rgba(215, 151, 31, 0.55);
  outline-offset: 1px;
}

.search-cell.is-highlighted {
  background: #fff36b;
  border-color: #d8bf00;
}

.matching-board {
  display: grid;
  grid-template-columns: 180px max-content;
  gap: 6px;
  align-items: start;
  justify-content: start;
}

.matching-left,
.matching-right {
  display: grid;
  gap: 7px;
  align-content: start;
}

.matching-row {
  display: grid;
  grid-template-columns: max-content max-content;
  gap: 5px;
  align-items: center;
  min-height: 48px;
  padding: 7px;
}

.matching-prompt {
  font-weight: 800;
}

.matching-right .drag-chip {
  justify-content: center;
  width: 100%;
  min-height: 34px;
  padding: 5px 6px;
  overflow-wrap: anywhere;
  text-align: center;
}

#exercise7 .drop-zone {
  min-width: var(--answer-width, 9ch);
  padding-inline: 4px;
}

#exercise7 .drop-zone:empty::before {
  width: max(4ch, calc(var(--answer-width, 9ch) - 4ch));
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
}

.primary-button {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
  padding: 0 18px;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button,
.ghost-button,
.mark-card-button {
  padding: 0 16px;
}

.secondary-button:hover,
.ghost-button:hover,
.segment:hover {
  border-color: var(--teal);
}

.result {
  font-weight: 700;
}

.result.good {
  color: var(--success);
}

.result.needs-work {
  color: var(--danger);
}

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.segment {
  min-height: 38px;
  border-color: transparent;
  padding: 0 12px;
}

.segment.is-active {
  background: var(--berry);
  color: #fff;
}

.flashcard-area {
  display: grid;
  gap: 16px;
}

.flash-filter-bar {
  display: flex;
  justify-content: center;
}

.flashcard {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 260px;
  padding: 38px 22px;
  border: 1px solid rgba(0, 127, 122, 0.25);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(231, 246, 242, 1), rgba(250, 238, 242, 0.9)),
    #fff;
  color: var(--ink);
  text-align: center;
  box-shadow: 0 12px 28px rgba(0, 95, 91, 0.08);
  overflow: hidden;
}

.flashcard::after {
  content: attr(data-status-flash);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(0, 95, 91, 0.34);
  font-size: clamp(7rem, 28vw, 18rem);
  font-weight: 900;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.86);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.flashcard.show-status-flash::after {
  opacity: 1;
  transform: scale(1);
}

.card-meta {
  position: absolute;
  top: 14px;
  right: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.card-front,
.card-back {
  display: block;
  max-width: 780px;
  font-size: clamp(1.65rem, 7vw, 4rem);
  font-weight: 850;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.card-back {
  display: none;
  color: var(--teal-dark);
  font-size: clamp(1.35rem, 5vw, 2.8rem);
}

.flashcard.is-flipped .card-front {
  display: none;
}

.flashcard.is-flipped .card-back {
  display: block;
}

.flash-actions,
.flash-progress {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: center;
}

.flash-progress {
  justify-content: space-between;
  color: var(--muted);
  font-weight: 700;
}

.mark-card-button {
  display: inline-grid;
  place-items: center;
  min-width: 48px;
  padding: 0 12px;
  font-size: 1.45rem;
  line-height: 1;
}

.mark-card-button.learned {
  border-color: rgba(32, 122, 66, 0.55);
  color: var(--success);
}

.mark-card-button.review {
  border-color: rgba(185, 48, 48, 0.45);
  color: var(--danger);
}

.mark-card-button.learned.is-active,
.mark-card-button.learned:hover {
  background: #f0fbf3;
  border-color: var(--success);
}

.mark-card-button.review.is-active,
.mark-card-button.review:hover {
  background: #fff3f3;
  border-color: var(--danger);
}

.mark-card-button:disabled,
.flashcard:disabled,
.secondary-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.number-table {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 8px;
}

.large-number-table {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.number-table-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.number-table-row strong {
  color: var(--teal-dark);
}

.number-table-row span {
  overflow-wrap: normal;
  word-break: normal;
}

.scheme-grid {
  display: grid;
  gap: 12px;
}

.scheme-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.scheme-title {
  color: var(--teal-dark);
  font-weight: 900;
}

.scheme-number {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  font-size: clamp(1.4rem, 5vw, 2.4rem);
  font-weight: 900;
}

.scheme-digit {
  display: inline-grid;
  place-items: center;
  width: 1.45em;
  height: 1.45em;
  border: 1px solid var(--scheme-border, rgba(0, 127, 122, 0.28));
  border-radius: 6px;
  background: var(--scheme-bg, var(--mint));
  color: var(--scheme-text, var(--ink));
}

.scheme-word {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.scheme-part {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid var(--scheme-border, transparent);
  border-radius: 6px;
  background: var(--scheme-bg, var(--blue));
  color: var(--scheme-text, var(--ink));
  font-weight: 800;
}

.scheme-color-ones {
  --scheme-bg: #e7f6f2;
  --scheme-border: #65b7aa;
  --scheme-text: #005f5b;
}

.scheme-color-tens {
  --scheme-bg: #faeef2;
  --scheme-border: #db8aa3;
  --scheme-text: #8f2445;
}

.scheme-color-hundreds {
  --scheme-bg: #eaf2fb;
  --scheme-border: #8fb8de;
  --scheme-text: #225982;
}

.scheme-color-thousands {
  --scheme-bg: #fff4d8;
  --scheme-border: #d7a73d;
  --scheme-text: #7a5510;
}

.scheme-color-join {
  --scheme-bg: #f5f8f9;
  --scheme-border: #dce4e8;
  --scheme-text: #65727d;
}

.scheme-join {
  color: var(--muted);
  font-weight: 900;
}

.scheme-result {
  color: var(--success);
  font-weight: 900;
  overflow-wrap: anywhere;
}

@media (max-width: 780px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 10px;
  }

  .topbar {
    grid-template-columns: 1fr;
    padding: 22px;
  }

  .brand-logo {
    max-width: 210px;
  }

  .score-panel {
    width: 100%;
    height: auto;
    min-height: 82px;
  }

  .tabs,
  .two-col {
    grid-template-columns: 1fr;
  }

  .number-table {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }

  .large-number-table {
    grid-template-columns: 1fr;
  }

  .number-find-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #exercise1 .number-find-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  #exercise1 .answer-row {
    grid-template-columns: max-content minmax(0, 1fr);
    width: 100%;
  }

  #exercise1 .answer-row input {
    width: 100%;
  }

  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .exercise-block,
  .reference-section,
  .flashcard-area {
    padding: 16px;
  }

  .answer-row {
    grid-template-columns: 1fr;
  }

  .clue-list {
    grid-template-columns: 1fr;
  }

  .letter-solution {
    grid-template-columns: repeat(5, minmax(52px, 1fr));
    gap: 6px;
  }

  .matching-board {
    grid-template-columns: 120px minmax(0, max-content);
    gap: 4px;
  }

  .matching-row {
    grid-template-columns: 1fr;
    font-size: 0.9rem;
  }

  .matching-right .drag-chip {
    font-size: 0.84rem;
    padding: 4px 5px;
  }
}
