:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: rgba(0, 0, 0, .45);
  --line: rgba(0, 0, 0, .14);
  --felt: rgba(0, 0, 0, .05);
  --cw: 62px;
  --mw: 44px;
  --ch: calc(var(--cw) * 1.4);
  --red: #c8102e;
  --black: #111;
  --sel: #2563eb;
  --seatw: 150px;
  --seath: 56px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; overflow: hidden;
  transition: background-color .2s;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input { font: inherit; }
#app { height: 100dvh; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.game { --ch: calc(var(--cw) * 1.4); flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ---------- start / join ---------- */
.start { margin: auto; width: min(320px, 100% - 32px); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.start h1 { font-weight: 600; font-size: 22px; margin: 0 0 8px; }
.start input { padding: 12px; border: 1px solid var(--line); border-radius: 10px; text-align: center; background: #fff; color: #111; font-size: 18px; }
.start input.code { text-transform: uppercase; letter-spacing: .2em; }
.btn { padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); }
.btn.primary { background: var(--fg); color: var(--bg); border-color: transparent; }
.link { color: var(--muted); font-size: 14px; padding: 6px; }
.err { color: var(--red); font-size: 14px; min-height: 1.3em; }

/* ---------- phone: the table, shrunk to a strip ---------- */
.strip { display: flex; align-items: flex-start; gap: 4px; padding: 8px 6px 0; }
.piles { flex: 1; display: flex; justify-content: center; align-items: flex-start; gap: 14px; overflow-x: auto; scrollbar-width: none; }
.piles::-webkit-scrollbar { display: none; }
.pile.mini { --cw: var(--mw); --ch: calc(var(--mw) * 1.4); gap: 2px; }
.pile.mini .label, .addpile .addlabel { font-size: 11px; opacity: .75; }

/* pass targets: only on screen while you are holding cards */
.people { display: flex; justify-content: center; gap: 2px; margin-bottom: 4px; min-height: 28px;
  overflow-x: auto; scrollbar-width: none; opacity: 0; pointer-events: none; transition: opacity .15s; }
.people::-webkit-scrollbar { display: none; }
.people.show, body.handdrag .people { opacity: 1; pointer-events: auto; }
.who { padding: 5px 8px; border-radius: 15px; font-size: 13px; white-space: nowrap; color: var(--muted); transition: background-color .15s, transform .15s; }
.who b { font-weight: 600; color: var(--fg); margin-right: 4px; }
.who.me b { text-decoration: underline; text-underline-offset: 3px; }
.who.off { opacity: .4; }
.who.target { outline: 1.5px dashed var(--sel); color: var(--fg); }
.who.hover { background: var(--sel); color: #fff; transform: scale(1.06); }
.who.hover b { color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #e0a100; display: none; flex: none; margin: 0 4px; }
.offline .dot { display: block; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .3; } }
.more { padding: 6px 10px; font-size: 19px; letter-spacing: 1px; color: var(--muted); }

/* ---------- piles ---------- */
.pile { display: flex; flex-direction: column; align-items: center; gap: 4px; border-radius: 10px; padding: 4px; transition: background-color .15s; }
.pile.spread { flex-basis: 100%; }
.piles .pile.spread { flex-basis: auto; }
.pile.hover { background: rgba(37, 99, 235, .12); }
.slot { position: relative; width: var(--cw); height: var(--ch); border-radius: 7px; }
.slot.empty { border: 1.5px dashed var(--line); }
.slot.thick1 { box-shadow: 1px 1px 0 var(--line); }
.slot.thick2 { box-shadow: 1px 1px 0 var(--line), 2px 2px 0 var(--line); }
.slot.thick3 { box-shadow: 1px 1px 0 var(--line), 2px 2px 0 var(--line), 3px 3px 0 var(--line); }
.slot.target, .spreadbox.target { outline: 2px dashed var(--sel); outline-offset: 3px; }
.spreadbox { position: relative; min-height: var(--ch); min-width: var(--cw); border-radius: 7px; }
.spreadbox.empty { border: 1.5px dashed var(--line); width: var(--cw); }
.label { font-size: 13px; color: var(--muted); padding: 2px 8px; border-radius: 10px; }
.label.draw { color: var(--fg); font-weight: 600; }

/* add a pile: a ghost slot at the end of the row */
.addpile { align-self: center; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px; opacity: .4; }
.addpile:active { opacity: .9; }
.slot.plus { width: calc(var(--cw) * .6); height: calc(var(--cw) * .6); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 20px; color: var(--muted); }
.addlabel { font-size: 12px; color: var(--muted); }

/* ---------- cards ---------- */
.card {
  position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch);
  border-radius: 7px; background: #fff; border: 1px solid rgba(0,0,0,.25);
  box-shadow: 0 1px 2px rgba(0,0,0,.12); color: var(--black);
  touch-action: none; will-change: transform;
}
.card.red { color: var(--red); }
.card .c, .card .c2 { position: absolute; left: 4px; top: 3px; font-size: calc(var(--cw) * .25); line-height: 1; font-weight: 600; text-align: center; letter-spacing: -.04em; }
.card .c2 { left: auto; top: auto; right: 4px; bottom: 3px; transform: rotate(180deg); }
.card .c span, .card .c2 span { display: block; font-size: .9em; }
.card .m { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--cw) * .5); }
.card.joker .m { font-size: calc(var(--cw) * .2); font-weight: 700; letter-spacing: .05em; writing-mode: vertical-rl; }
.card.back { background: #2f4a7a; border: 3px solid #fff; outline: 1px solid rgba(0,0,0,.25); }
.card.back::after { content: ""; position: absolute; inset: 3px; border-radius: 3px; background: repeating-linear-gradient(45deg, rgba(255,255,255,.12) 0 4px, transparent 4px 8px); }
/* a picked card lifts but keeps its place in the fan, so the card to its right stays tappable */
.card.sel { box-shadow: 0 0 0 2px var(--sel), 0 6px 14px rgba(0,0,0,.22); }
.card.held { filter: brightness(.95); }
.card.pending { opacity: .35; }
.card:focus-visible, .label:focus-visible, .who:focus-visible, .more:focus-visible, .addpile:focus-visible { outline: 2px solid var(--sel); outline-offset: 2px; }
.ghost { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 50; }
.ghost .card { box-shadow: 0 10px 24px rgba(0,0,0,.3); }
.dragging { opacity: .25; }

/* ---------- phone: your hand ---------- */
.handwrap { position: relative; margin-top: auto; padding: 6px 10px 6px; }
.hand { position: relative; min-height: var(--ch); margin: 0 auto; border-radius: 10px; }
.hand .card { transition: box-shadow .15s; }
.hand.hover { background: rgba(37, 99, 235, .08); }
.hand.target { outline: 2px dashed var(--sel); outline-offset: 6px; }
.hand-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }

