/* Blackjack Coach — pixel UI. Palette: Sweetie 16. */
:root {
  --bg: #0f1020;
  --panel: #1a1c2c;
  --panel2: #262b44;
  --line: #333c57;
  --line2: #566c86;
  --text: #f4f4f4;
  --muted: #94b0c2;
  --ink: #0b0c16;

  --red: #b13e53;
  --orange: #ef7d57;
  --yellow: #ffcd75;
  --lime: #a7f070;
  --green: #38b764;
  --teal: #257179;
  --navy: #29366f;
  --blue: #3b5dc9;
  --sky: #41a6f6;
  --cyan: #73eff7;
  --plum: #5d275d;

  --felt: #1f6e3c;
  --felt2: #1c6537;
  --rail: #6b3e1f;
  --rail2: #8a5a2b;

  --act-H: var(--lime);
  --act-S: var(--yellow);
  --act-D: var(--sky);
  --act-P: var(--orange);
  --act-R: var(--muted);

  --cw: 72px;
  --ch: 100px;
  --px: 'Press Start 2P', ui-monospace, Menlo, monospace;
  --vt: 'VT323', ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--vt);
  font-size: 20px;
  line-height: 1.15;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;
}
/* faint CRT scanlines */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(rgba(0, 0, 0, .09) 0 1px, transparent 1px 3px);
  z-index: 100;
}
button { font: inherit; color: inherit; }
h2, h3 { font-family: var(--px); font-weight: normal; margin: 0; }
[hidden] { display: none !important; }

/* Pixel frame: four offset shadows give notched corners. */
.px-btn, .panel, .total-pill, .bet-box, .bank, .upcard-alert, .verdict, .table-msg,
.modal-box, .toast, .rec-action, .seg button, .tabs button, .chip-btn, .hand.active, .lastplay, .gp-card {
  --fc: var(--ink);
  box-shadow: 0 -4px 0 0 var(--fc), 0 4px 0 0 var(--fc), -4px 0 0 0 var(--fc), 4px 0 0 0 var(--fc);
}

/* ---------- Buttons ---------- */
.px-btn {
  --bc: var(--panel2);
  --tc: var(--text);
  font-family: var(--px);
  font-size: 11px;
  line-height: 1;
  background: var(--bc);
  color: var(--tc);
  border: 0;
  padding: 12px 14px;
  margin: 4px;
  cursor: pointer;
  position: relative;
  box-shadow: 0 -4px 0 0 var(--fc), 0 4px 0 0 var(--fc), -4px 0 0 0 var(--fc), 4px 0 0 0 var(--fc),
    inset 0 -4px 0 0 rgba(0, 0, 0, .3), inset 0 4px 0 0 rgba(255, 255, 255, .15);
  white-space: nowrap;
}
.px-btn:hover:not(:disabled) { filter: brightness(1.15); }
.px-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 -4px 0 0 var(--fc), 0 4px 0 0 var(--fc), -4px 0 0 0 var(--fc), 4px 0 0 0 var(--fc),
    inset 0 4px 0 0 rgba(0, 0, 0, .3);
}
.px-btn:disabled { opacity: .3; cursor: not-allowed; }
.px-btn:focus-visible, .seg button:focus-visible, .tabs button:focus-visible, .chip-btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 6px; }
.px-btn.small { font-size: 9px; padding: 9px 10px; }
.px-btn.icon { font-size: 14px; padding: 7px 10px; }
.px-btn.primary { --bc: var(--green); --tc: var(--ink); }
.px-btn.off { opacity: .45; }
.px-btn .key {
  display: inline-block;
  background: rgba(0, 0, 0, .28);
  padding: 3px 4px;
  margin-right: 7px;
  font-size: 8px;
  vertical-align: 1px;
}
.act-H { --bc: var(--act-H); --tc: var(--ink); }
.act-S { --bc: var(--act-S); --tc: var(--ink); }
.act-D { --bc: var(--act-D); --tc: var(--ink); }
.act-P { --bc: var(--act-P); --tc: var(--ink); }
.act-R { --bc: var(--act-R); --tc: var(--ink); }
.px-btn.rec::after {
  content: '';
  position: absolute;
  top: -16px;
  right: -10px;
  width: 16px;
  height: 16px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath fill='%23ffcd75' d='M3 0h1v2h3v1H6v1H5v1h1v2H5V6H4V5H3v1H2v1H1V5h1V4H1V3H0V2h3z'/%3E%3C/svg%3E") no-repeat center / contain;
  filter: drop-shadow(2px 2px 0 var(--ink));
  animation: blink 1s steps(2) infinite;
}
.ico { display: inline-block; width: 1.05em; height: auto; vertical-align: -0.12em; }

/* Segmented control */
.seg { display: inline-flex; flex-wrap: wrap; gap: 8px; padding: 4px; }
.seg button {
  --fc: var(--line);
  font-family: var(--px);
  font-size: 9px;
  background: var(--panel);
  color: var(--muted);
  border: 0;
  padding: 8px 9px;
  cursor: pointer;
}
.seg button.on { background: var(--cyan); color: var(--ink); --fc: var(--ink); }
.seg button:disabled { opacity: .35; cursor: not-allowed; }

