/* ==========================================================================
   IB-Flip — table styles
   ========================================================================== */
:root {
  --felt: #0f5132;
  --felt-dark: #0a3522;
  --felt-light: #177245;
  --rim: #3b2416;
  --rim-light: #6b4226;
  --gold: #d8b45c;
  --gold-soft: rgba(216, 180, 92, 0.35);
  --ink: #1d1b19;
  --red: #c0392b;
  --paper: #fffdf6;
  --paper-shade: #f1ebdb;
  --panel: rgba(16, 24, 22, 0.92);
  --text: #f4efe2;
  --muted: rgba(244, 239, 226, 0.62);
  --accent: #f2c14e;
  --accent-ink: #2b1d00;
  --danger: #ff6b5b;
  --ok: #57d68d;
  --card-w: clamp(54px, min(6.2vw, 10.5vh), 88px);
  --card-h: calc(var(--card-w) * 1.4);
  --table-card-w: clamp(40px, 4.2vw, 62px);
  --opp-card-w: clamp(28px, 3vw, 44px);
  --pile-card-w: clamp(56px, 6vw, 88px);
  --radius: 14px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 50% 35%, #145c3b 0%, #0b3c27 45%, #06231a 100%);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* Felt texture overlay */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image:
    repeating-radial-gradient(circle at 17% 32%, rgba(255,255,255,.04) 0 1px, transparent 1px 3px),
    repeating-radial-gradient(circle at 83% 71%, rgba(0,0,0,.06) 0 1px, transparent 1px 4px);
  mix-blend-mode: overlay;
}

/* ------------------------------------------------------------------ screens */
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; }

.panel {
  background: var(--panel);
  border: 1px solid rgba(216, 180, 92, 0.25);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.05);
  backdrop-filter: blur(8px);
}

