/* Blackjack Trainer - dark felt theme */

:root {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --bg-sunken: #0a0d12;
  --felt: #14532d;
  --felt-2: #0f3d22;
  --line: #263041;
  --text: #e6edf3;
  --text-dim: #8b98a9;
  --text-faint: #5c6a7d;
  --gold: #d9a441;
  --good: #3fb950;
  --bad: #f05252;
  --warn: #e3b341;
  --accent: #4a9eff;
  --card-face: #f6f7f9;
  --card-ink: #14181f;
  --card-red: #c0392b;
  --radius: 10px;
  /* Card sizing drives every card-relative font size below. These are the
     SIMPLE (default) values; advanced mode overrides them. */
  --card-w: 104px;
  --card-h: 146px;
  --shadow: 0 6px 20px rgba(0,0,0,.45);
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

/* Author display rules outrank the UA [hidden] rule, so hidden rows would
   otherwise keep their flex/grid display. Make [hidden] actually hide. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; overflow: hidden; }

button { font: inherit; color: inherit; cursor: pointer; }
kbd {
  font: 600 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 4px;
  padding: 2px 4px;
  margin-left: 6px;
  opacity: .75;
  vertical-align: middle;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 16px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  background: var(--gold); color: #1a1206;
  font-weight: 800; font-size: 14px;
  border-radius: 7px;
}
.brand-text { font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }

.shoe-meter { flex: 1 1 auto; min-width: 90px; max-width: 320px; }
.shoe-meter-bar {
  position: relative;
  height: 7px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.shoe-meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #6fb4ff);
  transition: width .25s ease;
}
.shoe-meter-cut {
  position: absolute; top: -2px; bottom: -2px;
  width: 2px;
  background: var(--gold);
  box-shadow: 0 0 5px var(--gold);
}
.shoe-meter-label {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
}

.hud { display: flex; gap: 8px; flex: 0 0 auto; }
.hud-item {
  display: flex; flex-direction: column;
  min-width: 86px;
  padding: 5px 11px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.25;
}
.hud-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.hud-sys { color: var(--text-dim); text-transform: none; letter-spacing: 0; }
.hud-value { font: 700 17px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.hud-sub { font-size: 10px; color: var(--text-faint); }
.hud-value.pos { color: var(--good); }
.hud-value.neg { color: var(--bad); }
#countBox.is-hidden .hud-value { color: var(--text-faint); letter-spacing: .1em; }

.topbar-actions { display: flex; gap: 5px; flex: 0 0 auto; }
.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  transition: background .12s, border-color .12s;
}
.icon-btn:hover { background: #1d2431; border-color: #37445c; }
.icon-btn.is-on { background: var(--accent); border-color: var(--accent); color: #06121f; }

/* ---------- layout ---------- */

.layout { flex: 1 1 auto; display: flex; min-height: 0; }

.felt {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px 18px 16px;
  background:
    radial-gradient(120% 85% at 50% 0%, var(--felt) 0%, var(--felt-2) 55%, #0b2d19 100%);
  overflow-y: auto;
  overflow-x: hidden;
}
/* Mistake feedback.
 *
 * Full-viewport motion and a bright wash across the centre of the screen are
 * genuinely fatiguing when repeated a few hundred times a session, which is
 * exactly what a trainer asks of you. The default ("soft") therefore keeps
 * motion LOCAL to the element you got wrong and turns the red into an edge
 * vignette, so the centre of the screen - where your eyes actually are -
 * stays calm. body[data-fx] selects the intensity. */

/* Small, local, quickly damped. Used for hands and buttons. */
@keyframes nudge {
  25%  { transform: translateX(-3px); }
  55%  { transform: translateX(3px); }
  80%  { transform: translateX(-1.5px); }
  100% { transform: translateX(0); }
}

/* The original whole-table shake, kept for anyone who wants it. */
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

.hand.nudge { animation: nudge .28s ease-out; }
.felt.shake { animation: shake .38s cubic-bezier(.36,.07,.19,.97); }

/* Soft (default): red arrives from the edges, never across the middle. */
.felt.flash-bad::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(118% 96% at 50% 50%,
              rgba(240,82,82,0) 54%, rgba(240,82,82,.20) 100%);
  pointer-events: none;
  animation: fadeOut .5s ease forwards;
}

/* Strong: the original centre wash. */
body[data-fx="full"] .felt.flash-bad::after {
  background: radial-gradient(80% 60% at 50% 50%,
              rgba(240,82,82,.28), rgba(240,82,82,0) 70%);
  animation: fadeOut .55s ease forwards;
}

/* Correct answers get no screen flash in soft mode. They happen constantly,
   and a green pulse on every one of them is most of the flicker. The button
   turning green and the banner are enough. */
body[data-fx="full"] .felt.flash-good::after {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(80% 60% at 50% 50%,
              rgba(63,185,80,.16), rgba(63,185,80,0) 70%);
  pointer-events: none;
  animation: fadeOut .4s ease forwards;
}

@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

.rules-strip {
  align-self: center;
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: rgba(255,255,255,.38);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: 4px 14px;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.dealer-area, .player-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.player-area {
  flex: 0 0 auto;
  justify-content: center;
  flex-direction: row;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  padding: 6px 0;
}

.dealer-area { margin-top: auto; }

.seat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.5);
}
.seat-total {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  background: rgba(0,0,0,.4);
  border-radius: 999px;
  font: 700 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  letter-spacing: 0;
}

