:root {
  --ink: #17202a;
  --muted: #5e6a75;
  --line: #d8e0e7;
  --paper: #fbfcfd;
  --panel: #ffffff;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #14815f;
  --red: #c2413a;
  --yellow: #b7791f;
  --shadow: 0 16px 40px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, "Noto Sans TC", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 24px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background: #f3c74f;
  color: #1f2937;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.eyebrow {
  margin: 0;
}

.brand h1 {
  font-size: 22px;
}

.brand p,
.eyebrow,
.quick-stats small,
.word-meta,
.translation,
.panel-heading span {
  color: var(--muted);
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 10px 12px;
}

.nav-tab.active,
.nav-tab:hover {
  background: #eaf1ff;
  border-color: #c7d8ff;
  color: var(--blue-dark);
}

.main {
  padding: 28px;
  min-width: 0;
  overflow-x: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 320px) minmax(360px, auto);
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}

.topbar h2 {
  font-size: 30px;
  margin-top: 4px;
}

.quick-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(82px, 1fr));
  gap: 10px;
}

.student-switcher {
  display: grid;
  gap: 6px;
}

.student-switcher label {
  color: var(--muted);
  font-size: 14px;
}

.student-switcher > div {
  display: flex;
  gap: 8px;
}

.student-switcher input {
  min-width: 0;
  flex: 1;
}

.quick-stats div,
.result-grid div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.quick-stats span,
.result-grid span {
  display: block;
  font-size: 24px;
  font-weight: 800;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar,
.quiz-setup,
.section-heading {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.search-box,
.field-group {
  display: grid;
  gap: 6px;
}

.search-box {
  min-width: min(360px, 100%);
}

.search-box span,
.field-group label,
.field-group span {
  color: var(--muted);
  font-size: 14px;
}

input,
select,
textarea {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: #ffffff;
  color: var(--ink);
}

textarea {
  width: 100%;
  resize: vertical;
  line-height: 1.5;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--blue);
  color: #ffffff;
}

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

.secondary-button,
.icon-button {
  background: #ffffff;
  border-color: var(--line);
  color: var(--ink);
}

.secondary-button:hover,
.icon-button:hover {
  border-color: #9bb2c8;
}

.learn-grid {
  display: grid;
  grid-template-columns: minmax(300px, 460px) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
}

.word-card,
.word-list-panel,
.question-card,
.result-panel,
.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.word-card {
  padding: 28px;
}

.word-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
}

.word-card h3 {
  margin: 18px 0 6px;
  font-size: 58px;
  line-height: 1;
}

.phonetic {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 22px;
  font-weight: 700;
}

.meaning {
  margin: 0 0 18px;
  font-size: 30px;
  font-weight: 800;
  color: var(--green);
}

.example {
  margin: 0 0 8px;
  font-size: 20px;
}

.translation {
  margin: 0 0 24px;
}

.card-actions,
.question-top {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.word-list-panel {
  overflow: hidden;
}

.panel-heading,
.section-heading {
  justify-content: space-between;
}

.panel-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h3,
.section-heading h3 {
  margin: 0;
}

.word-list,
.review-list,
.score-list,
.admin-list {
  display: grid;
  gap: 10px;
}

.word-list {
  max-height: 62vh;
  overflow: auto;
  padding: 12px;
}

.word-row,
.review-row,
.score-row,
.admin-row {
  display: grid;
  gap: 4px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.word-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.word-row button {
  min-height: 36px;
  padding: 7px 10px;
}

.word-row strong,
.review-row strong {
  font-size: 18px;
}

.tag-line {
  color: var(--muted);
  font-size: 14px;
}

.quiz-runner {
  display: grid;
  gap: 16px;
  max-width: 780px;
}

.quiz-progress {
  display: grid;
  gap: 8px;
}

.quiz-progress > div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

progress {
  width: 100%;
  height: 12px;
  accent-color: var(--blue);
}

.question-card,
.result-panel {
  padding: 24px;
}

.question-top {
  justify-content: space-between;
  align-items: center;
}

#question-kind {
  color: var(--muted);
  font-weight: 700;
}

#question-prompt {
  margin: 20px 0 10px;
  font-size: 44px;
}

#question-hint {
  min-height: 24px;
  margin: 0 0 18px;
  color: var(--muted);
}

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

.choice-option {
  min-height: 64px;
  background: #ffffff;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 800;
}

.choice-option:hover {
  border-color: var(--blue);
}

.choice-option.correct {
  border-color: var(--green);
  background: #ecfdf5;
}

.choice-option.wrong {
  border-color: var(--red);
  background: #fff1f2;
}

.spelling-form {
  display: flex;
  gap: 10px;
}

.spelling-form input {
  flex: 1;
}

.answer-feedback {
  min-height: 32px;
  margin-top: 14px;
  font-weight: 800;
}

.answer-feedback.good {
  color: var(--green);
}

.answer-feedback.bad {
  color: var(--red);
}

.review-list,
.score-list,
.admin-list {
  max-width: 900px;
}

.review-row,
.score-row,
.admin-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.review-actions {
  display: flex;
  gap: 8px;
}

.score-row strong {
  font-size: 24px;
}

.score-row meter {
  width: 200px;
}

.manager-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(320px, 1fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.form-panel {
  padding: 18px;
}

.form-panel h3 {
  margin: 0 0 14px;
}

.word-form,
.csv-form {
  display: grid;
  gap: 12px;
}

.word-form label,
.csv-form label {
  display: grid;
  gap: 6px;
}

.word-form label span,
.csv-form label span,
.helper-text {
  color: var(--muted);
  font-size: 14px;
}

.helper-text {
  margin: 0;
}

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

.form-message {
  min-height: 22px;
  margin: 0;
  color: var(--green);
  font-weight: 700;
}

.manage-list-panel {
  max-width: 900px;
}

.admin-list {
  padding: 12px;
}

.result-panel {
  max-width: 560px;
}

.result-panel h3 {
  margin-top: 0;
}

#result-score {
  margin: 0 0 14px;
  font-size: 48px;
  font-weight: 800;
  color: var(--blue-dark);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.empty-state {
  background: #ffffff;
  border: 1px dashed #9bb2c8;
  border-radius: 8px;
  padding: 22px;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

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

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

  .nav-tabs {
    grid-template-columns: repeat(5, minmax(100px, 1fr));
    overflow-x: auto;
  }

  .topbar,
  .learn-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }
}

@media (max-width: 620px) {
  .main,
  .sidebar {
    padding: 18px;
  }

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

  .word-card h3,
  #question-prompt {
    font-size: 38px;
  }

  .meaning {
    font-size: 24px;
  }

  .choice-options,
  .result-grid,
  .review-row,
  .score-row,
  .admin-row,
  .manager-grid {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .quiz-setup,
  .section-heading,
  .spelling-form {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .field-group,
  .search-box,
  .student-switcher,
  .toolbar > button,
  .quiz-setup > button,
  .section-heading > button {
    width: 100%;
  }

  .student-switcher > div {
    display: grid;
    grid-template-columns: 1fr;
  }

  input,
  select,
  textarea,
  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .question-card,
  .word-card,
  .result-panel {
    padding: 18px;
  }
}
