/* Table redesign (big cards, felt, chips, deal animations) and the phone layout.
   Loaded after styles.css, so these rules win where they overlap. */
.tabbar, .sheet, .mhud, .page-title { display: none; }

/* ---- the table (desktop) ---------------------------------------------- */
.table-view { --cw-dealer: 104px; --cw-me: 116px; --cw-other: 64px; }
.table-view .hud { align-items: center; }
.table-view .hud .sound-btn { font-size: 1.25rem; padding: 0.4rem 0.7rem; align-self: stretch; }
.table-view .felt {
  position: relative; overflow: hidden; min-height: 600px;
  display: grid; grid-template-rows: auto 1fr auto; justify-items: center; gap: 0.6rem;
  padding: 1rem 1.2rem 2.4rem;
  border-radius: 26px 26px 50% 50% / 26px 26px 30% 30%;
  border: 14px solid #5a361b; border-top-width: 10px;
  background:
    radial-gradient(ellipse 70% 55% at 50% 30%, rgba(255, 255, 255, 0.08), transparent 70%),
    radial-gradient(ellipse at 50% 0%, #1c7150 0%, #135a3f 45%, #0b3d2b 100%);
  box-shadow: inset 0 0 0 2px rgba(227, 188, 95, 0.35), inset 0 0 80px rgba(0, 0, 0, 0.45), 0 14px 40px rgba(0, 0, 0, 0.45), 0 0 0 2px #2d1a0b;
}
.table-view .felt::after {
  content: ""; position: absolute; inset: 10px; border-radius: inherit;
  border: 1.5px solid rgba(227, 188, 95, 0.28); pointer-events: none;
}
.felt-arc { display: block; width: min(560px, 78%); height: auto; align-self: center; margin: -0.4rem 0; pointer-events: none; opacity: 0.55; }
.felt-arc .arc-big { fill: var(--gold); font: 700 20px Georgia, serif; letter-spacing: 3px; }
.felt-arc .arc-small { fill: rgba(255, 255, 255, 0.55); font: 600 11px system-ui, sans-serif; letter-spacing: 2px; text-transform: uppercase; }
.felt-tray { position: absolute; top: 14px; left: 18px; display: flex; flex-direction: column; align-items: center; gap: 4px; z-index: 1; }
.felt-tag { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; color: rgba(255, 255, 255, 0.55); }
.felt-shoe { position: absolute; top: 14px; right: 18px; display: flex; flex-direction: column; align-items: center; gap: 4px; z-index: 1; }
.shoe-body {
  position: relative; width: 78px; height: 56px; border-radius: 8px 14px 8px 8px;
  background: linear-gradient(160deg, #2a2a30, #0d0d10);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transform: perspective(200px) rotateY(-12deg);
}
.shoe-body::before {
  content: ""; position: absolute; left: 6px; right: 6px; bottom: 6px;
  height: calc(38px * var(--left, 1)); max-height: 38px; border-radius: 3px;
  background: repeating-linear-gradient(0deg, #e9e3d3 0 2px, #bdb4a0 2px 3px); opacity: 0.9;
}
.shoe-card {
  position: absolute; left: -16px; bottom: 8px; width: 30px; height: 40px; border-radius: 4px; transform: rotate(-24deg);
  background: repeating-linear-gradient(45deg, #7a1d2a 0 4px, #8e2733 4px 8px); border: 2px solid #fbfaf6;
}

.table-view .dealer-zone { margin: 0; z-index: 2; padding-top: 0.2rem; }
.table-view .dealer-zone .card { --cw: var(--cw-dealer); }
.table-view .seats { z-index: 2; align-self: end; width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 1rem; }
.table-view .others { display: flex; gap: 1rem; align-items: flex-end; }
.table-view .others.left { justify-content: flex-end; }
.table-view .others.right { justify-content: flex-start; }
.table-view .seat.other { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; opacity: 1; }
.table-view .seat.other .card { --cw: var(--cw-other); }
.table-view .seat.other .hand { min-height: calc(var(--cw-other) * 1.4); }
.table-view .seat.me { background: none; padding: 0; display: flex; flex-direction: column; align-items: center; }
.table-view .seat.me .card { --cw: var(--cw-me); }
.table-view .my-hands.n2 .card { --cw: calc(var(--cw-me) * 0.84); }
.table-view .my-hands.n3 .card,
.table-view .my-hands.n4 .card { --cw: calc(var(--cw-me) * 0.66); }
.table-view .my-hands { justify-content: center; gap: 1.2rem; flex-wrap: nowrap; }
.table-view .hand > .card + .card { margin-left: calc(var(--cw) * -0.36); }
.table-view .hand { min-height: calc(var(--cw, 70px) * 1.4); }
.table-view .slot { width: var(--cw); height: calc(var(--cw) * 1.4); border-color: rgba(255, 255, 255, 0.16); border-radius: calc(var(--cw) * 0.09); }
.table-view .dealer-zone .slot { --cw: var(--cw-dealer); }
.table-view .seat.me .slot { --cw: var(--cw-me); }
.table-view .slot + .slot { margin-left: calc(var(--cw) * -0.36); }
.table-view .zone-label { justify-content: center; margin: 0.3rem 0; color: rgba(255, 255, 255, 0.7); }
.table-view .zone-label.you { color: var(--gold); font-weight: 700; }
.badge.bust { background: var(--bad); color: #2a0703; }
.badge.bj { background: var(--gold); color: #1d1606; }

.table-view .my-hand { position: relative; display: flex; flex-direction: column; align-items: center; padding: 0.5rem 0.6rem 0.3rem; border-radius: 16px; }
.table-view .my-hand.active {
  border-color: var(--gold);
  background: radial-gradient(ellipse at 50% 60%, rgba(227, 188, 95, 0.18), transparent 70%);
  box-shadow: 0 0 24px rgba(227, 188, 95, 0.25);
}
.table-view .hand-meta { margin-top: 0.4rem; min-height: 1.6rem; }
.result-bubble {
  position: absolute; top: -0.4rem; left: 50%; transform: translateX(-50%); z-index: 5; white-space: nowrap;
  padding: 0.25rem 0.9rem; border-radius: 999px; font-weight: 800; letter-spacing: 0.02em;
  animation: bubble 0.35s cubic-bezier(0.2, 1.6, 0.4, 1) both; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4); background: #333;
}
.my-hand.win .result-bubble { background: var(--good); color: #062014; }
.my-hand.lose .result-bubble { background: var(--bad); color: #2a0703; }
.my-hand.push .result-bubble { background: #d8d3c4; color: #222; }
@keyframes bubble { from { transform: translate(-50%, 10px) scale(0.6); opacity: 0; } }

/* betting circle + chips */
.bet-spot {
  margin-top: 0.4rem; width: 92px; height: 92px; border-radius: 50%; border: 2px dashed rgba(227, 188, 95, 0.6);
  display: grid; place-items: center; background: radial-gradient(circle, rgba(0, 0, 0, 0.18), transparent 70%);
}
.chip-stack { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.discs { display: flex; flex-direction: column-reverse; align-items: center; padding-top: 8px; }
.chip-disc {
  display: block; width: 46px; height: 13px; border-radius: 50%; margin-top: -8px; --c: #1f8a4c;
  background: repeating-linear-gradient(90deg, var(--c) 0 7px, #f5f1e6 7px 10px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45), inset 0 2px 0 rgba(255, 255, 255, 0.35), inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  animation: chipDrop 0.25s ease-out both; animation-delay: calc(var(--i) * 30ms);
}
.chip-disc.green { --c: #1f8a4c; }
.chip-disc.red { --c: #c1272d; }
.chip-disc.black { --c: #1b1b1f; }
.chip-disc.white { background: repeating-linear-gradient(90deg, #e8e4d8 0 7px, #3a6fd8 7px 10px); }
@keyframes chipDrop { from { transform: translateY(-14px); opacity: 0; } }
.chip-amt { font-size: 0.78rem; font-weight: 700; background: rgba(0, 0, 0, 0.45); padding: 0 0.45rem; border-radius: 999px; }

.chip-btn {
  --c: #1f8a4c; position: relative; width: 68px; height: 68px; border-radius: 50%; border: 0; cursor: pointer;
  color: #fff; font: 800 1.05rem system-ui, sans-serif; display: grid; place-items: center; touch-action: manipulation;
  background:
    radial-gradient(circle, var(--c) 0 46%, rgba(255, 255, 255, 0.9) 47% 50%, var(--c) 51% 64%, transparent 65%),
    repeating-conic-gradient(var(--c) 0 22.5deg, #f5f1e6 22.5deg 45deg);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45), 0 8px 16px rgba(0, 0, 0, 0.35); transition: transform 0.12s, box-shadow 0.12s;
}
.chip-btn.green { --c: #1f8a4c; }
.chip-btn.orange { --c: #d9711c; }
.chip-btn.purple { --c: #6b3fb5; }
.chip-btn:hover:not(:disabled) { transform: translateY(-3px); }
.chip-btn.on { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--gold), 0 10px 20px rgba(0, 0, 0, 0.4); color: #fff; border: 0; }
.chip-btn, .chip-btn.on {
  background:
    radial-gradient(circle, var(--c) 0 46%, rgba(255, 255, 255, 0.9) 47% 50%, var(--c) 51% 64%, transparent 65%),
    repeating-conic-gradient(var(--c) 0 22.5deg, #f5f1e6 22.5deg 45deg);
}
.chip-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.chip-btn .chip-face { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.chip-btn kbd { position: absolute; bottom: -1.3rem; left: 50%; transform: translateX(-50%); }
.table-view .bet-quick { gap: 0.9rem; padding-bottom: 1rem; }
.table-view .bet-row { gap: 1.4rem; }

/* actions */
.table-view .controls { margin-top: 0.4rem; }
.table-acts .btn.act { flex-direction: column; gap: 0.15rem; min-width: 112px; padding: 0.7em 0.9em; }
.act-icon { font-size: 1.35rem; line-height: 1; font-weight: 800; }
.act-label { font-size: 0.95rem; }
.ins-row { flex-direction: column; }
.ins-btns { display: flex; gap: 0.8rem; }

/* deal from the shoe, flip the hole card */
.table-view .felt .card.deal { animation: fromShoe 0.38s cubic-bezier(0.2, 0.8, 0.3, 1) both; }
.table-view .dealer-zone { --fx: 340px; --fy: -10px; }
.table-view .seats { --fx: 360px; --fy: -360px; }
@keyframes fromShoe { from { transform: translate(var(--fx), var(--fy)) rotate(22deg) scale(0.5); opacity: 0.3; } }
.card.flip { animation: flipIn 0.38s ease-out both; }
@keyframes flipIn { 0% { transform: rotateY(90deg) scale(1.05); } 100% { transform: rotateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .table-view .felt .card.deal, .card.flip, .chip-disc, .result-bubble { animation: none; }
}
.table-view .feedback { cursor: pointer; }

/* ---- phone layout ------------------------------------------------------ */
@media (max-width: 640px) {
  :root { --tab-h: calc(62px + env(safe-area-inset-bottom)); }
  body { padding-bottom: var(--tab-h); }

  /* Top bar: brand + page title. Mode pills move to the bottom tab bar. */
  #nav { display: none; }
  .topbar { flex-direction: row; align-items: center; justify-content: space-between; padding: calc(0.45rem + env(safe-area-inset-top)) 1rem 0.45rem; }
  .brand { padding: 0; font-size: 1rem; }
  .logo { width: 24px; height: 30px; }
  .page-title { display: block; font-weight: 700; color: var(--gold); font-size: 0.95rem; }

  .tabbar {
    display: grid; grid-template-columns: repeat(6, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: var(--tab-h); padding-bottom: env(safe-area-inset-bottom);
    background: rgba(5, 24, 17, 0.94); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
  }
  .tab {
    appearance: none; background: none; border: 0; color: var(--muted); font: 600 0.68rem system-ui, sans-serif;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    text-decoration: none; touch-action: manipulation; cursor: pointer;
  }
  .tab-icon { font-size: 1.3rem; line-height: 1; filter: grayscale(1); opacity: 0.8; }
  .tab.active { color: var(--gold); }
  .tab.active .tab-icon { filter: none; opacity: 1; }

  .sheet { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0); pointer-events: none; transition: background 0.2s; }
  .sheet.open { background: rgba(0, 0, 0, 0.55); pointer-events: auto; }
  .sheet-panel {
    position: absolute; left: 0; right: 0; bottom: 0; background: #0b2a1f; border-radius: 22px 22px 0 0;
    border-top: 1px solid var(--line); padding: 0.5rem 1rem calc(1rem + env(safe-area-inset-bottom));
    transform: translateY(100%); transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1); max-height: 80dvh; overflow-y: auto;
  }
  .sheet.open .sheet-panel { transform: none; }
  .sheet-grab { width: 42px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, 0.25); margin: 0.2rem auto 0.7rem; }
  .sheet-title { font: 700 1.1rem Georgia, serif; color: var(--gold); margin-bottom: 0.6rem; }
  .sheet-list { display: flex; flex-direction: column; gap: 0.45rem; }
  .sheet-item { display: flex; align-items: center; gap: 0.8rem; text-decoration: none; padding: 0.75rem 0.8rem; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
  .sheet-item:active { background: rgba(227, 188, 95, 0.12); }
  .sheet-text { display: flex; flex-direction: column; }

  /* Drills: answer buttons ride in a sticky thumb-zone dock. */
  .strat-stage + .actions, .view > .actions.bets {
    position: sticky; bottom: calc(var(--tab-h) + 0.4rem); z-index: 5; padding: 0.5rem; margin: 0 -0.5rem 1rem;
    border-radius: 18px; background: rgba(5, 24, 17, 0.92); backdrop-filter: blur(10px); border: 1px solid var(--line);
  }
  .actions.four .btn.act, .actions.bets .btn.act { padding: 1rem 0.4rem; font-size: 1.05rem; }
  .strat-stage .card { --cw: 72px; }
  .strat-stage { padding: 0.9rem; gap: 0.6rem; }
  .mode-grid { grid-template-columns: 1fr 1fr; }
  .mode-card { grid-template-columns: 1fr; padding: 0.7rem; }
  .mode-num { grid-row: auto; margin-bottom: 0.3rem; }
  .ready-card { padding: 0.9rem; }
  .ready-head h1 { font-size: 1.25rem; }
  .ready-icon { width: 44px; height: 44px; font-size: 1.3rem; }

  /* ---- table & training: a full-screen game view ---- */
  body[data-view="table"] .topbar, body[data-view="training"] .topbar { display: none; }
  body[data-view="table"] main, body[data-view="training"] main { padding: 0; }
  .table-view { --cw-dealer: 66px; --cw-me: 84px; --cw-other: 34px; display: flex; flex-direction: column; min-height: calc(100dvh - var(--tab-h)); }
  .table-view .rules-line, .table-view .hud, .table-view .training-bar { display: none; }
  .mhud {
    display: flex; align-items: center; gap: 0.5rem; position: sticky; top: 0; z-index: 10;
    padding: calc(0.45rem + env(safe-area-inset-top)) 0.75rem 0.45rem;
    background: rgba(5, 24, 17, 0.95); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  }
  .m-stack { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
  .m-stack .v { font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
  .m-delta { font-size: 0.72rem; font-weight: 700; }
  .m-count {
    flex: 1; min-width: 0; appearance: none; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); color: var(--muted);
    border-radius: 999px; padding: 0.5rem 0.7rem; font: 700 0.9rem system-ui, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .m-count.on { color: #1d1606; background: var(--gold); border-color: transparent; }
  .m-count small { font-weight: 500; opacity: 0.7; }
  .m-icon {
    appearance: none; width: 40px; height: 40px; flex: none; border-radius: 50%; border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.06); font-size: 1.15rem; display: grid; place-items: center; padding: 0; color: var(--ink);
  }
  .m-icon.cheat-btn.on { background: #ff5fa2; border-color: transparent; }

  .table-view .cheat-panel.on { grid-template-columns: repeat(4, 1fr); gap: 0.3rem; margin: 0.4rem 0.5rem 0; padding: 0.45rem 0.55rem; font-size: 0.78rem; }
  .table-view .cheat-item .k { font-size: 0.6rem; }
  .table-view .cheat-item.wide .v { font-size: 0.92rem; }

  .table-view .felt {
    flex: 1; min-height: 0; margin: 0.4rem 0.4rem 0; padding: 0.55rem 0.4rem 1.6rem; gap: 0.3rem;
    border-width: 0 6px 9px; border-radius: 18px 18px 50% 50% / 18px 18px 16% 16%;
  }
  .table-view .felt::after { inset: 4px; }
  .felt-arc { width: 92%; margin: -0.6rem 0 -0.8rem; opacity: 0.45; }
  .felt-tray { top: 8px; left: 10px; transform: scale(0.7); transform-origin: top left; }
  .felt-shoe { top: 8px; right: 6px; transform: scale(0.6); transform-origin: top right; }
  .felt-tag { display: none; }
  .table-view .dealer-zone { --fx: 120px; --fy: -10px; }
  .table-view .seats { --fx: 130px; --fy: -300px; grid-template-columns: 1fr 1fr; grid-template-areas: "l r" "me me"; gap: 0.3rem 0.4rem; }
  .table-view .others.left { grid-area: l; justify-content: flex-start; gap: 0.5rem; }
  .table-view .others.right { grid-area: r; justify-content: flex-end; gap: 0.5rem; }
  .table-view .seat.me { grid-area: me; }
  .table-view .seat.other .zone-label { margin: 0.1rem 0 0; font-size: 0.62rem; gap: 0.25rem; }
  .table-view .seat.other .badge { padding: 0 0.35rem; font-size: 0.7rem; }
  .table-view .my-hands.n2 .card { --cw: 64px; }
  .table-view .my-hands.n3 .card, .table-view .my-hands.n4 .card { --cw: 46px; }
  .table-view .my-hands { gap: 0.4rem; }
  .table-view .my-hand { padding: 0.35rem 0.3rem 0.1rem; }
  .table-view .zone-label { margin: 0.15rem 0; font-size: 0.7rem; }
  .bet-spot { width: 66px; height: 66px; margin-top: 0.2rem; }
  .chip-disc { width: 36px; height: 10px; margin-top: -6px; }
  .table-view .hand-meta { min-height: 1.3rem; margin-top: 0.25rem; }

  .table-view .dock { position: sticky; bottom: var(--tab-h); z-index: 12; padding: 0.4rem 0.6rem 0.55rem; background: linear-gradient(rgba(5, 24, 17, 0), rgba(5, 24, 17, 0.96) 22%); }
  .table-view .feedback { margin: 0 0 0.35rem; min-height: 1.3rem; font-size: 0.82rem; display: block; }
  .table-view .feedback .fb-line { display: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .table-view .feedback .fb-line:last-child { display: block; }
  .table-view .feedback.expanded { background: rgba(0, 0, 0, 0.6); border-radius: 12px; padding: 0.5rem; }
  .table-view .feedback.expanded .fb-line { display: block; white-space: normal; }
  .table-view .controls { min-height: 0; margin: 0; }
  .table-acts { display: grid; gap: 0.4rem; }
  .table-acts.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .table-acts.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .table-acts.four .btn.act, .table-acts.five .btn.act { min-width: 0; padding: 0.55rem 0.1rem; border-radius: 14px; min-height: 64px; }
  .table-acts .act-icon { font-size: 1.45rem; }
  .table-acts .act-label { font-size: 0.75rem; }
  .table-view .bet-row { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "chips adj" "deal deal"; gap: 0.5rem 0.6rem; align-items: center; }
  .table-view .bet-quick { grid-area: chips; gap: 0.5rem; padding: 0; justify-content: flex-start; }
  .chip-btn { width: 54px; height: 54px; font-size: 0.92rem; }
  .chip-btn kbd { display: none; }
  .table-view .bet-adjust { grid-area: adj; gap: 0.3rem; }
  .table-view .bet-adjust .btn.round { width: 36px; height: 36px; font-size: 1.1rem; }
  .table-view .bet-amt { min-width: 60px; }
  .table-view .bet-amt .v { font-size: 1.1rem; }
  .table-view .btn.deal { grid-area: deal; width: 100%; padding: 0.9rem; font-size: 1.1rem; border-radius: 14px; }
  .table-view .bet-sub { margin-top: 0.4rem; gap: 0.9rem; }
  .table-view .ins-row { gap: 0.5rem; }
  .table-view .ins-btns { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .table-view .ins-btns .btn { min-height: 56px; }
  .table-view .session-start { padding: 0.8rem; font-size: 0.88rem; }
  .table-view .check { padding: 0.7rem; gap: 0.5rem; }
  .table-view .check-fields .numfield input.num { width: 5.5em; }
}
@media (max-width: 380px) {
  .chip-btn { width: 48px; height: 48px; }
}

/* ==== One-screen table: no scrolling. =====================================
   The felt is a size container, so card and chip sizes are fractions of its
   real height (cqh) and the whole table always fits the window. */

/* Chips in the betting circle: a top-down pile using the same art as the bet buttons. */
.chip-pile { --chip: min(9cqh, 56px); display: flex; flex-direction: column; align-items: center; gap: 3px; }
.pile { position: relative; width: var(--chip); height: calc(var(--chip) + (var(--n) - 1) * 4px); }
.pchip {
  --c: #1f8a4c; --s: #f5f1e6;
  position: absolute; left: 0; bottom: calc(var(--i) * 4px); width: var(--chip); height: var(--chip); border-radius: 50%;
  display: grid; place-items: center; color: #fff; font: 800 calc(var(--chip) * 0.3) system-ui, sans-serif; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  background:
    radial-gradient(circle, var(--c) 0 46%, rgba(255, 255, 255, 0.85) 47% 50%, var(--c) 51% 64%, transparent 65%),
    repeating-conic-gradient(var(--c) 0 22.5deg, var(--s) 22.5deg 45deg);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.55), 0 4px 8px rgba(0, 0, 0, 0.35);
  animation: chipDrop 0.25s ease-out both; animation-delay: calc(var(--i) * 40ms);
}
.pchip.green { --c: #1f8a4c; }
.pchip.red { --c: #c1272d; }
.pchip.black { --c: #1b1b1f; }
.pchip.white { --c: #ece8dc; --s: #3a6fd8; color: #2a2a2a; text-shadow: none; }
@media (prefers-reduced-motion: reduce) { .pchip { animation: none; } }
.table-view .bet-spot { width: min(15cqh, 100px); height: min(15cqh, 100px); }

@media (min-width: 641px) {
  body[data-view="table"] main, body[data-view="training"] main { max-width: 1500px; padding: 0.6rem 1rem 0.7rem; }
  .table-view {
    --cw-dealer: min(15cqh, 120px); --cw-me: min(17cqh, 130px); --cw-other: min(8.5cqh, 68px);
    height: calc(100dvh - var(--topbar-h, 64px) - 1.3rem); min-height: 480px;
    display: grid; gap: 0.6rem 1rem;
    grid-template-columns: minmax(0, 1fr) 270px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "head side" "felt side" "dock side";
  }
  .table-view > .rules-line, .table-view > .training-bar { grid-area: head; margin: 0; font-size: 0.8rem; }
  .table-view .side { grid-area: side; display: flex; flex-direction: column; gap: 0.6rem; min-height: 0; }
  .table-view .side .hud { display: flex; flex-direction: column; align-items: stretch; gap: 0.5rem; margin: 0; }
  .table-view .side .hud-info { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }
  .table-view .side .hud-info .stat.count { grid-column: 1 / -1; }
  /* Chips/stack on top at full width (like Count); Decisions and Hands share the row below. */
  .table-view .side .hud-info .stat:first-child { grid-column: 1 / -1; }
  .table-view .side .hud .sound-btn { align-self: flex-start; }
  .table-view .side .cheat-panel.on { grid-template-columns: 1fr 1fr; margin: 0; }
  .table-view .side .feedback {
    flex: 1; min-height: 0; margin: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 0.35rem;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0.6rem 0.7rem; font-size: 0.86rem;
  }
  .table-view .side .feedback::before { content: "Hand log"; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
  .table-view .felt { grid-area: felt; min-height: 0; container-type: size; padding: 0.7rem 1rem 1.4rem; gap: 0.2rem; }
  .table-view .dock { grid-area: dock; }
  .table-view .controls { margin: 0; min-height: 0; }
  .felt-arc { width: auto; height: 10cqh; max-width: 78%; margin: 0; }
  .table-view .zone-label { margin: 0.15rem 0; }
  .table-view .hand-meta { margin-top: 0.2rem; min-height: 1.4rem; }
  .table-view .my-hand { padding: 0.3rem 0.5rem 0.2rem; }
  .table-view .bet-quick { padding-bottom: 0.9rem; }
  .table-view .session-start { padding: 0.7rem; gap: 0.5rem; }
}
@media (min-width: 641px) and (max-width: 1050px) {
  /* Narrower windows: stats sit in a row above the felt instead of a side column. */
  .table-view {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "head" "side" "felt" "dock";
  }
  .table-view .side { flex-direction: column; gap: 0.45rem; }
  .table-view .side .hud { flex-direction: row; align-items: stretch; }
  .table-view .side .hud-info { flex: 1; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.4rem; }
  .table-view .side .hud-info .stat { padding: 0.3rem 0.55rem; font-size: 0.85rem; }
  .table-view .side .hud-info .stat.count,
  .table-view .side .hud-info .stat:first-child { grid-column: auto; }
  .table-view .side .cheat-panel.on { grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 0.45rem 0.6rem; font-size: 0.8rem; gap: 0.3rem; }
  .table-view .side .feedback { display: none; }
}

@media (max-width: 640px) {
  .table-view {
    --cw-dealer: min(15cqh, 74px); --cw-me: min(18cqh, 92px); --cw-other: min(7.5cqh, 36px);
    height: calc(100dvh - var(--tab-h)); min-height: 0;
  }
  .table-view .side { display: contents; }
  .table-view .side .hud { display: none; }
  .table-view .mhud { order: 0; }
  .table-view .side .cheat-panel { order: 1; }
  .table-view .felt { order: 2; flex: 1; min-height: 0; container-type: size; }
  .table-view .side .feedback { order: 3; margin: 0.3rem 0.7rem 0; }
  .table-view .dock { order: 4; position: static; background: none; }
  .felt-arc { width: auto; height: 7cqh; max-width: 92%; margin: 0; }
  .table-view .bet-spot { width: min(13cqh, 70px); height: min(13cqh, 70px); }
  .chip-pile { --chip: min(8cqh, 40px); }
  /* Cheat strip: RC / TC / bet on one line, the correct play on the next. */
  .table-view .cheat-panel.on { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .table-view .cheat-panel.on .cheat-item:nth-child(2) { display: none; }
}
@media (max-width: 640px) and (max-height: 740px) {
  /* Short phones: give the cards the space. */
  .felt-arc, .felt-tray, .felt-shoe { display: none; }
  .table-view { --cw-dealer: min(17cqh, 70px); --cw-me: min(20cqh, 86px); --cw-other: min(8cqh, 32px); }
  .table-view .cheat-panel.on { margin-top: 0.25rem; padding: 0.3rem 0.5rem; font-size: 0.72rem; }
  .table-view .cheat-item .k { display: none; }
  .table-view .cheat-item .v::before { color: var(--muted); font-weight: 500; margin-right: 0.25rem; }
  .table-view .cheat-item:nth-child(1) .v::before { content: "RC"; }
  .table-view .cheat-item:nth-child(3) .v::before { content: "TC"; }
  .table-view .cheat-item:nth-child(4) .v::before { content: "Bet"; }
  .table-view .zone-label.you { display: none; }
  .table-view .felt { padding-bottom: 1rem; }
  .table-view .mhud { padding-top: calc(0.3rem + env(safe-area-inset-top)); padding-bottom: 0.3rem; }
}

/* ==== Hand log: high-contrast right / wrong ============================== */
.table-view .fb-line {
  display: flex; align-items: flex-start; gap: 0.55rem; padding: 0.45rem 0.6rem; line-height: 1.35;
  border-radius: 10px; border-left: 5px solid rgba(255, 255, 255, 0.2); background: rgba(255, 255, 255, 0.05); color: var(--ink);
}
.table-view .fb-line .fb-icon {
  flex: none; width: 1.55rem; height: 1.55rem; margin-top: -0.05rem; border-radius: 50%;
  display: grid; place-items: center; font-weight: 900; font-size: 0.95rem;
}
.table-view .fb-line .fb-text { min-width: 0; }
.table-view .fb-line .fb-tag {
  display: inline-block; margin-right: 0.45rem; padding: 0 0.4rem; border-radius: 4px;
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; vertical-align: 0.08em;
}
.table-view .fb-line.good { background: #0d3f24; border-left-color: #3ee07f; color: #eafff2; }
.table-view .fb-line.good .fb-icon, .table-view .fb-line.good .fb-tag { background: #3ee07f; color: #03210f; }
.table-view .fb-line.bad { background: #551411; border-left-color: #ff4d40; color: #fff1ef; }
.table-view .fb-line.bad .fb-icon, .table-view .fb-line.bad .fb-tag { background: #ff4d40; color: #2a0503; }
.table-view .fb-line.warn { background: #3f2f06; border-left-color: #ffc13d; color: #fff7e0; }
.table-view .fb-line.warn .fb-icon, .table-view .fb-line.warn .fb-tag { background: #ffc13d; color: #2a1c00; }
.table-view .fb-line.info { background: rgba(132, 200, 255, 0.08); border-left-color: rgba(132, 200, 255, 0.5); color: #c6e6ff; }
.table-view .fb-line.play { font-weight: 600; font-size: 1em; }
.table-view .fb-line.bet { font-size: 0.88em; }
.table-view .fb-line.latest { animation: fbIn 0.3s ease-out both; }
.table-view .fb-line.bad.latest { animation: fbIn 0.3s ease-out both, fbShake 0.35s 0.25s; box-shadow: 0 0 0 2px #ff4d40, 0 0 18px rgba(255, 77, 64, 0.45); }
.table-view .fb-line.good.play.latest { box-shadow: 0 0 0 2px #3ee07f; }
@keyframes fbIn { from { transform: translateX(-10px); opacity: 0; } }
@keyframes fbShake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { .table-view .fb-line.latest, .table-view .fb-line.bad.latest { animation: none; } }

@media (max-width: 640px) {
  /* Phones: the last two lines, so your play's verdict isn't replaced by the round result. */
  .table-view .feedback { display: flex; flex-direction: column; gap: 0.25rem; }
  .table-view .feedback .fb-line { display: none; padding: 0.3rem 0.5rem; font-size: 0.82rem; }
  .table-view .feedback .fb-line:nth-last-child(-n + 2) { display: flex; }
  .table-view .feedback .fb-line .fb-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .table-view .feedback .fb-line .fb-icon { width: 1.3rem; height: 1.3rem; font-size: 0.8rem; }
  .table-view .feedback.expanded .fb-line { display: flex; }
  .table-view .feedback.expanded .fb-line .fb-text { white-space: normal; }
}
@media (max-width: 640px) {
  /* Leave room for the two-line log strip under the felt. */
  .table-view { --cw-dealer: min(14cqh, 74px); --cw-me: min(17cqh, 92px); }
  .table-view .felt { padding-bottom: 1.1rem; }
}
@media (max-width: 640px) {
  /* Up to two other players sit beside you (one each side), like a real table;
     bigger tables keep them in a row above you. */
  .table-view .seats.o0, .table-view .seats.o1, .table-view .seats.o2 {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); grid-template-areas: "l me r"; align-items: end;
  }
  .table-view .seats.o0, .table-view .seats.o1, .table-view .seats.o2 { --cw-me: min(19cqh, 92px); }
  .table-view .seats.o1 .others.left, .table-view .seats.o2 .others.left { justify-content: flex-start; padding-bottom: 2.2rem; }
  .table-view .seats.o1 .others.right, .table-view .seats.o2 .others.right { justify-content: flex-end; padding-bottom: 2.2rem; }
  .table-view { --cw-dealer: min(15cqh, 74px); }
}

/* Round results: muted red/green so your decisions stay the loudest lines. */
.table-view .fb-line.round { font-size: 0.85em; font-weight: 500; padding-top: 0.3rem; padding-bottom: 0.3rem; animation: none; box-shadow: none; }
.table-view .fb-line.round.won { background: rgba(62, 224, 127, 0.07); border-left-color: rgba(62, 224, 127, 0.35); color: rgba(170, 230, 192, 0.8); }
.table-view .fb-line.round.lost { background: rgba(255, 77, 64, 0.07); border-left-color: rgba(255, 77, 64, 0.35); color: rgba(240, 175, 168, 0.8); }
.table-view .fb-line.round.even { background: rgba(255, 255, 255, 0.04); border-left-color: rgba(255, 255, 255, 0.2); color: rgba(255, 255, 255, 0.6); }
