/* TableView Mini App — dark, calm, blue (palette taken from assets/Tv.png).
   CSP is style-src 'self': no inline style attributes anywhere — classes only. */
:root {
  color-scheme: dark;
  --bg: #060a14;
  --bg-2: #0a1222;
  --surface: #0e1628;
  --surface-2: #142036;
  --surface-3: #1a2842;
  --line: rgba(140, 175, 255, 0.10);
  --line-strong: rgba(140, 175, 255, 0.20);
  --text: #eaf1ff;
  --text-2: #c3cfe6;
  --muted: #7f8daa;
  --blue: #2f8cff;
  --cyan: #22c3ff;
  --grad: linear-gradient(135deg, #1f7bff 0%, #22b8ff 100%);
  --glow: 0 10px 30px -10px rgba(34, 150, 255, 0.55);
  /* Action colors: same semantics as the bot (hit blue, stand red, double yellow, split green). */
  --hit: #3d9bff;
  --stand: #ff6470;
  --double: #f6c453;
  --split: #35d39a;
  --surrender: #c9d2e3;
  --neutral: #8a97b3;
  --radius: 18px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(34, 140, 255, 0.16) 0%, rgba(34, 140, 255, 0) 60%),
    var(--bg);
  background-attachment: fixed;
}

#app {
  min-height: 100vh;
  min-height: var(--tg-viewport-stable-height, 100vh);
  display: flex;
  flex-direction: column;
  padding: 14px 16px calc(18px + var(--safe-bottom));
  max-width: 520px;
  margin: 0 auto;
}

