:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-strong: #eef4f3;
  --ink: #17212b;
  --muted: #5a6673;
  --soft: #8a96a3;
  --line: #dce3e8;
  --teal: #167f7a;
  --teal-dark: #0f5f5b;
  --coral: #e5534b;
  --amber: #f2b33d;
  --blue: #4b7bec;
  --green: #2f9a68;
  --shadow: 0 18px 42px rgba(23, 33, 43, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", Arial, sans-serif;
  letter-spacing: 0;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.sprite {
  display: none;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  min-width: 0;
  padding: 24px 18px;
  background: #ffffff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 26px;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: #ffffff;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

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

.nav-item {
  min-height: 42px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  font-size: 14px;
  font-weight: 700;
  text-align: left;
}

.nav-item svg,
.primary-link svg,
.primary-action svg,
.secondary-action svg,
.ghost-action svg,
.icon-button svg,
.drop-zone svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.nav-item.active,
.nav-item:hover {
  background: var(--surface-strong);
  color: var(--teal-dark);
}

.goal-control {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #fbfcfd;
}

.mini-label,
.section-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.goal-number {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 8px 0 10px;
}

.goal-number span {
  font-size: 34px;
  line-height: 1;
  font-weight: 800;
}

.goal-number small {
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

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

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

.topbar h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.16;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions,
.import-actions,
.review-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cloud-pill {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 800;
}

.cloud-pill svg,
.sheet-source svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cloud-pill.synced {
  color: var(--teal-dark);
  border-color: rgba(22, 127, 122, 0.28);
  background: #edf8f7;
}

.cloud-pill.partial {
  color: #8a5b00;
  border-color: rgba(242, 179, 61, 0.42);
  background: #fff8e6;
}

.cloud-pill.offline {
  color: #a9312b;
  border-color: rgba(229, 83, 75, 0.3);
  background: #fff1f0;
}

.primary-link,
.primary-action,
.secondary-action,
.ghost-action,
.icon-button,
.grade-button {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.primary-link,
.primary-action {
  background: var(--teal);
  color: #ffffff;
  border-color: var(--teal);
}

.secondary-action {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
}

.ghost-action,
.icon-button,
.grade-button {
  background: #ffffff;
  color: var(--ink);
}

.icon-button {
  width: 42px;
  padding: 0;
}

.primary-link:hover,
.primary-action:hover,
.secondary-action:hover,
.ghost-action:hover,
.icon-button:hover,
.grade-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.grade-button:disabled {
  color: var(--soft);
  background: #f4f6f8;
  cursor: not-allowed;
}

.grade-button.again:not(:disabled) {
  border-color: rgba(229, 83, 75, 0.36);
  color: #a9312b;
}

.grade-button.hard:not(:disabled) {
  border-color: rgba(75, 123, 236, 0.3);
  color: #2c55b6;
}

.grade-button.good:not(:disabled) {
  border-color: rgba(22, 127, 122, 0.35);
  color: var(--teal-dark);
}

.grade-button.easy:not(:disabled) {
  border-color: rgba(47, 154, 104, 0.35);
  color: #207246;
}

.today-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: stretch;
}

.review-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.review-card {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.review-head,
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.review-head h2,
.panel-title span {
  margin: 4px 0 0;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 800;
}

.panel-title span {
  margin: 0;
}

.panel-title strong {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.memory-widget {
  width: 112px;
  min-height: 56px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.memory-widget span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.memory-widget strong {
  font-size: 22px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  background: #eef2f5;
  border-radius: var(--radius);
}

.mode-tab {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mode-tab.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(23, 33, 43, 0.08);
}

.word-stage {
  min-height: 392px;
  border-radius: var(--radius);
  border: 1px solid #d8e5e2;
  background: linear-gradient(180deg, #f9fbfb 0%, #ffffff 72%);
  padding: 22px;
  display: grid;
  gap: 14px;
}

.word-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.word-meta span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.word-meta span:first-child {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--teal-dark);
  background: #ffffff;
}

.phonetic {
  margin: 0;
  color: var(--blue);
  font-size: 14px;
  font-weight: 800;
}

#wordTerm {
  margin: 0;
  font-size: 58px;
  line-height: 1.04;
  word-break: break-word;
}

.recall-box {
  display: grid;
  gap: 8px;
}

.recall-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--ink);
  background: #ffffff;
  line-height: 1.5;
  outline: none;
}

textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(22, 127, 122, 0.14);
}

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

.choice-grid button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  padding: 10px 12px;
  font-weight: 700;
}

.choice-grid button.selected {
  border-color: var(--teal);
  background: #edf8f7;
}

.answer-panel {
  display: grid;
  gap: 8px;
  border-left: 4px solid var(--teal);
  border-radius: var(--radius);
  background: #eef8f7;
  padding: 12px 14px;
}

.answer-panel span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.answer-panel strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
}

.answer-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.feedback-panel {
  min-height: 58px;
  border-radius: var(--radius);
  padding: 10px 12px;
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  background: #fbfcfd;
}

.feedback-panel strong {
  font-size: 14px;
}

.feedback-panel span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.feedback-panel.success {
  border-color: rgba(47, 154, 104, 0.28);
  background: #effaf4;
}

.feedback-panel.warning {
  border-color: rgba(242, 179, 61, 0.38);
  background: #fff8e6;
}

.feedback-panel.danger {
  border-color: rgba(229, 83, 75, 0.32);
  background: #fff1f0;
}