/* ---------- Top bar ---------- */
.app { max-width: 1440px; margin: 0 auto; padding: 12px 16px 40px; }
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 8px 4px 18px;
}
.logo {
  font-family: var(--px);
  font-size: 18px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  text-shadow: 2px 2px 0 var(--plum);
}
.logo-sub { font-size: 10px; color: var(--lime); text-shadow: none; align-self: flex-end; margin-bottom: 2px; }
.logo-suit .suit { width: 21px; color: var(--lime); display: block; filter: drop-shadow(2px 2px 0 var(--plum)); }
.back-link { font-family: var(--px); font-size: 8px; color: var(--muted); text-decoration: none; }
.back-link:hover { color: var(--cyan); }
.modes { display: flex; gap: 4px; }
.mode-btn { font-size: 10px; }
.mode-btn.on { --bc: var(--cyan); --tc: var(--ink); }
.bank {
  font-family: var(--px);
  font-size: 13px;
  background: var(--panel);
  padding: 10px 12px;
  margin-left: auto;
  color: var(--yellow);
  display: flex;
  gap: 10px;
  align-items: center;
}
.bank .lbl, .bet-box .lbl { font-size: 8px; color: var(--muted); }
.top-actions { display: flex; gap: 2px; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 22px;
  align-items: start;
}
.side { display: flex; flex-direction: column; gap: 20px; padding: 4px; }

/* ---------- Felt ---------- */
.felt {
  position: relative;
  min-height: 560px;
  padding: 18px 20px 22px;
  margin: 8px;
  background-color: var(--felt);
  background-image: repeating-conic-gradient(var(--felt2) 0 25%, transparent 0 50%);
  background-size: 4px 4px;
  box-shadow:
    0 -8px 0 0 var(--rail), 0 8px 0 0 var(--rail), -8px 0 0 0 var(--rail), 8px 0 0 0 var(--rail),
    0 -12px 0 0 var(--ink), 0 12px 0 0 var(--ink), -12px 0 0 0 var(--ink), 12px 0 0 0 var(--ink),
    -8px -8px 0 0 var(--ink), 8px 8px 0 0 var(--ink), 8px -8px 0 0 var(--ink), -8px 8px 0 0 var(--ink),
    inset 0 0 0 4px var(--rail2), inset 0 6px 0 4px rgba(0, 0, 0, .25);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden; /* cards fly in from off-felt; don't let them widen the page */
}
.zone { display: flex; flex-direction: column; align-items: center; }
.zone-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; min-height: 30px; }
.zone-name { font-family: var(--px); font-size: 10px; color: rgba(244, 244, 244, .55); }
.total-pill {
  font-family: var(--px);
  font-size: 10px;
  background: var(--panel);
  padding: 7px 8px;
  margin: 4px;
}
.total-pill:empty { display: none; }
.cards { display: flex; align-items: flex-start; min-height: calc(var(--ch) + 14px); padding: 4px 0 0 4px; }
.cards .card + .card { margin-left: calc(var(--cw) * -0.42); }
.dealer-zone .cards .card + .card { margin-left: calc(var(--cw) * -0.2); }

.felt-print {
  text-align: center;
  font-family: var(--px);
  color: rgba(255, 205, 117, .55);
  padding: 4px 0;
  margin: auto 0;
}
.fp-main { font-size: 13px; letter-spacing: 1px; }
.fp-sub { font-size: 8px; margin-top: 8px; color: rgba(244, 244, 244, .35); }

.player-zone { position: relative; min-height: 190px; justify-content: flex-end; }
.hands { display: flex; justify-content: center; align-items: flex-end; gap: 22px; flex-wrap: wrap; }
.hand {
  position: relative;
  padding: 10px 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 128px;
}
.hand.active { --fc: var(--yellow); background: rgba(255, 205, 117, .08); }
.hand.active::before {
  content: '';
  position: absolute;
  top: -22px;
  width: 21px;
  height: 12px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 4' shape-rendering='crispEdges'%3E%3Cpath fill='%23ffcd75' d='M0 0h7v1H6v1H5v1H4v1H3V3H2V2H1V1H0z'/%3E%3C/svg%3E") no-repeat center / contain;
  filter: drop-shadow(2px 2px 0 var(--ink));
  animation: bob .7s steps(2) infinite;
}
.hand-meta { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.hand-bet { display: flex; align-items: center; gap: 4px; font-family: var(--px); font-size: 9px; color: var(--yellow); }
.hand-bet .chip-svg { width: 18px; }
.badge {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-6deg);
  font-family: var(--px);
  font-size: 11px;
  padding: 7px 9px;
  color: var(--ink);
  background: var(--muted);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink);
  z-index: 3;
  white-space: nowrap;
  animation: popBadge .25s steps(3) both;
}
.badge.win, .badge.blackjack { background: var(--lime); }
.badge.blackjack { background: var(--yellow); }
.badge.lose, .badge.bust { background: var(--red); color: var(--text); }
.badge.surrender { background: var(--line2); color: var(--text); }

/* Round results and table notices share the grader's spot above your hand
   (only one shows at a time), so neither covers your cards or the dealer alert. */
