/* Gin Rummy, ivory cards on a soft green baize table, on a calm linen page. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #f1ece3;
  --bg-2: #e7dfd2;
  --ink: #2b2a33;
  --muted: #847c71;
  --paper: #fffdf8;
  --line: #e2d9ca;
  --felt: #2f6a53;
  --felt-hi: #3b7d63;
  --felt-lo: #245543;
  --red: #c42c3b;
  --black: #1f222b;
  --back: #2f4c7c;
  --gold: #f2c14e;
  --s0: #e9a23b;   /* you */
  --s1: #7db3a2;   /* Ana, left */
  --s2: #a9a3d6;   /* Ben, across */
  --s3: #e59478;   /* Cleo, right */
  /* tutorial kit (tutorial.css) */
  --tut-accent: #f2c14e;
  --tut-accent-ink: #2b2a33;
  --tut-bubble: #fffdf8;
  --tut-ink: #2b2a33;
  --tut-muted: #847c71;
  --tut-dim: rgba(14, 30, 24, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 30%, #f8f5ef 0%, var(--bg) 60%, var(--bg-2) 100%) fixed;
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- bar ---------- */
.app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 980px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
}
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 60px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; padding: 12px 2px; }
.back:hover, .back:focus-visible { color: var(--ink); }
.bar-actions { display: flex; gap: 8px; }

.btn {
  min-height: 44px; min-width: 44px; padding: 0 18px; border-radius: 22px;
  border: 0; background: var(--paper); color: var(--ink);
  font-weight: 650; cursor: pointer; box-shadow: 0 1px 2px rgba(43, 42, 51, .12), 0 0 0 1px var(--line);
  transition: transform .12s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.icon { padding: 0; width: 44px; font-size: 22px; line-height: 1; letter-spacing: .04em; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--paper); box-shadow: none; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled, .row:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .pc:focus-visible, .seg button:focus-visible, .row:focus-visible, .link:focus-visible {
  outline: 3px solid var(--s0); outline-offset: 2px;
}

/* ---------- game ---------- */
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px; padding-bottom: 10px;
}
.turn {
  justify-self: center; display: inline-flex; align-items: center; gap: 9px;
  padding: 8px 18px; border-radius: 999px; background: var(--paper);
  box-shadow: 0 0 0 1px var(--line); font-weight: 650; font-size: 16px; min-height: 40px;
}
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; transition: background .2s; }
.dot.s0 { background: var(--s0); } .dot.s1 { background: var(--s1); }
.dot.s2 { background: var(--s2); } .dot.s3 { background: var(--s3); }
.turn.thinking #turn-text::after { content: ''; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.hint { justify-self: center; min-height: 22px; font-size: 15px; color: var(--muted); text-align: center; line-height: 1.35; }
.hint b { color: var(--ink); }
.hint .sym { display: inline-block; width: .9em; height: .9em; vertical-align: -.1em; }