/* ---------- cards ---------- */

.cards {
  display: flex;
  gap: calc(var(--card-w) * 0.1);
  min-height: var(--card-h);
  align-items: flex-start;
}

.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  background: var(--card-face);
  color: var(--card-ink);
  border-radius: calc(var(--card-w) * 0.09);
  box-shadow: var(--shadow);
  font-weight: 800;
  animation: dealIn .22s ease-out;
  flex: 0 0 auto;
}
@keyframes dealIn {
  from { opacity: 0; transform: translateY(-16px) rotate(-4deg); }
  to   { opacity: 1; transform: none; }
}
.card.red { color: var(--card-red); }

/* Corner indices, top-left and bottom-right rotated, as on a real card. */
.card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: .95;
}
.card .corner.tl { top: 5.5%; left: 7%; }
.card .corner.br { bottom: 5.5%; right: 7%; opacity: .55; }
.card .corner b { font-size: calc(var(--card-w) * 0.25); font-weight: 800; letter-spacing: -.03em; }
.card .corner i { font-size: calc(var(--card-w) * 0.18); font-style: normal; }

.card .face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--card-w) * 0.46);
  opacity: .92;
}

.card.back {
  background:
    repeating-linear-gradient(45deg, #1e3a5f 0 6px, #16304f 6px 12px);
  border: 2px solid #0d1d31;
}
/* Inner panel gives the back some depth instead of a flat hatch. */
.card.back::after {
  content: '';
  position: absolute;
  inset: 8%;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: calc(var(--card-w) * 0.05);
}

.hand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 9px 12px 10px;
  border-radius: 12px;
  border: 2px solid transparent;
  transition: border-color .15s, background .15s;
}
.hand.is-active {
  border-color: var(--gold);
  background: rgba(217,164,65,.07);
  box-shadow: 0 0 0 4px rgba(217,164,65,.07);
}
.hand.is-done { opacity: .62; }
.hand-meta { display: flex; gap: 7px; align-items: center; font-size: 11px; color: rgba(255,255,255,.55); }
.hand-bet {
  font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(0,0,0,.35);
  border-radius: 999px;
  padding: 3px 8px;
}
.hand-result {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  padding: 2px 9px; border-radius: 999px;
}
.hand-result.win, .hand-result.blackjack { background: rgba(63,185,80,.2); color: #7ee787; }
.hand-result.lose { background: rgba(240,82,82,.2); color: #ff9c9c; }
.hand-result.push { background: rgba(255,255,255,.12); color: var(--text-dim); }
.hand-result.surrender { background: rgba(227,179,65,.18); color: #f0cc6e; }

/* ---------- banner ---------- */

.banner {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px 14px;
  margin: 6px auto;
  max-width: 620px;
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.45;
  color: transparent;
  transition: background .15s, color .15s, border-color .15s;
  border: 1px solid transparent;
}
.banner.info { background: rgba(0,0,0,.32); color: rgba(255,255,255,.8); border-color: rgba(255,255,255,.1); }
.banner.good { background: rgba(63,185,80,.16); color: #9ff0a8; border-color: rgba(63,185,80,.35); }
.banner.bad  { background: rgba(240,82,82,.18); color: #ffb3b3; border-color: rgba(240,82,82,.45); }
.banner strong { color: #fff; }
.banner .why { display: block; margin-top: 3px; font-size: 12px; opacity: .8; }

/* ---------- controls ---------- */

.controls { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 10px; padding-top: 4px; margin-top: auto; }

.action-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.act {
  min-width: 104px;
  padding: 11px 16px;
  background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: var(--radius);
  font-weight: 650;
  letter-spacing: .01em;
  backdrop-filter: blur(3px);
  transition: transform .1s, background .12s, border-color .12s, opacity .12s;
}
.act:hover:not(:disabled) { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.3); }
.act:active:not(:disabled) { transform: translateY(1px); }
.act:disabled { opacity: .25; cursor: not-allowed; }
.act.wrong { animation: nudge .28s ease-out; background: rgba(240,82,82,.28); border-color: var(--bad); }
body[data-fx="full"] .act.wrong { animation: buzz .36s cubic-bezier(.36,.07,.19,.97); background: rgba(240,82,82,.35); }
@keyframes buzz {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}
.act.right { background: rgba(63,185,80,.32); border-color: var(--good); }
.act.hint-correct { box-shadow: 0 0 0 2px var(--good) inset; }

.act-yes { background: rgba(63,185,80,.2); border-color: rgba(63,185,80,.45); }
.act-no  { background: rgba(240,82,82,.16); border-color: rgba(240,82,82,.4); }
.insurance-row { align-items: center; gap: 10px; }
.insurance-prompt { font-size: 13px; color: rgba(255,255,255,.8); }

.deal-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center; }

.bet-control {
  display: flex; align-items: center; gap: 2px;
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  padding: 3px;
}
.chip-btn {
  width: 28px; height: 28px;
  border: 0; border-radius: 999px;
  background: rgba(255,255,255,.1);
  font-weight: 700;
}
.chip-btn:hover { background: rgba(255,255,255,.2); }
.bet-amount {
  min-width: 58px; text-align: center;
  font: 700 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--gold);
}
.bet-amount::before { content: '$'; opacity: .55; }

.deal-btn {
  padding: 11px 30px;
  background: var(--gold);
  color: #1a1206;
  border: 0;
  border-radius: var(--radius);
  font-weight: 750;
  transition: filter .12s, transform .1s;
}
.deal-btn:hover { filter: brightness(1.08); }
.deal-btn:active { transform: translateY(1px); }
.deal-btn:disabled { opacity: .35; cursor: not-allowed; }
.deal-btn kbd { background: rgba(0,0,0,.16); border-color: rgba(0,0,0,.2); }

.mini-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: rgba(255,255,255,.62); }

/* ---------- side panel ---------- */

.panel {
  flex: 0 0 340px;
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border-left: 1px solid var(--line);
  min-height: 0;
}
.panel[hidden] { display: none; }

.panel-tabs { display: flex; border-bottom: 1px solid var(--line); flex: 0 0 auto; }

/* The panel overlays the whole page on small screens and sits ABOVE the top
   bar, which means the gear that opened it is physically covered. Without a
   close control of its own the panel becomes a one-way door on a phone. */
.panel-close {
  flex: 0 0 auto;
  width: 46px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-dim);
  font-size: 22px;
  line-height: 1;
}
.panel-close:hover { color: var(--text); background: rgba(255,255,255,.05); }

.panel-scrim { display: none; }
.tab {
  flex: 1;
  padding: 11px 8px;
  background: none; border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-size: 13px; font-weight: 600;
}
.tab.is-active { color: var(--text); border-bottom-color: var(--gold); }

.panel-body { flex: 1 1 auto; overflow-y: auto; padding: 14px; }
.tab-page { display: none; }
.tab-page.is-active { display: block; }

.group { margin-bottom: 22px; }
.group h3 {
  margin: 0 0 10px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint);
}

