/* Poker Night 牌局帳本 — one deliberate dark "card room" theme (used at night, at the table). */
:root {
  color-scheme: dark;
  --bg: #0b100e;
  --surface: #131b18;        /* cards + chart surface (palette validated against this) */
  --surface-2: #19231f;
  --surface-3: #212d28;
  --felt: #16392c;
  --felt-hi: #21513f;
  --rail: #070a09;
  --ink: #f1efe8;
  --ink-2: #b9c3bc;
  --ink-3: #8a9a91;
  --line: rgba(241, 239, 232, 0.08);
  --line-2: rgba(241, 239, 232, 0.15);
  --grid: #26312c;           /* hairline gridlines */
  --axis: #3a4640;
  --gold: #f0b541;
  --gold-2: #f7cd74;
  --gold-ink: #1d1403;
  /* polarity (diverging): profit warm, loss cool — always paired with a +/− sign */
  --up: #f2b84b;
  --up-fill: #c98500;
  --down: #86b6ef;
  --down-fill: #3987e5;
  /* status (reserved) */
  --ok: #0ca30c;
  --warn: #fab219;
  --crit: #d03b3b;
  /* player identity — categorical slots, fixed order (validated dark palette) */
  --p0: #3987e5; --p1: #d95926; --p2: #199e70; --p3: #c98500;
  --p4: #d55181; --p5: #008300; --p6: #9085e9; --p7: #e66767; --p8: #6f7d76;
  --f-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-xl: 24px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --tabbar-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--f-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.tnum { font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--ink-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------------------------------------------------------------- shell */
.app {
  min-height: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 28px);
  background: radial-gradient(120% 50% at 50% -8%, rgba(33, 81, 63, 0.38), transparent 62%), var(--bg);
}
.app.wide { max-width: 1180px; }
.app.no-tabs { padding-bottom: calc(var(--safe-b) + 28px); }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 8px) 12px 8px;
  background: linear-gradient(to bottom, rgba(11, 16, 14, 0.97), rgba(11, 16, 14, 0.86));
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 17px; font-weight: 750; letter-spacing: 0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; }
.brand .logo { width: 30px; height: 30px; flex: none; }
.brand b { font-size: 19px; font-weight: 800; letter-spacing: 0.02em; }
.brand small { display: block; font-size: 11px; color: var(--ink-3); font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; }
.icon-btn {
  position: relative; flex: none;
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  color: var(--ink-2); background: var(--surface); border: 1px solid var(--line);
}
.icon-btn.bare { background: none; border-color: transparent; }
.icon-btn:active { transform: scale(0.95); }
.icon-btn svg { width: 21px; height: 21px; }
.view { padding: 12px 16px 0; }

/* sync pill */
.sync {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 32px; padding: 0 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 12px; font-weight: 650; color: var(--ink-2);
}
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.sync.on i { background: var(--ok); box-shadow: 0 0 0 3px rgba(12, 163, 12, 0.18); animation: pulse 2.4s ease-in-out infinite; }
.sync.wait i { background: var(--warn); }
.sync.off i { background: var(--ink-3); }
.sync svg { width: 15px; height: 15px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(12, 163, 12, 0.05); } }