/* ---------- table ---------- */
.table {
  position: relative; min-height: 0;
  border-radius: 28px;
  background: radial-gradient(ellipse at 50% 42%, var(--felt-hi) 0%, var(--felt) 55%, var(--felt-lo) 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08), inset 0 10px 30px rgba(0, 0, 0, .18), 0 8px 20px rgba(43, 42, 51, .14);
  overflow: hidden;
  display: flex; flex-direction: column; align-items: center;
  padding-top: 10px;
  user-select: none; -webkit-user-select: none;
}
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 16px;
  background: rgba(16, 40, 31, .38); color: #f4f1e8;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
  transition: box-shadow .2s, background .2s;
  white-space: nowrap; font-size: 14px;
}
.chip.active { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(242, 193, 78, .45); background: rgba(16, 40, 31, .55); }
.chip .nm { font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.chip .nm i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chip .sc { font-variant-numeric: tabular-nums; color: rgba(244, 241, 232, .78); }
.chip .sc b { color: #fff; font-size: 15px; }
.chip .dw { font-variant-numeric: tabular-nums; color: rgba(244, 241, 232, .78); padding-left: 8px; border-left: 1px solid rgba(255, 255, 255, .18); }
.chip .dw b { color: #fff; }
.chip .dw.ok b { color: var(--gold); }

.opp { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: none; }
.opp-hand { position: relative; height: 56px; }
.opp-hand .pc { --cw: 40px; top: 0; }
.opp-hand .pc.took { transform: translateY(6px); }

.piles { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; gap: calc(var(--cw) * .45); padding: 8px 0; }
.pile {
  position: relative; border: 0; padding: 0; background: transparent; cursor: default;
  width: calc(var(--cw) * 1.25); height: calc(var(--cw) * 1.4);
}
.pile.stock { width: var(--cw); }
.pile .pc { left: auto; right: 0; top: 0; }
.pile .under { right: calc(var(--cw) * .25); transform: rotate(-5deg); filter: brightness(.93); }
.pile .slot { position: absolute; right: 0; top: 0; width: var(--cw); height: calc(var(--cw) * 1.4); border-radius: calc(var(--cw) * .09); border: 2px dashed rgba(255, 255, 255, .25); }
.pile .count {
  position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%); z-index: 3;
  min-width: 30px; padding: 1px 8px; border-radius: 999px; background: rgba(16, 40, 31, .85); color: #f4f1e8;
  font-size: 13px; font-weight: 750; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums;
}
.pile.stock .count.low { background: #b5452f; }
.pile.can { cursor: pointer; }
.pile.can .top { box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(242, 193, 78, .55), 0 2px 4px rgba(0, 0, 0, .3); }
.pile.stock.can .pc.back { box-shadow: inset 0 0 0 calc(var(--cw) * .05) #fffdf8, 0 0 0 3px var(--gold), 0 0 18px rgba(242, 193, 78, .55); }
@media (hover: hover) { .pile.can:hover .top { transform: translateY(-4%); } }
.pile .top.fresh { animation: land .35s ease-out; box-shadow: 0 0 0 3px rgba(255, 255, 255, .8), 0 4px 12px rgba(0, 0, 0, .3); }
@keyframes land { from { transform: translateY(-30%) rotate(4deg); opacity: .4; } }
.pile .top { transition: transform .15s; }

.actions { flex: none; display: flex; gap: 10px; justify-content: center; min-height: 0; }
.actions .act { min-width: 120px; min-height: 46px; margin-bottom: 8px; }
.btn.gold { background: var(--gold); color: #2b2a33; box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.btn.gold.on { background: #fff4d6; }
.me { flex: none; margin-bottom: 4px; }

/* ---------- cards ---------- */
.pc {
  --r: calc(var(--cw) * .09);
  position: absolute; width: var(--cw); height: calc(var(--cw) * 1.4);
  border-radius: var(--r); border: 0; padding: 0; margin: 0;
  background: linear-gradient(180deg, #fffefb, #faf6ec);
  color: var(--black);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .28), 0 0 0 1px rgba(31, 34, 43, .12);
  font-size: var(--cw); line-height: 1;
  text-align: left;
}
.pc.red { color: var(--red); }
.pc .ix { position: absolute; left: .06em; top: .07em; width: .3em; display: flex; flex-direction: column; align-items: center; }
.pc .ix b { font-size: .29em; font-weight: 800; letter-spacing: -.02em; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
.pc .ix b.ten { letter-spacing: -.09em; margin-left: -.06em; }
.pc .ix svg { width: .21em; height: .21em; margin-top: .03em; fill: currentColor; }
.pc .mid { position: absolute; left: .3em; right: .08em; top: .3em; bottom: .12em; display: grid; place-items: center; }
.pc .mid svg { width: .5em; height: .5em; fill: currentColor; }
.pc .mid.ace svg { width: .56em; height: .56em; }
.pc .face {
  position: absolute; left: .32em; right: .09em; top: .33em; bottom: .1em;
  border-radius: .06em; border: .012em solid currentColor; opacity: .92;
  display: grid; place-items: center; align-content: center; gap: .02em;
  background: linear-gradient(180deg, rgba(242, 193, 78, .16), rgba(242, 193, 78, .05));
}
.pc .face b { font: 700 .4em/1 Georgia, "Times New Roman", serif; }
.pc .face svg { width: .2em; height: .2em; fill: currentColor; }
.pc.back {
  background: repeating-linear-gradient(45deg, rgba(255, 255, 255, .13) 0 3px, transparent 3px 8px),
              repeating-linear-gradient(-45deg, rgba(255, 255, 255, .13) 0 3px, transparent 3px 8px), var(--back);
  box-shadow: inset 0 0 0 calc(var(--cw) * .05) #fffdf8, 0 1px 2px rgba(0, 0, 0, .28);
}

/* ---------- hand ---------- */
.hand { position: relative; flex: none; min-height: 60px; width: calc(100% - 16px); margin: 0 8px 6px; }
.hand .pc .hit { position: absolute; left: 0; top: 0; }
.hand .pc { cursor: pointer; transition: transform .16s ease-out, filter .16s, left .2s, top .2s; }
.hand .pc.dim { filter: brightness(.84); cursor: default; }
.hand .pc.sel { transform: translateY(-18%); box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(0, 0, 0, .25); }
.hand .pc.new::after {
  content: ''; position: absolute; left: .1em; top: .6em; width: .1em; height: .1em; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 0 .02em rgba(0, 0, 0, .15);
}
.pc.meld { box-shadow: inset 0 calc(var(--cw) * .045) 0 #d9a92e, 0 1px 2px rgba(0, 0, 0, .28), 0 0 0 1px rgba(31, 34, 43, .12); }
@media (hover: hover) { .hand .pc.can:hover { transform: translateY(-8%); } .hand .pc.sel:hover { transform: translateY(-18%); } }
.hand .pc.can:active { transform: translateY(-5%); }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(43, 42, 51, .38);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(241, 236, 227, .5); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet, .card-box {
  background: var(--paper); color: var(--ink);
  width: 100%; max-width: 440px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  overflow: auto; overscroll-behavior: contain;
  border-radius: 24px; padding: 8px 20px 20px;
  box-shadow: 0 20px 50px rgba(43, 42, 51, .25);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .overlay { align-items: center; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.row {
  display: block; width: 100%; text-align: left; min-height: 50px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; font-weight: 600; cursor: pointer;
}
.group { padding: 12px 0 4px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--bg); }
.seg button {
  flex: 1 1 0; min-height: 44px; border: 0; border-radius: 12px; background: transparent;
  font-weight: 600; cursor: pointer; color: var(--muted); transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(43, 42, 51, .18); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.menu-sheet #menu-undo { border-top: 1px solid var(--line); }
.menu-sheet #menu-scores { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet .btn.wide { margin-top: 16px; }

.sum-card, .over-card { max-width: 380px; text-align: center; padding: 24px 22px 14px; }
.sum-title, .over-title { font-size: 26px; font-weight: 800; }
.sum-sub { color: var(--muted); font-size: 15px; min-height: 4px; margin-top: 2px; }
.tally { margin: 14px 0 18px; text-align: left; }
.tally .tr { display: grid; grid-template-columns: 1fr auto 3.2em; gap: 8px; align-items: center; padding: 7px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.tally .tr:last-child { border-bottom: 0; }
.tally .tr span { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.tally .tr i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.tally .tr em { font-style: normal; color: var(--red); font-weight: 700; font-size: 14px; }
.tally .tr em.zero { color: var(--muted); font-weight: 500; }
.tally .tr b { text-align: right; font-size: 18px; }
.tally .tr.best b { color: #1f7a4f; }
.link { display: block; margin: 8px auto 0; min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
i.c0 { background: var(--s0); } i.c1 { background: var(--s1); } i.c2 { background: var(--s2); } i.c3 { background: var(--s3); }

.reveal { margin: 12px 0 2px; text-align: left; }
.reveal .who { font-size: 13px; color: var(--muted); margin: 8px 0 4px; display: flex; justify-content: space-between; }
.reveal .who b { color: var(--ink); }
.reveal .cards { display: flex; flex-wrap: wrap; gap: 6px 10px; }
.reveal .grp { display: flex; gap: 2px; }
.mc {
  width: 25px; height: 35px; border-radius: 4px; background: #fffdf8; color: var(--black);
  box-shadow: 0 0 0 1px rgba(31, 34, 43, .18), 0 1px 1px rgba(0, 0, 0, .12);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
}
.mc.red { color: var(--red); }
.mc b { font-size: 12px; font-weight: 800; letter-spacing: -.04em; }
.mc svg { width: 11px; height: 11px; fill: currentColor; margin-top: 2px; }
.mc.meld { box-shadow: inset 0 3px 0 #d9a92e, 0 0 0 1px rgba(31, 34, 43, .18); }
.mc.dead { background: #f7e9e3; }
.mc.laid { box-shadow: 0 0 0 2px var(--s1); background: #eef6f2; }
.score-grid { display: grid; grid-template-columns: 3em repeat(4, 1fr); font-variant-numeric: tabular-nums; text-align: center; padding-bottom: 8px; }
.score-grid > div { padding: 7px 2px; border-bottom: 1px solid var(--line); font-size: 15px; }
.score-grid .h { font-weight: 700; font-size: 14px; }
.score-grid .n { color: var(--muted); }
.score-grid .t { font-weight: 800; border-bottom: 0; }

.help-sheet { max-width: 560px; }
.help-body { padding-bottom: 6px; }
.help-body h3 { font-size: 16px; margin: 18px 0 4px; }
.help-body p, .help-body li { font-size: 15px; margin: 4px 0; }
.help-body ul { padding-left: 20px; }

/* ---------- small phones ---------- */
@media (max-width: 380px) {
  .app { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .btn { padding: 0 14px; }
  .back { font-size: 13px; }
  .chip { padding: 5px 9px 5px 6px; }
}
@media (max-height: 700px) {
  .bar { min-height: 52px; }
  .game { gap: 6px; padding-bottom: 6px; }
  .turn { min-height: 36px; padding: 6px 16px; font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* The tutorial kit's first-visit chip sits over the turn pill instead of on top of your hand
   (it goes away once you make your first move). */
body > .tut-chip { top: calc(env(safe-area-inset-top, 0px) + 58px); bottom: auto; }

/* ---------- online (a table with a friend: tables.js) ---------- */
/* a short notice (connection lost, the table was updated, the friend left) floats just under the turn
   pill, over the table's top edge, so the board never moves */
.turn { position: relative; }
.turn .net-note { position: absolute; left: 50%; top: calc(100% + 4px); transform: translateX(-50%); z-index: 6; width: max-content; max-width: min(88vw, 360px);
  padding: 4px 12px; border-radius: 12px; background: var(--ink); color: var(--paper); font-size: 12.5px; font-weight: 700; line-height: 1.3; text-align: center;
  white-space: normal; box-shadow: 0 4px 14px rgba(43, 42, 51, .3); pointer-events: none; animation: fade .25s ease-out; }
.turn .net-note[hidden] { display: none; }
/* a friend whose page stopped checking in */
.chip.away .nm { opacity: .7; }
.chip .aw { font-size: 12px; font-style: italic; color: rgba(244, 241, 232, .72); }
body.is-online #btn-new { display: none; }
body.is-online .menu-sheet #menu-leave { border-top: 1px solid var(--line); }
.over-card #over-leave { margin-top: 8px; }