.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.field > span { color: var(--text-dim); flex: 0 0 auto; }
.field select {
  flex: 1 1 auto; min-width: 0; max-width: 190px;
  padding: 6px 8px;
  background: var(--bg-sunken);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit; font-size: 12.5px;
}
.check { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; font-size: 13px; color: var(--text-dim); line-height: 1.4; cursor: pointer; }
.check input { margin-top: 2px; flex: 0 0 auto; accent-color: var(--gold); }

.edge-note { font-size: 12px; color: var(--text-faint); margin: 10px 0 0; }
.edge-note strong { color: var(--warn); }
.sys-blurb { font-size: 12px; color: var(--text-faint); line-height: 1.5; margin: 2px 0 10px; }
.hint { font-size: 12px; color: var(--text-faint); margin: 0 0 10px; }

.warn {
  font-size: 12px; line-height: 1.5;
  color: #f0cc6e;
  background: rgba(227,179,65,.1);
  border: 1px solid rgba(227,179,65,.3);
  border-radius: 7px;
  padding: 8px 10px;
  margin: 10px 0 0;
}
.warn.small { font-size: 11.5px; }

.ghost-btn {
  width: 100%;
  padding: 9px;
  margin-bottom: 8px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
}
.ghost-btn:hover { background: #1d2431; }
.ghost-btn.danger { color: #ff9c9c; border-color: rgba(240,82,82,.3); }
.ghost-btn.danger:hover { background: rgba(240,82,82,.12); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
.stat-k { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.stat-v { font: 700 16px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.stat-v.pos { color: var(--good); }
.stat-v.neg { color: var(--bad); }

.mistake-list, .leak-list { list-style: none; margin: 0; padding: 0; }
.mistake-list li, .leak-list li {
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-left: 3px solid var(--bad);
  border-radius: 6px;
  font-size: 12.5px;
  line-height: 1.5;
}
.mistake-list .m-hand { font-weight: 650; }
.mistake-list .m-detail { color: var(--text-faint); }
.mistake-list .m-detail .chose { color: #ff9c9c; }
.mistake-list .m-detail .right { color: #7ee787; }
.leak-list .l-count { float: right; color: var(--text-faint); font-size: 11px; }
.empty { color: var(--text-faint); font-size: 12.5px; font-style: italic; }

/* ---------- modals ---------- */

.modal {
  position: fixed; inset: 0;
  background: rgba(2,5,10,.72);
  display: grid; place-items: center;
  padding: 20px;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
  max-width: 100%;
  max-height: 90vh;
  display: flex; flex-direction: column;
  width: 420px;
}
.modal-wide { width: 900px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.modal-sub { font-size: 12px; font-weight: 400; color: var(--text-faint); margin-left: 8px; }
.modal-body { padding: 16px; overflow: auto; flex: 1 1 auto; }

.quiz-prompt { margin: 0 0 12px; font-size: 14px; }
.quiz-input {
  width: 100%;
  padding: 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: 700 22px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
}
.quiz-actions { margin-top: 12px; display: flex; justify-content: center; }
.quiz-result { margin: 12px 0 0; font-size: 13px; text-align: center; line-height: 1.6; }
.quiz-result.good { color: #9ff0a8; }
.quiz-result.bad { color: #ffb3b3; }

/* ---------- strategy chart ---------- */

.chart-block { margin-bottom: 18px; }
.chart-block h3 {
  margin: 0 0 7px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint);
}
table.chart { border-collapse: separate; border-spacing: 2px; width: 100%; }
table.chart th, table.chart td {
  text-align: center;
  font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 5px 2px;
  border-radius: 4px;
  min-width: 30px;
}
table.chart th { color: var(--text-faint); font-weight: 700; background: var(--bg-sunken); }
.c-H  { background: #6e2b2b; color: #ffd9d9; }
.c-S  { background: #2b5e33; color: #d6ffd9; }
.c-D  { background: #2a4d7a; color: #d6e8ff; }
.c-Ds { background: #2a4d7a; color: #d6e8ff; }
.c-P  { background: #6a4a1e; color: #ffe9c2; }
.c-Ph { background: #6a4a1e; color: #ffe9c2; opacity: .8; }
.c-Rh, .c-Rs, .c-Rp { background: #4a3a6b; color: #e4d9ff; }
td.is-current { outline: 2px solid var(--gold); outline-offset: 1px; }

.chart-legend {
  display: flex; flex-wrap: wrap; gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 11px; color: var(--text-dim);
  flex: 0 0 auto;
}
.chart-legend span { display: flex; align-items: center; gap: 5px; }
.chart-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: toastIn .2s ease;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .panel { position: fixed; inset: 0 0 0 auto; width: min(340px, 88vw); flex: none; z-index: 50; box-shadow: -8px 0 30px rgba(0,0,0,.5); }
  .panel-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(2,5,10,.55);
    z-index: 45;
  }
  .brand-text { display: none; }
  .hud-item { min-width: 70px; padding: 4px 8px; }
}

@media (max-width: 640px) {
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 8px 10px; }
  .shoe-meter { order: 3; flex-basis: 100%; max-width: none; }
  .hud { flex: 1 1 auto; }
  .hud-item { flex: 1; min-width: 0; }
  .felt { padding: 10px 10px 14px; }
  :root { --card-w: 76px; --card-h: 107px; }
  body[data-ui="advanced"] { --card-w: 50px; --card-h: 70px; }
  .act { min-width: 0; flex: 1 1 30%; padding: 12px 8px; font-size: 13px; }
  .act kbd { display: none; }
  .deal-btn kbd { display: none; }
  .modal-wide { width: 100%; }
  table.chart th, table.chart td { min-width: 24px; font-size: 10px; padding: 4px 1px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; transition: none !important; }
}

/* ==================== UI MODES ====================
   Two looks, one markup tree. SIMPLE is the default (declared on :root and
   applied via :not([data-ui="advanced"])) so the page paints correctly before
   app.js stamps the attribute. ADVANCED restores the dense trainer layout. */

/* ---------- the switch itself ---------- */

.ui-switch {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 9px;
  flex: 0 0 auto;
}
.ui-switch button {
  padding: 5px 12px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .01em;
  transition: background .12s, color .12s;
}
.ui-switch button:hover:not(.is-on) { background: rgba(255,255,255,.06); color: var(--text); }
.ui-switch button.is-on { background: var(--gold); color: #1a1206; }
.panel .ui-switch { width: 100%; }
.panel .ui-switch button { flex: 1; padding: 8px; font-size: 13px; }

/* ---------- ADVANCED: the dense trainer layout ---------- */

body[data-ui="advanced"] {
  --card-w: 64px;
  --card-h: 90px;
}

/* ---------- SIMPLE: bigger cards, less chrome, more game ---------- */

body:not([data-ui="advanced"]) .rules-strip,
body:not([data-ui="advanced"]) .shoe-meter-label,
body:not([data-ui="advanced"]) .hud-sub,
body:not([data-ui="advanced"]) .hud-sys,
body:not([data-ui="advanced"]) .hand-bet,
body:not([data-ui="advanced"]) .hand-meta > span:not(.hand-result) {
  display: none;
}

/* A soft table arc behind the dealer reads as a felt, not a dashboard. */
body:not([data-ui="advanced"]) .felt::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 4%;
  width: 128%;
  height: 78%;
  transform: translateX(-50%);
  border: 2px solid rgba(255,255,255,.055);
  border-radius: 50%;
  pointer-events: none;
}

body:not([data-ui="advanced"]) .topbar { padding: 12px 18px; gap: 14px; }
body:not([data-ui="advanced"]) .shoe-meter { max-width: 200px; }
body:not([data-ui="advanced"]) .hud-item {
  min-width: 74px;
  padding: 7px 14px;
  background: transparent;
  border-color: transparent;
}
body:not([data-ui="advanced"]) .hud-value { font-size: 20px; }
body:not([data-ui="advanced"]) .hud-label { font-size: 9.5px; }

body:not([data-ui="advanced"]) .seat-label { font-size: 12.5px; letter-spacing: .1em; }
body:not([data-ui="advanced"]) .seat-total { font-size: 14px; padding: 2px 10px; }
body:not([data-ui="advanced"]) .hand { padding: 14px 18px 15px; border-radius: 16px; }

body:not([data-ui="advanced"]) .banner {
  min-height: 54px;
  font-size: 15.5px;
  padding: 11px 20px;
  border-radius: 12px;
}

body:not([data-ui="advanced"]) .act {
  min-width: 138px;
  padding: 16px 24px;
  font-size: 15.5px;
  border-radius: 14px;
  background: rgba(255,255,255,.11);
}
body:not([data-ui="advanced"]) .act:hover:not(:disabled) { background: rgba(255,255,255,.2); }
body:not([data-ui="advanced"]) .action-row { gap: 11px; }
body:not([data-ui="advanced"]) .deal-btn {
  padding: 16px 48px;
  font-size: 16.5px;
  border-radius: 14px;
}
body:not([data-ui="advanced"]) .controls { gap: 16px; padding-bottom: 6px; }
body:not([data-ui="advanced"]) .bet-amount { font-size: 16px; min-width: 66px; }
body:not([data-ui="advanced"]) .chip-btn { width: 32px; height: 32px; }
body:not([data-ui="advanced"]) .insurance-prompt { font-size: 15px; }

@media (max-width: 640px) {
  body:not([data-ui="advanced"]) .act { min-width: 0; flex: 1 1 30%; padding: 15px 6px; font-size: 14px; }
  body:not([data-ui="advanced"]) .deal-btn { padding: 15px 34px; }
  body:not([data-ui="advanced"]) .felt::before { width: 165%; }
  .ui-switch button { padding: 5px 9px; font-size: 11px; }
}

/* A hidden count in simple mode shows nothing rather than mystery dots -
   the tile reappears the moment you reveal the count with C. */
body:not([data-ui="advanced"]) #countBox.is-hidden { display: none; }

/* ---------- keybinding editor ---------- */

.keybind-list { margin-bottom: 12px; }
.kb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.kb-row:last-child { border-bottom: 0; }
.kb-label { flex: 1 1 auto; font-size: 12.5px; color: var(--text-dim); min-width: 0; }
.kb-row.is-conflict .kb-label { color: #ff9c9c; }
.kb-keys { display: flex; gap: 4px; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }

.kb-key, .kb-add {
  padding: 3px 8px;
  min-width: 26px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 5px;
  font: 600 11px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  transition: background .12s, border-color .12s, color .12s;
}
.kb-key:hover { background: rgba(240,82,82,.16); border-color: rgba(240,82,82,.45); color: #ff9c9c; }
.kb-key.is-conflict { border-color: var(--bad); color: #ff9c9c; }
.kb-add { color: var(--text-faint); }
.kb-add:hover { background: #1d2431; color: var(--text); }
.kb-add.is-capturing {
  background: var(--gold);
  border-color: var(--gold);
  color: #1a1206;
  animation: kbPulse 1s ease-in-out infinite;
}
@keyframes kbPulse { 50% { opacity: .6; } }
.kb-none { font-size: 11px; color: var(--text-faint); font-style: italic; align-self: center; }

/* ---------- volume slider ---------- */

.field input[type="range"] {
  flex: 1 1 auto;
  max-width: 190px;
  accent-color: var(--gold);
  background: transparent;
}
.field input[type="range"]:disabled { opacity: .35; }

/* ==================== TRENDS ====================
   Single-series columns only. Accuracy and volume are different scales, so they
   get separate charts rather than a second y-axis. One hue per chart, so no
   categorical palette and no legend — the heading names the series. */

.trend-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.trend-tile {
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
}
.trend-tile .t-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); margin-bottom: 3px;
}
.trend-tile .t-value {
  font: 700 24px/1.15 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  letter-spacing: -.02em;
}
.trend-tile .t-sub { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.trend-tile .t-value.pos { color: var(--good); }
.trend-tile .t-value.neg { color: var(--bad); }

.chart-sec { margin-bottom: 26px; }
.chart-sec h3 {
  margin: 0 0 2px;
  font-size: 12.5px; font-weight: 650; color: var(--text);
}
.chart-sec .sub {
  margin: 0 0 12px;
  font-size: 11.5px; color: var(--text-faint);
}
.chart-wrap { overflow-x: auto; }
.chart-wrap svg { display: block; }

/* Recessive grid: hairline, solid, one step off the surface. */
.g-line { stroke: rgba(255,255,255,.09); stroke-width: 1; }
.g-base { stroke: rgba(255,255,255,.2); stroke-width: 1; }
.g-text { fill: var(--text-faint); font: 10px ui-monospace, SFMono-Regular, Menlo, monospace; }
.g-label { fill: var(--text-dim); font: 10px ui-sans-serif, -apple-system, sans-serif; }
.g-ref { stroke: var(--gold); stroke-width: 1; opacity: .4; }
.g-reftext { fill: var(--gold); font: 9.5px ui-sans-serif, sans-serif; opacity: .85; }
.g-endlabel { fill: var(--text); font: 700 11px ui-monospace, SFMono-Regular, Menlo, monospace; }

.bar-hit { fill: transparent; cursor: default; }
.bar-hit:hover + .bar-mark, .bar-group:hover .bar-mark { opacity: .78; }
.bar-empty { fill: rgba(255,255,255,.05); }

.trend-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.trend-table th {
  text-align: right; padding: 6px 8px;
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); font-weight: 700;
  border-bottom: 1px solid var(--line);
}
.trend-table th:first-child, .trend-table td:first-child { text-align: left; }
.trend-table td {
  padding: 7px 8px; text-align: right;
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace;
  border-bottom: 1px solid rgba(255,255,255,.045);
}
.trend-table tr:last-child td { border-bottom: 0; }
.trend-table td.pos { color: var(--good); }
.trend-table td.neg { color: var(--bad); }
.trend-table td.dim { color: var(--text-faint); }

.trend-empty {
  padding: 34px 16px; text-align: center;
  color: var(--text-faint); font-size: 13px; line-height: 1.6;
}
