:root {
  --paper: #f3ecdf;
  --sheet: #fffaf2;
  --ink: #241910;
  --muted: #5c4f44;
  --line: #e4d3bc;
  --seal: #c4272e;
  --seal-deep: #8e1520;
  --gold: #a67c3d;
  --win: #9f1d28;
  --maybe: #8a4b12;
  --info: #1d4a44;
  --shadow: 0 10px 30px rgba(60, 30, 12, 0.08);
  color-scheme: light;
  font-family: "PingFang TC", "Heiti TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(circle at top, #4a2a24 0, #2a1814 42%, #1a100e 100%);
  color: var(--ink);
  font-size: 18px;
  line-height: 1.45;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.phone {
  width: min(480px, 100%);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}

.top, .status, .nav { flex-shrink: 0; }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  background: var(--seal-deep);
  color: #fff6ea;
}
.brand { margin: 0; font-size: 1.55rem; font-weight: 800; letter-spacing: 0.08em; }
.brand-sub { margin: 0; color: #f0d0c4; font-size: 0.95rem; }
.total-chip {
  border: 0;
  background: #fff6ea;
  color: var(--seal-deep);
  border-radius: 999px;
  min-height: 48px;
  padding: 8px 14px;
  font-weight: 800;
  white-space: nowrap;
}

.status {
  margin: 0;
  padding: 8px 16px;
  background: #efe2cf;
  color: var(--ink);
  font-weight: 700;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.status-bad { background: #f3d2cb; color: var(--seal-deep); }
.status-warn { background: #f3e2c0; color: #6a3e08; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 16px 8px;
}
.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding-bottom: 12px;
  scroll-padding-top: 8px;
}
#screen-scan.is-idle { justify-content: safe center; }

.hero { display: flex; flex-direction: column; gap: 10px; }
.btn-primary, .btn-ghost, .seg button, .fold summary {
  border-radius: 16px;
  min-height: 56px;
}
.btn-primary {
  width: 100%;
  border: 0;
  background: var(--seal);
  color: white;
  font-size: 1.7rem;
  font-weight: 800;
  padding: 18px 16px;
  box-shadow: 0 8px 0 var(--seal-deep);
}
.btn-primary:active { transform: translateY(2px); box-shadow: 0 4px 0 var(--seal-deep); }
.btn-primary:disabled { opacity: 0.6; }
.btn-ghost {
  width: 100%;
  border: 2px solid var(--ink);
  background: transparent;
  font-weight: 800;
  padding: 10px 14px;
}
.fine, .kicker { margin: 0; color: var(--muted); }
.kicker { font-size: 0.95rem; font-weight: 700; }

.stage {
  position: relative;
  height: 34dvh;
  min-height: 210px;
  background: #14110f;
  border-radius: 18px;
  overflow: hidden;
}
video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #14110f;
  display: block;
}
.guide {
  position: absolute;
  border: 3px dashed #ffe8a3;
  border-radius: 12px;
  color: #ffe8a3;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 4px;
  font-weight: 800;
  text-shadow: 0 1px 2px #000;
  pointer-events: none;
}

.result {
  border-radius: 22px;
  padding: 16px 16px 14px;
  background: var(--sheet);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.result-kicker { margin: 0; font-weight: 700; color: var(--muted); }
.result-title {
  margin: 2px 0 0;
  font-size: 4rem;
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0.04em;
}
.result-amount {
  margin: 6px 0 0;
  font-size: 2rem;
  font-weight: 900;
}
.result-number {
  margin: 8px 0 0;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}
.result-note { margin: 8px 0 0; font-size: 1.05rem; }
.result-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.result-actions .btn-primary, .result-actions .btn-ghost { font-size: 1.2rem; }

.result-win { background: var(--win); color: #fff8ef; border-color: transparent; }
.result-win .result-kicker, .result-win .result-note { color: #ffd9cc; }
.result-lose .result-title { color: #4e453d; }
.result-maybe { background: #fff4df; border-color: #e2c48a; }
.result-maybe .result-title { color: var(--maybe); font-size: 2.6rem; }
.result-not-drawn, .result-missing-period, .result-no-data {
  background: #e7f2ef;
  border-color: #b7d5ce;
}
.result-not-drawn .result-title,
.result-missing-period .result-title,
.result-no-data .result-title { color: var(--info); font-size: 2.5rem; }
.result-idle .result-title { font-size: 2.4rem; }

@media (prefers-reduced-motion: no-preference) {
  .result-win .result-title { animation: stamp 420ms cubic-bezier(.2, 1.4, .4, 1) both; }
}
@keyframes stamp {
  from { transform: scale(1.35) rotate(-8deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1;
  border: 2px solid var(--ink);
  background: transparent;
  font-weight: 800;
  padding: 10px 8px;
}
.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

.dock, .fold { display: flex; flex-direction: column; gap: 10px; }
.fold {
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 4px 12px 12px;
}
.fold summary {
  display: flex;
  align-items: center;
  font-weight: 800;
  font-size: 1.2rem;
  cursor: pointer;
}
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.field input, .field select {
  min-height: 56px;
  border: 2px solid #cbbba6;
  border-radius: 12px;
  background: white;
  padding: 8px 12px;
  font-size: 1.45rem;
  letter-spacing: 0.04em;
}
.alert, .notice {
  margin: 0;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
}
.alert { background: #fde8e4; color: var(--seal-deep); }
.notice { background: #e5f2ea; color: #1d4a44; }
.hint {
  background: #fff6ea;
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prize-card, .history-item {
  background: var(--sheet);
  border-radius: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.prize-card + .prize-card, .history-item + .history-item { margin-top: 12px; }
.prize-card h2 { margin: 0; font-size: 1.45rem; }
.prize-meta { margin: 4px 0 10px; color: var(--muted); }
.prize-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px dashed var(--line); }
.prize-name { font-weight: 800; }
.prize-num {
  color: var(--seal);
  font-weight: 900;
  font-size: 1.55rem;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.prize-block { padding-top: 8px; }
.prize-block .prize-num { display: block; text-align: left; font-size: 1.7rem; }

.history-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.history-total { margin: 0; font-size: 2rem; font-weight: 900; }
.history-item { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.history-num { margin: 0; font-size: 1.35rem; font-weight: 900; letter-spacing: 0.04em; }
.history-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.95rem; }
.history-prize { margin: 0; font-weight: 900; text-align: right; }
.history-prize.won { color: var(--seal); }
.delete {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  min-height: 44px;
  padding: 8px;
}
.empty { margin: 24px 0; text-align: center; color: var(--muted); font-size: 1.2rem; }

.nav {
  display: flex;
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: #fffaf2;
  border-top: 1px solid var(--line);
}
.nav button {
  flex: 1;
  min-height: 64px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  font-size: 1.2rem;
  font-weight: 800;
}
.nav button[aria-current="page"] { background: var(--seal-deep); color: #fff6ea; }

:focus-visible { outline: 3px solid var(--info); outline-offset: 2px; }
.noscript {
  max-width: 480px;
  margin: 12px auto;
  background: white;
  padding: 16px;
}

@media (min-width: 900px) {
  body { padding: 24px 0; }
  .phone {
    height: calc(100dvh - 48px);
    max-height: calc(100dvh - 48px);
    border-radius: 28px;
  }
}