.table-msg {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  font-family: var(--px);
  font-size: 14px;
  background: var(--panel);
  padding: 9px 12px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  z-index: 7;
  white-space: nowrap;
}
.table-msg.show { opacity: 1; animation: popTop .25s steps(3) both; }
.table-msg.good { color: var(--lime); }
.table-msg.bad { color: #ff7a8f; }
.table-msg small { display: inline; font-size: 8px; color: var(--muted); margin-left: 10px; }

.verdict {
  position: absolute;
  bottom: calc(100% + 6px); /* above the hand, so a new card is never covered */
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--px);
  font-size: 10px;
  padding: 9px 11px;
  background: var(--panel);
  white-space: nowrap;
  z-index: 6;
  opacity: 0;
  pointer-events: none;
}
.verdict.show { opacity: 1; animation: popTop .2s steps(3) both; }
.verdict.ok { --fc: var(--green); color: var(--lime); }
.verdict.no { --fc: var(--red); color: #ff7a8f; }

/* Dealer upcard alert */
.upcard-alert {
  --tier: var(--muted);
  --fc: var(--tier);
  margin: 6px auto 0;
  max-width: 660px;
  width: calc(100% - 16px);
  padding: 10px 12px;
  background: rgba(15, 16, 32, .9);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.upcard-alert .bang {
  font-family: var(--px);
  font-size: 16px;
  color: var(--ink);
  background: var(--tier);
  padding: 6px 8px;
  animation: blink 1.2s steps(2) infinite;
}
.upcard-alert .ua-head { font-family: var(--px); font-size: 10px; color: var(--tier); line-height: 1.5; }
.upcard-alert .ua-plan { font-size: 19px; margin-top: 3px; color: var(--text); }
.tier-bust { --tier: var(--lime); }
.tier-weak { --tier: var(--cyan); }
.tier-strong { --tier: var(--yellow); }
.tier-danger { --tier: #ff6b81; }

/* ---------- Cards ---------- */
.card {
  width: var(--cw);
  height: var(--ch);
  background: var(--text);
  position: relative;
  flex: 0 0 auto;
  box-shadow:
    0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink),
    8px 8px 0 0 rgba(0, 0, 0, .28), 4px 8px 0 0 rgba(0, 0, 0, .28), 8px 4px 0 0 rgba(0, 0, 0, .28),
    inset -4px -4px 0 0 #c2c3c7;
}
.card.red { color: var(--red); }
.card.black { color: var(--panel); }
.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-family: var(--px);
  font-size: 11px;
  letter-spacing: -2px;
  line-height: 1;
}
.corner.tl { top: 6px; left: 5px; }
.corner.br { bottom: 7px; right: 7px; transform: rotate(180deg); }
.suit { display: block; height: auto; }
.suit.tiny { width: 14px; }
.suit.mid { width: 28px; }
.suit.ace { width: 42px; }
.pip, .court { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.court { flex-direction: column; gap: 4px; }
.card.is-court::before {
  content: '';
  position: absolute;
  inset: 22px 14px;
  box-shadow: inset 0 0 0 3px currentColor;
  opacity: .35;
}
.court-letter { font-family: var(--px); font-size: 20px; }
.suit.court-suit { width: 14px; }
.hl-tag {
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--px);
  font-size: 8px;
  padding: 3px 4px;
  color: var(--ink);
  box-shadow: 0 0 0 2px var(--ink);
  z-index: 2;
}
.hl-tag.plus { background: var(--lime); }
.hl-tag.minus { background: #ff6b81; }
.hl-tag.zero { background: var(--muted); }
.card.back { background: var(--red); }
.card.back .back-inner {
  position: absolute;
  inset: 6px;
  background-color: var(--plum);
  background-image: repeating-conic-gradient(var(--red) 0 25%, transparent 0 50%);
  background-size: 8px 8px;
  box-shadow: 0 0 0 2px var(--text);
}
.card.deal { animation: dealIn .3s steps(6) both; }
.dealer-zone .card.deal { --dy: -80px; }
.player-zone .card.deal { --dy: -300px; }
.card.flip { animation: flip .32s steps(4) both; }

/* ---------- Controls ---------- */
.controls { padding: 18px 4px 0; min-height: 86px; }
.ctrl-row { display: none; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 8px; }
.controls[data-show='bet'] .bet-row,
.controls[data-show='act'] .action-row,
.controls[data-show='ins'] .ins-row,
.controls[data-show='drill'] .action-row,
.controls[data-show='drill'] .drill-row { display: flex; }
.controls[data-show='drill'] .drill-row { margin-top: 14px; }
.chips { display: flex; gap: 10px; margin-right: 6px; }
.chip-btn {
  --fc: transparent;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  position: relative;
  width: 52px;
  height: 52px;
  box-shadow: none;
}
.chip-btn .chip-svg { width: 48px; display: block; filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, .45)); }
.chip-btn span {
  position: absolute;
  inset: 0 4px 4px 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--px);
  font-size: 8px;
  color: var(--text);
  text-shadow: 1px 1px 0 var(--ink);
}
.chip-btn:hover:not(:disabled) { transform: translateY(-3px); }
.chip-btn:disabled { opacity: .3; cursor: not-allowed; }
.bet-box {
  font-family: var(--px);
  font-size: 13px;
  background: var(--panel);
  padding: 10px 12px;
  margin: 4px 8px;
  color: var(--yellow);
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 112px;
}
.ins-q { font-family: var(--px); font-size: 11px; color: var(--yellow); margin-right: 8px; }

