:root {
  --ink: #172033;
  --muted: #6b7280;
  --line: #e4dccb;
  --soft-line: #efe8d9;
  --page: #f5f1e8;
  --panel: #ffffff;
  --olive: #687638;
  --olive-dark: #424d24;
  --olive-soft: #eef4dc;
  --gold: #c4932d;
  --cream: #fffaf0;
  --red: #b42318;
  --blue: #2861a8;
  --shadow-sm: 0 6px 18px rgba(43, 35, 18, 0.07);
  --shadow-md: 0 18px 42px rgba(43, 35, 18, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(245, 241, 232, 0.4)),
    var(--page);
  color: var(--ink);
  font-family: Arial, "Noto Sans Thai", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
}

.sidebar {
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  background: rgba(255, 252, 245, 0.96);
  border-right: 1px solid var(--line);
  color: var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 8px;
  background: #172238;
  color: white;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

.brand-logo {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
}

.brand p {
  margin: 3px 0 0;
  color: #d6dfed;
  font-size: 12px;
}

.search-box {
  display: grid;
  gap: 6px;
  color: #46505f;
  font-size: 12px;
  font-weight: 800;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

.search-box input:focus {
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(104, 118, 56, 0.16);
}

.search-box input::placeholder {
  color: #9aa3b2;
}

.mobile-unit-select {
  display: none;
}

.mobile-unit-select span {
  color: #46505f;
  font-size: 12px;
  font-weight: 800;
}

.mobile-unit-select select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 10px 38px 10px 12px;
  outline: none;
}

.mobile-unit-select select:focus {
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(104, 118, 56, 0.16);
}

.progress-panel {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.progress-panel strong {
  color: var(--olive-dark);
  font-size: 24px;
}

.progress-panel span {
  color: var(--muted);
}

.progress-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #ece6d8;
}

.progress-bar span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--olive), var(--gold));
  transition: width 180ms ease;
}

.unit-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  gap: 7px;
  padding-right: 3px;
}

.unit-btn {
  width: 100%;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.unit-btn:hover {
  background: #f3efdf;
}

.unit-btn.is-active {
  border-color: #d8c99f;
  background: white;
  box-shadow: var(--shadow-sm);
}

.unit-btn .num {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #edf1e2;
  color: var(--olive-dark);
  font-size: 12px;
  font-weight: 900;
}

.unit-btn .title {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.unit-btn .title strong,
.unit-btn .title small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-btn .title strong {
  font-size: 14px;
}

.unit-btn .title small {
  color: var(--muted);
  font-size: 11px;
}

.unit-btn .done {
  color: var(--olive);
  font-weight: 900;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin: -22px -22px 20px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 241, 232, 0.92);
  backdrop-filter: blur(10px);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow-sm);
}

.home-link {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--olive-dark);
  font-weight: 900;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  white-space: nowrap;
}

.tab,
.icon-btn,
.primary-btn,
.secondary-btn,
.token,
.choice-btn {
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.tab {
  min-width: 124px;
  padding: 10px 13px;
  background: transparent;
  color: #556070;
  font-weight: 800;
}

.tab.is-active {
  background: var(--olive);
  color: white;
}

.toolbar {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  background: white;
  color: var(--olive-dark);
  border: 1px solid var(--line);
  font-size: 24px;
  box-shadow: var(--shadow-sm);
}

.view {
  display: none;
  max-width: 1180px;
  margin: 0 auto;
}

.view.is-active {
  display: block;
}

.practice-hero,
.drag-head,
.vocab-head,
.practice-card,
.drag-card,
.vocab-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.practice-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: stretch;
  margin-bottom: 16px;
  padding: 18px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(255, 250, 240, 0.92)),
    white;
}

.banner-image {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #e4dcc9;
  order: -1;
}

.drag-head,
.vocab-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
  padding: 18px;
}

.practice-character {
  width: 118px;
  height: 118px;
  object-fit: cover;
  object-position: center 24%;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--olive-dark);
  font-size: 12px;
  font-weight: 900;
}

h2 {
  margin: 0;
  font-size: 31px;
  line-height: 1.15;
}

h3 {
  margin: 0 0 10px;
  font-size: 15px;
  color: #354222;
}

