:root {
  color-scheme: light;
  --bg: #eef3f4;
  --panel: #ffffff;
  --panel-strong: #f7faf9;
  --text: #102126;
  --muted: #66777b;
  --border: #d9e2e1;
  --accent: #0f6f68;
  --accent-dark: #0b4f4b;
  --amber: #b7791f;
  --green: #147d4f;
  --red: #b42318;
  --shadow: 0 20px 45px rgba(16, 33, 38, 0.1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: linear-gradient(135deg, #eef3f4 0%, #f9fbfa 55%, #e9f1ef 100%);
}

.developer-credit {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 20;
  padding: 7px 12px;
  color: var(--accent-dark);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 18px rgba(16, 33, 38, 0.08);
  font-size: 14px;
  font-weight: 800;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 370px) minmax(0, 1fr);
  gap: 20px;
  width: min(1380px, calc(100vw - 32px));
  min-height: calc(100vh - 64px);
  margin: 48px auto 16px;
}

.setup-panel,
.quiz-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.setup-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-radius: 8px;
}

.quiz-panel {
  min-height: calc(100vh - 32px);
  padding: 28px;
  border-radius: 8px;
}

.brand {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 14px;
  align-items: start;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border-radius: 8px;
  font-size: 24px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 23px;
  line-height: 1.2;
}

.brand p,
.empty-state p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.setup-form {
  display: grid;
  gap: 14px;
}

.control-group,
.exam-list-wrap {
  display: grid;
  gap: 10px;
  padding: 14px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

.control-heading span,
.stat-label,
.quiz-header p,
.progress-row,
.score-block span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.control-heading strong {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
}

.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.year-button,
.segment-button,
.custom-count-field {
  min-height: 48px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.segment-button {
  cursor: pointer;
}

.year-button {
  display: grid;
  gap: 2px;
  padding: 10px;
  text-align: left;
}

.year-button span,
.segment-button {
  font-size: 16px;
  font-weight: 700;
}

.year-button strong {
  color: var(--muted);
  font-size: 12px;
}

.year-button.selected,
.segment-button.selected {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.custom-count-field.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(16, 121, 106, 0.14);
}

.year-button.selected strong {
  color: rgba(255, 255, 255, 0.84);
}

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

.segment-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.custom-count-field {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.custom-count-field span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.custom-count-field input {
  width: 100%;
  min-width: 0;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  text-align: right;
  background: transparent;
  border: 0;
  outline: 0;
}

.custom-count-field input::placeholder {
  color: var(--muted);
  font-weight: 700;
}

.exam-list {
  display: grid;
  gap: 8px;
  max-height: 148px;
  overflow: auto;
}

.exam-row {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.exam-row.muted {
  opacity: 0.45;
}

.exam-row strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.exam-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.actions,
.quiz-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  min-height: 42px;
  padding: 0 16px;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.button:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button.secondary {
  color: var(--text);
  background: #fff;
  border-color: var(--border);
}

.button.secondary:hover:not(:disabled) {
  color: var(--accent-dark);
  background: #f4f8f7;
  border-color: #a9bfbc;
}

.button.submit {
  margin-left: auto;
  background: #12323a;
  border-color: #12323a;
}

.button.start {
  min-width: 120px;
}

.status-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.status-panel > div {
  padding: 14px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.status-panel strong {
  display: block;
  margin-top: 4px;
  font-size: 28px;
}

.warnings {
  padding: 12px 14px;
  color: #624000;
  background: #fff8e6;
  border: 1px solid #f2d18b;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.quiz-header h2 {
  margin-top: 5px;
  font-size: 28px;
  line-height: 1.25;
}

.empty-state {
  display: grid;
  max-width: 520px;
  min-height: 460px;
  place-content: center;
  margin: auto;
  text-align: center;
}

.empty-icon {
  display: grid;
  width: 88px;
  height: 112px;
  place-items: center;
  margin: 0 auto 18px;
  color: var(--accent);
  background: #e4f1ef;
  border: 1px solid #bcd8d3;
  border-radius: 8px;
  font-size: 22px;
  font-weight: 900;
}

.question-view {
  padding-top: 24px;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.progress-track {
  height: 8px;
  margin: 10px 0 26px;
  overflow: hidden;
  background: #e1e9e8;
  border-radius: 99px;
}

#progressBar {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.question-stem {
  max-width: 920px;
  min-height: 118px;
  font-size: 22px;
  font-weight: 750;
  line-height: 1.6;
  white-space: pre-wrap;
}

.question-media {
  display: grid;
  gap: 14px;
  max-width: 920px;
  margin: 18px 0 26px;
  padding: 14px;
  background: #f7faf9;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.media-heading {
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 900;
}

.question-media figure {
  margin: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.question-media img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 560px;
  margin: 0 auto;
  object-fit: contain;
  object-position: top center;
  background: #fff;
}

.question-media figcaption {
  padding: 8px 10px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 800;
}

.choice-list {
  display: grid;
  gap: 12px;
  max-width: 920px;
  margin: 26px 0;
}

.choice {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 14px;
  align-items: start;
  width: 100%;
  padding: 16px;
  color: var(--text);
  text-align: left;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.choice:hover {
  border-color: #8fb2ad;
}

.choice.selected {
  background: #e9f5f3;
  border-color: var(--accent);
}

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

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

.choice-label {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  color: var(--accent);
  background: #edf6f4;
  border-radius: 8px;
  font-weight: 900;
}

.choice-text {
  font-size: 17px;
  line-height: 1.55;
}

.result-view {
  display: grid;
  gap: 22px;
  padding-top: 24px;
}

.score-block {
  display: grid;
  gap: 4px;
  padding: 22px;
  background: #f6faf9;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.score-block strong {
  font-size: 58px;
  line-height: 1;
}

.score-block p {
  color: var(--muted);
  font-weight: 700;
}

.review-list {
  display: grid;
  gap: 12px;
}

.review-item {
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 5px solid var(--green);
  border-radius: 8px;
}

.review-item.missed {
  border-left-color: var(--red);
}

.review-summary {
  display: grid;
  gap: 8px;
  padding: 16px;
  cursor: pointer;
  list-style: none;
}

.review-summary::-webkit-details-marker {
  display: none;
}

.review-title {
  display: block;
  color: var(--text);
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 900;
}

.review-answer-line,
.review-preview {
  color: var(--muted);
  font-size: 15px;
  font-weight: 750;
  line-height: 1.5;
}

.review-cue::after {
  content: "查看原題";
  display: inline-block;
  width: fit-content;
  margin-top: 2px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 900;
}

.review-item[open] .review-cue::after {
  content: "收合";
}

.review-detail {
  display: grid;
  gap: 14px;
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
}

.review-stem {
  padding-top: 16px;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.65;
  white-space: pre-wrap;
}

.review-choice-list {
  display: grid;
  gap: 10px;
}

.review-choice {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: start;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

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

.review-choice.picked .choice-label {
  color: #fff;
  background: #12323a;
}

.review-media {
  margin: 0;
}

.review-media img {
  max-height: 520px;
}

.page-dialog {
  width: min(920px, 94vw);
  max-height: 92vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.page-dialog::backdrop {
  background: rgba(16, 33, 38, 0.55);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.page-dialog img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    width: min(100vw - 20px, 680px);
    margin: 48px auto 10px;
  }

  .quiz-panel {
    min-height: 620px;
  }

  .quiz-header {
    flex-direction: column;
  }

  .quiz-header h2 {
    font-size: 24px;
  }

  .question-stem {
    font-size: 19px;
  }

  .button.submit {
    margin-left: 0;
  }
}