/* ---------- Side panels ---------- */
.panel {
  --fc: var(--line);
  background: var(--panel);
  padding: 14px 14px 16px;
  margin: 4px;
}
.panel:empty { display: none; }
.panel-title {
  font-family: var(--px);
  font-size: 9px;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.panel-title .tag { color: var(--ink); background: var(--cyan); padding: 3px 5px; font-size: 8px; }
.panel p { margin: 8px 0 0; }
.sit { font-family: var(--px); font-size: 10px; line-height: 1.6; color: var(--text); margin-bottom: 12px; }
.sit .vs { color: var(--muted); }
.rec-action {
  font-family: var(--px);
  font-size: 24px;
  text-align: center;
  padding: 16px 8px;
  margin: 4px 4px 12px;
  color: var(--ink);
  background: var(--muted);
}
.rec-action.hidden-rec { background: var(--panel2); color: var(--muted); font-size: 14px; line-height: 1.5; }
.rec-action small { display: block; font-size: 8px; margin-top: 8px; opacity: .7; }
.bg-H { background: var(--act-H); }
.bg-S { background: var(--act-S); }
.bg-D { background: var(--act-D); }
.bg-P { background: var(--act-P); }
.bg-R { background: var(--act-R); }
.why { font-size: 19px; color: #dfe7ee; }
.callout {
  margin-top: 12px;
  padding: 9px 10px;
  background: var(--panel2);
  border-left: 4px solid var(--yellow);
  font-size: 18px;
}
.callout b { font-family: var(--px); font-size: 9px; display: block; margin-bottom: 5px; font-weight: normal; }
.callout.dev { border-color: var(--cyan); }
.callout.dev b { color: var(--cyan); }
.callout.trap { border-color: var(--orange); }
.callout.trap b { color: var(--orange); }
.callout.note { border-color: var(--line2); color: var(--muted); }
.lastplay { --fc: var(--line); margin-top: 16px; padding: 10px; background: #14162a; }
.lastplay.ok { --fc: var(--green); }
.lastplay.no { --fc: var(--red); }
.lastplay .lp-head { font-family: var(--px); font-size: 9px; margin-bottom: 6px; line-height: 1.5; }
.lastplay.ok .lp-head { color: var(--lime); }
.lastplay.no .lp-head { color: #ff7a8f; }
.lastplay .lp-body { font-size: 18px; color: var(--muted); }
.lbl-short { display: none; }

/* EV bars */
.ev-row { display: grid; grid-template-columns: 96px 1fr 70px; align-items: center; gap: 10px; margin: 7px 0; }
.ev-name { font-family: var(--px); font-size: 8px; display: flex; gap: 6px; align-items: center; }
.ev-name .dot { width: 10px; height: 10px; flex: 0 0 auto; }
.ev-val { font-family: var(--px); font-size: 9px; text-align: right; }
.ev-val.pos { color: var(--lime); }
.ev-val.neg { color: #ff8fa0; }
.ev-bar { position: relative; height: 12px; background: #0f1020; }
.ev-bar::before { content: ''; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--line2); }
.ev-fill { position: absolute; top: 0; bottom: 0; }
.ev-fill.neg { right: 50%; background: var(--red); }
.ev-fill.pos { left: 50%; background: var(--green); }
.ev-row.na { opacity: .3; }
.ev-row.best .ev-name::after { content: ''; width: 9px; height: 9px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath fill='%23ffcd75' d='M3 0h1v2h3v1H6v1H5v1h1v2H5V6H4V5H3v1H2v1H1V5h1V4H1V3H0V2h3z'/%3E%3C/svg%3E") no-repeat center / contain; }
.ev-foot { font-size: 17px; color: var(--muted); margin-top: 10px; }

/* Dealer outlook bars */
.dist-row { display: grid; grid-template-columns: 54px 1fr 48px; gap: 10px; align-items: center; margin: 5px 0; }
.dist-row .lbl { font-family: var(--px); font-size: 8px; color: var(--muted); }
.dist-row .val { font-family: var(--px); font-size: 8px; text-align: right; }
.dist-bar { height: 10px; background: #0f1020; position: relative; }
.dist-bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--line2); }
.dist-row.bust .lbl, .dist-row.bust .val { color: var(--lime); }
.dist-row.bust .dist-bar i { background: var(--lime); }

/* Count panel */
.count-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: center; }
.count-grid .big { font-family: var(--px); font-size: 18px; margin-top: 6px; }
.count-grid .lbl { font-family: var(--px); font-size: 7px; color: var(--muted); }
.big.pos { color: var(--lime); }
.big.neg { color: #ff8fa0; }
.shoe-bar { height: 10px; background: #0f1020; position: relative; margin: 16px 0 6px; }
.shoe-bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--sky); }
.shoe-bar b { position: absolute; top: -5px; bottom: -5px; width: 3px; background: var(--red); }
.shoe-cap { font-family: var(--px); font-size: 7px; color: var(--muted); display: flex; justify-content: space-between; }
.bet-advice {
  margin-top: 14px;
  padding: 10px;
  background: var(--panel2);
  font-size: 19px;
}
.bet-advice b { font-family: var(--px); font-size: 9px; font-weight: normal; color: var(--yellow); display: block; margin-bottom: 6px; line-height: 1.5; }
details.explain { margin-top: 12px; }
details.explain summary { font-family: var(--px); font-size: 8px; color: var(--cyan); cursor: pointer; padding: 4px 0; }
details.explain p { font-size: 18px; color: #dfe7ee; }
.count-check { display: flex; gap: 6px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.count-check input {
  width: 72px;
  font-family: var(--px);
  font-size: 11px;
  background: #0f1020;
  color: var(--text);
  border: 0;
  padding: 9px 8px;
  box-shadow: 0 0 0 3px var(--line2);
  margin: 4px;
}

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-grid div { background: #14162a; padding: 8px; text-align: center; }
.stat-grid .lbl { font-family: var(--px); font-size: 7px; color: var(--muted); display: block; }
.stat-grid .v { font-family: var(--px); font-size: 12px; display: block; margin-top: 6px; }
.mistakes { list-style: none; margin: 12px 0 0; padding: 0; font-size: 17px; }
.mistakes li { padding: 5px 0; border-top: 2px solid var(--line); color: var(--muted); }
.mistakes li b { color: var(--text); font-weight: normal; }
.mistakes li em { font-style: normal; color: #ff8fa0; }

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 18, .86);
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: auto;
  padding: 36px 16px;
}
.modal-box { --fc: var(--line2); background: var(--panel); width: 100%; max-width: 640px; padding: 20px; margin: 4px; }
.modal-box.wide { max-width: 1120px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.modal-head h2 { font-size: 14px; color: var(--yellow); }
.sub-h { font-size: 10px; color: var(--muted); margin: 22px 0 8px; }
.settings { display: flex; flex-direction: column; gap: 10px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.setting .lbl { font-family: var(--px); font-size: 9px; color: var(--text); }
.settings-actions { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.note { font-size: 18px; color: var(--muted); }

.tabs { display: flex; flex-wrap: wrap; gap: 10px; padding: 4px; margin-bottom: 18px; }
.tabs button {
  --fc: var(--line);
  font-family: var(--px);
  font-size: 9px;
  background: var(--panel2);
  color: var(--muted);
  border: 0;
  padding: 10px 11px;
  cursor: pointer;
}
.tabs button.on { background: var(--yellow); color: var(--ink); --fc: var(--ink); }
.guide-body h3 { font-size: 11px; color: var(--yellow); margin: 22px 0 10px; line-height: 1.5; }
.guide-body h3:first-child { margin-top: 0; }
.guide-body p, .guide-body li { font-size: 19px; color: #dfe7ee; }
.guide-body ul { padding-left: 20px; margin: 6px 0; }
.guide-body li { margin: 4px 0; }
.guide-body b { color: var(--text); font-weight: normal; font-family: var(--px); font-size: 9px; }
.chart-wrap { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr)); gap: 24px; }
.chart-scroll { overflow-x: auto; padding-bottom: 6px; }
.chart { border-collapse: separate; border-spacing: 3px; font-family: var(--px); font-size: 9px; }
.chart caption { text-align: left; font-size: 10px; color: var(--yellow); padding: 0 0 8px; }
.chart th { color: var(--muted); font-weight: normal; padding: 4px 6px; white-space: nowrap; }
.chart thead th { color: var(--text); }
.chart td {
  width: 30px;
  height: 26px;
  text-align: center;
  color: var(--ink);
  cursor: pointer;
  position: relative;
  padding: 0;
}
.chart td:hover { filter: brightness(1.2); outline: 2px solid var(--text); }
.chart td.sel { outline: 3px solid var(--text); outline-offset: 1px; }
.chart td.hl { outline: 3px solid var(--cyan); outline-offset: 1px; animation: blink 1s steps(2) infinite; }
.chart td .ix { position: absolute; top: 1px; right: 2px; font-size: 6px; }
.chart td .miss {
  position: absolute;
  bottom: -4px;
  right: -4px;
  background: var(--red);
  color: var(--text);
  font-size: 6px;
  padding: 2px 3px;
  z-index: 1;
}
.c-H { background: var(--act-H); }
.c-S { background: var(--act-S); }
.c-D { background: var(--act-D); }
.c-Ds { background: var(--act-D); box-shadow: inset 0 -5px 0 0 var(--act-S); }
.c-P { background: var(--act-P); }
.c-R { background: var(--act-R); }
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 4px 0 16px; font-size: 17px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 22px; height: 16px; font-style: normal; font-family: var(--px); font-size: 7px; color: var(--ink); text-align: center; line-height: 16px; }
.cell-detail { background: var(--panel2); padding: 12px 14px; margin-top: 18px; min-height: 70px; }
.cell-detail .cd-head { font-family: var(--px); font-size: 10px; line-height: 1.6; margin-bottom: 6px; }
.cell-detail .cd-evs { display: flex; flex-wrap: wrap; gap: 8px 16px; font-family: var(--px); font-size: 8px; color: var(--muted); margin: 8px 0; }
.cell-detail .cd-evs .best { color: var(--lime); }

.gp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: 22px; padding: 4px; }
.gp-card { --fc: var(--line); background: var(--panel2); padding: 12px; margin: 4px; }
.gp-card.tier-bust { --fc: var(--lime); }
.gp-card.tier-weak { --fc: var(--cyan); }
.gp-card.tier-strong { --fc: var(--yellow); }
.gp-card.tier-danger { --fc: #ff6b81; }
.gp-top { display: flex; gap: 14px; align-items: center; }
.gp-top .card { --cw: 48px; --ch: 66px; }
.gp-top .corner { font-size: 8px; }
.gp-top .suit.tiny { width: 7px; }
.gp-top .suit.mid { width: 21px; }
.gp-top .suit.ace { width: 28px; }
.gp-top .court-letter { font-size: 14px; }
.gp-top .card.is-court::before { inset: 14px 9px; }
.gp-label { font-family: var(--px); font-size: 9px; color: var(--tier); line-height: 1.6; }
.gp-bust { font-family: var(--px); font-size: 16px; margin-top: 6px; }
.gp-bust small { font-size: 7px; color: var(--muted); display: block; margin-top: 4px; }
.gp-plan { font-size: 18px; margin: 10px 0 8px; }
.gp-list { list-style: none; padding: 0; margin: 0; }
.gp-list li { font-size: 17px; padding: 3px 0; border-top: 2px solid var(--line); }
.gp-list li b { display: inline-block; width: 96px; color: var(--muted); }
.mini-dist { display: flex; gap: 3px; align-items: flex-end; height: 44px; margin-left: auto; }
.mini-dist div { width: 14px; background: var(--line2); position: relative; }
.mini-dist div.bust { background: var(--lime); }
.mini-dist span { position: absolute; bottom: -14px; left: 50%; transform: translateX(-50%); font-family: var(--px); font-size: 5px; color: var(--muted); }

.g-table { border-collapse: collapse; margin: 8px 0; font-size: 18px; width: 100%; max-width: 640px; }
.g-table th, .g-table td { border: 2px solid var(--line); padding: 6px 8px; text-align: left; }
.g-table th { font-family: var(--px); font-size: 8px; color: var(--muted); font-weight: normal; }
.hl-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.hl-row .grp { display: flex; align-items: center; gap: 6px; background: var(--panel2); padding: 8px 10px; }
.hl-row .grp .card { --cw: 40px; --ch: 56px; }
.hl-row .grp .cards .card + .card { margin-left: -16px; }
.hl-row .corner { font-size: 7px; }
.hl-row .suit.tiny { width: 7px; }
.hl-row .suit.mid, .hl-row .suit.court-suit { width: 14px; }
.hl-row .court-letter { font-size: 11px; }
.hl-row .card.is-court::before { inset: 12px 7px; }
.hl-row .val { font-family: var(--px); font-size: 14px; margin-left: 8px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(200%);
  opacity: 0;
  pointer-events: none;
  background: var(--panel);
  --fc: var(--cyan);
  font-family: var(--px);
  font-size: 10px;
  padding: 12px 14px;
  z-index: 60;
  max-width: calc(100vw - 40px);
  line-height: 1.6;
  text-align: center;
  transition: transform .2s steps(4);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ---------- Animations ---------- */
@keyframes dealIn {
  from { transform: translate(240px, var(--dy, -120px)) rotate(-10deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@keyframes flip { 0% { transform: scaleX(0); } 100% { transform: scaleX(1); } }
@keyframes pop { 0% { transform: translate(-50%, -50%) scale(.6); } 100% { transform: translate(-50%, -50%) scale(1); } }
@keyframes popTop { 0% { transform: translateX(-50%) scale(.6); } 100% { transform: translateX(-50%) scale(1); } }
@keyframes popBadge { 0% { transform: translate(-50%, -50%) rotate(-6deg) scale(.5); } 100% { transform: translate(-50%, -50%) rotate(-6deg) scale(1); } }
@keyframes blink { 50% { opacity: .35; } }
@keyframes bob { 50% { transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
}
@media (max-width: 620px) {
  :root { --cw: 54px; --ch: 76px; }
  body { font-size: 18px; }
  .app { padding: 8px 16px 32px; }
  .topbar { gap: 10px; }
  .logo { font-size: 13px; }
  .bank { margin-left: 0; }
  .felt { padding: 14px 10px 16px; min-height: 480px; }
  .corner { font-size: 9px; }
  .suit.tiny { width: 7px; }
  .suit.mid { width: 21px; }
  .suit.ace { width: 28px; }
  .court-letter { font-size: 14px; }
  .card.is-court::before { inset: 16px 10px; }
  .hand { min-width: 0; padding: 8px 6px 6px; }
  .hands { gap: 12px; }
  .px-btn { font-size: 9px; padding: 10px 9px; }
  .px-btn .key { display: none; }
  .chips { gap: 4px; }
  .chip-btn { width: 44px; height: 44px; }
  .chip-btn .chip-svg { width: 40px; }
  .side { grid-template-columns: minmax(0, 1fr); }
  .table-msg { font-size: 13px; }
  .verdict { font-size: 8px; white-space: normal; width: max-content; max-width: 92%; }
  .upcard-alert .ua-plan { font-size: 17px; }
  .ev-row { grid-template-columns: 84px 1fr 62px; }
}

/* ---------- Fit table + buttons in one screen (laptop / desktop) ---------- */
@media (min-width: 721px) {
  .table-col { display: flex; flex-direction: column; height: clamp(500px, calc(100vh - var(--topbar, 80px) - 20px), 860px); }
  .felt { flex: 1 1 auto; min-height: 0; }
  .controls { flex: 0 0 auto; padding-top: 16px; }
}
@media (min-width: 1081px) {
  /* keep the table in view while scrolling the coach panels */
  .table-col { position: sticky; top: 8px; }
}
@media (min-width: 721px) and (max-height: 820px) {
  :root { --cw: 62px; --ch: 86px; }
  .felt { padding: 12px 16px 14px; gap: 6px; }
  .zone-head { margin-bottom: 4px; min-height: 26px; }
  .cards { min-height: calc(var(--ch) + 10px); }
  .player-zone { min-height: 150px; }
  .hand { padding: 8px 8px 6px; }
  .fp-main { font-size: 11px; }
  .fp-sub { display: none; }
  .upcard-alert { padding: 7px 10px; }
  .upcard-alert .ua-plan { font-size: 17px; }
  .corner { font-size: 10px; }
  .suit.tiny { width: 10px; }
  .suit.mid { width: 21px; }
  .suit.ace { width: 35px; }
  .court-letter { font-size: 17px; }
  .card.is-court::before { inset: 19px 12px; }
}
@media (min-width: 721px) and (max-height: 660px) {
  .felt { gap: 4px; padding-top: 10px; }
  .upcard-alert .ua-plan { font-size: 16px; line-height: 1.05; }
}

/* ---------- Phones: compact header, table + buttons on one screen ---------- */
@media (max-width: 720px) {
  .app { padding: max(8px, env(safe-area-inset-top)) 12px 28px; }
  .topbar { gap: 4px 6px; padding: 2px 0 8px; }
  /* Home button: a real, thumb-sized target (the visible square plus an invisible 44px hit area). */
  .back-link { order: 0; position: relative; display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 30px; margin: 2px 4px 2px 2px;
    font-size: 11px; color: var(--text); background: var(--panel2); box-shadow: 0 0 0 2px var(--ink), inset 0 -3px 0 0 rgba(0, 0, 0, .3); }
  .back-link::after { content: ''; position: absolute; inset: -8px -6px; }
  .back-link:active { transform: translateY(1px); }
  .bl-txt { display: none; }
  .logo { order: 1; font-size: 12px; gap: 6px; }
  .logo-suit .suit { width: 14px; }
  .logo-sub { font-size: 7px; }
  .bank { order: 2; margin-left: auto; font-size: 10px; padding: 7px 8px; }
  .topbar::after { content: ''; order: 3; flex-basis: 100%; height: 0; }
  .bank .lbl { display: none; }
  .modes { order: 4; }
  .top-actions { order: 5; margin-left: auto; }
  .topbar .px-btn { margin: 4px 3px; font-size: 8px; padding: 8px 8px; }
  .topbar .px-btn.icon { font-size: 12px; padding: 5px 8px; }

  .table-col { display: flex; flex-direction: column; height: clamp(430px, calc(100vh - var(--topbar, 90px) - 10px), 860px); height: clamp(430px, calc(100dvh - var(--topbar, 90px) - 10px), 860px); }
  .felt { flex: 1 1 auto; min-height: 0; margin: 6px; padding: 10px 8px; gap: 6px; }
  .felt-print { display: none; }
  .zone-head { margin-bottom: 2px; min-height: 24px; }
  .cards { min-height: calc(var(--ch) + 8px); }
  .player-zone { min-height: 0; }
  .hands { gap: 8px; }
  .hands.many { gap: 4px; }
  .hands.many .card { --cw: 42px; --ch: 60px; }
  .hands.many .suit.mid { width: 14px; }
  .hands.many .suit.ace { width: 21px; }
  .hands.many .court-letter { font-size: 11px; }
  .hands.many .hand { padding: 6px 2px 4px; }
  .upcard-alert { padding: 6px 8px; gap: 8px; width: 100%; margin-top: 2px; }
  .upcard-alert .bang { font-size: 11px; padding: 4px 5px; }
  .upcard-alert .ua-head { font-size: 7px; }
  .upcard-alert .ua-plan { font-size: 15px; line-height: 1.05; }

  .controls { flex: 0 0 auto; min-height: 0; padding: 6px 0 0; }
  .controls[data-show='act'] .action-row, .controls[data-show='drill'] .action-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0 4px; }
  .action-row .px-btn { margin: 4px 2px; padding: 12px 2px; font-size: 8px; }
  .lbl-full { display: none; }
  .lbl-short { display: inline; }
  .controls[data-show='bet'] .bet-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 4px; }
  .bet-row .chips { grid-column: 1 / 3; margin: 0; gap: 4px; }
  .bet-row .bet-box { grid-column: 3; margin: 4px; min-width: 0; justify-content: center; font-size: 11px; }
  .bet-row .px-btn { margin: 4px 2px; padding: 11px 2px; }
  .drill-row { gap: 4px; }
  .controls[data-show='drill'] .drill-row { margin-top: 4px; }
  .drill-row .seg button { padding: 7px 6px; font-size: 7px; }
  .ins-q { flex-basis: 100%; text-align: center; margin: 0 0 2px; font-size: 9px; }

  .modal { padding: 12px 8px; }
  .modal-box { padding: 14px 12px; }
  .tabs { gap: 6px; }
  .tabs button { font-size: 8px; padding: 8px 7px; }
}
@media (max-width: 720px) and (min-height: 680px) {
  .felt-print { display: block; padding: 0; }
  .fp-main { font-size: 9px; }
  .fp-sub { display: none; }
}

/* ---------- Phone coach strip (between table and buttons) ---------- */
.mcoach { display: none; }
@media (max-width: 720px) {
  .mcoach {
    display: block; flex: 0 0 auto; height: 94px; overflow: hidden; margin: 4px 6px 0; padding: 7px 9px;
    background: var(--panel); box-shadow: 0 0 0 3px var(--line); cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .mcoach:empty { display: none; }
  .mc-top { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; overflow: hidden; }
  .mc-tag { font-family: var(--px); font-size: 7px; color: var(--muted); }
  .mc-act { font-family: var(--px); font-size: 11px; color: var(--text); }
  .mc-act.mc-H { color: var(--act-H); } .mc-act.mc-S { color: var(--act-S); } .mc-act.mc-D { color: var(--act-D); }
  .mc-act.mc-P { color: var(--act-P); } .mc-act.mc-R { color: var(--act-R); }
  .mc-meta { margin-left: auto; font-family: var(--px); font-size: 7px; color: var(--cyan); }
  .mc-ev { display: grid; grid-template-columns: repeat(auto-fit, minmax(50px, 1fr)); gap: 3px; margin-top: 6px; }
  .mc-ev div { background: #14162a; padding: 3px 2px; text-align: center; }
  .mc-ev .mark { box-shadow: inset 0 0 0 2px var(--yellow); }
  .mc-ev .l { display: block; font-family: var(--px); font-size: 6px; color: var(--muted); }
  .mc-ev .v { display: block; font-family: var(--px); font-size: 7px; margin-top: 2px; }
  .mc-ev .v.pos { color: var(--lime); } .mc-ev .v.neg { color: #ff8fa0; }
  .mc-why { font-size: 15px; line-height: 1.05; color: #dfe7ee; margin-top: 5px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .mc-ev + .mc-why { -webkit-line-clamp: 2; }
  .mc-why .ico { width: 12px; }
  /* make room: tighter drill controls */
  .controls[data-show='drill'] .drill-row { margin-top: 0; flex-wrap: nowrap; }
  .drill-row .seg { flex-wrap: nowrap; gap: 3px; padding: 2px; }
  .drill-row .seg button { padding: 7px 4px; font-size: 6px; }
  .drill-row #btnNext { padding: 9px 8px; margin: 2px; }
}
@media (max-width: 720px) and (max-height: 640px) {
  .mcoach { height: 80px; }
  .mc-ev + .mc-why { -webkit-line-clamp: 1; }
  .mc-why { -webkit-line-clamp: 2; }
  .upcard-alert .ua-plan { display: none; }
}
/* Phones: the home button replaces the logo's suit icon, keeping the header at two rows. */
@media (max-width: 720px) {
  .logo-suit { display: none; }
  .logo { gap: 5px; }
  .back-link { margin-right: 2px; }
}

/* ---------- Phones: buttons lifted off the bottom edge, pop-up slot above the hand ---------- */
@media (max-width: 720px) {
  .table-col {
    height: clamp(430px, calc(100vh - var(--topbar, 90px) - clamp(28px, 6vh, 48px)), 860px);
    height: clamp(430px, calc(100dvh - var(--topbar, 90px) - clamp(28px, 6dvh, 48px)), 860px);
  }
  :root { --cw: 50px; --ch: 70px; }
  .corner { font-size: 9px; }
  .suit.tiny { width: 7px; }
  .suit.mid { width: 21px; }
  .suit.ace { width: 28px; }
  .court-letter { font-size: 14px; }
  .card.is-court::before { inset: 16px 9px; }
  /* reserved slot: the grader and result pop-ups sit here, never on the alert or cards */
  .player-zone { padding-top: 32px; }
  .verdict, .table-msg { top: 2px; bottom: auto; }
  .table-msg { font-size: 10px; padding: 7px 9px; white-space: normal; width: max-content; max-width: 94%; line-height: 1.4; }
  .table-msg small { font-size: 7px; margin-left: 6px; }
  .hand.active::before { display: none; } /* the active hand's yellow frame marks it; the arrow would sit in the pop-up slot */
  .upcard-alert .ua-plan { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
@media (max-width: 720px) and (max-height: 640px) {
  :root { --cw: 46px; --ch: 64px; }
  .suit.mid { width: 14px; }
  .suit.ace { width: 21px; }
  .upcard-alert .ua-plan { display: none; }
}
/* Phones: reclaim height so the lifted buttons still leave room for everything —
   the dealer's label sits beside their cards, and the hand's padding is tighter. */
@media (max-width: 720px) {
  .dealer-zone { flex-direction: row; justify-content: center; align-items: center; gap: 12px; }
  .dealer-zone .zone-head { flex-direction: column; align-items: center; margin: 0; gap: 4px; min-height: 0; }
  .dealer-zone .cards { min-height: calc(var(--ch) + 6px); }
  .player-zone { padding-top: 30px; }
  .player-zone .cards { min-height: calc(var(--ch) + 4px); }
  .hand { padding: 2px 6px; }
  .hand-meta { margin-top: 4px; }
  .hand-meta .total-pill { padding: 5px 7px; margin: 3px; }
}