/* ---------- shared table display (iPad): seats around the edge ---------- */
.tablemode { --cw: 96px; }
.felt { position: relative; display: block; flex: 1; margin: 8px; padding: 0; overflow: hidden;
  border-radius: 20px; background: var(--felt); box-shadow: inset 0 0 0 1px var(--line); }
.felt .center { position: absolute; inset: calc(var(--seath) + 14px) calc(var(--seath) + 14px);
  display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 18px 16px; overflow-y: auto; }
.seat { position: absolute; width: var(--seatw); height: var(--seath);
  display: flex; align-items: center; gap: 8px; padding: 0 10px; border-radius: 12px;
  transition: background-color .15s; }
.seat.bottom { left: var(--p); bottom: 6px; transform: translateX(-50%); }
.seat.top { left: var(--p); top: 6px; transform: translateX(-50%) rotate(180deg); }
.seat.left { top: var(--p); left: calc(6px - (var(--seatw) - var(--seath)) / 2); transform: translateY(-50%) rotate(90deg); }
.seat.right { top: var(--p); right: calc(6px - (var(--seatw) - var(--seath)) / 2); transform: translateY(-50%) rotate(-90deg); }
.seat .minifan { position: relative; width: 74px; height: 38px; flex: none; }
.seat .card.mini { width: 26px; height: 36px; border-radius: 4px; border-width: 2px; }
.seat .card.mini::after { inset: 2px; }
.seat .nm { min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.seat .nm b { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .ct { font-size: 12px; color: var(--muted); }
.seat.off { opacity: .4; }
.seat.target { outline: 1.5px dashed var(--sel); }
.seat.hover { background: var(--sel); color: #fff; }
.seat.hover .ct { color: rgba(255,255,255,.8); }
.tcode { position: absolute; right: 8px; top: 6px; display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; letter-spacing: .12em; }
.joinhint { flex-basis: 100%; text-align: center; color: var(--muted); font-size: 15px; }

/* ---------- contextual bar / toast ---------- */
.ctx { display: flex; gap: 2px; align-items: center; width: max-content; margin: 0 auto 6px;
  background: var(--fg); color: var(--bg); border-radius: 18px; padding: 3px; font-size: 14px; white-space: nowrap; z-index: 45;
  box-shadow: 0 2px 8px rgba(0,0,0,.2); animation: pop .14s ease; }
.ctx.float { position: absolute; left: 50%; bottom: calc(var(--seath) + 18px); transform: translateX(-50%); margin: 0; animation: popx .14s ease; }
.ctx button { padding: 6px 11px; border-radius: 15px; }
.ctx button.on { background: var(--bg); color: var(--fg); }
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
@keyframes popx { from { transform: translateX(-50%) scale(.9); opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: calc(var(--handh, 140px) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); border-radius: 18px; padding: 8px 14px; font-size: 14px; z-index: 60; display: flex; gap: 12px;
  align-items: center; white-space: nowrap; animation: pop .14s ease; }
.toast button { font-weight: 600; text-decoration: underline; }

/* ---------- sheets ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 80; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; color: #111; width: min(440px, 100%); max-height: 85dvh; overflow-y: auto; border-radius: 14px 14px 0 0;
  padding: 8px 0 calc(12px + env(safe-area-inset-bottom)); -webkit-user-select: none; animation: up .15s ease; }
@keyframes up { from { transform: translateY(20px); opacity: 0; } }
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 14px; } }
.sheet h3 { margin: 10px 16px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: #888; }
.sheet .note { margin: 0 16px 6px; font-size: 12px; color: #888; }
.sheet .row { display: flex; align-items: center; gap: 8px; padding: 0 16px; min-height: 46px; }
.sheet .item { display: block; width: 100%; text-align: left; padding: 12px 16px; }
.sheet .item:active, .sheet .item:hover { background: #f3f3f3; }
.sheet .item.danger { color: var(--red); }
.sheet .item[disabled] { color: #bbb; }
.sheet .grow { flex: 1; }
.sheet .chip { padding: 7px 12px; border: 1px solid #ddd; border-radius: 16px; font-size: 14px; }
.sheet .chip.on { background: #111; color: #fff; border-color: #111; }
.sheet .chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 16px 8px; }
.sheet .stepper { display: flex; align-items: center; gap: 10px; }
.sheet .stepper button { width: 36px; height: 36px; border: 1px solid #ddd; border-radius: 50%; font-size: 18px; }
.sheet .stepper b { min-width: 28px; text-align: center; }
.sheet input[type=text] { flex: 1; padding: 8px 10px; border: 1px solid #ddd; border-radius: 8px; }
.sheet input[type=color] { width: 44px; height: 32px; border: 0; background: none; padding: 0; }
.sheet .code { font-size: 26px; letter-spacing: .2em; font-weight: 600; }
.sheet hr { border: 0; border-top: 1px solid #eee; margin: 6px 0; }

/* ---------- sizes ---------- */
@media (min-width: 700px) and (min-height: 600px) {
  .game.phone { --mw: 52px; }
  .tablemode { --cw: 118px; --seatw: 170px; --seath: 62px; }
  .tablemode .seat .minifan { width: 86px; height: 44px; }
  .tablemode .seat .card.mini { width: 30px; height: 42px; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
