:root {
  color-scheme: light;
  --ink: #17252b;
  --muted: #607078;
  --line: #d7e0e3;
  --surface: #ffffff;
  --page: #f3f6f5;
  --primary: #164e63;
  --primary-strong: #0e3b4b;
  --accent: #d97706;
  --hint-bg: #fff7e6;
  --hint-line: #f0b95b;
  --note-bg: #edf7f4;
  --note-line: #4f9d89;
  --success: #2f7d5b;
  --shadow: 0 6px 18px rgb(23 37 43 / 8%);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Noto Sans TC", "PingFang TC",
    "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  background: rgb(255 255 255 / 96%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.header-main,
.progress-row,
main {
  width: min(100%, 760px);
  margin-inline: auto;
}

.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 1px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.3;
}

.icon-button,
.back-to-top,
.clear-search {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  height: 42px;
  color: white;
  background: var(--primary);
  border-radius: 8px;
}

.icon-button svg,
.back-to-top svg,
.clear-search svg,
.search-wrap > svg,
.empty-state svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.progress-row {
  margin-top: 10px;
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
}

.text-button {
  padding: 0;
  border: 0;
  color: var(--primary);
  background: transparent;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.progress-track {
  height: 5px;
  margin-top: 5px;
  overflow: hidden;
  background: #dfe8ea;
  border-radius: 3px;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--success);
  transition: width 180ms ease;
}

main {
  padding: 18px 14px calc(40px + env(safe-area-inset-bottom));
}

.primary-nav {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 4px;
  margin-bottom: 16px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8eeef;
}

.primary-nav-button {
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
  cursor: pointer;
}

.primary-nav-button.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 7px rgb(23 37 43 / 16%);
}

.controls {
  display: grid;
  gap: 12px;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-wrap > svg {
  position: absolute;
  left: 13px;
  color: var(--muted);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  min-height: 48px;
  padding: 10px 48px 10px 44px;
  border: 1px solid #bac8cd;
  border-radius: 8px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
}

.search-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(22 78 99 / 12%);
}

.notes-tools {
  display: grid;
  gap: 12px;
}

.section-jump {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.section-jump select {
  min-width: 0;
  min-height: 44px;
  padding: 8px 34px 8px 11px;
  border: 1px solid #bac8cd;
  border-radius: 8px;
  outline: none;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.section-jump select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgb(22 78 99 / 12%);
}

.notes-heading {
  margin: 24px 2px 14px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--primary);
}

.notes-heading h2 {
  margin: 2px 0 3px;
  font-size: 1.3rem;
  line-height: 1.4;
}

.notes-heading p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.notes-content {
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.notes-section {
  scroll-margin-top: 112px;
  padding: 20px 2px 24px;
  border-bottom: 1px solid var(--line);
}

.notes-section:last-child {
  border-bottom: 0;
}

.notes-section > h2 {
  margin: 0 12px 14px;
  color: var(--primary-strong);
  font-size: 1.22rem;
  line-height: 1.45;
}

.notes-markdown {
  padding-inline: 12px;
  overflow-wrap: anywhere;
}

.notes-markdown h3 {
  margin: 25px 0 9px;
  padding-left: 9px;
  border-left: 4px solid var(--accent);
  color: var(--primary-strong);
  font-size: 1.05rem;
  line-height: 1.45;
}

.notes-markdown h4 {
  margin: 21px 0 7px;
  color: var(--ink);
  font-size: 0.98rem;
}

.notes-markdown p {
  margin: 0 0 0.85em;
}

.notes-markdown ul,
.notes-markdown ol {
  margin: 0.55em 0 1em;
  padding-left: 1.4em;
}

.notes-markdown blockquote {
  margin: 12px 0;
  padding: 10px 12px;
  border-left: 4px solid var(--note-line);
  background: var(--note-bg);
  color: #34585b;
}

.note-figure {
  margin: 18px 0 22px;
}

.note-figure a {
  display: block;
}

.note-figure img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
}

