:root {
  --ink: #17313a;
  --muted: #5e747a;
  --paper: #fffdf8;
  --surface: #f4f8f5;
  --line: #d6e3df;
  --brand: #0b6b5c;
  --brand-dark: #084e45;
  --ocean: #174b6e;
  --sun: #f4b942;
  --danger: #b43c36;
  --ok: #26734d;
  --shadow: 0 16px 40px rgba(15, 55, 58, .12);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--surface);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background:
  radial-gradient(circle at 8% 4%, rgba(244,185,66,.16), transparent 28rem),
  radial-gradient(circle at 94% 12%, rgba(23,75,110,.12), transparent 30rem),
  var(--surface); }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
a { color: var(--ocean); }
button { min-height: 44px; }

.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; padding: 10px 14px; color: #fff; background: var(--brand-dark); border-radius: 8px; }
.skip-link:focus { top: 12px; }

.hero {
  position: relative;
  overflow: hidden;
  min-height: 220px;
  padding: 42px 20px 28px;
  color: #fff;
  background:
    linear-gradient(125deg, rgba(5,57,52,.98), rgba(14,107,92,.94) 50%, rgba(23,75,110,.95)),
    repeating-linear-gradient(60deg, transparent 0 28px, rgba(255,255,255,.04) 28px 30px);
}
.hero::before, .hero::after { content: ""; position: absolute; border: 1px solid rgba(255,255,255,.16); border-radius: 50%; }
.hero::before { width: 360px; height: 360px; right: -90px; top: -190px; }
.hero::after { width: 190px; height: 190px; right: 92px; top: -62px; }
.hero-inner { position: relative; max-width: 860px; margin: 0 auto; text-align: center; z-index: 1; }
.hero-mark { position: absolute; inset: -18px -20px auto; display: flex; justify-content: space-between; color: rgba(255,255,255,.09); font-family: Georgia, serif; font-size: clamp(1.3rem, 3vw, 2.3rem); font-weight: 900; transform: rotate(-2deg); pointer-events: none; }
.eyebrow { display: inline-flex; align-items: center; margin-bottom: 14px; padding: 5px 11px; border: 1px solid rgba(255,255,255,.3); border-radius: 999px; font-size: .78rem; background: rgba(255,255,255,.1); }
.hero h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.2rem); line-height: 1.15; letter-spacing: .12em; text-shadow: 0 2px 12px rgba(0,0,0,.25); }
.hero p { margin: 8px 0 0; color: #dcefeb; font-size: .98rem; line-height: 1.7; }
.hero-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin-top: 19px; }
.hero-nav a { min-height: 44px; display: inline-flex; align-items: center; color: #fff; font-size: .88rem; font-weight: 700; text-decoration-color: rgba(255,255,255,.45); text-underline-offset: 4px; }

.shell { width: min(860px, calc(100% - 28px)); margin: 16px auto 52px; position: relative; z-index: 2; }
.card { background: rgba(255,253,248,.97); border: 1px solid rgba(214,227,223,.95); border-radius: 20px; box-shadow: var(--shadow); }
.control-card { padding: 22px; }
.section-title { margin: 0 0 5px; font-size: 1.22rem; }
.section-note { margin: 0 0 18px; color: var(--muted); line-height: 1.65; }
.intro-box { margin-bottom: 16px; padding: 14px 16px; border-left: 4px solid var(--brand); border-radius: 0 12px 12px 0; background: #e8f2ef; color: #36575b; font-size: .9rem; line-height: 1.75; }
.intro-box h2 { margin: 0 0 5px; color: var(--brand-dark); font-size: 1rem; }
.intro-box p { margin: 4px 0; }
.intro-box strong { color: var(--ink); }
.quick-start { margin-bottom: 16px; padding: 18px; border-radius: 4px 18px 4px 18px; text-align: center; background: linear-gradient(135deg, var(--brand-dark), var(--brand) 56%, var(--ocean)); box-shadow: var(--shadow); }
.quick-start .btn { padding: 13px 28px; font-size: 1.06rem; color: var(--brand-dark); background: #fff7dc; box-shadow: 0 3px 12px rgba(0,0,0,.2); }
.quick-start .btn:hover { background: #fff1bd; }
.quick-start p { margin: 8px 0 0; color: #dcefeb; font-size: .82rem; line-height: 1.6; }
.control-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.control-heading .section-note { margin-bottom: 14px; }
.text-link { min-height: 44px; display: inline-flex; align-items: center; white-space: nowrap; font-size: .82rem; font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
.stat { padding: 14px; border-radius: 14px; background: #edf5f2; border: 1px solid #d8e8e3; }
.stat b { display: block; color: var(--brand-dark); font-size: 1.4rem; }
.stat span { color: var(--muted); font-size: .82rem; }

.filters { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 14px; }
.field { display: grid; gap: 7px; }
.field > span, .field legend { font-size: .86rem; font-weight: 700; color: #36575b; }
.field select, .field input[type="number"], .lookup-input, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; color: var(--ink); background: #fff;
  border: 1px solid #bfd1cc; border-radius: 10px; font-size: 16px;
}
.subject-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; grid-column: 1 / -1; border: 0; padding: 0; margin: 0; }
.subject-chip { position: relative; }
.subject-chip input { position: absolute; opacity: 0; pointer-events: none; }
.subject-chip span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px; border: 1px solid #bfd1cc; border-radius: 11px; background: #fff; color: #486064; cursor: pointer; font-weight: 700; transition: .15s ease; }
.subject-chip input:checked + span { color: #fff; background: var(--brand); border-color: var(--brand); transform: translateY(-1px); }
.subject-chip input:focus-visible + span { outline: 3px solid rgba(244,185,66,.55); outline-offset: 2px; }
.filter-details { border-top: 1px solid var(--line); padding-top: 4px; }
.filter-details > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; min-height: 48px; color: var(--brand-dark); cursor: pointer; font-weight: 900; list-style-position: inside; }
.filter-details > summary small { color: var(--muted); font-size: .78rem; font-weight: 500; }
.filter-details[open] > summary { margin-bottom: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.btn { appearance: none; border: 1px solid transparent; border-radius: 11px; padding: 10px 16px; font-weight: 800; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 7px; }
.btn-primary { color: #fff; background: var(--brand); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { color: var(--ocean); background: #edf4f8; border-color: #c7d9e4; }
.btn-ghost { color: #fff; border-color: rgba(255,255,255,.35); background: rgba(255,255,255,.08); }
.btn:disabled { cursor: not-allowed; opacity: .48; }

.workspace { display: none; margin-top: 18px; }
.workspace.active { display: block; }
.workspace-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; margin-bottom: 12px; }
.progress-track { flex: 1; height: 9px; overflow: hidden; background: #dce8e4; border-radius: 999px; }
.progress-bar { width: 0; height: 100%; background: linear-gradient(90deg, var(--brand), #3e9d87); transition: width .2s ease; }
.progress-label, .timer { white-space: nowrap; color: var(--muted); font-size: .86rem; font-weight: 700; }

.question-card { overflow: hidden; }
.question-main { padding: 22px; }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-bottom: 14px; }
.pill { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border-radius: 999px; font-size: .78rem; font-weight: 800; background: #e7f1ee; color: var(--brand-dark); }
.pill-blue { background: #e8f0f6; color: var(--ocean); }
.pill-gold { background: #fff0c7; color: #72500b; }
.question-no { margin-left: auto; font-weight: 900; color: var(--ocean); }
.pass-line { color: var(--muted); font-size: .86rem; }
.stem, .passage { line-height: 1.85; white-space: pre-line; }
.passage { margin: 0 0 16px; padding: 14px; border-left: 4px solid var(--sun); background: #fff9e9; border-radius: 8px; color: #394c4e; }
.stem { margin: 0 0 18px; font-size: 1.08rem; font-weight: 650; }
.options { display: grid; gap: 9px; }
.option { position: relative; display: grid; grid-template-columns: 18px 28px minmax(0, 1fr); align-items: start; gap: 10px; min-height: 50px; padding: 12px; border: 1px solid #c8d7d3; border-radius: 12px; background: #fff; cursor: pointer; }
.option:hover { border-color: #82aaa0; background: #fbfdfa; }
.option input { margin-top: 5px; }
.option-letter { font-weight: 900; color: var(--brand); }
.option.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(11,107,92,.12); }
.option.correct { border-color: var(--ok); background: #eaf7ef; }
.option.wrong { border-color: var(--danger); background: #fff0ef; }
.option-text:empty::after { content: "請對照官方題面中的圖形選項"; color: var(--muted); font-size: .9rem; }

.written-box { display: grid; gap: 10px; }
textarea { min-height: 140px; resize: vertical; line-height: 1.65; }
.feedback { display: none; margin-top: 15px; padding: 14px; border-radius: 11px; line-height: 1.65; }
.feedback.show { display: block; }
.feedback.ok { background: #eaf7ef; border: 1px solid #b8dbc5; color: #1f573b; }
.feedback.bad { background: #fff0ef; border: 1px solid #ecc0bd; color: #7e302b; }
.feedback.info { background: #edf4f8; border: 1px solid #c7d9e4; color: #264e65; }
.question-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 17px; }

.source-panel { border-top: 1px solid var(--line); background: #edf4f2; }
.source-panel summary { min-height: 48px; padding: 13px 22px; cursor: pointer; color: var(--brand-dark); font-weight: 800; }
.source-pages { display: grid; gap: 12px; padding: 0 14px 16px; }
.source-pages img { display: block; width: 100%; height: auto; border: 1px solid #b8c9c5; border-radius: 10px; background: white; }

.summary-card { display: none; margin-top: 18px; padding: 24px; }
.summary-card.show { display: block; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.summary-grid div { padding: 16px; border-radius: 12px; background: #edf5f2; }
.summary-grid strong { display: block; font-size: 1.5rem; color: var(--brand-dark); }

.lookup-shell { width: min(860px, calc(100% - 28px)); margin: 28px auto 52px; }
.lookup-bar { display: grid; grid-template-columns: 1fr auto; gap: 9px; padding: 18px; }
.lookup-result { margin-top: 14px; }
.notice { padding: 13px 15px; border-radius: 10px; background: #fff7df; border: 1px solid #efdca9; color: #6b5419; line-height: 1.65; }

.info-page { width: min(860px, calc(100% - 28px)); margin: 34px auto 60px; padding: 28px; line-height: 1.85; }
.info-page h1, .info-page h2 { color: var(--brand-dark); }
.info-page table { width: 100%; border-collapse: collapse; overflow: hidden; border-radius: 10px; }
.info-page th, .info-page td { padding: 10px; border: 1px solid var(--line); text-align: left; }
.info-page th { background: #e7f1ee; }

footer { padding: 28px 16px 40px; text-align: center; color: var(--muted); font-size: .86rem; }
footer nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-bottom: 10px; }

@media (max-width: 760px) {
  .hero { min-height: 205px; padding-top: 34px; }
  .shell { width: min(100% - 18px, 860px); }
  .control-card, .question-main { padding: 17px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .subject-grid { grid-template-columns: repeat(2, 1fr); }
  .subject-chip:last-child { grid-column: 1 / -1; }
  .question-no { width: 100%; margin: 3px 0 0; }
  .summary-grid { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
  .hero h1 { letter-spacing: .06em; }
  .hero-nav { gap: 2px 14px; }
  .control-heading { align-items: center; }
  .filters { grid-template-columns: 1fr; }
  .field, .subject-grid { grid-column: 1; }
  .actions .btn, .question-actions .btn { flex: 1 1 100%; }
  .workspace-head { align-items: flex-start; flex-wrap: wrap; }
  .progress-track { order: 3; flex-basis: 100%; }
}

@media print {
  .hero, .control-card, .workspace-head, .question-actions, .source-panel summary, footer { display: none !important; }
  body, .shell { background: #fff; margin: 0; width: 100%; }
  .workspace, .question-card { display: block; box-shadow: none; border: 0; }
  .source-panel { display: block; background: #fff; }
  .source-pages { padding: 0; }
}
