:root {
  --cream: #f3e2c6;
  --ink: #3c2718;
  --muted: #8d6b4f;
  --orange: #c56f28;
  --green: #4e7c3c;
  --blue: #35685f;
  --purple: #8d4e3c;
  --red: #b84a3c;
  --soft-green: #e7f0dc;
  --soft-red: #f8e6df;
  --soft-yellow: #f8ecc4;
  --plank: #fff6ea;
  --rim: #e4c49a;
  --shadow: 0 8px 18px rgba(92, 54, 24, 0.14);
  color-scheme: only light;
  font-family: ui-rounded, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
html, body {
  background-color: #e4c08a;
  background-image:
    repeating-linear-gradient(90deg, rgba(110, 64, 24, 0.05) 0 2px, transparent 2px 13px),
    repeating-linear-gradient(90deg, transparent 0 6px, rgba(90, 48, 18, 0.04) 6px 7px, transparent 7px 23px),
    repeating-linear-gradient(180deg, transparent 0 128px, rgba(110, 64, 24, 0.08) 128px 130px),
    radial-gradient(120% 70% at 15% 0%, rgba(255, 236, 210, 0.45), transparent 55%),
    linear-gradient(180deg, #f2d4a8 0%, #deb67a 100%);
}
body {
  margin: 0;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible {
  outline: 3px solid rgba(176, 106, 42, 0.55);
  outline-offset: 2px;
}

.page {
  height: 100%;
  width: min(100%, var(--page-max, 640px));
  margin: 0 auto;
  overflow: auto;
  padding-bottom: env(safe-area-inset-bottom);
}
.page.home { --page-max: 560px; }
.page.board { --page-max: 960px; }
.page.sign { --page-max: 520px; --accent: var(--orange); }
.page.result { overflow: hidden; display: flex; flex-direction: column; }

.ops {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 28px 20px 0;
}
.hero {
  margin: 16px 20px 0;
  text-align: center;
  font-size: 34px;
  line-height: 1.25;
  font-weight: 800;
  color: #4a2c16;
  text-shadow: 0 1px 0 rgba(255, 244, 226, 0.6);
}
.lede, .section-note, .sign-mode {
  color: var(--muted);
  text-align: center;
  font-size: 17px;
  line-height: 1.5;
}
.lede { margin: 6px 20px 0; }
.menu { display: flex; flex-direction: column; gap: 14px; padding: 24px 20px 8px; }
.install, .ios-hint {
  display: block;
  width: calc(100% - 40px);
  margin: 8px 20px 28px;
  text-align: center;
}
.install {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  font-size: 17px;
  min-height: 44px;
}
.ios-hint { color: var(--muted); font-size: 15px; }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border-radius: 50%;
  color: white;
  font-weight: 800;
  line-height: 1;
  background-image: linear-gradient(180deg, rgba(255, 248, 236, 0.34), rgba(62, 32, 12, 0.16));
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 236, 0.45),
    0 2px 0 rgba(74, 42, 18, 0.22);
  text-shadow: 0 1px 0 rgba(62, 32, 12, 0.28);
}
.menu-card,
.qcard,
.mistake,
.grade-card,
.board-card,
.dialog,
.option,
.sign-input {
  background-color: var(--plank);
  background-image:
    linear-gradient(180deg, rgba(255, 252, 246, 0.72), rgba(255, 244, 226, 0.18)),
    repeating-linear-gradient(90deg, rgba(186, 140, 82, 0.05) 0 1px, transparent 1px 16px);
  border: 1px solid var(--rim);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 4px 0 #e6c79a,
    var(--shadow);
}
.menu-card {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding: 18px;
  border-radius: 24px;
  text-align: left;
  touch-action: manipulation;
}
.menu-card:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 2px 0 #e6c79a; }
.menu-copy { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.menu-copy strong { font-size: 26px; line-height: 1.3; font-weight: 800; }
.menu-copy span { color: var(--muted); font-size: 17px; }
.chevron { font-size: 34px; font-weight: 700; opacity: 0.7; line-height: 1; }

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 56px;
  padding: 6px 12px 6px 8px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(243, 226, 198, 0.94);
  border-bottom: 1px solid rgba(196, 148, 90, 0.35);
}
.topbar h1 { flex: 1; margin: 0; font-size: 22px; line-height: 1.3; font-weight: 800; }
.icon-btn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
}
.icon-btn svg { width: 26px; height: 26px; }

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px rgba(92, 54, 24, 0.08);
}