/* ---------------------------------------------------------------- tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  padding-bottom: var(--safe-b);
  background: rgba(11, 16, 14, 0.94);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border-top: 1px solid var(--line);
}
.tabbar .inner { max-width: 600px; margin: 0 auto; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; height: var(--tabbar-h); }
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-3); font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
}
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--gold); }

/* ---------------------------------------------------------------- common blocks */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 14px;
}
.card + .card { margin-top: 10px; }
.section-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 22px 2px 10px;
  font-size: 13px; font-weight: 750; color: var(--ink-2); letter-spacing: 0.04em;
}
.section-title .aside { font-size: 12px; font-weight: 600; color: var(--ink-3); letter-spacing: 0; }
.section-title:first-child { margin-top: 6px; }
.row { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.hint { font-size: 12.5px; color: var(--ink-3); line-height: 1.5; }
.hint b { color: var(--ink-2); }
.divider { height: 1px; background: var(--line); margin: 12px 0; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi {
  padding: 11px 12px 10px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
  min-width: 0;
}
.kpi .k { font-size: 11.5px; color: var(--ink-3); font-weight: 650; white-space: nowrap; }
.kpi .v { margin-top: 2px; font-size: 21px; font-weight: 750; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .v small { font-size: 12px; font-weight: 600; color: var(--ink-3); margin-left: 3px; }
.kpi .s { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 14px;
  font-weight: 750; font-size: 15.5px;
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--ink);
  transition: transform 0.12s var(--ease), background 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn.primary {
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  color: var(--gold-ink); border-color: transparent;
  box-shadow: 0 8px 22px rgba(240, 181, 65, 0.22);
}
.btn.danger { color: #ff9c9c; border-color: rgba(208, 59, 59, 0.45); background: rgba(208, 59, 59, 0.08); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 14px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn svg { width: 19px; height: 19px; flex: none; }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1; }
.link-btn { color: var(--gold); font-weight: 700; font-size: 13.5px; padding: 6px 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 36px; padding: 6px 13px; border-radius: 11px;
  background: var(--surface-3); border: 1px solid var(--line);
  color: var(--ink-2); font-size: 14px; font-weight: 650; white-space: nowrap;
}
.chip:active { transform: scale(0.97); }
.chip.on { background: rgba(240, 181, 65, 0.15); border-color: rgba(240, 181, 65, 0.6); color: var(--gold-2); }
.chip.add { color: var(--ink-3); border-style: dashed; }

.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px;
  padding: 3px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--line);
}
.seg button { min-height: 36px; padding: 6px 8px; border-radius: 9px; font-size: 14px; font-weight: 650; color: var(--ink-2); }
.seg button.on { background: var(--ink); color: var(--bg); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); }

.field { display: block; margin-top: 14px; }
.field:first-child { margin-top: 0; }
.field > span { display: block; font-size: 12.5px; font-weight: 700; color: var(--ink-3); margin: 0 2px 6px; }
.input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 13px;
  background: var(--surface-3); border: 1px solid var(--line-2); color: var(--ink);
  font-size: 17px; outline: none;
}
.input:focus { border-color: rgba(240, 181, 65, 0.7); box-shadow: 0 0 0 3px rgba(240, 181, 65, 0.14); }
.input.num { font-variant-numeric: tabular-nums; font-weight: 700; }
.input::placeholder { color: #66756d; font-weight: 500; }
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row .input { flex: 1; min-width: 0; }
.input-row .unit { color: var(--ink-3); font-size: 14px; font-weight: 650; flex: none; }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 12px 2px; }
.switch-row .t { flex: 1; font-size: 15px; font-weight: 600; }
.switch-row .t small { display: block; font-size: 12.5px; color: var(--ink-3); font-weight: 500; }
.toggle { position: relative; width: 51px; height: 31px; flex: none; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.toggle i { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--line-2); transition: background 0.2s; pointer-events: none; }
.toggle i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 25px; height: 25px; border-radius: 50%; background: var(--ink); transition: transform 0.2s var(--ease); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4); }
.toggle input:checked + i { background: var(--ok); border-color: transparent; }
.toggle input:checked + i::after { transform: translateX(20px); }

/* avatar dot / initial */
.av {
  --c: var(--p8);
  position: relative; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--c) 22%, var(--surface-2));
  color: var(--ink); font-weight: 800; font-size: 15px;
  box-shadow: inset 0 0 0 2px var(--c);
}
.av.sm { width: 26px; height: 26px; font-size: 12px; box-shadow: inset 0 0 0 2px var(--c); }
.av .online { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 2px var(--surface); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--p8)); flex: none; }
.key-line { display: inline-block; width: 14px; height: 3px; border-radius: 2px; background: var(--c, var(--p8)); flex: none; }

