:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #616e7c;
  --line: #d9dde3;
  --accent: #1f4e8c;
  --accent-soft: #e8eef7;
  --ok: #1f8a4c;
  --err: #c0392b;
  --quiz-bg: #14182b;
  --quiz-card: #1f2440;
  --c0: #e0484f;
  --c1: #3a6fd8;
  --c2: #e2a017;
  --c3: #2a9d5c;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}
body.quiz { background: var(--quiz-bg); color: #fff; }
#app { min-height: 100vh; min-height: 100dvh; }

/* ---------- form / waiting ---------- */
.card {
  background: var(--card);
  max-width: 640px;
  margin: 32px auto;
  padding: 32px 36px;
  border-radius: 12px;
  border: 1px solid var(--line);
}
.card.center { text-align: center; }
@media (max-width: 680px) {
  .card { margin: 0; border-radius: 0; border: 0; padding: 24px 16px 40px; min-height: 100vh; min-height: 100dvh; }
}
h1 { font-size: 1.5rem; line-height: 1.35; margin: 0 0 8px; }
.intro { color: var(--muted); margin: 0 0 24px; white-space: pre-line; }
.muted { color: var(--muted); }

.field { margin: 0 0 22px; }
.field > label, .field > .label {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-weight: 600; margin-bottom: 6px;
}
.req { color: var(--err); font-weight: 600; }
.help { color: var(--muted); font-size: .875rem; margin: -2px 0 6px; }
.same-as { font-weight: 400; font-size: .9rem; color: var(--muted); margin-left: auto; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
input[type=text], input[type=email], input[type=tel], input[type=number], select, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input[readonly] { background: #f6f7f9; color: var(--muted); }
textarea { min-height: 110px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #777 50%), linear-gradient(135deg, #777 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.choices { display: grid; gap: 8px; }
.choice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
  font-weight: 400;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 5px; accent-color: var(--accent); }
.other-input { margin-top: 8px; }
.field.invalid input, .field.invalid select, .field.invalid textarea, .field.invalid .choice { border-color: var(--err); }
.err-msg { color: var(--err); font-size: .875rem; margin-top: 4px; }
.form-error { color: var(--err); }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 0; border-radius: 8px; padding: 12px 20px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:disabled { opacity: .6; cursor: progress; }
.btn.block { width: 100%; }

.received { text-align: center; padding: 8px 0 20px; }
.check {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; margin: 0 auto 14px;
  background: #e6f4ec; color: var(--ok);
}
.check.big { width: 80px; height: 80px; background: rgba(42,157,92,.18); color: #5fd394; }
.receipt { margin: 0; border-top: 1px solid var(--line); }
.receipt div { display: grid; grid-template-columns: 9em 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.receipt dt { color: var(--muted); }
.receipt dd { margin: 0; word-break: break-word; }
@media (max-width: 420px) { .receipt div { grid-template-columns: 1fr; gap: 0; } }
.status-line { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 22px; color: var(--muted); font-size: .875rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
.dot.bad { background: var(--err); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }

.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 40px auto; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg) } }

/* ---------- quiz ---------- */
.quiz-shell {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: 0 16px max(16px, env(safe-area-inset-bottom));
  max-width: 960px; margin: 0 auto; position: relative;
  user-select: none; -webkit-user-select: none;
}
.quiz-intro { margin: auto; text-align: center; max-width: 520px; padding: 32px 0; }
.eyebrow { letter-spacing: .12em; color: #9aa3c7; font-size: .85rem; margin: 0 0 6px; }
.quiz-intro h1 { font-size: 2rem; margin-bottom: 20px; }
.rules { text-align: left; padding: 18px 20px 18px 38px; margin: 0 0 28px; background: var(--quiz-card); border-radius: 12px; line-height: 1.8; }
.btn.start { background: #fff; color: var(--quiz-bg); font-size: 1.15rem; padding: 14px 44px; border-radius: 999px; }
.btn.start:active { transform: scale(.97); }
.hint { color: #9aa3c7; font-size: .85rem; }
.muted-dark { color: #b6bddb; }
.score { font-size: 1.25rem; font-weight: 700; }

.countdown { margin: auto; font-size: 8rem; font-weight: 800; animation: pop .9s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0 } 30% { opacity: 1 } to { transform: scale(1) } }

.timebar { height: 8px; background: rgba(255,255,255,.12); border-radius: 0 0 4px 4px; overflow: hidden; margin: 0 -16px; }
.timebar div { height: 100%; width: 100%; background: #fff; transform-origin: left; }
.timebar div.low { background: var(--c0); }
.q-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 0 0; color: #b6bddb; font-weight: 600; }
.q-timer { font-size: 1.5rem; color: #fff; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.q-timer.low { color: var(--c0); }
.q-body { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 16px 0 24px; gap: 16px; }
.q-text { font-size: clamp(1.4rem, 4.5vw, 2.2rem); line-height: 1.4; margin: 0; }
.q-code {
  font: 600 clamp(1rem, 3.6vw, 1.45rem)/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  background: #0b0e1c; color: #8ef0b5; padding: 14px 18px; border-radius: 10px; margin: 0;
  max-width: 100%; overflow-x: auto; white-space: pre-wrap; word-break: break-all; text-align: left;
}
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.opt {
  font: inherit; font-weight: 700; font-size: clamp(1rem, 3.6vw, 1.35rem); color: #fff;
  border: 0; border-radius: 12px; cursor: pointer;
  min-height: 92px; padding: 14px 16px;
  display: flex; align-items: center; gap: 12px; text-align: left;
  box-shadow: inset 0 -5px 0 rgba(0,0,0,.22);
  transition: transform .08s, opacity .2s, filter .2s;
  word-break: break-word;
}
.opt:active { transform: translateY(2px); }
.opt .shape { flex: none; width: 26px; height: 26px; display: grid; place-items: center; }
.opt .shape svg { width: 100%; height: 100%; fill: #fff; }
.opt.c0 { background: var(--c0); } .opt.c1 { background: var(--c1); }
.opt.c2 { background: var(--c2); } .opt.c3 { background: var(--c3); }
.options.locked .opt { cursor: default; }
.options.locked .opt:not(.picked) { opacity: .25; }
.options.locked .opt.picked { outline: 4px solid #fff; outline-offset: -4px; }
@media (max-width: 520px) {
  .opt { min-height: 84px; padding: 12px; flex-direction: column; justify-content: center; text-align: center; gap: 6px; }
  .opt .shape { width: 20px; height: 20px; }
}
.q-overlay {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(20,24,43,.72); backdrop-filter: blur(2px);
  font-size: 1.8rem; font-weight: 800; animation: fade .2s;
}
.q-overlay .sub { display: block; font-size: 1rem; font-weight: 600; color: #b6bddb; margin-top: 4px; text-align: center; }
@keyframes fade { from { opacity: 0 } }

.gate-icon { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; margin: 24px auto 14px; background: var(--accent-soft); color: var(--accent); }