.note-figure figcaption {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.clear-search {
  position: absolute;
  right: 8px;
  width: 36px;
  height: 36px;
  color: var(--muted);
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8eeef;
}

.segment {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}

.segment.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 1px 5px rgb(23 37 43 / 12%);
}

.view-options {
  display: flex;
  align-items: center;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.view-options::-webkit-scrollbar {
  display: none;
}

.view-options label,
.review-check {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 19px;
  height: 19px;
  margin: 0;
  accent-color: var(--primary);
}

.outline-button {
  min-height: 36px;
  flex: 0 0 auto;
  padding: 5px 11px;
  border: 1px solid #9fb1b7;
  border-radius: 6px;
  background: transparent;
  color: var(--primary);
  font-size: 0.83rem;
  font-weight: 750;
  cursor: pointer;
}

.result-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 22px 2px 9px;
}

.result-summary strong {
  color: var(--primary);
  font-size: 1.05rem;
}

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

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

.question-item {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.question-item.reviewed {
  border-left: 4px solid var(--success);
}

.question-toggle {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 24px;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 64px;
  padding: 12px 13px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.question-number {
  display: grid;
  place-items: center;
  width: 42px;
  height: 34px;
  border: 1px solid #a9c0c8;
  border-radius: 6px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 800;
}

.question-title {
  min-width: 0;
  font-size: 0.98rem;
  font-weight: 750;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.chevron {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition: transform 160ms ease;
}

.question-toggle[aria-expanded="true"] .chevron {
  transform: rotate(90deg);
}

.question-detail {
  padding: 0 14px 16px;
  border-top: 1px solid var(--line);
}

.hint-block,
.note-block {
  margin-top: 14px;
  padding: 12px;
  border-left: 4px solid;
}

.hint-block {
  border-color: var(--hint-line);
  background: var(--hint-bg);
}

.note-block {
  border-color: var(--note-line);
  background: var(--note-bg);
}

.answer-block {
  margin-top: 18px;
}

.block-label {
  display: block;
  margin-bottom: 5px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.hint-block .block-label {
  color: #9a5700;
}

.hint-text,
.note-text {
  margin: 0;
}

.answer-content {
  overflow-wrap: anywhere;
}

.answer-content p {
  margin: 0 0 0.75em;
}

.answer-content ul,
.answer-content ol {
  margin: 0.5em 0 0.9em;
  padding-left: 1.4em;
}

.answer-content pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 12px;
  border: 1px solid #c7d3d7;
  border-radius: 6px;
  background: #f5f8f8;
  font-size: 0.82rem;
  line-height: 1.55;
}

.notes-markdown pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 12px;
  border: 1px solid #c7d3d7;
  border-radius: 6px;
  background: #f5f8f8;
  font-size: 0.82rem;
  line-height: 1.55;
}

code {
  padding: 0.1em 0.3em;
  border-radius: 4px;
  background: #edf1f2;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
}

pre code {
  padding: 0;
  background: transparent;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 10px 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.88rem;
  line-height: 1.55;
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #eaf0f1;
  color: var(--primary-strong);
}

tr:last-child td {
  border-bottom: 0;
}

.review-check {
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 13px;
  border-top: 1px solid var(--line);
}

.hint-mode .answer-block,
.hint-mode .note-block {
  display: none;
}

.empty-state {
  padding: 56px 20px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 40px;
  height: 40px;
}

.empty-state h2 {
  margin: 12px 0 2px;
  color: var(--ink);
  font-size: 1.15rem;
}

.empty-state p {
  margin: 0;
}

.back-to-top {
  position: fixed;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  box-shadow: 0 8px 20px rgb(14 59 75 / 28%);
}

@media (min-width: 720px) {
  .app-header {
    padding-inline: 24px;
  }

  main {
    padding-inline: 0;
  }

  .question-toggle {
    padding: 14px 18px;
  }

  .question-detail {
    padding: 0 20px 20px;
  }

  .notes-section {
    padding-inline: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