.chinese-title {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.lesson-lead {
  max-width: 760px;
  margin: 10px 0 0;
  color: #536070;
  line-height: 1.55;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.chip {
  border: 1px solid #d6dfbd;
  border-radius: 999px;
  background: #fbfff1;
  color: var(--olive-dark);
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 900;
}

.practice-list,
.drag-list,
.vocab-list {
  display: grid;
  gap: 14px;
}

.practice-card,
.drag-card {
  padding: 16px;
}

.practice-card h3,
.drag-card h3 {
  padding-bottom: 9px;
  border-bottom: 1px solid var(--soft-line);
}

.question-group {
  display: grid;
  gap: 11px;
}

.question-row,
.choice-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.78fr) 76px;
  gap: 10px;
  align-items: center;
}

.question-row label,
.choice-row label {
  line-height: 1.35;
}

.question-row input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px;
  background: #fff;
}

.question-row input:focus {
  outline: none;
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(104, 118, 56, 0.16);
}

.choice-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-quiz {
  display: grid;
  gap: 16px;
  min-height: 430px;
  align-content: start;
}

.choice-quiz-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--soft-line);
}

.choice-count {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.choice-question {
  padding: 18px;
  border-radius: 8px;
  background: var(--cream);
  border: 1px solid #eadfca;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.45;
}

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

.choice-options-stacked .choice-btn {
  min-height: 56px;
  justify-content: flex-start;
  text-align: left;
  padding: 14px 16px;
  font-size: 18px;
}

.input-quiz input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px 14px;
  background: #fff;
  font-size: 18px;
}

.input-quiz input:focus {
  outline: none;
  border-color: var(--olive);
  box-shadow: 0 0 0 3px rgba(104, 118, 56, 0.16);
}

.input-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.hint-text,
.feedback-text {
  display: none;
  margin: 0;
  border-radius: 7px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
}

.hint-text.is-visible,
.feedback-text.is-visible {
  display: block;
}

.hint-text {
  border: 1px solid #d8c99f;
  background: #fffaf0;
  color: #6f4d0b;
}

.feedback-text.ok {
  border: 1px solid #bddfc5;
  background: #e8f5e9;
  color: #1f7a38;
}

.feedback-text.no {
  border: 1px solid #f0c4c0;
  background: #fff1f0;
  color: var(--red);
}

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

.choice-pager button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.choice-btn {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid #d4c8aa;
  background: white;
  color: var(--ink);
  font-weight: 800;
}

.choice-btn:hover {
  background: #fffaf0;
}

.choice-btn.is-selected {
  background: var(--olive-soft);
  border-color: var(--olive);
  color: var(--olive-dark);
  box-shadow: inset 0 0 0 2px rgba(104, 118, 56, 0.2);
}

.result,
.drag-result {
  min-height: 30px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 900;
}

.result.ok,
.drag-result.ok {
  background: #e8f5e9;
  color: #1f7a38;
  padding: 4px 10px;
}

.result.no,
.drag-result.no {
  background: #fff1f0;
  color: var(--red);
  padding: 4px 10px;
}

.answer {
  display: none;
  grid-column: 2 / -1;
  color: #8b6418;
  font-size: 13px;
}

.answer.is-visible {
  display: block;
}

.practice-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px -4px -4px;
  padding: 10px 4px 4px;
  background: linear-gradient(180deg, rgba(245, 241, 232, 0), rgba(245, 241, 232, 0.96) 28%);
}

.primary-btn {
  background: var(--olive);
  color: white;
  padding: 11px 16px;
  font-weight: 900;
}

.secondary-btn {
  background: white;
  color: var(--olive-dark);
  border: 1px solid var(--line);
  padding: 10px 14px;
  font-weight: 900;
}

.vocab-list {
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.vocab-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 12px;
  align-items: center;
  padding: 14px;
}

.vocab-word {
  grid-row: span 2;
  min-width: 58px;
  min-height: 58px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--olive-soft);
  color: var(--olive-dark);
  border: 1px solid #d6dfbd;
  font-size: 28px;
  font-weight: 900;
  padding: 0;
  position: relative;
}

.vocab-pinyin {
  color: var(--blue);
  font-weight: 900;
}

.vocab-tone {
  color: var(--muted);
  font-size: 12px;
}

.vocab-thai {
  grid-column: 2;
  color: #3f4757;
  line-height: 1.4;
}

.drag-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.drag-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.drop-zone,
.token-bank {
  min-height: 58px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
}

.drop-zone {
  margin-bottom: 10px;
  border: 2px dashed #c8b98f;
  background: #fffdf7;
}

