/* Le République on a phone: the same card-room felt, laid out for a portrait screen.
   Card sizes come from the viewport so the whole table fits without scrolling. */
:root {
  --felt-1: #2f7a4a;
  --felt-2: #1d4f30;
  --ink: #eef6ee;
  --red: #c62828;
  --gold: #c9a227;
  --cream: #f7f1dc;
  --yellow: #ffd54f;
  --label: #ffe082;
  --jester: #5b2a86;
  --vh: 100dvh;
  /* Lane card width: six columns across, or less when the screen is short. */
  --cw: clamp(28px, min(calc((min(100vw, 520px) - 40px) / 6 - 4px), calc((var(--vh) - 330px) / 5.6)), 64px);
  --ch: calc(var(--cw) * 1.38);
  --peek: calc(var(--cw) * .44);
  /* Hand cards are a little bigger. */
  --hw: clamp(36px, min(calc((min(100vw, 520px) - 52px) / 6), calc(var(--cw) * 1.25)), 72px);
  --hh: calc(var(--hw) * 1.4);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@supports not (height: 100dvh) { :root { --vh: 100vh; } }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body.felt-page {
  background: radial-gradient(ellipse at 50% 40%, var(--felt-1), var(--felt-2) 75%, #133a22);
  background-attachment: fixed;
  color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
}
body[data-screen=table] { overflow: hidden; }
button { font: inherit; color: inherit; }
h1, h2 { margin: 0; font-weight: 700; }
#app { max-width: 520px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }

/* ---------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px; flex: none;
  padding-top: env(safe-area-inset-top, 0px); box-sizing: content-box;
  background: rgba(0, 0, 0, .22);
}
.topbar .brand { font-family: Georgia, "Times New Roman", serif; font-size: 17px; color: var(--cream); white-space: nowrap; }
.topbar .code { font-size: 12px; font-weight: 700; letter-spacing: .1em; opacity: .7; }
.topbar .tools { margin-left: auto; display: flex; gap: 4px; }
body[data-screen=table] .topbar .tools { margin-right: 74px; } /* room for the chat button */
@media (max-width: 370px) {
  .topbar .brand { font-size: 15px; }
  .topbar .code { display: none; }
  .icon-btn { width: 30px; }
}
.icon-btn {
  width: 34px; height: 34px; border: 0; border-radius: 8px; background: rgba(255, 255, 255, .1);
  font-size: 16px; font-weight: 800; line-height: 1; cursor: pointer;
}

/* ---------------------------------------------------------- forms: home, invite, login */
.page { display: flex; flex-direction: column; gap: 14px; padding: 18px 16px calc(24px + var(--safe-b)); }
.page h1 { font-family: Georgia, "Times New Roman", serif; font-size: 32px; color: var(--cream); }
.panel.login { max-width: 420px; margin: 8vh auto 0; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.panel.login h1 { font-family: Georgia, "Times New Roman", serif; font-size: 30px; color: var(--cream); }
.login form { display: flex; flex-direction: column; gap: 14px; }
.sub { margin: -6px 0 0; opacity: .85; }
.box { background: rgba(0, 0, 0, .2); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.box h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; opacity: .85; }
.field, .login label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.field-label { font-size: 13px; opacity: .8; }
input[type=text], input[type=password], input:not([type]) {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming in on focus */
  padding: 11px 12px; border-radius: 9px; border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(0, 0, 0, .25); color: var(--ink); outline: none; width: 100%; min-width: 0;
}
input:focus { border-color: var(--yellow); }
#code { text-transform: uppercase; letter-spacing: .25em; font-weight: 700; }
.row { display: flex; gap: 8px; align-items: center; }
.err { color: #ffab91; min-height: 1em; margin: 0; }
.fine { margin: 0; font-size: 13px; opacity: .7; text-align: center; }
.fine a { color: inherit; }
.btn {
  border: 0; border-radius: 10px; padding: 11px 18px; cursor: pointer; font-weight: 700;
  background: rgba(255, 255, 255, .16); color: var(--ink); white-space: nowrap;
}
.btn.primary { background: var(--yellow); color: #222; }
.btn.wide { width: 100%; padding: 13px 18px; font-size: 16px; }
.btn[disabled] { opacity: .65; }
.seg-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border-radius: 10px; overflow: hidden; border: 1px solid rgba(255, 255, 255, .2); }
.seg-opt { position: relative; text-align: center; cursor: pointer; }
.seg-opt input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-opt span { display: block; padding: 10px 2px; font-size: 14px; font-weight: 700; }
.seg-opt + .seg-opt span { border-left: 1px solid rgba(255, 255, 255, .2); }
.seg-opt input:checked + span { background: var(--cream); color: #222; }
.rules-link { margin: -4px 0 0; font-size: 14px; }
.linkish { background: none; border: 0; padding: 0; color: var(--yellow); font-weight: 700; text-decoration: underline; cursor: pointer; }
.gone-title { font-size: 20px; color: var(--yellow); }

/* ---------------------------------------------------------- the table */
.tbl {
  position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0;
  height: calc(var(--vh) - 40px - env(safe-area-inset-top, 0px));
  padding: 4px 6px calc(4px + var(--safe-b));
}
.tbl.turn-me { box-shadow: inset 0 0 0 3px var(--yellow), inset 0 0 24px rgba(255, 213, 79, .25); border-radius: 10px; }

/* score strip */
.score { display: flex; flex-direction: column; gap: 3px; padding: 5px 8px; border-radius: 10px; background: rgba(0, 0, 0, .2); flex: none; font-size: 13px; }
.prow { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(40px, 1fr) 24px auto; align-items: center; gap: 8px; min-height: 22px; }
.prow .pn { display: flex; align-items: center; gap: 6px; min-width: 0; }
.prow .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow.on .nm { color: var(--yellow); }
.away { font-style: normal; font-size: 11px; opacity: .75; }
.pill { flex: none; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.pill.me { background: var(--yellow); color: #222; animation: pillPulse 1.4s ease-in-out infinite; }
.pill.opp { background: rgba(198, 40, 40, .9); color: #fff; }
@keyframes pillPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 213, 79, .7); } 50% { box-shadow: 0 0 0 5px rgba(255, 213, 79, 0); } }
.bar50 { position: relative; height: 8px; border-radius: 4px; background: rgba(127, 127, 127, .3); }
.bar50 .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; }
.bar50 .fill.y { background: var(--yellow); }
.bar50 .fill.o { background: #e05252; }
.bar50 .goal { position: absolute; top: -3px; bottom: -3px; border-left: 2px dashed #fff; }
.prow .tt { font-weight: 800; font-size: 15px; text-align: right; font-variant-numeric: tabular-nums; }
.clock { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 12px; padding: 1px 6px; border-radius: 5px; background: rgba(0, 0, 0, .25); }
.clock.running { background: var(--cream); color: #222; }
.clock.low { color: #fff; background: var(--red); }
.clock.out { background: #444; color: #ddd; font-size: 10px; }
.round-btn { background: none; border: 0; padding: 0; text-align: left; font-size: 12px; cursor: pointer; opacity: .9; }
.round-btn .dim { opacity: .75; }
.round-btn::after { content: " ›"; opacity: .7; }

/* hands */
.hand { display: flex; gap: 6px; justify-content: center; flex: none; }
.hand.opp { gap: 3px; padding: 5px 0 2px; }
.hand.opp .card { width: calc(var(--cw) * .5); height: calc(var(--cw) * .7); border-width: 2px; border-radius: 4px; }
.tbl.turn-opp .hand.opp .card.back { box-shadow: 0 0 0 2px rgba(255, 138, 128, .6); }
.hand.mine { padding: 12px 0 2px; }
.hand.mine .card { width: var(--hw); height: var(--hh); border-radius: 7px; }
.hand.mine .card .corner b { font-size: calc(var(--hw) * .34); }
.hand.mine .card .corner i { font-size: calc(var(--hw) * .28); }
.hand.mine .card .pip { font-size: calc(var(--hw) * .55); }
.hand.mine .card.pickable { cursor: pointer; transition: transform .12s ease, box-shadow .12s ease; }
.hand.mine .card.sel { transform: translateY(-10px); box-shadow: 0 0 0 3px var(--yellow), 0 6px 14px rgba(0, 0, 0, .5); }
body:not([data-turn=me]) .hand.mine .card.face { filter: saturate(.8) brightness(.92); }

.prompt { text-align: center; font-weight: 700; color: var(--label); font-size: 14px; min-height: 20px; flex: none; padding-top: 2px; }
.tbl.turn-me .prompt { color: var(--yellow); }

/* cards */
.card { width: var(--cw); height: var(--ch); border-radius: 5px; position: relative; flex: none; }
.card.face { background: #fff; color: #111; box-shadow: 0 1px 3px rgba(0, 0, 0, .45); }
.card.face.red { color: var(--red); }
.card .corner { position: absolute; left: 3px; top: 2px; display: flex; flex-direction: column; align-items: center; line-height: 1; }
.card .corner b { font-size: calc(var(--cw) * .36); font-weight: 800; letter-spacing: -.06em; }
.card .corner i { font-style: normal; font-size: calc(var(--cw) * .3); }
.card .pip { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: flex-end; padding: 0 5px 3px 0; font-size: calc(var(--cw) * .5); line-height: 1; }
.card.back { background: repeating-linear-gradient(45deg, #7b1e1e 0 3px, #9a2a2a 3px 6px); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .45); }
.card.slot { border: 1.5px dashed #d7efdc; background: rgba(0, 0, 0, .08); opacity: .45; box-shadow: none; }
.hand-slot { opacity: .3; }

/* lanes: six columns; each stack is absolutely laid out so card corners always show */
.lanes { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; align-content: center; padding: 2px 0; }
.lane { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 3px 0; border-radius: 8px; transition: background .15s, opacity .15s; }
.lane.playable { background: rgba(255, 213, 79, .12); box-shadow: inset 0 0 0 1.5px rgba(255, 213, 79, .55); cursor: pointer; }
.lane.full { opacity: .45; }
.hl { height: 13px; font-size: 9.5px; font-weight: 800; white-space: nowrap; color: var(--label); letter-spacing: -.02em; overflow: hidden; max-width: 100%; text-align: center; }
.stack { position: relative; width: var(--cw); height: calc(var(--ch) + var(--peek) * 2); flex: none; }
.stack > .card { position: absolute; left: 0; }
/* bottom (yours): first card nearest the Royalty row, later ones lower down; open slots as strips after them */
.stack.bottom > :nth-child(1) { top: 0; }
.stack.bottom > :nth-child(2) { top: var(--peek); }
.stack.bottom > :nth-child(3) { top: calc(var(--peek) * 2); }
.stack.bottom > .slot:nth-child(2) { top: calc(var(--ch) + 3px); height: calc(var(--peek) - 3px); }
.stack.bottom > .slot:nth-child(3) { top: calc(var(--ch) + var(--peek) + 3px); height: calc(var(--peek) - 3px); }
/* top (opponent): mirrored, the card nearest the Royalty row is the one fully shown */
.stack.top > :nth-child(1) { top: 0; }
.stack.top > :nth-child(2) { top: var(--peek); }
.stack.top > :nth-child(3) { top: calc(var(--peek) * 2); }
.stack.top > .slot:not(:last-child) { height: calc(var(--peek) - 3px); }
.card.fresh { animation: fresh 1.8s ease-out; }
@keyframes fresh { 0%, 60% { box-shadow: 0 0 0 3px var(--yellow), 0 0 14px 3px rgba(255, 213, 79, .7); } 100% { box-shadow: 0 1px 3px rgba(0, 0, 0, .45); } }

.royal-slot { position: relative; margin: 3px 0; }
.royal {
  width: calc(var(--cw) + 2px); height: calc(var(--cw) * 1.08); border-radius: 6px; position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  background: var(--cream); color: #111; border: 2px solid var(--gold); box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
}
.royal .kk { display: flex; align-items: baseline; gap: 1px; }
.royal b { font-family: Georgia, "Times New Roman", serif; font-size: calc(var(--cw) * .42); line-height: 1; }
.royal i { font-style: normal; font-size: calc(var(--cw) * .34); line-height: 1; }
.royal .red { color: var(--red); }
.royal .jest { color: var(--jester); }
.royal i.name { font-size: calc(var(--cw) * .2); font-weight: 800; letter-spacing: .04em; }
.royal .pts { position: absolute; right: 2px; bottom: 1px; font-size: calc(var(--cw) * .2); font-weight: 800; opacity: .65; }
.jester-icon { width: calc(var(--cw) * .48); height: calc(var(--cw) * .48); background: url(/jester.svg) center / contain no-repeat; }

/* reveal */
.lane.rv .hl { color: #fff; }
.lane.won-bottom .stack.bottom .card.face, .lane.won-top .stack.top .card.face { box-shadow: 0 0 0 2px var(--yellow), 0 0 10px 2px rgba(255, 213, 79, .6); }
.lane.won-bottom .hl.bottom, .lane.won-top .hl.top { color: var(--yellow); }
.lane.won-bottom .royal { transform: translateY(calc(var(--cw) * .22)) scale(.92); }
.lane.won-top .royal { transform: translateY(calc(var(--cw) * -.22)) scale(.92); }
.lane.won-bottom .royal, .lane.won-top .royal { box-shadow: 0 0 0 2px var(--yellow), 0 3px 12px rgba(0, 0, 0, .5); }
.lane.dead .stack, .lane.dead .hl { filter: grayscale(1); opacity: .5; }
.lane.dead .royal { opacity: .12; filter: grayscale(1); }
.tag {
  position: absolute; z-index: 4; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-12deg);
  background: #444; color: #fff; border: 1px solid #888; font-size: 8.5px; font-weight: 800; text-transform: uppercase;
  padding: 2px 3px; border-radius: 3px; white-space: nowrap;
}

/* end of round: a panel docked where the hand was */
.dock { flex: none; padding-top: 6px; }
.result {
  display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: 14px;
  background: rgba(14, 38, 23, .96); box-shadow: 0 -6px 30px rgba(0, 0, 0, .5), inset 0 0 0 2px rgba(201, 162, 39, .55);
}
.dock .result { max-height: calc(var(--vh) * .6); overflow-y: auto; }
/* With the round-over panel showing, the table scrolls and the panel stays pinned to the
   bottom of what's visible, above Safari's toolbar and the home indicator. */
.tbl.has-result { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tbl.has-result > * { flex-shrink: 0; }
.tbl.has-result .dock { position: sticky; bottom: 0; z-index: 20; margin-top: auto; padding-bottom: calc(6px + var(--safe-b)); }
.result h2 { font-family: Georgia, "Times New Roman", serif; font-size: 19px; color: var(--cream); }
.result .detail { margin: 0; opacity: .85; font-size: 14px; }
.result .dim { opacity: .6; }
.score-table { border-collapse: collapse; font-size: 13px; width: 100%; }
.score-table th { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; opacity: .7; text-align: left; padding: 0 6px 2px 0; }
.score-table td { padding: 2px 6px 2px 0; vertical-align: middle; }
.score-table .nm { font-weight: 700; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-table .lanes-won, .score-table .points-won, .score-table .tot { font-size: 16px; font-weight: 800; }
.score-table .tot { color: var(--yellow); }
.score-table .chips { line-height: 1.7; }
.chip { display: inline-block; margin: 0 2px 0 0; padding: 0 3px; border-radius: 3px; font-size: 10px; font-weight: 700; border: 1px solid currentColor; line-height: 1.4; }
.chip.red { color: #ff8a80; }
.chip sub { font-size: 8px; opacity: .7; margin-left: 1px; }
.choice { display: grid; grid-template-columns: 1fr 1fr; }
.seg-btn { border-radius: 0; }
.seg-btn:first-child { border-radius: 10px 0 0 10px; }
.seg-btn:last-child { border-radius: 0 10px 10px 0; }
.seg-btn.on { background: var(--cream); color: #222; }
.offer-banner { margin: 0; font-size: 17px; font-weight: 800; color: var(--yellow); }
.result.offer { box-shadow: 0 -6px 30px rgba(0, 0, 0, .5), inset 0 0 0 3px var(--yellow), 0 0 24px 4px rgba(255, 213, 79, .45); }
.btn.pulse { animation: btnPulse 1s ease-in-out infinite; }
@keyframes btnPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 213, 79, .8); } 50% { box-shadow: 0 0 0 8px rgba(255, 213, 79, 0); } }

/* waiting room and pause overlays */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 12px; z-index: 10; background: rgba(0, 0, 0, .35); }
.overlay .result { width: 100%; max-width: 420px; }
.result .link { font-size: 13px; padding: 9px 10px; }

#toast {
  position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #222; color: #fff; padding: 9px 16px; border-radius: 9px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  transition: opacity .2s, transform .2s; z-index: 500; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------- sheets: rules, hands, score */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 300; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 520px; max-height: 86vh; overflow-y: auto; padding: 16px 16px calc(16px + var(--safe-b));
  border-radius: 16px 16px 0 0; display: flex; flex-direction: column; gap: 10px;
  background: radial-gradient(ellipse at top, var(--felt-1), var(--felt-2)); box-shadow: 0 -10px 40px rgba(0, 0, 0, .5), inset 0 0 0 2px rgba(201, 162, 39, .35);
  animation: sheetIn .22s ease-out;
}
@keyframes sheetIn { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { font-family: Georgia, "Times New Roman", serif; font-size: 22px; color: var(--cream); }
.sheet h3 { margin: 8px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--label); }
.sheet p { margin: 4px 0; line-height: 1.5; }
.royal-row { display: flex; gap: 6px; margin: 6px 0; --cw: 42px; }
.hands-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; counter-reset: h; }
.hands-list li { display: flex; align-items: center; gap: 12px; counter-increment: h; }
.hands-list li::before { content: counter(h); font-weight: 800; color: var(--yellow); width: 14px; }
.hands-list .what { font-size: 12px; opacity: .75; }
/* Hand-ranking examples: fixed card proportions (5:7), never stretched by the row they sit in. */
.mini-hand { display: flex; gap: 3px; align-items: flex-start; align-self: center; flex: none; --cw: 30px; --ch: 42px; --peek: 13px; }
.mini-hand .card { width: 30px; height: 42px; aspect-ratio: 5 / 7; flex: none; }
.hist { border-collapse: collapse; width: 100%; font-size: 13px; }
.hist th, .hist td { padding: 4px 6px; text-align: left; border-top: 1px solid rgba(255, 255, 255, .1); }
.hist th { font-size: 11px; opacity: .75; font-weight: 600; border-top: 0; }
.hist tr.now td { font-style: italic; opacity: .8; }
.hist tr.sum td { font-weight: 800; color: var(--yellow); }

/* ---------------------------------------------------------- room chat (chat.ts) */
  display: flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border: 0; border-radius: 8px; cursor: pointer;
  background: rgba(255, 255, 255, .1); color: var(--cream); font-weight: 700; font-size: 14px;
}

/* ---------------------------------------------------------- celebration (fireworks.ts) */
#celebration { position: fixed; inset: 0; z-index: 400; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: opacity .8s; padding: 16px; }
#celebration.fade { opacity: 0; }
#fireworks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.celebration-banner {
  position: relative; padding: 18px 22px; border-radius: 16px; text-align: center;
  font-family: Georgia, "Times New Roman", serif; font-size: 28px; font-weight: 700; color: var(--cream);
  background: rgba(14, 38, 23, .88); box-shadow: 0 0 0 3px var(--gold), 0 20px 60px rgba(0, 0, 0, .6);
  animation: bannerIn .7s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes bannerIn { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }

/* Card lettering is generated content: not text, so it can't be selected, looked up or long-pressed. */
.g::before { content: attr(data-t); }
.card, .royal, .card *, .royal *, .hand, .lanes {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-user-drag: none;
}
.lanes, .hand { touch-action: manipulation; }
