:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-muted: #edf2ef;
  --text: #18211d;
  --muted: #657069;
  --line: #d8e0dc;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d9f0ed;
  --danger: #b42318;
  --danger-soft: #fbe4e2;
  --ok: #177245;
  --ok-soft: #dcf4e6;
  --warn: #945b00;
  --shadow: 0 14px 38px rgba(22, 35, 30, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.08), transparent 34%),
    linear-gradient(180deg, #ffffff, var(--bg) 24rem);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans TC", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  min-height: 2.5rem;
  border-radius: 8px;
  padding: 0.55rem 0.8rem;
  cursor: pointer;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.25);
  outline-offset: 2px;
}

.app-shell {
  width: min(1320px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0 2rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0 1rem;
}

.eyebrow {
  margin: 0 0 0.1rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.75rem;
  line-height: 1.15;
}

.top-actions,
.nav-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.72);
}

.danger {
  color: var(--danger);
}

.layout {
  display: grid;
  grid-template-columns: 21rem minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 1rem;
  display: grid;
  gap: 0.8rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding-right: 0.15rem;
}

.panel,
.question-card {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 0.9rem;
}

.panel h2 {
  margin: 0 0 0.7rem;
  font-size: 0.95rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.stats-grid div {
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem;
}

.stats-grid span {
  display: block;
  font-size: 1.25rem;
  font-weight: 800;
}

.stats-grid small {
  color: var(--muted);
}

.controls {
  display: grid;
  gap: 0.7rem;
}

label {
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.85rem;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  min-height: 2.45rem;
  padding: 0.48rem 0.65rem;
}

.question-list {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
}

.question-list button {
  min-height: 2rem;
  padding: 0.2rem;
  font-size: 0.78rem;
  border-radius: 6px;
}

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

.question-list .correct {
  background: var(--ok-soft);
  border-color: rgba(23, 114, 69, 0.35);
}

.question-list .wrong {
  background: var(--danger-soft);
  border-color: rgba(180, 35, 24, 0.35);
}

.question-list .correct,
.question-list .wrong {
  color: var(--text);
}

.question-list .marked::after {
  content: "";
  display: inline-block;
  width: 0.38rem;
  height: 0.38rem;
  margin-left: 0.2rem;
  border-radius: 50%;
  background: var(--warn);
  vertical-align: middle;
}

.practice-area {
  min-width: 0;
}

.question-card {
  padding: 1.2rem;
  min-height: calc(100vh - 5.5rem);
}

.question-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.85rem;
  margin-bottom: 1rem;
}

.question-meta {
  margin: 0 0 0.25rem;
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 800;
}

.question-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  gap: 0.5rem;
}

#translateBtn {
  min-width: 6rem;
}

#translateBtn[aria-expanded="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.question-translation {
  border-left: 3px solid var(--accent);
  padding: 0.25rem 0 0.25rem 0.8rem;
  margin: 0 0 1rem;
  line-height: 1.7;
}

.option-translation {
  display: block;
  margin-top: 0.4rem;
  color: var(--muted);
  line-height: 1.6;
}

.question-text,
.question-translation,
.option-btn > span {
  overflow-wrap: anywhere;
  min-width: 0;
}

.question-head h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.25;
}

.mark-btn[aria-pressed="true"] {
  background: #fff4d6;
  border-color: #d69e2e;
}

.question-text {
  max-width: 72rem;
  margin-bottom: 1rem;
  font-size: 1.04rem;
}

.options {
  display: grid;
  gap: 0.65rem;
}

.option-btn {
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  align-items: start;
  width: 100%;
  min-height: 3rem;
  text-align: left;
  padding: 0.72rem;
  background: #fff;
}

.option-key {
  display: inline-grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 50%;
  background: var(--surface-muted);
  font-weight: 800;
}

.option-btn.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.option-btn.correct-answer {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.option-btn.wrong-answer {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.result-box,
.explanation {
  margin-top: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.9rem;
}

.result-box {
  font-weight: 800;
}

.result-box.ok {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: rgba(23, 114, 69, 0.35);
}

.result-box.bad {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: rgba(180, 35, 24, 0.35);
}

.explanation {
  background: #fbfcfb;
}

.explanation h3 {
  margin-bottom: 0.5rem;
}

.explanation p {
  margin-bottom: 0.65rem;
}

.explanation ul {
  margin: 0.45rem 0 0;
  padding-left: 1.2rem;
}

.explanation h4 {
  font-size: 0.95rem;
  margin: 1rem 0 0.4rem;
}

.explanation li {
  margin-bottom: 0.55rem;
}

.explanation,
.result-box {
  overflow-wrap: anywhere;
}

.result-box.reference,
.question-list .reference {
  background: #eef0f7;
  border-color: #a3adc6;
  color: #38405a;
}

.question-list .active {
  box-shadow: inset 0 0 0 2px var(--accent-strong);
}

.source-question {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 0.65rem;
}

.source-question summary {
  cursor: pointer;
  color: var(--accent-strong);
  margin-bottom: 0.65rem;
}

.review-note {
  border-left: 3px solid #7c89a8;
  padding-left: 0.75rem;
  margin-top: 0.9rem;
}

.bank-note {
  margin: 0.7rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

@media (max-width: 920px) {
  .question-list {
    max-height: 10rem;
    overflow-y: auto;
  }
}

.nav-row {
  justify-content: space-between;
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.nav-row button,
#shuffleBtn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

#showAnswerBtn {
  background: #10231f;
  border-color: #10231f;
}

.hidden {
  display: none;
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
    padding-right: 0;
  }

  .question-card {
    min-height: auto;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100vw - 1rem, 1320px);
    padding-top: 0.7rem;
  }

  .topbar,
  .question-head,
  .nav-row {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 1.45rem;
  }

  .question-card {
    padding: 0.9rem;
  }

  .question-list {
    grid-template-columns: repeat(8, 1fr);
  }

  .option-btn {
    grid-template-columns: 1.9rem 1fr;
  }
}