.drop-zone:empty::before {
  content: "วางคำตอบที่นี่";
  color: #a29370;
  font-weight: 800;
}

.token-bank {
  border: 1px solid #e1d7bf;
  background: var(--paper);
}

.drop-zone.is-over,
.token-bank.is-over {
  outline: 3px solid rgba(104, 118, 56, 0.22);
}

.token {
  min-width: 42px;
  min-height: 40px;
  padding: 8px 12px;
  background: white;
  border: 1px solid #cfc3a7;
  color: #172033;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 4px 10px rgba(46, 38, 18, 0.08);
  touch-action: manipulation;
}

.token.is-dragging {
  opacity: 0.55;
}

.drag-answer {
  margin: 10px 0 0;
}

/* Score page */
#practiceView.is-score .practice-hero,
#practiceView.is-score .practice-actions {
  display: none;
}

.score-card {
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
}

.score-header h3 {
  font-size: 22px;
  margin: 0 0 6px;
  padding-bottom: 0;
  border-bottom: none;
  font-weight: 900;
}

.score-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.score-circle-wrap {
  padding: 4px 0;
}

.score-percent-box {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 6px solid;
}

.score-percent-box.score-great {
  background: #e8f5e9;
  border-color: #1f7a38;
}

.score-percent-box.score-good {
  background: var(--olive-soft);
  border-color: var(--olive);
}

.score-percent-box.score-ok {
  background: #fff8e1;
  border-color: var(--gold);
}

.score-percent-box.score-poor {
  background: #fff1f0;
  border-color: var(--red);
}

.score-pct {
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
  color: var(--ink);
}

.score-pct-label {
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
  margin-top: 3px;
}

.score-stats {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.score-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 84px;
  padding: 14px 18px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: white;
}

.score-num {
  font-size: 30px;
  font-weight: 900;
}

.score-stat.correct .score-num { color: #1f7a38; }
.score-stat.skipped .score-num { color: var(--gold); }
.score-stat.missed .score-num { color: var(--muted); }

.score-lbl {
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
}

.score-footer {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

@media (min-width: 1200px) {
  .choice-quiz {
    min-height: 470px;
  }

  .app-shell {
    grid-template-columns: 360px minmax(0, 1fr);
  }

  .sidebar {
    padding: 20px;
    gap: 16px;
  }

  .brand {
    padding: 12px;
  }

  .brand-logo {
    width: 64px;
    height: 64px;
  }

  .workspace {
    padding: 24px 32px 28px;
  }

  .topbar {
    margin: -24px -32px 22px;
    padding: 14px 32px;
  }

  .view {
    max-width: 1320px;
  }

  .practice-hero {
    padding: 20px;
  }

  .practice-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .practice-card {
    min-height: 100%;
  }

  .practice-card.is-wide {
    grid-column: span 2;
  }

  .question-row,
  .choice-row {
    grid-template-columns: minmax(0, 1fr) minmax(260px, 0.82fr) 74px;
  }

  .vocab-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .drag-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .drag-head,
  .vocab-head {
    grid-template-columns: minmax(0, 1fr) 144px;
  }

  .practice-character {
    width: 144px;
    height: 144px;
  }
}

@media (max-width: 940px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .mobile-unit-select {
    display: grid;
    gap: 6px;
  }

  .unit-list {
    display: none;
  }

  .workspace {
    padding: 16px;
  }

  .topbar {
    margin: -16px -16px 16px;
    padding: 10px 16px;
    align-items: stretch;
  }

  .tabs {
    min-width: 0;
    flex: 1;
  }

  .home-link {
    min-height: 38px;
    padding: 0 10px;
    font-size: 13px;
  }

  .tab {
    min-width: 0;
    flex: 1;
    padding: 9px 6px;
    font-size: 14px;
  }

  .practice-hero,
  .drag-head,
  .vocab-head,
  .question-row,
  .choice-row {
    grid-template-columns: 1fr;
  }

  .banner-image {
    max-height: none;
  }

  .practice-character {
    display: none;
  }

  .answer {
    grid-column: auto;
  }

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

  .choice-question {
    font-size: 18px;
    padding: 14px;
  }

  .choice-quiz {
    min-height: 360px;
  }

  .practice-actions {
    position: static;
    margin: 16px 0 0;
    padding: 0;
    background: transparent;
  }

  h2 {
    font-size: 24px;
  }
}