/* ------------------------------------------------------------------ buttons */
.btn {
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(255,255,255,.07);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: .01em;
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease, opacity .2s;
}
.btn:hover { background: rgba(255,255,255,.13); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary {
  background: linear-gradient(180deg, #ffd56b, #e9a93a);
  color: var(--accent-ink);
  border-color: rgba(255, 220, 140, .8);
  box-shadow: 0 6px 18px rgba(233, 169, 58, .35), inset 0 1px 0 rgba(255,255,255,.6);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.big { padding: .85rem 1.4rem; font-size: 1.05rem; width: 100%; }
.btn.small { padding: .35rem .75rem; font-size: .85rem; }
.btn.danger { background: linear-gradient(180deg, #ff8a7a, #e0523f); color: #2a0702; border-color: #ffb2a6; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.25);
  display: grid; place-items: center;
  font-size: 1rem;
}
.icon-btn:hover { background: rgba(255,255,255,.1); }
.link-btn { background: none; border: 0; color: var(--gold); text-decoration: underline; text-underline-offset: 3px; margin-top: 1rem; }

/* ------------------------------------------------------------------- home */
#home { align-items: center; justify-content: center; overflow-y: auto; }
.home-inner { width: min(440px, 92vw); display: flex; flex-direction: column; align-items: center; padding: 2rem 0 3rem; }
.hero-cards { position: relative; height: 140px; width: 260px; margin-bottom: .5rem; }
.hero-cards .card { position: absolute; left: 50%; top: 18px; --card-w: 74px; transform-origin: 50% 120%; animation: heroIn .9s cubic-bezier(.2,.9,.25,1.2) both; }
.hero-card[data-hero="0"] { --r: -28deg; animation-delay: .05s; }
.hero-card[data-hero="1"] { --r: -14deg; animation-delay: .12s; }
.hero-card[data-hero="2"] { --r: 0deg; animation-delay: .19s; }
.hero-card[data-hero="3"] { --r: 14deg; animation-delay: .26s; }
.hero-card[data-hero="4"] { --r: 28deg; animation-delay: .33s; }
.hero-card { transform: translateX(-50%) rotate(var(--r)); }
@keyframes heroIn { from { opacity: 0; transform: translate(-50%, 60px) rotate(0); } }
.home-inner:hover .hero-card { transition: transform .4s ease; transform: translateX(-50%) rotate(calc(var(--r) * 1.25)) translateY(-4px); }
.logo {
  font-family: var(--serif);
  font-size: clamp(3rem, 10vw, 4.6rem);
  margin: .2rem 0 0;
  letter-spacing: .02em;
  color: #fff6dc;
  text-shadow: 0 2px 0 #a37a2a, 0 10px 30px rgba(0,0,0,.45);
}
.logo span { color: var(--gold); padding: 0 .1em; }
.tagline { margin: .3rem 0 1.4rem; color: var(--muted); text-align: center; }
.home-panel { width: 100%; padding: 1.4rem; display: flex; flex-direction: column; gap: 1rem; }
.field { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--muted); }
.field input, .join-row input {
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  color: var(--text);
  padding: .75rem .9rem;
  font-size: 1.05rem;
  outline: none;
}
.field input:focus, .join-row input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.mode-tabs { display: grid; grid-template-columns: 1fr 1fr; background: rgba(0,0,0,.3); border-radius: 999px; padding: 4px; }
.tab { border: 0; background: none; padding: .55rem; border-radius: 999px; color: var(--muted); font-weight: 600; }
.tab.active { background: rgba(255,255,255,.12); color: var(--text); }
.tab-body { display: flex; flex-direction: column; gap: .9rem; }
.row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }
.row-label { color: var(--muted); font-size: .9rem; }
.seg { display: flex; background: rgba(0,0,0,.3); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { border: 0; background: none; padding: .45rem .8rem; border-radius: 9px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--paper); color: var(--ink); }
.seg small { font-size: .65rem; opacity: .7; }
.or { text-align: center; color: var(--muted); font-size: .85rem; position: relative; }
.or::before, .or::after { content: ""; position: absolute; top: 50%; width: 32%; border-top: 1px solid rgba(255,255,255,.12); }
.or::before { left: 0; } .or::after { right: 0; }
.join-row { display: flex; gap: .6rem; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .35em; text-align: center; font-weight: 700; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: .9rem; text-align: center; }
.server-note { color: var(--muted); font-size: .8rem; min-height: 1em; }

/* ------------------------------------------------------------------ lobby */
#lobby { align-items: center; justify-content: center; }
.lobby-inner { position: relative; width: min(480px, 94vw); padding: 2rem 1.5rem 1.5rem; display: flex; flex-direction: column; align-items: center; gap: .6rem; }
.back { position: absolute; left: 14px; top: 14px; }
.eyebrow { text-transform: uppercase; letter-spacing: .2em; font-size: .75rem; color: var(--muted); margin: 0; }
.room-code { font-family: var(--serif); font-size: 3.4rem; letter-spacing: .25em; padding-left: .25em; color: var(--gold); text-shadow: 0 6px 24px rgba(216,180,92,.25); }
.seat-list { list-style: none; padding: 0; margin: .6rem 0; width: 100%; display: flex; flex-direction: column; gap: .45rem; }
.seat-item {
  display: flex; align-items: center; gap: .8rem;
  padding: .55rem .8rem; border-radius: 14px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.06);
  animation: popIn .35s cubic-bezier(.2,.9,.3,1.3) both;
}
.seat-item .avatar { width: 38px; height: 38px; font-size: 1.3rem; }
.seat-item .who { flex: 1; display: flex; flex-direction: column; }
.seat-item .who small { color: var(--muted); }
.seat-item select { background: rgba(0,0,0,.3); color: var(--text); border: 1px solid rgba(255,255,255,.15); border-radius: 8px; padding: .25rem .4rem; }
.seat-item .x { border: 0; background: none; color: var(--muted); font-size: 1.1rem; }
.seat-empty { opacity: .45; border-style: dashed; justify-content: center; color: var(--muted); }
.host-controls { width: 100%; display: flex; flex-direction: column; gap: .8rem; }
.add-bot { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; justify-content: center; color: var(--muted); font-size: .9rem; }
@keyframes popIn { from { opacity: 0; transform: scale(.9) translateY(6px); } }

.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 1.5rem;
  background: radial-gradient(circle at 35% 30%, #fff8e6, #e6d6ad);
  box-shadow: 0 0 0 3px rgba(0,0,0,.25), 0 4px 10px rgba(0,0,0,.35);
  position: relative;
}
.avatar .dot { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid #0b2a1e; }
.avatar .dot.off { background: #777; }

/* ------------------------------------------------------------------- HUD */
#game { flex-direction: column; }
.hud {
  position: relative; z-index: 5;
  display: flex; align-items: center; gap: .8rem;
  padding: .55rem .9rem;
  padding-top: max(.55rem, env(safe-area-inset-top));
}
.hud-room { font-size: .85rem; }
.hud-room b { color: var(--gold); letter-spacing: .15em; }
.hud-status { flex: 1; text-align: center; font-weight: 600; font-size: .95rem; }
.hud-right { display: flex; gap: .5rem; }

/* ------------------------------------------------------------------ table */
.table-wrap { flex: 1; min-height: 0; padding: 0 2.5vw; display: flex; }
.table {
  position: relative; flex: 1;
  border-radius: 48% / 42%;
  background:
    radial-gradient(ellipse at 50% 40%, var(--felt-light) 0%, var(--felt) 45%, var(--felt-dark) 100%);
  box-shadow:
    0 0 0 10px var(--rim),
    0 0 0 13px var(--rim-light),
    0 0 0 15px #22140b,
    0 30px 60px rgba(0,0,0,.55),
    inset 0 0 80px rgba(0,0,0,.45);
  margin: 18px 10px 4px;
}
.table::before {
  content: "IB·FLIP"; position: absolute; left: 50%; top: 77%; transform: translate(-50%, -50%);
  font-family: var(--serif); font-weight: 700; letter-spacing: .3em; font-size: clamp(.9rem, 2vw, 1.4rem);
  color: rgba(0,0,0,.18); text-shadow: 0 1px 0 rgba(255,255,255,.05); pointer-events: none;
}
.table::after {
  content: ""; position: absolute; inset: 9%;
  border: 2px solid rgba(216,180,92,.18);
  border-radius: 48% / 42%;
  pointer-events: none;
}
.felt-ring { position: absolute; inset: 9%; pointer-events: none; border-radius: 48% / 42%; }
.felt-ring span {
  position: absolute; font-size: 1rem; color: rgba(216,180,92,.45);
  transition: transform .6s cubic-bezier(.3,.8,.3,1.2);
}
.felt-ring span:nth-child(1) { left: 50%; top: -11px; transform: translateX(-50%) rotate(0deg); }
.felt-ring span:nth-child(2) { right: -8px; top: 50%; transform: translateY(-50%) rotate(90deg); }
.felt-ring span:nth-child(3) { left: 50%; bottom: -11px; transform: translateX(-50%) rotate(180deg); }
.felt-ring span:nth-child(4) { left: -8px; top: 50%; transform: translateY(-50%) rotate(270deg); }
.felt-ring.ccw span:nth-child(1) { transform: translateX(-50%) rotate(180deg); }
.felt-ring.ccw span:nth-child(2) { transform: translateY(-50%) rotate(270deg); }
.felt-ring.ccw span:nth-child(3) { transform: translateX(-50%) rotate(0deg); }
.felt-ring.ccw span:nth-child(4) { transform: translateY(-50%) rotate(90deg); }
.felt-ring.spin { animation: ringPulse .8s ease; }
@keyframes ringPulse { 50% { filter: drop-shadow(0 0 8px var(--gold)); } }

/* ---------------------------------------------------------------- center */
.center {
  position: absolute; left: 50%; top: 52%;
  transform: translate(-50%, -50%);
  display: flex; align-items: flex-end; gap: clamp(14px, 3vw, 44px);
}
.pile-col { display: flex; flex-direction: column; align-items: center; gap: .4rem; }
.pile { position: relative; width: var(--pile-card-w); height: calc(var(--pile-card-w) * 1.4); }
.pile::before {
  content: ""; position: absolute; inset: 0;
  border-radius: 9px;
  border: 2px dashed rgba(255,255,255,.14);
}
.pile .card { position: absolute; left: 0; top: 0; --card-w: var(--pile-card-w); }
.live-col .pile { width: calc(var(--pile-card-w) * 1.55); }
.live-pile .card { left: calc(var(--pile-card-w) * .27); transition: transform .25s ease; }
.pile-label {
  font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: rgba(255,255,255,.55);
  background: rgba(0,0,0,.25); padding: .15rem .55rem; border-radius: 999px;
  white-space: nowrap;
}
.pile-label b { color: var(--text); letter-spacing: 0; }
.draw-pile.clickable { cursor: pointer; }
.draw-pile.clickable .card:last-child { animation: nudge 1.4s ease-in-out infinite; box-shadow: 0 0 0 3px var(--accent), 0 0 24px rgba(242,193,78,.6); }
.live-pile.clickable { cursor: pointer; }
.live-pile.clickable::after {
  content: "Pick up"; position: absolute; left: 50%; bottom: -1.9rem; transform: translateX(-50%);
  background: var(--danger); color: #2a0702; font-weight: 700; font-size: .75rem; padding: .15rem .6rem; border-radius: 999px;
}
@keyframes nudge { 50% { transform: translateY(-5px); } }
.live-col .pile.fourloop::before { border-color: #ff9d5c; box-shadow: 0 0 30px rgba(255,140,60,.55), inset 0 0 20px rgba(255,140,60,.35); border-style: solid; }

.callout {
  position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%) scale(.6);
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(2rem, 6vw, 4.2rem);
  color: #fff4d1;
  text-shadow: 0 4px 0 #8b5e14, 0 12px 40px rgba(0,0,0,.6);
  pointer-events: none; opacity: 0; white-space: nowrap; z-index: 30;
}
.callout.show { animation: callout 1.15s cubic-bezier(.2,.9,.25,1.1) both; }
.callout.bad { color: #ffd8d2; text-shadow: 0 4px 0 #8b1d14, 0 12px 40px rgba(0,0,0,.6); }
@keyframes callout {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5) rotate(-6deg); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(2deg); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(.96); }
}

/* ----------------------------------------------------------------- seats */
.seats { position: absolute; inset: 0; }
.seat {
  position: absolute; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: .3rem;
  transition: filter .3s;
  z-index: 2;
}
.seat-head { display: flex; align-items: center; gap: .5rem; padding: .25rem .7rem .25rem .25rem; border-radius: 999px; background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.08); position: relative; }
.seat-head .avatar { width: 34px; height: 34px; font-size: 1.15rem; }
.seat-name { font-weight: 700; font-size: .85rem; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-sub { font-size: .7rem; color: var(--muted); }
.seat.turn .seat-head { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent), 0 0 24px rgba(242,193,78,.55); }
.seat.turn .seat-head::after {
  content: ""; position: absolute; inset: -6px; border-radius: 999px;
  border: 2px solid rgba(242,193,78,.6); animation: ping 1.4s ease-out infinite;
}
@keyframes ping { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(1.18); } }
.seat.out { filter: grayscale(.9) brightness(.7); }
.seat.ready-wait .seat-sub::after { content: " · fixing…"; }
.seat.ready .seat-sub::after { content: " · ready ✓"; color: var(--ok); }