.timer { padding: 4px 20px 0; }
.timer-row { display: flex; align-items: center; }
.timer-row span { flex: 1; color: var(--muted); }
#time-label { font-size: 26px; font-weight: 800; }
.timer-track {
  height: 14px;
  margin-top: 6px;
  border-radius: 999px;
  background: rgba(92, 54, 24, 0.12);
  box-shadow: inset 0 2px 3px rgba(92, 54, 24, 0.16);
  overflow: hidden;
}
.timer-fill { height: 100%; width: 100%; border-radius: inherit; transition: width 0.1s linear, background 0.2s linear; }

.qcard {
  margin: 16px 20px 0;
  padding: 20px;
  border-radius: 28px;
}
.qmeta { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.qindex { color: var(--muted); font-size: 15px; }
.prompt {
  min-height: 150px;
  margin: 16px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 800;
}
.options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 20px 20px 28px;
}
.option {
  min-height: 84px;
  padding: 10px;
  border-radius: 22px;
  border-width: 2px;
  color: var(--ink);
  font-weight: 800;
  touch-action: manipulation;
  word-break: break-word;
}
.option:disabled { opacity: 1; }
.option.correct,
.option.wrong {
  color: white;
  background-image: linear-gradient(180deg, rgba(255, 248, 236, 0.24), rgba(62, 32, 12, 0.14));
  box-shadow: inset 0 1px 0 rgba(255, 248, 236, 0.35);
}
.option.correct { background-color: var(--green); border-color: #3d6630; }
.option.wrong { background-color: var(--red); border-color: #8e382e; }

.score-block { display: flex; flex-direction: column; align-items: center; text-align: center; }
.score-orb {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
  background-image: linear-gradient(180deg, rgba(255, 248, 236, 0.28), rgba(62, 32, 12, 0.16));
  box-shadow:
    inset 0 2px 0 rgba(255, 248, 236, 0.35),
    0 8px 0 rgba(92, 54, 24, 0.12);
}
.score-orb strong { font-size: 60px; line-height: 1; font-weight: 800; }
.score-orb span { font-size: 18px; font-weight: 800; }
.summary { margin: 12px 0 4px; font-size: 18px; font-weight: 700; }
.score-block h2, .section-title { margin: 12px 0 8px; font-size: 22px; }
.result-scroll { flex: 1; overflow: auto; padding: 4px 20px 12px; }
.empty-note { color: var(--muted); text-align: center; font-size: 17px; padding: 24px 0; }
.mistakes { display: flex; flex-direction: column; gap: 12px; }
.mistake { border-radius: 20px; padding: 16px; }
.mistake-top { display: flex; align-items: center; gap: 10px; }
.mistake-prompt { margin: 10px 0; font-size: 22px; font-weight: 800; }
.answers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.answer { border-radius: 14px; padding: 8px 12px; }
.answer span { display: block; font-size: 15px; font-weight: 700; }
.answer strong { display: block; font-size: 22px; font-weight: 800; word-break: break-word; }
.answer.bad { background: var(--soft-red); color: var(--red); }
.answer.good { background: var(--soft-green); color: var(--green); }
.footer { padding: 8px 20px calc(12px + env(safe-area-inset-bottom)); }

.primary {
  display: block;
  width: 100%;
  border-radius: 18px;
  border: 1px solid rgba(62, 32, 12, 0.28);
  color: white;
  font-size: 20px;
  font-weight: 800;
  padding: 16px;
  touch-action: manipulation;
  background-image: linear-gradient(180deg, rgba(255, 248, 236, 0.28), rgba(62, 32, 12, 0.16));
  box-shadow: inset 0 1px 0 rgba(255, 248, 236, 0.4), 0 4px 0 rgba(74, 42, 18, 0.22);
  text-shadow: 0 1px 0 rgba(62, 32, 12, 0.25);
}
.primary:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255, 248, 236, 0.4), 0 2px 0 rgba(74, 42, 18, 0.22); }
.primary:disabled { opacity: 0.45; cursor: default; }