/* status tags */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
  background: rgba(241, 239, 232, 0.07); color: var(--ink-2);
}
.tag.in { background: rgba(12, 163, 12, 0.13); color: #7fd87f; }
.tag.out { background: rgba(241, 239, 232, 0.07); color: var(--ink-3); }
.tag.host { background: rgba(240, 181, 65, 0.13); color: var(--gold-2); }
.tag svg { width: 12px; height: 12px; }

/* ---------------------------------------------------------------- ledger */
.plist { display: grid; gap: 8px; }
.prow {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line);
  text-align: left; width: 100%;
  transition: background 0.2s;
}
.prow.flash { animation: flash 1.2s var(--ease); }
@keyframes flash { 0% { background: rgba(240, 181, 65, 0.22); } 100% { background: var(--surface); } }
.prow .main { flex: 1; min-width: 0; }
.prow .name { display: flex; align-items: center; gap: 6px; font-size: 16px; font-weight: 750; }
.prow .name span.n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow .meta { margin-top: 2px; font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow .meta b { color: var(--ink-2); font-weight: 650; }
.prow .right { text-align: right; flex: none; }
.prow .right .big { font-size: 17px; font-weight: 750; font-variant-numeric: tabular-nums; }
.prow .right .small { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.plus-btn {
  flex: none; height: 40px; min-width: 64px; padding: 0 10px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  background: rgba(240, 181, 65, 0.12); border: 1px solid rgba(240, 181, 65, 0.35);
  color: var(--gold-2); font-weight: 800; font-size: 14px; font-variant-numeric: tabular-nums;
}
.plus-btn:active { transform: scale(0.95); background: rgba(240, 181, 65, 0.22); }
.add-row {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; border-radius: 16px;
  border: 1.5px dashed var(--line-2); color: var(--ink-2); font-weight: 700;
}
.add-row svg { width: 20px; height: 20px; }

.feed { display: grid; }
.feed .it { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.feed .it:last-child { border-bottom: 0; }
.feed .time { width: 42px; flex: none; color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.feed .txt { flex: 1; min-width: 0; color: var(--ink-2); }
.feed .txt b { color: var(--ink); font-weight: 700; }
.feed .amt { font-variant-numeric: tabular-nums; font-weight: 700; }
.feed .undo { flex: none; color: var(--ink-3); font-size: 12.5px; font-weight: 700; padding: 6px 4px; }

.empty {
  padding: 26px 18px; text-align: center; color: var(--ink-3); font-size: 14px;
  border: 1.5px dashed var(--line-2); border-radius: var(--r-lg);
}
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.empty svg { width: 44px; height: 44px; color: var(--ink-3); margin-bottom: 6px; }

/* ---------------------------------------------------------------- board: table */
.board-grid { display: grid; gap: 14px; }
.tablewrap { position: relative; margin-top: 6px; }
.ptable {
  position: relative;
  width: 100%; aspect-ratio: 1 / 1.16;
  max-width: 560px;
  margin: 0 auto;
}
.ptable .felt {
  position: absolute; inset: 17% 16%;
  border-radius: 999px;
  background:
    radial-gradient(80% 60% at 50% 30%, var(--felt-hi), transparent 72%),
    radial-gradient(120% 120% at 50% 110%, #0e281f, transparent 60%),
    var(--felt);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.35),
    inset 0 16px 40px rgba(0, 0, 0, 0.3),
    0 0 0 9px var(--rail),
    0 0 0 10px rgba(240, 181, 65, 0.22),
    0 24px 50px rgba(0, 0, 0, 0.5);
  display: grid; place-content: center; text-align: center;
}
.ptable.done { aspect-ratio: 16 / 10; }
.ptable.done .felt { inset: 8% 10% 18%; }
.ptable .felt .lbl { font-size: 11.5px; font-weight: 700; color: rgba(241, 239, 232, 0.55); letter-spacing: 0.08em; }
.ptable .felt .tot { font-size: clamp(22px, 7vw, 34px); font-weight: 800; line-height: 1.1; color: var(--ink); }
.ptable .felt .sub2 { font-size: 11.5px; color: rgba(241, 239, 232, 0.6); margin-top: 2px; }
.ptable .felt .warnline { margin-top: 6px; font-size: 11.5px; color: var(--warn); font-weight: 650; }
.seat {
  --c: var(--p8);
  position: absolute; transform: translate(-50%, -50%);
  width: clamp(84px, 25%, 128px);
  padding: 7px 8px 8px; border-radius: 14px;
  background: rgba(19, 27, 24, 0.94); border: 1px solid var(--line-2);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  text-align: center;
  transition: left 0.5s var(--ease), top 0.5s var(--ease), opacity 0.3s;
}
.seat::before { content: ""; position: absolute; left: 10px; right: 10px; top: -1px; height: 3px; border-radius: 0 0 3px 3px; background: var(--c); }
.seat .nm { display: flex; align-items: center; justify-content: center; gap: 5px; font-size: 13px; font-weight: 750; white-space: nowrap; overflow: hidden; }
.seat .nm span { overflow: hidden; text-overflow: ellipsis; }
.seat .ch { margin-top: 2px; font-size: clamp(17px, 5vw, 22px); font-weight: 800; line-height: 1.1; }
.seat .dl { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.seat .src { font-size: 10.5px; color: var(--ink-3); margin-top: 1px; white-space: nowrap; }
.seat.out { opacity: 0.55; }
.seat.lead { border-color: rgba(240, 181, 65, 0.55); }
.seat .crown { position: absolute; top: -13px; left: 50%; transform: translateX(-50%); width: 22px; height: 16px; color: var(--gold); filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.5)); }
.seat .stack { display: flex; flex-direction: column-reverse; align-items: center; height: 24px; margin: 3px auto 0; }
.seat .stack i { display: block; width: 24px; height: 5px; border-radius: 50%; background: var(--c); box-shadow: 0 1.5px 0 rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25); margin-top: -1.5px; flex: none; }
.seat.tap { cursor: pointer; }
.seat.me { box-shadow: 0 0 0 2px var(--gold), 0 10px 24px rgba(0, 0, 0, 0.45); }
.chipflash { animation: chipflash 1.4s var(--ease); }
@keyframes chipflash { 0% { transform: translate(-50%, -50%) scale(1.06); box-shadow: 0 0 0 3px var(--gold), 0 10px 24px rgba(0, 0, 0, 0.45); } 100% { transform: translate(-50%, -50%) scale(1); } }

/* source line under the board */
.srcbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-3); }
.srcbar .live { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 650; }
.srcbar .live i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }

/* diverging P&L bars (HTML) */
.dbars { display: grid; gap: 4px; }
.dbar { display: grid; grid-template-columns: minmax(56px, 92px) 1fr auto; align-items: center; gap: 8px; min-height: 30px; }
.dbar .who { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 650; min-width: 0; }
.dbar .who span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dbar .track { position: relative; height: 30px; }
.dbar .track::before { content: ""; position: absolute; left: 50%; top: 2px; bottom: 2px; width: 1px; background: var(--axis); }
.dbar .bar { position: absolute; top: 50%; height: 16px; margin-top: -8px; transition: width 0.6s var(--ease), left 0.6s var(--ease); }
.dbar .bar.pos { left: 50%; background: var(--up-fill); border-radius: 0 4px 4px 0; }
.dbar .bar.neg { right: 50%; background: var(--down-fill); border-radius: 4px 0 0 4px; }
.dbar .val { min-width: 74px; text-align: right; font-size: 13px; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink); }

/* trend chart */
.chart-card { padding: 12px 10px 10px; }
.chart { position: relative; touch-action: pan-y; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .tick { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; transition: opacity 0.2s; }
.chart .ln.dim, .chart .endpt.dim { opacity: 0.16; }
.chart .endpt { stroke: var(--surface); stroke-width: 2; }
.chart .xhair { stroke: var(--ink-3); stroke-width: 1; }
.chart .endlbl { fill: var(--ink-2); font-size: 11.5px; font-weight: 650; }
.tip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 140px; padding: 8px 10px; border-radius: 10px;
  background: rgba(8, 12, 10, 0.95); border: 1px solid var(--line-2);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5); font-size: 12.5px;
}
.tip .tt { color: var(--ink-3); font-size: 11.5px; margin-bottom: 4px; }
.tip .tr { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 6px; line-height: 1.7; }
.tip .tr b { font-variant-numeric: tabular-nums; font-weight: 750; text-align: right; }
.tip .tr span { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 8px; }
.legend button { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 9px; font-size: 12.5px; font-weight: 650; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); }
.legend button.on { border-color: var(--line-2); color: var(--ink); background: var(--surface-3); }
.legend button.off { opacity: 0.45; }