.opp-hand { position: relative; height: calc(var(--opp-card-w) * 1.4); min-width: calc(var(--opp-card-w) * 1.2); display: flex; justify-content: center; }
.opp-hand .card { --card-w: var(--opp-card-w); margin-left: calc(var(--opp-card-w) * -0.72); box-shadow: 0 2px 4px rgba(0,0,0,.35); }
.opp-hand .card:first-child { margin-left: 0; }
.hand-count {
  position: absolute; right: -10px; top: -8px; z-index: 3;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--paper); color: var(--ink); font-weight: 800; font-size: .75rem;
  display: grid; place-items: center; box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.known { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; max-width: 170px; position: relative; z-index: 4; margin-top: 2px; }
.known::before { content: "seen"; font-size: .58rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-right: 3px; align-self: center; }
.chip {
  font-size: .68rem; font-weight: 800; padding: 1px 4px; border-radius: 4px;
  background: var(--paper); color: var(--ink); line-height: 1.2;
}
.chip.red { color: var(--red); }
.known-label { font-size: .62rem; color: var(--muted); }

.slots { display: flex; gap: calc(var(--table-card-w) * .14); }
.slot { position: relative; width: var(--table-card-w); height: calc(var(--table-card-w) * 1.4 + 8px); }
.slot .card { position: absolute; left: 0; --card-w: var(--table-card-w); }
.slot .card.down { top: 0; }
.slot .card.up { top: 8px; }
.slot .card.up + .card.up { top: 14px; left: 4px; }
.slot .card.up + .card.up + .card.up { top: 20px; left: 8px; }
.slot .card.up + .card.up + .card.up + .card.up { top: 26px; left: 12px; }
.slot.empty::before { content: ""; position: absolute; inset: 0 0 8px; border: 1.5px dashed rgba(255,255,255,.12); border-radius: 7px; }
.seat .slots { --table-card-w: var(--opp-card-w); }

