:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #65707d;
  --line: #d7dde3;
  --panel: #ffffff;
  --surface: #f5f7fa;
  --accent: #28666e;
  --accent-strong: #17474e;
  --ok: #1f7a4d;
  --bad: #b83b3b;
  --warn: #9a6b16;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--surface);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  line-height: 1.55;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

[hidden] {
  display: none !important;
}

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

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 6vw, 3.75rem);
  line-height: 1;
}

.progress-box {
  min-width: 180px;
  color: var(--muted);
  font-weight: 700;
  text-align: right;
}

.progress-track {
  width: 100%;
  height: 8px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce4e8;
}

#progressFill {
  width: 0;
  height: 100%;
  background: var(--accent);
}

.start-view {
  display: block;
}

.setup-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.setup-section {
  display: grid;
  gap: 12px;
}

.setup-section h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading button {
  min-height: 34px;
  padding: 0 12px;
  color: var(--accent-strong);
  font-weight: 700;
}

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

.segmented-control button,
.filter-grid button,
.topic-grid button,
.type-filter-grid button,
.difficulty-filter-grid button {
  min-height: 44px;
  padding: 0 12px;
  text-align: left;
}

.segmented-control button.active,
.filter-grid button.active,
.topic-grid button.active,
.type-filter-grid button.active,
.difficulty-filter-grid button.active {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

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

.filter-grid button {
  text-align: center;
}

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

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

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

.type-filter-grid button,
.difficulty-filter-grid button {
  text-align: center;
}

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

.review-grid article {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 8px 12px;
  align-items: center;
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.review-grid strong {
  display: block;
  font-size: 1.45rem;
}

.review-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

.review-grid button {
  grid-column: 2;
  grid-row: 1 / span 2;
  min-height: 38px;
  color: var(--accent-strong);
  font-weight: 700;
}

.start-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 180px;
  gap: 16px;
  align-items: center;
  padding-top: 4px;
}

.start-actions p {
  margin-bottom: 0;
  color: var(--muted);
  font-weight: 700;
}

.primary-action {
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 800;
  background: var(--accent);
}

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

.sidebar,
.quiz-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.sidebar {
  position: sticky;
  top: 16px;
  padding: 14px;
}

.tool-button {
  width: 100%;
  margin-bottom: 8px;
  text-align: left;
  padding: 0 14px;
}

.tool-button.active {
  border-color: var(--accent);
  color: #ffffff;
  background: var(--accent);
}

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

.stat-grid div {
  min-height: 66px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

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

.stat-grid strong {
  font-size: 1.35rem;
}

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

.question-list {
  display: grid;
  gap: 6px;
  max-height: 420px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.question-list-toggle {
  display: none;
}

.question-list button {
  width: 100%;
  min-height: 38px;
  padding: 0 10px;
  text-align: left;
}

.question-list button.active {
  border-color: var(--accent);
  background: #edf6f7;
}

.question-list .is-correct {
  border-left: 4px solid var(--ok);
}

.question-list .is-wrong {
  border-left: 4px solid var(--bad);
}

.quiz-panel {
  min-height: 680px;
  padding: 28px;
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.question-meta span {
  min-height: 28px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.85rem;
  background: #fbfcfd;
}

h2 {
  margin-bottom: 16px;
  font-size: 1.45rem;
  line-height: 1.35;
}

.question-text {
  white-space: pre-line;
  font-size: 1.05rem;
}

.source-record {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.type-helper {
  display: grid;
  gap: 12px;
  margin: 18px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.type-helper h3 {
  margin-bottom: 0;
  font-size: 0.95rem;
}

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

.statement-grid section,
.mapping-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.statement-grid strong,
.mapping-grid strong {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-strong);
}

.statement-grid p {
  margin-bottom: 0;
}

.statement-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 24px;
}

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

.image-asset-grid {
  display: grid;
  gap: 12px;
}

.image-asset-grid figure {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.image-asset-grid img {
  display: block;
  width: 100%;
  max-height: 560px;
  object-fit: contain;
}

.image-asset-grid figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.options-form {
  display: grid;
  gap: 10px;
  margin: 22px 0;
}

.option-row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.option-row:hover {
  border-color: var(--accent);
}

.option-row input {
  margin-top: 4px;
}

.option-row.selected {
  border-color: var(--accent);
  background: #edf6f7;
}

.option-row.correct {
  border-color: var(--ok);
  background: #eef8f2;
}

.option-row.wrong {
  border-color: var(--bad);
  background: #fff1f1;
}

.option-label {
  font-weight: 700;
}

.answer-result {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 700;
}

.answer-result.correct {
  color: var(--ok);
  background: #eef8f2;
}

.answer-result.wrong {
  color: var(--bad);
  background: #fff1f1;
}

.session-summary {
  display: grid;
  gap: 12px;
  margin: 18px 0;
  padding: 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #edf6f7;
}

.session-summary h3 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

.session-summary button {
  justify-self: start;
  padding: 0 14px;
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
  font-weight: 800;
}

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

.summary-grid div {
  min-height: 70px;
  padding: 10px;
  border: 1px solid #c8dce0;
  border-radius: 8px;
  background: #ffffff;
}

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

.summary-grid strong {
  font-size: 1.35rem;
}

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

.explanation-panel {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.explanation-panel h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.reference-text {
  color: var(--muted);
  font-size: 0.95rem;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 24px;
}

.actions button {
  color: var(--accent-strong);
  font-weight: 700;
}

.actions #bookmarkButton.bookmarked {
  border-color: var(--warn);
  color: #ffffff;
  background: var(--warn);
}

.empty-state {
  padding: 14px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .topbar {
    display: block;
  }

  .progress-box {
    margin-top: 16px;
    text-align: left;
  }

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

  .quiz-panel {
    order: 1;
  }

  .sidebar {
    order: 2;
  }

  .setup-panel {
    padding: 16px;
  }

  .segmented-control,
  .filter-grid,
  .topic-grid,
  .type-filter-grid,
  .difficulty-filter-grid,
  .review-grid,
  .summary-grid,
  .start-actions {
    grid-template-columns: 1fr;
  }

  .review-grid article {
    grid-template-columns: 1fr;
  }

  .review-grid button {
    grid-column: auto;
    grid-row: auto;
  }

  .sidebar {
    position: static;
  }

  .question-list-toggle {
    display: block;
    width: 100%;
    margin: 12px 0 8px;
    color: var(--accent-strong);
    font-weight: 700;
    text-align: left;
    padding: 0 14px;
  }

  .question-list {
    max-height: 240px;
  }

  .question-list-collapsed .question-list {
    max-height: 0;
    overflow: hidden;
  }

  .quiz-panel {
    min-height: 0;
    padding: 20px 20px 112px;
  }

  .actions {
    position: fixed;
    right: 10px;
    bottom: 10px;
    left: 10px;
    z-index: 20;
    grid-template-columns: repeat(2, 1fr);
    margin: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 12px 32px rgba(32, 33, 36, 0.18);
  }

  .statement-grid,
  .mapping-grid {
    grid-template-columns: 1fr;
  }
}