.center { margin: auto; text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-height: 12px; }
.stack > * + * { margin-top: 12px; }
.icon { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Brand ---------- */
/* logo-mark.png: transparent logo mark derived from assets/Tv.png — no box, no background. */
.hero { text-align: center; padding: 26px 0 8px; position: relative; }
.hero::before {
  content: ""; position: absolute; left: 50%; top: 8px; width: 220px; height: 220px; transform: translateX(-50%);
  background: radial-gradient(circle, rgba(34, 150, 255, 0.22) 0%, rgba(34, 150, 255, 0) 65%);
  pointer-events: none;
}
.logo { display: block; width: 116px; height: 116px; object-fit: contain; margin: 0 auto; position: relative; }
.brand { font-size: 30px; font-weight: 750; letter-spacing: -0.03em; margin: 12px 0 2px; position: relative; }
.brand b { font-weight: 750; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { color: var(--muted); font-size: 15px; position: relative; }

.appbar { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; min-height: 32px; }
.appbar img { width: 30px; height: 30px; object-fit: contain; flex: none; }
.appbar .name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.appbar .name b { color: var(--cyan); font-weight: 700; }
.appbar .spacer { flex: 1; }
.appbar .bar-title { font-size: 15px; font-weight: 700; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.bar-right { display: flex; align-items: center; gap: 6px; min-width: 0; }
.nav-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-width: 40px; height: 40px; padding: 0 10px; margin-left: -4px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-size: 14.5px; font-weight: 650; cursor: pointer;
}
.nav-btn .icon { width: 20px; height: 20px; }
.nav-btn.home { color: var(--cyan); border-color: rgba(47, 140, 255, 0.35); background: rgba(47, 140, 255, 0.12); }
.nav-btn:active { transform: scale(0.96); background: var(--surface-2); }
.pill {
  font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--line); padding: 5px 10px; border-radius: 999px; white-space: nowrap;
}
button.pill { font-family: inherit; cursor: pointer; }
.pill.rules-pill { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; color: var(--cyan); border-color: rgba(47, 140, 255, 0.3); }
.screen-sub { color: var(--muted); font-size: 14px; margin: -8px 2px 6px; }

.screen-title { font-size: 24px; font-weight: 750; letter-spacing: -0.02em; margin: 2px 2px 14px; }
.section-title { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 20px 4px 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; padding: 12px 18px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 16px; font-weight: 650; cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, opacity .15s;
}
.btn:active { transform: scale(0.97); background: var(--surface-3); }
.btn[disabled] { opacity: .35; pointer-events: none; }
.btn.primary { background: var(--grad); border-color: transparent; color: #fff; box-shadow: var(--glow); }
.btn.primary:active { filter: brightness(0.95); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.split { background: rgba(53, 211, 154, 0.14); border-color: rgba(53, 211, 154, 0.45); color: #8ff0c8; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

/* Home: main call to action */
.cta {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 18px; border: 0; border-radius: var(--radius); cursor: pointer;
  background: var(--grad); color: #fff; box-shadow: var(--glow); font: inherit;
  transition: transform .08s ease, filter .15s;
}
.cta:active { transform: scale(0.98); filter: brightness(0.95); }
.cta .ic { width: 46px; height: 46px; border-radius: 14px; background: rgba(255, 255, 255, 0.18); display: grid; place-items: center; flex: none; }
.cta .ic .icon { width: 24px; height: 24px; stroke-width: 2; }
.cta .tx { flex: 1; min-width: 0; }
.cta .t1 { font-size: 18px; font-weight: 750; letter-spacing: -0.01em; }
.cta .t2 { font-size: 13.5px; opacity: .85; margin-top: 2px; }
.cta .chev { opacity: .8; }
.cta.secondary { background: var(--surface); color: var(--text); box-shadow: none; border: 1px solid var(--line-strong); }
.cta.secondary .ic { background: rgba(47, 140, 255, 0.14); color: var(--cyan); }
.cta.secondary .t2 { color: var(--muted); opacity: 1; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: 12px; text-align: left; min-width: 0;
  padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-size: 15px; font-weight: 650; cursor: pointer; min-height: 108px;
  transition: transform .08s ease, background .15s;
}
.tile:active { transform: scale(0.97); background: var(--surface-2); }
.badge {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: rgba(47, 140, 255, 0.14); color: var(--cyan); border: 1px solid rgba(47, 140, 255, 0.22);
}

/* "3 cards" how-to strip on Home */
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.step { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font-size: 12.5px; color: var(--text-2); line-height: 1.25; }
.step .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--cyan); background: rgba(47, 140, 255, 0.12); border: 1px solid rgba(47, 140, 255, 0.25); }

/* ---------- Hand / table ---------- */
.table {
  background: linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: grid; gap: 14px;
}
.seat { display: grid; gap: 8px; }
.seat + .seat { border-top: 1px solid var(--line); padding-top: 14px; }
.seat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.seat-label { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.seat.active .seat-label { color: var(--cyan); }
/* Total: label + a large number, no soft/hard qualifier. */
.total {
  display: inline-flex; align-items: baseline; gap: 7px;
  padding: 3px 12px 4px; border-radius: 12px;
  background: var(--surface-3); border: 1px solid var(--line);
}
.total .lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.total .num { font-size: 26px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; color: var(--text); font-variant-numeric: tabular-nums; }
.total.active { background: rgba(34, 195, 255, 0.10); border-color: rgba(34, 195, 255, 0.35); }
.total.active .num { color: #fff; }
.total.bust .num { color: var(--stand); }
.cards { display: flex; flex-wrap: wrap; gap: 8px; min-height: 64px; align-items: center; }
.card {
  width: 46px; height: 64px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(180deg, #ffffff 0%, #e6edf8 100%); color: #0b1430;
  font-weight: 800; font-size: 20px; letter-spacing: -0.02em;
  box-shadow: 0 6px 14px -6px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}
.card.slot { background: transparent; color: var(--muted); border: 1.5px dashed var(--line-strong); box-shadow: none; font-weight: 600; font-size: 18px; }
.card.slot.next { border-color: var(--cyan); color: var(--cyan); background: rgba(34, 195, 255, 0.06); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(34, 195, 255, 0.0); } 50% { box-shadow: 0 0 0 4px rgba(34, 195, 255, 0.12); } }

/* Recommendation */
.rec {
  --c: var(--neutral);
  position: relative; overflow: hidden;
  border-radius: var(--radius); padding: 16px; background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
  display: grid; grid-template-columns: auto 1fr; column-gap: 14px; align-items: center;
}
.rec::before { content: ""; position: absolute; inset: 0; background: radial-gradient(120% 100% at 0% 0%, color-mix(in srgb, var(--c) 18%, transparent) 0%, transparent 60%); pointer-events: none; }
.rec .mark { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 24px; background: color-mix(in srgb, var(--c) 18%, transparent); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); position: relative; }
.rec .dot { width: 18px; height: 18px; border-radius: 50%; background: var(--c); box-shadow: 0 0 14px color-mix(in srgb, var(--c) 70%, transparent); }
.rec .head { position: relative; min-width: 0; }
.rec .kicker { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.rec .label { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; color: var(--text); }
.rec .why { grid-column: 1 / -1; position: relative; color: var(--text-2); font-size: 14.5px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.rec.compact { padding: 10px 12px; column-gap: 10px; border-radius: var(--radius-sm); }
.rec.compact .mark { width: 34px; height: 34px; border-radius: 10px; font-size: 16px; }
.rec.compact .dot { width: 12px; height: 12px; }
.rec.compact .kicker { display: none; }
.rec.compact .label { font-size: 18px; }
.rec.compact .why { font-size: 13px; margin-top: 8px; padding-top: 8px; }
.rec.HIT { --c: var(--hit); }
.rec.STAND { --c: var(--stand); }
.rec.DOUBLE { --c: var(--double); }
.rec.SPLIT { --c: var(--split); }
.rec.SURRENDER { --c: var(--surrender); }
.rec.BLACKJACK { --c: var(--cyan); }
.rec.BUST { --c: var(--neutral); }

.note { font-size: 13px; color: var(--muted); text-align: center; }
.note.warn { color: var(--double); background: rgba(246, 196, 83, 0.08); border: 1px solid rgba(246, 196, 83, 0.25); border-radius: var(--radius-sm); padding: 9px 12px; text-align: left; }

/* Card picker */
.picker { margin-top: auto; padding-top: 16px; }
.prompt { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15.5px; margin: 0 2px 10px; color: var(--text); }
.prompt::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); flex: none; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.key {
  min-height: 56px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, var(--surface-3) 0%, var(--surface-2) 100%); color: var(--text);
  font: inherit; font-size: 21px; font-weight: 750; cursor: pointer; letter-spacing: -0.02em;
  transition: transform .06s ease, background .12s, border-color .12s;
}
.key:active { transform: scale(0.94); background: rgba(47, 140, 255, 0.25); border-color: var(--blue); }
.actions { margin-top: 12px; display: grid; gap: 10px; }

/* ---------- History ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.stat .badge { width: 32px; height: 32px; border-radius: 10px; }
.stat .badge .icon { width: 18px; height: 18px; }
.stat .n { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1; }
.stat .t { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { --c: var(--neutral); display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 6px 11px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--text-2); }
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.list { display: grid; gap: 8px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.item .cards-txt { font-weight: 650; font-size: 15px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.item .vs { font-size: 12px; font-weight: 600; color: var(--muted); }
.item .meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.act { --c: var(--neutral); font-size: 13px; font-weight: 700; white-space: nowrap; padding: 6px 10px; border-radius: 10px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); }
.HIT { --c: var(--hit); } .STAND { --c: var(--stand); } .DOUBLE { --c: var(--double); } .SPLIT { --c: var(--split); } .SURRENDER { --c: var(--surrender); } .BLACKJACK { --c: var(--cyan); }
.empty { text-align: center; padding: 28px 16px; border-radius: var(--radius); border: 1px dashed var(--line-strong); color: var(--muted); }
.empty .badge { margin: 0 auto 10px; }
.skeleton { height: 72px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Settings ---------- */
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.group-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.group-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.group-head .sub { font-size: 13px; color: var(--muted); margin-top: 1px; }
.group-head.flush { margin-bottom: 0; }
.seg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.opt {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text-2); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; text-align: left;
}
.opt:active { transform: scale(0.98); }
.opt.on { border-color: var(--blue); background: rgba(47, 140, 255, 0.14); color: var(--text); }
.opt .tick { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--line-strong); flex: none; display: grid; place-items: center; }
.opt.on .tick { border-color: var(--blue); background: var(--blue); }
.opt.on .tick::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle { width: 52px; height: 32px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface-3); position: relative; cursor: pointer; flex: none; transition: background .15s; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--muted); transition: transform .18s ease, background .15s; }
.toggle.on { background: var(--grad); border-color: transparent; }
.toggle.on::after { transform: translateX(20px); background: #fff; }
.rules { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.rules li { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--text-2); }
.rules li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); margin-top: 8px; flex: none; }
/* Settings rows that open another screen */
.group.link { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; color: var(--text); font: inherit; cursor: pointer; padding: 14px 16px; }
.group.link .tx { flex: 1; min-width: 0; }
.group.link h3 { margin: 0; font-size: 16px; font-weight: 700; }
.group.link .sub { font-size: 13px; color: var(--cyan); margin-top: 1px; }
.group.link .chev { color: var(--muted); }
.group.link:active { transform: scale(0.99); background: var(--surface-2); }
.tile .rules-chip { margin-top: -4px; font-size: 12px; font-weight: 600; color: var(--cyan); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* Game rules */
.presets { display: grid; gap: 8px; }
.preset {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; cursor: pointer;
}
.preset .tx { flex: 1; min-width: 0; }
.preset .t1 { font-size: 15.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.preset .t2 { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.preset .tag { font-size: 11px; font-weight: 700; color: var(--cyan); background: rgba(47, 140, 255, 0.14); border-radius: 999px; padding: 2px 8px; }
.preset .tick, .rules-custom .tick { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--line-strong); flex: none; display: grid; place-items: center; }
.preset.on { border-color: var(--blue); background: rgba(47, 140, 255, 0.12); }
.preset.on .tick { border-color: var(--blue); background: var(--blue); }
.preset.on .tick::after { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
.preset:active { transform: scale(0.99); }
.rules-custom { margin-top: 12px; }
.rules-custom.on { border-color: var(--blue); }
.rules-custom .group-head { margin-bottom: 8px; }
.rule-row { display: grid; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); }
.rule-label { font-size: 12.5px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.seg.tight { grid-template-columns: repeat(2, 1fr); gap: 6px; }
.seg.tight.three { grid-template-columns: repeat(3, 1fr); }
.seg.tight .opt { min-height: 42px; padding: 8px 10px; justify-content: center; text-align: center; font-size: 14px; }
.btn.reset { margin-top: 6px; min-height: 48px; }
ul.rules { margin: 14px 4px 4px; }

/* How to use */
.guide { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 10px; }
.guide li { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.guide .n { width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 14px; font-weight: 750; color: var(--cyan); background: rgba(47, 140, 255, 0.12); border: 1px solid rgba(47, 140, 255, 0.25); }
.guide .t1 { font-weight: 700; font-size: 15.5px; }
.guide .t2 { color: var(--text-2); font-size: 14px; margin-top: 2px; }

.footer { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 10px 0 4px; }
.footer img { width: 22px; height: 22px; object-fit: contain; opacity: .9; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--line-strong);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center; box-shadow: 0 10px 30px -8px rgba(0, 0, 0, 0.6);
}
.toast[hidden] { display: none; }

@media (max-width: 350px) {
  .nav-btn.home span { display: none; }
  .total .num { font-size: 22px; }
  .seg.tight.three .opt { font-size: 12.5px; padding: 8px 4px; }
  .grid { gap: 6px; }
  .key { min-height: 50px; font-size: 19px; }
  .card { width: 40px; height: 56px; font-size: 18px; }
  .rec .label { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
