:root {
  --bg: #07281e; --felt: #0f5a3f; --felt2: #0a4430; --panel: rgba(0, 0, 0, .28); --line: rgba(255, 255, 255, .14);
  --txt: #f3f7f4; --mut: #a9c4b6; --gold: #f5c542; --red: #d62839; --blue: #3b82f6; --ok: #34d399; --bad: #f87171;
  --cw: clamp(52px, 17vw, 84px); /* card width */
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--txt); font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; overscroll-behavior: none; }
body { background: radial-gradient(120% 90% at 50% 0%, #0e6a49 0%, var(--bg) 70%) fixed; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }
h1, h2, h3, p { margin: 0; }

/* ---------- buttons & bits ---------- */
.btn { background: rgba(255, 255, 255, .12); border: 1px solid var(--line); border-radius: 12px; padding: 9px 14px; font-weight: 600; touch-action: manipulation; }
.btn:hover { background: rgba(255, 255, 255, .2); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.gold { background: linear-gradient(#ffd75e, #f0b429); color: #2b2100; border-color: #b8860b; }
.btn.red { background: linear-gradient(#ef5a69, #c1202f); border-color: #8f1522; }
.btn.green { background: linear-gradient(#3fd8a4, #1ea577); color: #04281b; border-color: #138a60; }
.btn.big { padding: 13px 18px; font-size: 1.05rem; width: 100%; }
.btn.sm { padding: 5px 10px; font-size: .85rem; border-radius: 9px; }
.icon { background: transparent; border: 0; font-size: 1.25rem; padding: 6px 7px; border-radius: 10px; position: relative; }
.icon:hover { background: rgba(255, 255, 255, .12); }
.chip { background: rgba(255, 255, 255, .12); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: .9rem; }
.chip b { letter-spacing: .12em; color: var(--gold); }
.pill { font-size: .78rem; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.sub, .hint, .mut { color: var(--mut); font-size: .9rem; }
.err { color: var(--bad); margin-top: 8px; font-size: .92rem; }
.spacer { flex: 1; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #6b7f75; margin-right: 6px; }
.dot.on { background: var(--ok); }
#chatDot { position: absolute; top: 4px; right: 4px; width: 9px; height: 9px; background: var(--gold); border-radius: 50%; }

/* ---------- login ---------- */
#login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 18px; }
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 24px 20px; backdrop-filter: blur(6px); }
.logo { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 8px; }
.logo h1 { width: 100%; text-align: center; font-size: 2.4rem; letter-spacing: .25em; color: var(--gold); margin-top: 10px; }
.logo h1 small { display: block; font-size: .8rem; letter-spacing: .3em; color: var(--mut); text-transform: uppercase; }
.lcard { width: 46px; height: 64px; background: #fff; color: #111; border-radius: 7px; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 4px 10px rgba(0, 0, 0, .4); font-size: 1.2rem; }
.lcard.red { color: var(--red); } .lcard i { font-style: normal; }
.lcard.c1 { transform: rotate(-12deg); } .lcard.c3 { transform: rotate(12deg); } .lcard.c2 { transform: translateY(-6px); }
.tag { text-align: center; color: var(--mut); margin-bottom: 14px; }
.seg { display: flex; background: rgba(0, 0, 0, .3); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; background: transparent; border: 0; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--mut); }
.seg button.on { background: rgba(255, 255, 255, .16); color: var(--txt); }
.modes { margin-bottom: 12px; }
#loginForm label, .field { display: block; margin-bottom: 10px; font-size: .88rem; color: var(--mut); }
#loginForm input, .field input, .field select { display: block; width: 100%; margin-top: 4px; padding: 11px 12px; border-radius: 11px; border: 1px solid var(--line); background: rgba(0, 0, 0, .35); color: var(--txt); font-size: 1rem; }
#loginForm input#inCode { text-transform: uppercase; letter-spacing: .2em; }
.hint { text-align: center; margin-top: 12px; }
.spinner { width: 38px; height: 38px; margin: 14px auto; border: 4px solid rgba(255, 255, 255, .2); border-top-color: var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- room chrome ---------- */
#room { height: 100dvh; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 6px; padding: calc(6px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) 6px calc(8px + env(safe-area-inset-left)); background: rgba(0, 0, 0, .35); border-bottom: 1px solid var(--line); flex: none; }
.brand { display: flex; align-items: center; gap: 6px; }
.dot-ball { width: 26px; height: 26px; border-radius: 50%; background: var(--gold); color: #2b2100; font-weight: 800; display: grid; place-items: center; }
#soundBar { background: var(--gold); color: #2b2100; border: 0; padding: 8px; font-weight: 700; flex: none; }
#knockBar { background: #1e3a8a; padding: 8px 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: none; }
#knockBar .who { display: flex; align-items: center; gap: 6px; background: rgba(255, 255, 255, .12); border-radius: 10px; padding: 4px 8px; font-size: .9rem; }
#view { flex: 1; min-height: 0; overflow: auto; padding: 8px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left)); }
.card-box { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 10px; }
.card-box h3 { margin-bottom: 8px; font-size: 1.05rem; }

/* ---------- lobby ---------- */
.lobby { max-width: 640px; margin: 0 auto; }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: center; gap: 6px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.plist li:last-child { border-bottom: 0; }
.tagb { font-size: .72rem; border-radius: 999px; padding: 2px 8px; background: rgba(255, 255, 255, .14); }
.tagb.host { background: var(--gold); color: #2b2100; } .tagb.in { background: #166534; } .tagb.out { background: #7f1d1d; } .tagb.wait { background: #1e40af; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; color: var(--txt); }
.check input { width: 20px; height: 20px; margin: 0; }

/* ---------- cards ---------- */
.card { width: var(--cw); height: calc(var(--cw) * 1.4); background: #fff; color: #14181f; border-radius: calc(var(--cw) * .11); position: relative; box-shadow: 0 3px 8px rgba(0, 0, 0, .45); flex: none; user-select: none; transition: transform .12s, box-shadow .12s; border: 1px solid #cfd6dd; }
.card.red { color: var(--red); }
.card .rk { position: absolute; top: 3%; left: 8%; font-weight: 800; font-size: calc(var(--cw) * .34); line-height: 1; letter-spacing: -.04em; }
.card .st { position: absolute; top: 33%; left: 8%; font-size: calc(var(--cw) * .26); line-height: 1; }
.card .big { position: absolute; right: 8%; bottom: 4%; font-size: calc(var(--cw) * .56); line-height: 1; }
.card.jk { background: linear-gradient(135deg, #fff 0%, #ffe9a8 100%); }
.card.jk .big { font-size: calc(var(--cw) * .6); right: 50%; transform: translateX(50%); bottom: 14%; }
.card.jk .rk { font-size: calc(var(--cw) * .17); writing-mode: vertical-rl; top: 6%; letter-spacing: .06em; }
.card.back { background: repeating-linear-gradient(45deg, #1d4ed8 0 6px, #1e40af 6px 12px); border: 3px solid #fff; }
.card.mini { --cw: 34px; }
.hand .card { cursor: pointer; }
.hand .card.sel { transform: translateY(-16px); box-shadow: 0 0 0 3px var(--gold), 0 8px 14px rgba(0, 0, 0, .5); }
.hand .card.match::after { content: ''; position: absolute; inset: -2px; border-radius: inherit; box-shadow: 0 0 0 2px var(--ok), 0 0 12px var(--ok); pointer-events: none; }
.hand .card.fresh::before { content: 'NEW'; position: absolute; top: -9px; right: -4px; background: var(--blue); color: #fff; font-size: .62rem; font-weight: 800; border-radius: 6px; padding: 1px 5px; z-index: 2; }
.hand .card.locked { opacity: .55; cursor: not-allowed; }

/* ---------- table ---------- */
#table { height: 100%; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.opps { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 6px; flex: none; }
.opp { flex: none; min-width: 92px; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; padding: 6px 10px; text-align: center; position: relative; }
.opp .nm { font-weight: 700; font-size: .92rem; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp .meta { font-size: .78rem; color: var(--mut); }
.opp .cards { display: flex; justify-content: center; margin: 4px 0 2px; height: 30px; }
.opp .cards .card { --cw: 20px; margin-left: -9px; box-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.opp .cards .card:first-child { margin-left: 0; }
.opp.turn { border-color: var(--gold); box-shadow: 0 0 14px rgba(245, 197, 66, .55); }
.opp.offline { opacity: .5; } .opp.outp { opacity: .4; text-decoration: line-through; }
.centre { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: clamp(10px, 4vw, 34px); flex-wrap: wrap; align-content: center; padding: 6px 0; }
.pile { text-align: center; }
.pile .lab { font-size: .8rem; color: var(--mut); margin-top: 6px; }
.deck { position: relative; cursor: default; }
.deck.can { cursor: pointer; }
.deck.can .card { box-shadow: 0 0 0 3px var(--gold), 0 0 16px var(--gold); animation: pulse 1.2s infinite; }
.deck .card + .card { position: absolute; top: -3px; left: -3px; z-index: -1; }
.deck .cnt { position: absolute; bottom: -6px; right: -6px; background: #000a; border-radius: 999px; padding: 1px 8px; font-size: .78rem; }
@keyframes pulse { 50% { transform: scale(1.04); } }
.drop { display: flex; justify-content: center; min-height: calc(var(--cw) * 1.4); min-width: var(--cw); padding-left: calc(var(--cw) * .5); max-width: 92vw; }
.drop .card { margin-left: calc(var(--cw) * -.5); }
.drop.can .card { cursor: pointer; box-shadow: 0 0 0 3px var(--gold); }
.drop.can .card:hover { transform: translateY(-8px); }
.drop .empty { margin-left: calc(var(--cw) * -.5); width: var(--cw); height: calc(var(--cw) * 1.4); border: 2px dashed var(--line); border-radius: 10px; display: grid; place-items: center; color: var(--mut); font-size: .75rem; }
.logbox { width: min(260px, 90vw); font-size: .8rem; color: var(--mut); max-height: 110px; overflow: auto; background: rgba(0, 0, 0, .22); border-radius: 12px; padding: 6px 10px; }
.logbox div:last-child { color: var(--txt); font-weight: 600; }
.status { text-align: center; min-height: 22px; font-weight: 700; flex: none; }
.status.me { color: var(--gold); animation: glow 1.6s infinite; }
@keyframes glow { 50% { opacity: .6; } }
.mine { flex: none; padding-top: 4px; }
.mine .top { display: flex; justify-content: space-between; align-items: center; font-size: .9rem; color: var(--mut); padding: 0 4px 4px; }
.hand { display: flex; justify-content: center; padding: 20px 4px 6px; min-height: calc(var(--cw) * 1.4 + 30px); }
.hand .card { margin-left: calc(var(--cw) * -.22); }
.hand .card:first-child { margin-left: 0; }
.hand.few .card { margin-left: 6px; }
.hand .none { color: var(--mut); align-self: center; }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding-top: 14px; }
.actions .btn.show { margin-left: auto; margin-right: 4px; } /* Show sits at the right edge, well away from the cards */
.actions .btn { min-width: 108px; padding: 11px 14px; }
.hintline { text-align: center; font-size: .82rem; color: var(--mut); min-height: 18px; padding: 2px 8px; }

/* ---------- results ---------- */
.result { width: min(560px, 100%); margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px; overflow: auto; max-height: 100%; }
.result h2 { text-align: center; font-size: 1.3rem; }
.result h2.ok { color: var(--ok); } .result h2.bad { color: var(--bad); }
.rrow { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.rrow .nm { min-width: 84px; font-weight: 700; }
.rrow .cs { display: flex; flex: 1; min-width: 150px; padding-left: 10px; }
.rrow .cs .card { margin-left: -14px; }
.rrow .pts { text-align: right; min-width: 70px; font-weight: 800; }
.rrow .pts small { display: block; font-weight: 400; color: var(--mut); }
.rrow.claimer .nm::after { content: ' 🙋'; }
.winner { text-align: center; font-size: 1.5rem; margin: 6px 0; color: var(--gold); }

/* ---------- modal / tables ---------- */
#modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 12px; }
.modal-box { background: #0d3a2b; border: 1px solid var(--line); border-radius: 18px; padding: 16px; width: min(560px, 100%); max-height: 90dvh; overflow: auto; }
.modal-box h3 { margin-bottom: 10px; font-size: 1.15rem; display: flex; justify-content: space-between; align-items: center; }
table.score { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.score th, table.score td { padding: 6px 6px; text-align: center; border-bottom: 1px solid var(--line); }
table.score th:first-child, table.score td:first-child { text-align: left; }
table.score tr.tot td { font-weight: 800; border-top: 2px solid var(--line); }
table.score td.fail { color: var(--bad); font-weight: 700; } table.score td.zero { color: var(--ok); font-weight: 700; }
.scroll-x { overflow-x: auto; }
.chatlog { height: 200px; overflow: auto; background: rgba(0, 0, 0, .25); border-radius: 12px; padding: 8px; font-size: .92rem; margin-bottom: 8px; }
.chatlog p { margin: 2px 0; word-break: break-word; } .chatlog b { color: var(--gold); }
.emojis { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.emojis button { font-size: 1.5rem; background: rgba(255, 255, 255, .1); border: 0; border-radius: 12px; padding: 6px 10px; }
.chatform { display: flex; gap: 6px; } .chatform input { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, .35); color: var(--txt); }

/* ---------- toasts & reactions ---------- */
#toasts { position: fixed; top: 38%; right: 8px; z-index: 70; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; pointer-events: none; max-width: min(46vw, 260px); }
.toast { background: #000d; border: 1px solid var(--line); padding: 8px 14px; border-radius: 12px; font-size: .92rem; animation: tin .25s, tout .4s 2.5s forwards; text-align: left; font-size: .82rem; }
@keyframes tin { from { opacity: 0; transform: translateX(16px); } } @keyframes tout { to { opacity: 0; } }
#banner { position: fixed; top: 0; left: 0; right: 0; z-index: 80; background: var(--red); text-align: center; padding: 4px; font-weight: 700; }
#reactions { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.react { position: absolute; bottom: 90px; text-align: center; animation: floatup 3s ease-out forwards; font-size: 2.6rem; }
.react small { display: block; font-size: .75rem; background: #0009; border-radius: 8px; padding: 1px 6px; }
@keyframes floatup { to { transform: translateY(-60vh) scale(1.3); opacity: 0; } }

/* ---------- compact layouts (phone landscape / short screens): table on the left, my hand on the right ---------- */
@media (max-height: 520px) {
  :root { --cw: clamp(40px, 12vh, 62px); }
  #topbar { padding-top: 2px; padding-bottom: 2px; }
  #soundBar { padding: 3px; font-size: .85rem; }
  #view { padding-top: 4px; padding-bottom: 4px; }
  #table { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); grid-template-rows: auto auto minmax(0, 1fr); gap: 2px 10px; }
  .opps { grid-column: 1 / -1; padding: 0 0 2px; } .opp { padding: 2px 8px; min-width: 76px; } .opp .cards { display: none; }
  .status { grid-column: 1 / -1; min-height: 0; font-size: .9rem; }
  .centre { grid-column: 1; flex-wrap: nowrap; gap: 14px; } .logbox { display: none; }
  .pile .lab { font-size: .68rem; margin-top: 2px; }
  .mine { grid-column: 2; display: flex; flex-direction: column; justify-content: center; padding: 0; }
  .mine .top, .hintline { display: none; } .hand { padding: 12px 0 2px; min-height: 0; }
  .actions { padding-top: 8px; } .actions .btn { min-width: 84px; padding: 6px 10px; }
  .hand .card.sel { transform: translateY(-10px); }
  .result { grid-column: 1 / -1; }
}
@media (min-width: 900px) { :root { --cw: 92px; } .opp { min-width: 130px; } }

/* ---------- narrow phones: keep the whole top bar on one line ---------- */
.chip { white-space: nowrap; }
@media (max-width: 480px) {
  #topbar { gap: 3px; }
  .brand b { display: none; }
  .chip { padding: 4px 9px; font-size: .8rem; }
  .pill { font-size: .7rem; padding: 3px 7px; }
  .icon { font-size: 1.1rem; padding: 5px 4px; }
}

.brand { text-decoration: none; color: inherit; }
.homelink { display: block; text-align: center; color: var(--mut); text-decoration: none; font-size: .9rem; margin-bottom: 10px; }
.homelink:hover { color: var(--txt); }