.sign-mode { margin: 16px 24px 0; }
.sign-score { margin: 0; text-align: center; font-size: 56px; font-weight: 800; color: var(--accent); }
.sign-title { margin: 24px 24px 0; font-size: 26px; }
.section-note { margin: 6px 20px; white-space: pre-line; text-align: left; }
.section-note.tight { margin: 4px 24px 12px; text-align: left; }
.page.home .lede { text-align: center; }
.sign-field { display: block; margin: 0 24px; }
.sign-input {
  width: 100%;
  border-width: 2px;
  border-color: var(--accent);
  border-radius: 18px;
  padding: 14px 16px;
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
}
.sign-input.invalid { border-color: var(--red); }
.hint { margin: 6px 4px 16px; color: var(--muted); font-size: 14px; }
.page.sign .primary { width: calc(100% - 48px); margin: 0 24px 24px; }

.section-title { margin: 4px 20px; }
.reject {
  margin: 4px 20px 8px;
  padding: 12px;
  border-radius: 14px;
  background: var(--soft-red);
  color: var(--red);
  font-size: 18px;
  font-weight: 700;
  border: 1px solid rgba(184, 74, 60, 0.25);
}
.stack { display: flex; flex-direction: column; gap: 12px; padding: 8px 20px 24px; }
.grade-card { border-radius: 20px; overflow: hidden; }
.grade-head, .unit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 8px 12px;
}
.grade-head { cursor: pointer; }
.grade-copy { display: flex; flex-direction: column; gap: 6px; padding: 8px 8px 8px 0; }
.grade-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grade-name { font-size: 22px; font-weight: 800; }
.topic-blurb { color: var(--muted); font-size: 15px; line-height: 1.45; }
.grade-card input { width: 24px; height: 24px; margin: 12px; accent-color: var(--blue); flex: none; }
.grade-card:has(.count) input { accent-color: var(--purple); }
.count { margin-left: auto; color: var(--muted); font-size: 15px; padding-right: 8px; }
.count.on { color: var(--purple); font-weight: 700; }
.unit-list { border-top: 2px solid rgba(228, 196, 154, 0.7); padding: 4px 8px 8px 28px; }
.unit-row { min-height: 48px; padding: 0; cursor: pointer; }

.banner {
  margin: 4px 20px;
  padding: 14px;
  border-radius: 16px;
  background: var(--soft-yellow);
  border: 1px solid rgba(196, 148, 48, 0.35);
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}
.boards { display: grid; gap: 16px; padding: 16px 20px 28px; }
@media (min-width: 680px) {
  .boards { grid-template-columns: 1fr 1fr; }
}
.board-card { border-radius: 24px; overflow: hidden; }
.board-head {
  color: white;
  padding: 14px 20px;
  background-image: linear-gradient(180deg, rgba(255, 248, 236, 0.24), rgba(62, 32, 12, 0.14));
  text-shadow: 0 1px 0 rgba(62, 32, 12, 0.25);
}
.board-head h2 { margin: 0; font-size: 26px; }
.board-head p { margin: 2px 0 0; opacity: 0.92; }
.ranks { list-style: none; margin: 0; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.rank {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 10px;
  border-radius: 14px;
}
.rank.highlight { background: var(--soft-yellow); }
.name, .points { font-size: 22px; font-weight: 800; }
.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.name.empty, .points.empty { color: var(--muted); font-weight: 700; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(62, 36, 18, 0.46);
  display: grid;
  place-items: center;
  padding: 24px;
}
.dialog { width: min(100%, 420px); border-radius: 24px; padding: 22px 22px 12px; }
.dialog h2 { margin: 0 0 8px; font-size: 22px; }
.dialog p { margin: 0; color: var(--ink); font-size: 17px; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.text-btn {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  font-size: 16px;
  min-height: 44px;
  padding: 8px 12px;
}
.text-btn.danger { color: var(--red); }

@media (max-width: 380px) {
  .hero { font-size: 30px; }
  .menu-copy strong { font-size: 22px; }
  .prompt { min-height: 120px; }
}