.progress-rail {
  display: grid;
  gap: 18px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel.compact {
  box-shadow: none;
}

.progress-track {
  height: 9px;
  background: #e9eef1;
  border-radius: 999px;
  overflow: hidden;
  margin: 14px 0;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 200ms ease;
}

.progress-track.amber span {
  background: var(--amber);
}

.quest-list {
  display: grid;
  gap: 8px;
}

.quest-item,
.leader-row,
.timeline-item,
.upcoming-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.quest-item {
  padding: 9px 0;
  border-top: 1px solid #edf1f4;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.quest-item strong {
  color: var(--ink);
  white-space: nowrap;
}

.badge-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.badge {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  gap: 3px;
  color: var(--soft);
  background: #fbfcfd;
}

.badge strong {
  font-size: 16px;
}

.badge span {
  font-size: 10px;
  font-weight: 800;
}

.badge.earned {
  color: #8a5b00;
  border-color: rgba(242, 179, 61, 0.45);
  background: #fff9e8;
}

.leaderboard {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.leader-row span {
  width: 52px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.leader-bar {
  flex: 1;
  height: 8px;
  background: #e9eef1;
  border-radius: 999px;
  overflow: hidden;
}

.leader-bar i {
  display: block;
  height: 100%;
  width: 20%;
  border-radius: inherit;
  background: var(--blue);
}

.leader-row strong {
  width: 42px;
  text-align: right;
  font-size: 12px;
}

.insight-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1.1fr) minmax(260px, 0.9fr) minmax(300px, 1fr);
  gap: 18px;
  margin-top: 18px;
}

.history-panel {
  grid-row: span 2;
}

.drop-zone {
  position: relative;
  min-height: 76px;
  border: 1px dashed #b8c8cd;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin: 14px 0 12px;
  background: #fbfcfd;
  color: var(--teal-dark);
}

.sheet-source {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid #d8e5e2;
  border-radius: var(--radius);
  background: #f8fbfb;
  padding: 12px;
  margin-top: 14px;
}

.sheet-source span,
.sheet-source strong {
  display: block;
}

.sheet-source span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.sheet-source strong {
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.35;
}

.drop-zone.dragging {
  border-color: var(--teal);
  background: #eef8f7;
}

.drop-zone svg {
  width: 28px;
  height: 28px;
}

.drop-zone strong,
.drop-zone span {
  display: block;
}

.drop-zone span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.status-line {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

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

.engine-list label {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
}

.engine-list input {
  accent-color: var(--teal);
}

.schedule-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.schedule-card div {
  min-height: 72px;
  border-radius: var(--radius);
  background: #f5f8fa;
  padding: 10px;
}

.schedule-card span,
.schedule-card strong {
  display: block;
}

.schedule-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.schedule-card strong {
  margin-top: 8px;
  font-size: 24px;
}

.history-chart {
  height: 160px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: end;
  gap: 8px;
  margin: 18px 0;
  padding-top: 14px;
  border-bottom: 1px solid var(--line);
}

.chart-day {
  display: grid;
  gap: 6px;
  justify-items: center;
  align-items: end;
  height: 100%;
}

.chart-bar {
  width: 100%;
  min-height: 8px;
  border-radius: 6px 6px 0 0;
  background: var(--teal);
}

.chart-day small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  padding-bottom: 6px;
}

.timeline {
  display: grid;
  gap: 10px;
  max-height: 268px;
  overflow: auto;
  padding-right: 4px;
}

.timeline-item {
  border-top: 1px solid #edf1f4;
  padding-top: 10px;
}

.timeline-item div {
  min-width: 0;
}

.timeline-item strong,
.upcoming-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.timeline-item span,
.upcoming-item span {
  color: var(--muted);
  font-size: 12px;
}

.timeline-item i {
  font-style: normal;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.mastery-map {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.mastery-row {
  display: grid;
  grid-template-columns: minmax(80px, 1fr) 82px;
  gap: 10px;
  align-items: center;
}

.mastery-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.mini-meter {
  height: 8px;
  background: #e9eef1;
  border-radius: 999px;
  overflow: hidden;
}

.mini-meter span {
  display: block;
  height: 100%;
  background: var(--teal);
  border-radius: inherit;
}

.upcoming-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.upcoming-item {
  min-height: 52px;
  border-top: 1px solid #edf1f4;
  padding-top: 10px;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 16px 0 0;
}

@media (max-width: 1120px) {
  .today-grid,
  .insight-grid {
    grid-template-columns: 1fr;
  }

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

  .history-panel {
    grid-row: auto;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    padding: 14px;
  }

  .nav-list {
    display: flex;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .nav-item {
    flex: 0 0 auto;
  }

  .goal-control {
    margin-top: 0;
  }

  .workspace {
    padding: 18px;
  }

  .progress-rail {
    grid-template-columns: 1fr;
  }

  #wordTerm {
    font-size: 44px;
  }
}

@media (max-width: 620px) {
  .topbar,
  .review-head,
  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .review-actions,
  .import-actions {
    width: 100%;
  }

  .cloud-pill,
  .sheet-source {
    width: 100%;
  }

  .sheet-source {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-link,
  .primary-action,
  .secondary-action,
  .ghost-action,
  .grade-button {
    flex: 1 1 100%;
  }

  .choice-grid,
  .engine-list,
  .schedule-card {
    grid-template-columns: 1fr;
  }

  .memory-widget {
    width: 100%;
    justify-items: start;
    padding: 10px;
  }

  #wordTerm {
    font-size: 34px;
  }
}