/* ------------------------------------------------------------------ me */
.me { position: relative; z-index: 6; display: flex; flex-direction: column; align-items: center; padding: 0 1rem; padding-bottom: max(.4rem, env(safe-area-inset-bottom)); }
.prompt {
  min-height: 1.8rem; font-weight: 600; font-size: .95rem; text-align: center;
  padding: .3rem 1rem; border-radius: 999px; margin: -0.6rem 0 .25rem;
  transition: background .3s, color .3s;
}
.prompt.yours { background: linear-gradient(180deg, #ffd56b, #e9a93a); color: var(--accent-ink); box-shadow: 0 6px 22px rgba(233,169,58,.35); animation: popIn .3s ease both; }
.me-main {
  display: grid; width: 100%; max-width: 1400px;
  grid-template-columns: minmax(150px, auto) 1fr minmax(150px, auto);
  grid-template-areas: "left hand actions";
  align-items: end; gap: 1rem;
}
.me-left { grid-area: left; display: flex; flex-direction: column; align-items: center; gap: .35rem; }
.me-badge { display: flex; align-items: center; gap: .5rem; }
.me-badge .avatar { width: 34px; height: 34px; font-size: 1.15rem; }
.me.turn .me-badge .avatar { box-shadow: 0 0 0 3px var(--accent), 0 0 22px rgba(242,193,78,.6); }
.my-slots .slot { --table-card-w: clamp(44px, min(4.4vw, 7.5vh), 66px); }
.action-bar { grid-area: actions; display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; align-self: center; }
.hand { grid-area: hand; }
.hand {
  position: relative; display: flex; justify-content: center; align-items: flex-end;
  height: calc(var(--card-h) + 14px); width: 100%;
  margin-top: .2rem; padding-top: 12px;
}
.hand .card { margin: 0 calc(var(--card-w) * var(--overlap, -0.18)); transform-origin: 50% 140%; transform: translateY(var(--arc, 0px)) rotate(var(--rot, 0deg)) translateY(var(--lift, 0px)); transition: transform .18s ease, box-shadow .18s ease, filter .2s; }
.hand .card.legal { cursor: pointer; --lift: -12px; box-shadow: 0 0 0 3px var(--accent), 0 10px 26px rgba(0,0,0,.45), 0 0 26px rgba(242,193,78,.45); }
.hand .card.legal:hover { --lift: -26px; z-index: 50; }
.hand .card.dim { filter: brightness(.8) saturate(.75); }
.hand .card.selected { --lift: -34px; box-shadow: 0 0 0 3px #7dd3fc, 0 0 26px rgba(125,211,252,.6); }
.hand .card.known-mark::after { content: "seen"; position: absolute; top: -9px; left: 50%; transform: translateX(-50%); font-size: .55rem; background: #33251b; color: #e8d3a8; padding: 0 5px; border-radius: 4px; font-family: var(--sans); font-weight: 700; letter-spacing: .05em; }
.slot .card.legal, .slot .card.target { cursor: pointer; box-shadow: 0 0 0 3px var(--accent), 0 0 20px rgba(242,193,78,.55); }
.slot .card.legal:hover { transform: translateY(-6px); }
.slot .card.target { box-shadow: 0 0 0 3px #7dd3fc, 0 0 20px rgba(125,211,252,.6); }

/* ------------------------------------------------------------------ cards */
.card {
  --w: var(--card-w);
  position: relative; flex: none;
  width: var(--w); height: calc(var(--w) * 1.4);
  border-radius: calc(var(--w) * .1);
  background: linear-gradient(160deg, #fffefa 0%, var(--paper) 55%, var(--paper-shade) 100%);
  box-shadow: 0 1px 0 rgba(255,255,255,.8) inset, 0 4px 10px rgba(0,0,0,.35), 0 0 0 1px rgba(0,0,0,.12);
  color: var(--ink);
  font-family: var(--serif);
  overflow: hidden;
}
.card.red { color: var(--red); }
.card .ix { position: absolute; display: flex; flex-direction: column; align-items: center; line-height: .9; font-weight: 700; }
.card .ix b { font-size: calc(var(--w) * .25); letter-spacing: -.04em; }
.card .ix i { font-style: normal; font-size: calc(var(--w) * .2); }
.card .ix.tl { left: calc(var(--w) * .07); top: calc(var(--w) * .07); }
.card .ix.br { right: calc(var(--w) * .07); bottom: calc(var(--w) * .07); transform: rotate(180deg); }
.card .pip { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: calc(var(--w) * .58); line-height: 1; }
.card.face .pip { font-size: calc(var(--w) * .5); font-weight: 700; }
.card.face .pip::after { content: ""; }
.card.face::before {
  content: ""; position: absolute; inset: calc(var(--w) * .2) calc(var(--w) * .2);
  border: 1.5px solid currentColor; border-radius: 4px; opacity: .22;
}
.card .power {
  position: absolute; left: 50%; bottom: calc(var(--w) * .07); transform: translateX(-50%);
  font-family: var(--sans); font-size: calc(var(--w) * .105); font-weight: 800; letter-spacing: .06em;
  color: #6b5a3a; background: rgba(216,180,92,.22); padding: 0 .35em; border-radius: 4px; white-space: nowrap;
}
.card.tiny .ix.br, .card.tiny .power { display: none; }
.card.tiny .pip { font-size: calc(var(--w) * .5); top: 58%; }
.card.back {
  background:
    radial-gradient(circle at 50% 50%, rgba(216,180,92,.28) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.07) 0 4px, transparent 4px 9px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.07) 0 4px, transparent 4px 9px),
    linear-gradient(160deg, #8c1d2c, #5a0f1b);
  box-shadow: inset 0 0 0 calc(var(--w) * .05) #f3e7cf, inset 0 0 0 calc(var(--w) * .075) #8c1d2c, 0 4px 10px rgba(0,0,0,.35);
}
.card.back::after {
  content: "IB"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-family: var(--serif); font-weight: 700; font-size: calc(var(--w) * .26); color: rgba(243,231,207,.85);
}
.card.ghost { opacity: .35; }
.card.ace-one::after { content: "=1"; position: absolute; right: 6%; top: 40%; font-family: var(--sans); font-size: calc(var(--w)*.14); font-weight: 900; color: #2a7b4f; }

/* Live pile fan */
.live-pile .card:nth-last-child(1) { z-index: 5; }

/* Flying cards */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
.fly { position: fixed; left: 0; top: 0; will-change: transform; }
.fly .card { box-shadow: 0 16px 30px rgba(0,0,0,.45); }
.flip3d { perspective: 600px; }

/* --------------------------------------------------------------- emotes */
.emote-bar {
  position: fixed; right: 12px; bottom: 50%; transform: translateY(50%);
  display: flex; flex-direction: column; gap: 4px; z-index: 8;
  background: rgba(0,0,0,.25); padding: 6px; border-radius: 999px;
}
.emote-bar button { border: 0; background: none; font-size: 1.2rem; width: 34px; height: 34px; border-radius: 50%; transition: transform .15s; }
.emote-bar button:hover { transform: scale(1.25); background: rgba(255,255,255,.08); }
.bubble {
  position: fixed; z-index: 70; font-size: 2rem; pointer-events: none;
  animation: bubble 1.8s ease-out forwards;
}
.bubble.text { font-size: .9rem; background: var(--paper); color: var(--ink); padding: .35rem .7rem; border-radius: 14px; font-weight: 600; max-width: 220px; }
@keyframes bubble { 0% { opacity: 0; transform: translate(-50%, 0) scale(.5); } 15% { opacity: 1; transform: translate(-50%, -20px) scale(1.15); } 80% { opacity: 1; transform: translate(-50%, -46px) scale(1); } 100% { opacity: 0; transform: translate(-50%, -60px); } }

/* ---------------------------------------------------------------- toasts */
.toast-stack { position: fixed; left: 14px; top: 62px; display: flex; flex-direction: column; gap: 6px; z-index: 40; pointer-events: none; max-width: min(360px, 70vw); }
.toast {
  background: rgba(10,16,14,.86); border: 1px solid rgba(255,255,255,.08);
  padding: .45rem .8rem; border-radius: 12px; font-size: .82rem;
  animation: toastIn .3s ease both; box-shadow: 0 8px 20px rgba(0,0,0,.35);
}
.toast b { color: var(--gold); }
.toast.bad b { color: var(--danger); }
.toast.leaving { animation: toastOut .4s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-12px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* -------------------------------------------------------------- overlays */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(2,10,7,.6); display: grid; place-items: center; animation: fade .25s ease both; backdrop-filter: blur(3px); }
@keyframes fade { from { opacity: 0; } }
.result-panel { width: min(560px, 94vw); padding: 1.8rem; text-align: center; animation: popIn .4s cubic-bezier(.2,.9,.3,1.3) both; max-height: 92vh; overflow: auto; }
.result-emoji { font-size: 3.4rem; }
.result-panel h2 { font-family: var(--serif); font-size: 2.2rem; margin: .2rem 0; }
.result-actions { display: flex; gap: .6rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.reveal { display: flex; flex-direction: column; gap: .5rem; margin: 1rem 0; text-align: left; }
.reveal-row { display: flex; align-items: center; gap: .6rem; }
.reveal-row .name { width: 7em; font-weight: 700; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reveal-row .cards { display: flex; gap: 3px; flex-wrap: wrap; }
.reveal-row .card { --card-w: 30px; }
.scoreboard { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }
.score-pill { background: rgba(255,255,255,.07); border-radius: 999px; padding: .3rem .7rem; font-size: .85rem; }
.score-pill b { color: var(--gold); }
.menu-panel { width: min(340px, 90vw); padding: 1.4rem; display: flex; flex-direction: column; gap: .8rem; }
.menu-panel h3 { margin: 0; font-family: var(--serif); }
.rules-panel { position: relative; width: min(760px, 94vw); max-height: 90vh; overflow: auto; padding: 1.6rem 1.8rem; user-select: text; }
.rules-panel h2 { font-family: var(--serif); margin: 0 0 .4rem; font-size: 1.9rem; }
.rules-panel h3 { font-family: var(--serif); color: var(--gold); margin: 1.2rem 0 .5rem; }
.rules-panel .lead { color: var(--muted); }
.rules-panel .close { position: absolute; right: 14px; top: 14px; }
.flow { padding-left: 1.2rem; line-height: 1.55; }
.flow li { margin-bottom: .3rem; }
.powers { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .55rem; }
.power-item { display: flex; gap: .6rem; align-items: center; background: rgba(255,255,255,.05); padding: .45rem; border-radius: 10px; font-size: .85rem; line-height: 1.3; }
.power-item .card { --card-w: 38px; }
.matrix-wrap { overflow-x: auto; }
.matrix { border-collapse: collapse; font-size: .78rem; margin: 0 auto; }
.matrix th, .matrix td { width: 28px; height: 26px; text-align: center; border: 1px solid rgba(255,255,255,.06); }
.matrix th { color: var(--gold); font-family: var(--serif); }
.matrix td.y { background: rgba(87,214,141,.35); color: #dfffe9; }
.matrix td.n { color: rgba(255,255,255,.15); }
.matrix caption { caption-side: bottom; color: var(--muted); font-size: .75rem; padding-top: .4rem; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 760px) {
  :root {
    --card-w: clamp(46px, 13vw, 70px);
    --opp-card-w: clamp(22px, 5.6vw, 32px);
    --pile-card-w: clamp(46px, 12vw, 64px);
  }
  .table { border-radius: 38% / 26%; margin: 14px 4px 2px; }
  .table::after, .felt-ring { border-radius: 38% / 26%; }
  .table-wrap { padding: 0 2vw; }
  .me-badge { display: none; }
  .me-main { grid-template-columns: auto 1fr; grid-template-areas: "left actions" "hand hand"; gap: .3rem .6rem; }
  .action-bar { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .seat-name { max-width: 6em; font-size: .75rem; }
  .seat-head .avatar { width: 26px; height: 26px; font-size: .9rem; }
  .known { display: none; }
  .emote-bar { right: 2px; bottom: 36%; transform: none; padding: 3px; gap: 1px; }
  .center, .callout { top: 60%; }
  .emote-bar button { width: 28px; height: 28px; font-size: 1rem; }
  .hud-room { display: none; }
  .toast-stack { left: 50%; transform: translateX(-50%); top: 96px; bottom: auto; flex-direction: column; max-width: 92vw; }
  .toast-stack .toast:nth-child(n+3) { display: none; }
  .toast { font-size: .75rem; padding: .3rem .6rem; }
  .center { gap: 10px; }
}
@media (max-height: 640px) and (min-width: 761px) {
  :root { --card-w: clamp(48px, 5.4vw, 74px); --opp-card-w: 30px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Hints */
#hintBtn:disabled { opacity: .35; cursor: default; }
.hint-glow { animation: hintGlow 1.1s ease-in-out 3; }
.card.hint-glow { --lift: -30px !important; }
@keyframes hintGlow {
  50% { box-shadow: 0 0 0 4px #7dd3fc, 0 0 34px rgba(125,211,252,.9); }
}