/* ---------------------------------------------------------------- settle */
.rtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.rtable th { text-align: right; font-size: 11.5px; color: var(--ink-3); font-weight: 700; padding: 0 4px 8px; white-space: nowrap; }
.rtable th:first-child { text-align: left; }
.rtable td { padding: 10px 4px; border-top: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rtable td:first-child { text-align: left; }
.rtable td .who { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; max-width: 110px; }
.rtable td .who span { overflow: hidden; text-overflow: ellipsis; }
.rtable td.net { font-weight: 800; font-size: 15px; }
.rtable tr.total td { font-weight: 750; color: var(--ink-2); border-top: 1px solid var(--line-2); }
.cashlist { display: grid; gap: 8px; }
.cashrow { display: grid; grid-template-columns: 1fr 132px; align-items: center; gap: 10px; }
.cashrow .who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.cashrow .who .n { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cashrow .who .s { font-size: 12px; color: var(--ink-3); }
.cashrow .input { min-height: 44px; font-size: 17px; text-align: right; }
.checkline {
  display: flex; align-items: center; gap: 8px; margin-top: 12px; padding: 10px 12px; border-radius: 12px;
  background: var(--surface-2); font-size: 13.5px; color: var(--ink-2);
}
.checkline b { font-variant-numeric: tabular-nums; color: var(--ink); }
.checkline.ok { background: rgba(12, 163, 12, 0.1); }
.checkline.bad { background: rgba(250, 178, 25, 0.1); }
.checkline svg { width: 18px; height: 18px; flex: none; }
.checkline.ok svg { color: var(--ok); }
.checkline.bad svg { color: var(--warn); }
.alert {
  display: flex; gap: 10px; padding: 12px; border-radius: 14px;
  background: rgba(250, 178, 25, 0.09); border: 1px solid rgba(250, 178, 25, 0.35);
  font-size: 14px; color: var(--ink-2);
}
.alert svg { width: 20px; height: 20px; color: var(--warn); flex: none; margin-top: 1px; }
.alert b { color: var(--ink); }
.xfers { display: grid; gap: 8px; }
.xfer {
  display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: center; gap: 8px;
  padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line);
}
.xfer .p { display: flex; align-items: center; gap: 7px; min-width: 0; font-weight: 700; }
.xfer .p span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xfer .p.to { justify-content: flex-start; }
.xfer .arrow { color: var(--ink-3); width: 20px; height: 20px; }
.xfer .amt { font-size: 17px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.xfer.paid { opacity: 0.5; }
.xfer.paid .amt { text-decoration: line-through; }
.xfer .paidbtn { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--line-2); display: grid; place-items: center; color: transparent; }
.xfer.paid .paidbtn { background: var(--ok); border-color: var(--ok); color: #fff; }
.xfer .paidbtn svg { width: 17px; height: 17px; }

/* ---------------------------------------------------------------- home */
.hero {
  position: relative; overflow: hidden;
  margin-top: 8px; padding: 22px 18px 18px; border-radius: var(--r-xl);
  background:
    radial-gradient(90% 80% at 85% 0%, rgba(240, 181, 65, 0.16), transparent 60%),
    radial-gradient(80% 90% at 0% 100%, rgba(33, 81, 63, 0.7), transparent 70%),
    var(--surface);
  border: 1px solid var(--line-2);
}
.hero h2 { position: relative; margin: 0; padding-right: 64px; font-size: 24px; line-height: 1.25; font-weight: 800; }
.hero p { position: relative; margin: 8px 0 16px; color: var(--ink-2); font-size: 14.5px; }
.hero .art { position: absolute; right: -10px; top: -10px; width: 92px; opacity: 0.85; pointer-events: none; }
.glist { display: grid; gap: 8px; }
.gitem {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 13px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line);
}
.gitem .ic { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; background: var(--felt); color: var(--gold-2); flex: none; }
.gitem .ic svg { width: 22px; height: 22px; }
.gitem .main { flex: 1; min-width: 0; }
.gitem .t { font-weight: 750; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gitem .s { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gitem .chev { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
.lb { display: grid; }
.lb .r { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; padding: 10px 2px; border-top: 1px solid var(--line); }
.lb .r:first-child { border-top: 0; }
.lb .rk { color: var(--ink-3); font-weight: 800; font-size: 13px; text-align: center; font-variant-numeric: tabular-nums; }
.lb .nm { font-weight: 700; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb .nm small { color: var(--ink-3); font-weight: 600; margin-left: 6px; font-size: 12px; }
.lb .v { font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- sheets, toast, dialogs */
.backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.55); opacity: 0; transition: opacity 0.25s; }
.backdrop.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  max-width: 600px; margin: 0 auto;
  max-height: calc(100% - var(--safe-t) - 24px); overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 18px calc(var(--safe-b) + 20px);
  border-radius: 22px 22px 0 0;
  background: #141d19; border: 1px solid var(--line-2); border-bottom: 0;
  box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.5);
  transform: translateY(100%); transition: transform 0.32s var(--ease);
}
.sheet.show { transform: none; }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 2px auto 12px; }
.sheet h3 { margin: 0 0 4px; font-size: 20px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.sheet .lead { color: var(--ink-3); font-size: 13.5px; margin-bottom: 14px; }
.sheet .foot { margin-top: 18px; display: grid; gap: 8px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 80;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 12px;
  width: max-content; max-width: calc(100vw - 32px); padding: 11px 14px 11px 16px; border-radius: 14px;
  background: #f1efe8; color: #0b100e; font-weight: 650; font-size: 14.5px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  transition: opacity 0.2s, transform 0.25s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { color: #8a5a00; font-weight: 800; padding: 2px 4px; }
.qr { display: grid; place-items: center; padding: 14px; border-radius: 18px; background: #fff; width: min(260px, 72vw); margin: 4px auto 0; }
.qr svg { width: 100%; height: auto; display: block; }
.linkbox {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  padding: 8px 8px 8px 12px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink-2);
}
.linkbox code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
details.disclose { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
details.disclose > summary { list-style: none; cursor: pointer; font-weight: 700; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
details.disclose > summary::-webkit-details-marker { display: none; }
details.disclose > summary svg { width: 16px; height: 16px; transition: transform 0.2s; }
details.disclose[open] > summary svg { transform: rotate(90deg); }
.big-num-input { font-size: 30px !important; font-weight: 800; text-align: center; min-height: 64px !important; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.quick button { min-height: 44px; border-radius: 12px; background: var(--surface-3); border: 1px solid var(--line); font-weight: 750; font-variant-numeric: tabular-nums; }
.quick button:active { transform: scale(0.97); }
.hist { display: grid; margin-top: 6px; }
.hist .h { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.hist .h:last-child { border-bottom: 0; }
.hist .h .t { color: var(--ink-3); font-size: 12.5px; width: 44px; font-variant-numeric: tabular-nums; }
.hist .h .x { flex: 1; }
.hist .h .a { font-weight: 750; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- AI camera */
body.cam-open { overflow: hidden; }
.cam { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; background: #000; }
.cam-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.cam-stage video, .cam-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.cam-ov { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.cam-msg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(420px, calc(100% - 48px));
  padding: 16px; border-radius: 16px; background: rgba(19, 27, 24, 0.94); border: 1px solid var(--line-2);
  text-align: center; font-size: 14.5px; color: var(--ink-2); line-height: 1.6;
}
.cam-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 8px) 12px 18px;
  background: linear-gradient(rgba(0, 0, 0, 0.72), transparent);
}
.cam-title { flex: 1; display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; }
.cam-state { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: rgba(241, 239, 232, 0.12); color: var(--ink-2); }
.cam-state.on { background: rgba(12, 163, 12, 0.2); color: #8fe08f; }
.cam-state.busy { background: rgba(240, 181, 65, 0.2); color: var(--gold-2); }
.cam-panel {
  flex: none; max-height: 48vh; overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 16px calc(var(--safe-b) + 14px);
  background: #111a16; border-top: 1px solid var(--line-2);
}
.cam-h { font-size: 16px; font-weight: 800; margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; }
.cam-step { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cam-step .ck { width: 24px; height: 24px; border-radius: 50%; flex: none; border: 1.5px solid var(--line-2); display: grid; place-items: center; }
.cam-step.ok .ck { background: var(--ok); border-color: var(--ok); color: #fff; }
.cam-step .ck svg { width: 15px; height: 15px; }
.cam-step .tx { flex: 1; min-width: 0; }
.cam-step .tx b { display: block; font-size: 14.5px; }
.cam-step .tx small { display: block; font-size: 12.5px; color: var(--ink-3); }
.cam-rows { display: grid; }
.cam-row { display: grid; grid-template-columns: 10px auto 1fr auto; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.cam-row .nm { font-weight: 700; }
.cam-row .nt { color: var(--ink-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cam-row .v { font-variant-numeric: tabular-nums; font-size: 15px; }
.cam-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; margin-top: 10px; font-size: 12.5px; color: var(--ink-3); }
.chiped { display: grid; gap: 8px; }
.chiprow { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 8px; align-items: center; }
.chiprow select.input { appearance: none; -webkit-appearance: none; }
@media (orientation: landscape) and (max-height: 560px) {
  .cam { flex-direction: row; }
  .cam-panel { width: min(360px, 44vw); max-height: none; border-top: 0; border-left: 1px solid var(--line-2); padding-top: calc(var(--safe-t) + 14px); }
}

/* ---------------------------------------------------------------- wide screens (TV / laptop board) */
@media (min-width: 900px) {
  .app.wide .board-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; }
  .app.wide .board-grid .side { display: grid; gap: 14px; }
  /* keep the whole table on screen (TV / laptop): header + tab bar take ~190px */
  .app.wide .ptable { max-width: min(560px, calc((100vh - 190px) / 1.16)); }
}
@media (max-width: 360px) {
  .kpi .v { font-size: 18px; }
  .seat { width: 80px; padding: 6px 5px 7px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
