/* Layout: one phone column of cards; the felt table compass is the anchor at the top */
:root {
  --bg: #eef2ee; --surface: #ffffff; --fg: #1d2a24; --muted: #5d6b64; --line: #d6ddd8;
  --felt: #1f5c46; --felt-2: #2a7559; --ivory: #fbf8ef; --tile-edge: #c9c2ad;
  --seal: #c8322b; --wan: #b3261e; --tong: #1f4f9c; --suo: #1d7a3e; --amber: #b86e00; --amber-bg: #fff3dc;
  --display: "Space Grotesk", system-ui, sans-serif;
  --body: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", sans-serif;
  --han: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111815; --surface: #18221e; --fg: #e4ebe7; --muted: #9aaba2; --line: #2c3a34;
    --felt: #174836; --felt-2: #20604a; --ivory: #f3efe2; --tile-edge: #8f8a78;
    --seal: #e0574f; --amber: #f0a83a; --amber-bg: #3a2c12; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 15px; line-height: 1.5;
  padding: env(safe-area-inset-top, 0px) max(12px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
}
main { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.top { max-width: 560px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; padding: 12px 0; gap: 8px; }
h1 { font-family: var(--display); font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 8px; font-family: var(--han); }
.han { font-family: var(--han); }
.seal-text { color: var(--seal); font-weight: 900; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.cardhead { display: flex; justify-content: space-between; align-items: center; }
.cardhead h2 { margin: 0; }
.lab { font-size: 12px; color: var(--muted); font-weight: 600; min-width: 2.6em; font-family: var(--han); }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.rowline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rowline input { width: 72px; font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); }

.btn { font: inherit; font-weight: 600; border-radius: 12px; padding: 10px 14px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); cursor: pointer; text-align: center; font-family: var(--han); }
.btn.primary { background: var(--felt); color: #fff; border-color: var(--felt); }
.btn:disabled { opacity: .45; cursor: default; }
button:focus-visible, .btn:focus-visible, label.btn:focus-within { outline: 3px solid var(--amber); outline-offset: 2px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex: 1; min-width: 0; }
.seg button { flex: 1; font: inherit; font-family: var(--han); font-weight: 600; padding: 8px 4px; border: 0; background: var(--bg); color: var(--fg); cursor: pointer; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--felt); color: #fff; }
.seg button:disabled { opacity: .35; }
.seg.small { flex: 0 1 auto; }
.seg.small button { padding: 6px 10px; font-size: 13px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { font: inherit; width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); cursor: pointer; font-size: 18px; }
.stepper b { min-width: 1.5em; text-align: center; font-variant-numeric: tabular-nums; }

/* table compass */
.table { position: relative; aspect-ratio: 1.35; width: 100%; background: radial-gradient(circle at 50% 45%, var(--felt-2), var(--felt)); border-radius: 16px; color: #fff; }
.center { position: absolute; left: 33%; right: 33%; top: 30%; bottom: 30%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border: 1px dashed rgba(255,255,255,.35); border-radius: 12px; font-size: 12px; line-height: 1.3; }
.center .big { font-family: var(--han); font-size: 20px; font-weight: 900; }
.seat { position: absolute; width: 28%; background: rgba(0,0,0,.22); border: 1px solid rgba(255,255,255,.2); border-radius: 12px; padding: 5px 4px; text-align: center; color: #fff; font: inherit; cursor: pointer; line-height: 1.2; }
.seat .w { font-family: var(--han); font-size: 22px; font-weight: 900; display: block; }
.seat .n { font-size: 12px; display: block; font-family: var(--han); }
.seat .tag { font-size: 11px; display: block; opacity: .9; min-height: 1.2em; }
.seat.win { background: #fff; color: var(--felt); border-color: #fff; }
.seat.from { border: 2px dashed #ffd27a; }
.s0 { left: 36%; bottom: 4%; } .s1 { right: 3%; top: 34%; } .s2 { left: 36%; top: 4%; } .s3 { left: 3%; top: 34%; }
.sealmark { position: absolute; top: -9px; right: -6px; background: var(--seal); color: #fff; font-family: var(--han); font-weight: 900; font-size: 12px; width: 24px; height: 24px; border-radius: 5px; display: grid; place-items: center; transform: rotate(-8deg); box-shadow: 0 2px 4px rgba(0,0,0,.3); }

/* tiles */
.zone { border: 1px dashed var(--line); border-radius: 12px; padding: 6px 8px 8px; cursor: pointer; min-width: 0; }
.zone.active { border: 2px solid var(--felt-2); background: color-mix(in srgb, var(--felt-2) 7%, transparent); padding: 5px 7px 7px; }
.zonehead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.count.ok { color: var(--suo); font-weight: 700; }
.zrow { display: grid; grid-template-columns: auto 1fr; gap: 8px; }
.tiles { display: flex; flex-wrap: wrap; gap: 4px; min-height: 36px; align-items: flex-end; }
.tiles .empty { font-size: 12px; color: var(--muted); align-self: center; }
.grp { display: flex; gap: 1px; padding: 2px; border-radius: 6px; background: var(--bg); position: relative; }
.grp .gk { position: absolute; top: -8px; left: 2px; font-size: 9.5px; background: var(--surface); padding: 0 3px; border-radius: 4px; color: var(--muted); font-family: var(--han); }
.tile { width: 26px; height: 35px; background: var(--ivory); border: 1px solid var(--tile-edge); border-bottom-width: 3px; border-radius: 5px; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; font-family: var(--han); font-weight: 900; line-height: 1; color: #222; padding: 0; cursor: pointer; position: relative; }
.tile .v { font-size: 13px; } .tile .s { font-size: 10px; }
.tile.m .v, .tile.m .s { color: var(--wan); } .tile.p .s { color: var(--tong); } .tile.s .s { color: var(--suo); }
.tile.z { font-size: 16px; } .tile.red { color: var(--wan); } .tile.green { color: var(--suo); } .tile.blank::before { content: ""; width: 14px; height: 20px; border: 2px solid var(--tong); border-radius: 2px; }
.tile.f { color: var(--suo); font-size: 14px; }
.tile.q { outline: 2px solid var(--amber); outline-offset: 1px; }
.tile.q::after { content: "?"; position: absolute; top: -8px; right: -7px; background: var(--amber); color: #fff; font: 700 10px var(--body); width: 14px; height: 14px; border-radius: 50%; display: grid; place-items: center; }
.tile.sel { transform: translateY(-5px); box-shadow: 0 0 0 2px var(--seal); }
.tile.big { width: 30px; height: 41px; } .tile.big .v { font-size: 15px; }
.palette { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.palette .tile { width: 100%; height: auto; aspect-ratio: .74; }
.palette .tile .v { font-size: clamp(11px, 3.6vw, 15px); }
.palette .tile .s { font-size: clamp(9px, 2.8vw, 12px); }
.palette .tile.z, .palette .tile.f { font-size: clamp(13px, 4.2vw, 18px); }
.palette .tile:disabled { opacity: .3; cursor: default; }
.palette .gap { grid-column: span 1; }
.tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tools .btn { padding: 6px 12px; font-size: 13px; }
.status { margin: 0; font-size: 13px; padding: 8px 10px; border-radius: 10px; background: var(--bg); }
.status.warn { background: var(--amber-bg); border: 1px solid var(--amber); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: 13px; padding: 6px 11px; border-radius: 99px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font-family: var(--han); font-weight: 600; cursor: pointer; }
.chip.on { background: var(--felt); color: #fff; border-color: var(--felt); }
.chip small { opacity: .7; font-family: var(--body); font-weight: 400; }

/* result */
.result .total { display: flex; align-items: baseline; gap: 8px; }
.result .num { font-family: var(--display); font-size: 56px; font-weight: 700; line-height: 1; color: var(--felt-2); font-variant-numeric: tabular-nums; }
.result .unit { font-family: var(--han); font-size: 24px; font-weight: 900; }
.items { list-style: none; padding: 0; margin: 0; }
.items li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px dotted var(--line); }
.items li span:first-child { font-family: var(--han); font-weight: 600; }
.items .why { color: var(--muted); font-family: var(--body); font-weight: 400; font-size: 12px; margin-left: 6px; }
.items b { font-variant-numeric: tabular-nums; }
.pay { display: grid; grid-template-columns: auto 1fr auto auto; gap: 4px 10px; font-variant-numeric: tabular-nums; align-items: baseline; }
.pay .w { font-family: var(--han); font-weight: 900; }
.pay .r { text-align: right; font-weight: 700; }
.pay .note { color: var(--muted); font-size: 12px; }
.errors { margin: 0; padding-left: 18px; color: var(--muted); }
.actions { display: flex; gap: 8px; } .actions .btn { flex: 1; }
.foot { font-size: 12px; color: var(--muted); text-align: center; margin: 4px 0 0; }
#meldTiles { padding-top: 8px; }
.seat { z-index: 1; }
.row2 { display: flex; gap: 8px; }
