:root {
  --felt: #1f5a3b; --felt2: #174a30; --felt-edge: #0f3220; --wood: #5a3720;
  --ink: #fdf8ee; --muted: #cfe0d2; --gold: #e8b84a; --gold2: #c8922a;
  --card-w: clamp(44px, 6.4vw, 78px); --card-h: calc(var(--card-w) * 1.4);
  --sm-w: clamp(30px, 3.4vw, 42px);
  --t0: #f4c56a; --t1: #8fc9ff; --t2: #f19aa0;
  --back: repeating-linear-gradient(45deg, #8c2b2b 0 4px, #a63838 4px 8px);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 15px/1.4 "Segoe UI", system-ui, -apple-system, sans-serif; color: var(--ink);
  background: radial-gradient(ellipse at 50% 35%, var(--felt) 0%, var(--felt2) 65%, var(--felt-edge) 100%) fixed;
}
body::before { content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .18;
  background-image: radial-gradient(rgba(255,255,255,.08) 1px, transparent 1px); background-size: 3px 3px; }
button { font: inherit; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: rgba(0,0,0,.28); position: relative; z-index: 5; }
.topbar .home { color: var(--ink); text-decoration: none; font-weight: 600; white-space: nowrap; }
.brand { margin: 0; font: 700 1.35rem Georgia, "Times New Roman", serif; letter-spacing: .03em; color: var(--gold); flex: 1; text-align: center; }
.top-right { display: flex; align-items: center; gap: 6px; color: var(--ink); }
.lang { background: rgba(0,0,0,.3); color: var(--ink); border: 1px solid rgba(255,255,255,.3); border-radius: 8px; padding: 3px 6px; }
.lang option { color: #222; }
.loading { text-align: center; padding: 3rem; }
.muted { color: var(--muted); font-size: .88em; }

.btn { background: rgba(255,255,255,.12); color: var(--ink); border: 1.5px solid rgba(255,255,255,.45); border-radius: 999px; padding: .45rem 1rem; cursor: pointer; font-weight: 600; }
.btn:hover:not(:disabled) { background: rgba(255,255,255,.22); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.gold { background: linear-gradient(180deg, var(--gold), var(--gold2)); color: #2b1a05; border-color: #f7d888; }
.btn.big { padding: .7rem 1.6rem; font-size: 1.08rem; }
.btn.small { padding: .3rem .75rem; font-size: .88rem; }
.btn.tiny { padding: .15rem .5rem; font-size: .75rem; margin-top: 4px; }

/* ------------- menu */
.menu { min-height: calc(100vh - 52px); padding: 24px 12px 40px; display: flex; justify-content: center; align-items: flex-start;
  background: linear-gradient(rgba(10,25,15,.55), rgba(10,25,15,.75)), var(--bg) center/cover no-repeat; }
.menu-card { background: rgba(18, 38, 26, .9); border: 1px solid rgba(232,184,74,.4); border-radius: 18px; padding: 20px 24px; width: min(760px, 100%); box-shadow: 0 16px 50px rgba(0,0,0,.45); }
.menu-card h2 { margin: 0 0 12px; font: 700 1.5rem Georgia, serif; color: var(--gold); }
.field { margin: 12px 0; }
.field > label { display: block; font-weight: 700; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.sub { margin-top: 6px; }
.chip { background: rgba(255,255,255,.08); color: var(--ink); border: 1.5px solid rgba(255,255,255,.3); border-radius: 999px; padding: .35rem .85rem; cursor: pointer; }
.chip.on { background: var(--gold); color: #2b1a05; border-color: var(--gold); font-weight: 700; }
.chip.locked { opacity: .65; }
.note { margin: 6px 0 0; color: var(--muted); font-size: .88rem; }
.names { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.names input { background: rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.35); color: var(--ink); border-radius: 8px; padding: 6px 8px; width: 140px; }
details.house { margin: 14px 0; background: rgba(0,0,0,.18); border-radius: 12px; padding: 8px 12px; }
details.house summary { cursor: pointer; font-weight: 700; }
.house-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px 18px; margin: 10px 0; }
.hr { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.hr small { display: block; color: var(--muted); font-size: .78rem; font-weight: 400; }
.hr select, .settings select { background: #fdf8ee; border-radius: 8px; border: 0; padding: 4px 6px; max-width: 46%; }
.go { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; align-items: center; }
.settings { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 16px; font-size: .9rem; }
.stats { color: var(--muted); font-size: .85rem; margin: 10px 0 0; }
.resume { background: rgba(232,184,74,.14); border: 1px solid rgba(232,184,74,.5); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.resume span { flex: 1; min-width: 200px; }
.gate { background: rgba(0,0,0,.22); border-radius: 12px; padding: 10px 14px; margin-top: 12px; }
.gate p { margin: 0 0 8px; }
.waiting { min-height: 70vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.curtain { text-align: center; }

/* ------------- cards */
.card { position: relative; width: var(--card-w); height: calc(var(--card-w) * 1.4); border-radius: calc(var(--card-w) * .1); background: #fffdf7; color: #1d1d1d;
  box-shadow: 0 2px 5px rgba(0,0,0,.35); border: 1px solid #d8d0bf; flex: none; user-select: none; font-family: Georgia, serif; }
.card.red { color: #c0262d; }
.card .cr { position: absolute; top: 3%; left: 6%; font-weight: 700; font-size: calc(var(--card-w) * .22); line-height: .95; text-align: center; }
.card .cr.br { top: auto; left: auto; bottom: 3%; right: 6%; transform: rotate(180deg); }
.card .pip { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--card-w) * .55); }
.card .face { position: absolute; inset: 24% 22%; display: flex; align-items: center; justify-content: center; font: 700 calc(var(--card-w) * .48) Georgia, serif;
  border: 1.5px solid currentColor; border-radius: 6px; background: linear-gradient(160deg, rgba(232,184,74,.25), rgba(232,184,74,.05)); }
.card.joker .pip { font-size: calc(var(--card-w) * .5); }
.card.joker .jk { position: absolute; bottom: 4%; width: 100%; text-align: center; font: 700 calc(var(--card-w) * .13) system-ui; letter-spacing: .05em; }
.card.wild { box-shadow: 0 0 0 2px rgba(232,184,74,.75), 0 2px 5px rgba(0,0,0,.35); }
.card.back { background: var(--back); border: 3px solid #fffdf7; }
.card.empty { background: transparent; border: 2px dashed rgba(255,255,255,.3); box-shadow: none; }
.card.sm { --card-w: var(--sm-w); }
.card.sm .cr.br { display: none; }
.card.sm .face { inset: 34% 12% 8% 30%; border: 0; background: none; font-size: calc(var(--card-w) * .42); border-width: 1px; }
.card.sm .pip { top: 25%; font-size: calc(var(--card-w) * .5); }
.card.tiny { --card-w: 22px; }

/* ------------- table */
.table { display: grid; grid-template-rows: auto 1fr auto auto; min-height: calc(100vh - 52px); padding: 8px 10px 6px; gap: 6px; max-width: 1400px; margin: 0 auto; }
.players { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.seat { background: rgba(0,0,0,.25); border-radius: 12px; padding: 6px 12px; min-width: 120px; text-align: center; border: 2px solid transparent; }
.seat.turn { border-color: var(--gold); box-shadow: 0 0 14px rgba(232,184,74,.5); }
.seat .nm { font-weight: 700; }
.seat.t0 .nm, .sc.t0, th.t0 { color: var(--t0); }
.seat.t1 .nm, .sc.t1, th.t1 { color: var(--t1); }
.seat.t2 .nm, .sc.t2, th.t2 { color: var(--t2); }
.board { display: flex; flex-direction: column; gap: 6px; }
.teams-other { display: flex; gap: 6px; flex-wrap: wrap; }
.teams-other .team { flex: 1 1 300px; }
.team { background: rgba(0,0,0,.16); border-radius: 12px; padding: 6px 10px; min-height: 70px; }
.team.mine { background: rgba(255,255,255,.07); border: 1px solid rgba(232,184,74,.35); }
.team-head { display: flex; gap: 10px; align-items: center; font-size: .92rem; }
.team.t0 .team-head b { color: var(--t0); } .team.t1 .team-head b { color: var(--t1); } .team.t2 .team-head b { color: var(--t2); }
.r3 { display: flex; gap: 2px; }
.melds { display: flex; flex-wrap: wrap; gap: 8px 10px; margin-top: 4px; }
.empty-melds { padding: 8px 0; }
.meld { display: flex; flex-direction: column; align-items: center; border-radius: 8px; padding: 2px; }
.meld.mine { cursor: pointer; }
.meld.mine:hover { background: rgba(232,184,74,.2); }
.mcards { display: flex; }
.mcards .card + .card { margin-left: calc(var(--sm-w) * -0.62); }
.meld.done .mcards .card { box-shadow: 0 0 0 2px #fff, 0 0 0 4px #c0262d; }
.meld.done.dirty .mcards .card { box-shadow: 0 0 0 2px #fff, 0 0 0 4px #222; }
.mlabel { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.mlabel b { color: var(--ink); }
.center { display: flex; gap: 18px; align-items: center; justify-content: center; flex-wrap: wrap; padding: 4px; }
.pile-wrap { display: flex; gap: 14px; }
.stock, .pile { position: relative; background: none; border: 0; padding: 0; cursor: pointer; }
.stock:disabled, .pile:disabled { cursor: default; }
.stock:not(:disabled) .card, .pile:not(:disabled) .card { box-shadow: 0 0 0 3px var(--gold), 0 4px 10px rgba(0,0,0,.4); }
.cnt { position: absolute; bottom: -6px; right: -6px; background: #111c; color: #fff; border-radius: 99px; padding: 0 7px; font-size: .78rem; }
.frz { position: absolute; top: -8px; left: -8px; background: #9fd3ff; color: #08304f; border-radius: 99px; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-size: .85rem; }
.pile.frozen .card { transform: rotate(-4deg); }
.info { min-width: 240px; max-width: 460px; }
.score-line { display: flex; gap: 14px; flex-wrap: wrap; font-size: 1rem; }
.status { margin-top: 4px; font-weight: 600; }
.status.go { color: var(--gold); }
.hand-area { background: rgba(0,0,0,.2); border-radius: 14px; padding: 8px 10px; }
.hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 0; padding: 14px 4px 4px; min-height: calc(var(--card-h) + 18px); }
.hand .card { margin: 0 calc(var(--card-w) * -0.32) 6px 0; cursor: pointer; transition: transform .12s; }
.hand .card:hover { transform: translateY(-6px); }
.hand .card.sel { transform: translateY(-14px); box-shadow: 0 0 0 3px var(--gold), 0 6px 12px rgba(0,0,0,.45); z-index: 2; }
.staged { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: .88rem; padding: 4px; }
.sg { display: flex; cursor: pointer; padding: 3px; border-radius: 6px; background: rgba(232,184,74,.2); }
.sg .card + .card { margin-left: calc(var(--sm-w) * -0.55); }
.foot-note { text-align: center; color: var(--muted); font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; padding-top: 6px; }
.sel-info { flex-basis: 100%; text-align: center; }
.log { text-align: center; color: var(--muted); font-size: .9rem; }
.table-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal.peek { background: transparent; pointer-events: none; align-items: flex-end; }
.modal.peek .results { pointer-events: auto; max-height: 120px; overflow: hidden; opacity: .95; }
.results table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.results td, .results th { padding: 5px 8px; text-align: right; border-bottom: 1px solid rgba(255,255,255,.1); }
.results td:first-child { text-align: left; }
.results tr.sum td { font-weight: 700; }
.results tr.total td { font-weight: 800; color: var(--gold); font-size: 1.08rem; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 30px); background: #1b1206ee; color: #fff; padding: 10px 18px; border-radius: 12px;
  opacity: 0; transition: .25s; z-index: 50; max-width: 92vw; text-align: center; pointer-events: none; border: 1px solid var(--gold2); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------- rules */
.rules { padding: 16px 10px 40px; display: flex; justify-content: center; }
.rules-card { background: #fbf6ea; color: #2a2116; border-radius: 16px; padding: 18px 24px; width: min(900px, 100%); box-shadow: 0 12px 40px rgba(0,0,0,.4); }
.rules-top { display: flex; justify-content: space-between; align-items: center; }
.rules-card h2 { font: 700 1.6rem Georgia, serif; margin: 0; color: #6b3d0f; }
.rules-card h3 { font: 700 1.2rem Georgia, serif; color: #6b3d0f; margin: 18px 0 6px; }
.rules-card h4 { margin: 14px 0 4px; }
.rules-card .btn { color: #2a2116; border-color: #9b8a6a; }
.rules-card .chip { color: #2a2116; border-color: #b9a885; }
.rules-card .chip.on { color: #2b1a05; }
.tabs { margin: 12px 0 6px; }
.rules-card table { border-collapse: collapse; width: 100%; margin: 6px 0; }
.rules-card th, .rules-card td { border-bottom: 1px solid #e2d6bd; padding: 6px 8px; text-align: left; vertical-align: top; }
.rules-card th small { display: block; font-weight: 400; color: #7a6a52; font-size: .8rem; }
.rules-card tr.changed td:nth-child(2) { color: #a5470c; font-weight: 700; }
.rules-card .muted { color: #7a6a52; }
.rules-card li { margin: 3px 0; }

@media (max-width: 640px) {
  .brand { font-size: 1.1rem; }
  .topbar .home span { display: none; }
  .menu-card { padding: 16px 14px; }
  .info { min-width: 0; }
  .seat { min-width: 90px; padding: 4px 8px; font-size: .85rem; }
  .hr select { max-width: 55%; }
}

/* ------------- dark mode (the site's Auto / Light / Dark setting: <html data-iht-theme>) */
[data-iht-theme="dark"] { color-scheme: dark; }
[data-iht-theme="dark"] body { --felt: #163d29; --felt2: #102e1f; --felt-edge: #081a11; --muted: #b5c7b9; }
[data-iht-theme="dark"] body[data-theme="burgundy"] { --felt: #4c1620; --felt2: #3c1119; --felt-edge: #1e070b; }
[data-iht-theme="dark"] body[data-theme="navy"] { --felt: #14263f; --felt2: #0f1e33; --felt-edge: #070e18; }
[data-iht-theme="dark"] body[data-theme="walnut"] { --felt: #3f2917; --felt2: #332112; --felt-edge: #180f08; }
[data-iht-theme="dark"] body[data-theme="sage"] { --felt: #44593f; --felt2: #384a34; --felt-edge: #1d271b; }
[data-iht-theme="dark"] .menu-card { background: rgba(16, 24, 18, .94); }
[data-iht-theme="dark"] .card { background: #ece5d6; border-color: #b9ad94; }
[data-iht-theme="dark"] .card.back { border-color: #ece5d6; }
[data-iht-theme="dark"] .card.empty { background: transparent; }
[data-iht-theme="dark"] .rules-card { background: #2a2018; color: #f1e6d2; }
[data-iht-theme="dark"] .rules-card h2, [data-iht-theme="dark"] .rules-card h3 { color: #e8b84a; }
[data-iht-theme="dark"] .rules-card th, [data-iht-theme="dark"] .rules-card td { border-color: #4a3a2a; }
[data-iht-theme="dark"] .rules-card th small, [data-iht-theme="dark"] .rules-card .muted { color: #bfae92; }
[data-iht-theme="dark"] .rules-card .btn, [data-iht-theme="dark"] .rules-card .chip { color: #f1e6d2; border-color: #7a6a52; }
[data-iht-theme="dark"] .rules-card .chip.on { color: #2b1a05; }
[data-iht-theme="dark"] .rules-card tr.changed td:nth-child(2) { color: #f0a868; }
[data-iht-theme="dark"] .hr select, [data-iht-theme="dark"] .settings select { background: #2a2018; color: #f1e6d2; }
.blk { position: absolute; top: -8px; right: -8px; font-size: 1rem; }
.meld.hint { background: rgba(232,184,74,.35); outline: 2px dashed var(--gold); }

/* ------------- phones: the hand and buttons stay at the bottom, the table scrolls above them */
.status-m, .seat .bot-i { display: none; }
.seat .pt { color: var(--gold); font-size: .8em; }
.card, .btn, .chip, .stock, .pile, .meld { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.melds::-webkit-scrollbar, .players::-webkit-scrollbar { height: 4px; }

@media (max-width: 640px), (max-height: 520px) {
  .topbar { padding: 4px 10px; gap: 8px; }
  .brand { font-size: 1.05rem; }
  .lang { padding: 2px 4px; font-size: .85rem; }
  .table { display: flex; flex-direction: column; height: calc(100dvh - var(--top, 40px)); min-height: 0; padding: 4px 6px 6px; gap: 4px;
    --card-w: clamp(44px, 13.6vw, 58px); --sm-w: 25px; }
  .upper { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; overscroll-behavior: contain; }
  .players { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; gap: 4px; flex: none; }
  .seat { min-width: 0; flex: 1 0 auto; padding: 3px 8px; border-radius: 9px; display: flex; flex-direction: column; align-items: center; font-size: .78rem; line-height: 1.2; }
  .seat .role { display: none; }
  .seat .bot-i { display: inline; font-size: .85em; margin-right: 2px; }
  .seat .cards-left { font-size: .74rem; white-space: nowrap; }
  .board { gap: 4px; flex: none; }
  .teams-other { flex-wrap: nowrap; flex-direction: column; gap: 4px; }
  .teams-other .team { flex: none; }
  .team { padding: 4px 6px; min-height: 0; border-radius: 9px; }
  .team-head { font-size: .8rem; gap: 6px; }
  .melds { flex-wrap: nowrap; overflow-x: auto; gap: 6px; margin-top: 2px; padding-bottom: 2px; }
  .meld { flex: none; padding: 1px; }
  .mlabel { font-size: .66rem; }
  .empty-melds { padding: 2px 0; font-size: .75rem; }
  .r3 .card.tiny { --card-w: 16px; }
  .center { flex-wrap: nowrap; justify-content: flex-start; gap: 10px; padding: 2px 2px; }
  .pile-wrap { gap: 10px; flex: none; }
  .center .card { --card-w: 46px; }
  .cnt { font-size: .7rem; padding: 0 5px; }
  .frz, .blk { width: 18px; height: 18px; font-size: .7rem; top: -6px; }
  .info { min-width: 0; flex: 1; font-size: .78rem; line-height: 1.3; }
  .score-line { font-size: .82rem; gap: 2px 10px; }
  .info .status { display: none; }
  .hand-area { flex: none; padding: 4px 6px 6px; border-radius: 12px; }
  .status-m { display: block; text-align: center; font-size: .82rem; margin: 0; line-height: 1.25; }
  .hand { flex-wrap: wrap; padding: 12px 0 0; min-height: calc(var(--card-w) * 1.4 + 12px); }
  .hand .card { margin-bottom: 4px; }
  .hand .card:hover { transform: none; }
  .hand .card.sel { transform: translateY(-11px); }
  .staged { flex-wrap: nowrap; overflow-x: auto; font-size: .75rem; gap: 6px; padding: 2px; }
  .staged span:first-child { flex: none; max-width: 40%; }
  .foot-note { font-size: .74rem; }
  .actions { gap: 6px; padding-top: 4px; }
  .actions .btn { padding: .5rem .85rem; font-size: .9rem; min-height: 40px; }
  .sel-info { font-size: .75rem; }
  .sel-info.tip { display: none; }
  .log { font-size: .78rem; line-height: 1.3; }
  .table-bar { flex: none; gap: 6px; justify-content: center; }
  .table-bar .btn { padding: .3rem .8rem; min-height: 34px; }
  .table-bar .lbl { display: none; }
  .table-bar .muted { font-size: .75rem; }
  .modal { padding: 8px; }
  .results { padding: 14px 12px; }
  .results h2 { font-size: 1.25rem; }
  .results table { font-size: .82rem; }
  .results td, .results th { padding: 4px 5px; }
  .rules { padding: 8px 6px 30px; }
  .rules-card { padding: 14px 14px; }
  .rules-card th, .rules-card td { padding: 5px 4px; font-size: .88rem; }
  .facts th { width: 38%; }
  .menu { padding: 12px 8px 30px; min-height: calc(100dvh - var(--top, 40px)); }
  .menu-card { padding: 14px 12px; }
  .menu-card h2 { font-size: 1.25rem; }
  .chip { padding: .45rem .8rem; min-height: 38px; }
  .hr { flex-direction: column; align-items: stretch; gap: 4px; }
  .hr select { max-width: none; padding: 7px 6px; font-size: .95rem; }
  .settings { gap: 10px 14px; }
}
/* Short landscape phones: melds and info take less height. */
@media (max-height: 520px) and (orientation: landscape) {
  .table { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); grid-template-rows: minmax(0, 1fr) auto;
    --card-w: clamp(40px, 6.4vw, 54px); padding-left: max(6px, env(safe-area-inset-left)); padding-right: max(6px, env(safe-area-inset-right)); }
  .upper { grid-column: 1; grid-row: 1 / span 2; }
  .hand-area { grid-column: 2; grid-row: 1; overflow-y: auto; display: flex; flex-direction: column; justify-content: center; }
  .table-bar { grid-column: 2; grid-row: 2; }
  .center .card { --card-w: 40px; }
  .seat { flex: 1 1 0; padding: 2px 4px; }
}
@media (max-width: 640px) {
  .seat { flex: 1 1 0; padding: 3px 4px; }
  .seat .nm { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .seat .cards-left { font-size: .7rem; }
  .actions .btn { padding: .5rem .7rem; font-size: .86rem; }
}
@media (max-width: 380px) {
  .seat { font-size: .72rem; }
  .seat .bot-i { display: none; }
}
