:root { color-scheme: light dark; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100dvh; margin: 0; overflow: hidden; overscroll-behavior: none; }
body { font-family: system-ui, -apple-system, sans-serif; display: flex; flex-direction: column; background: #0e3b2e; color: #fff; }
header { position: fixed; top: 0; left: 0; right: 0; height: 60px; z-index: 40; display: flex; align-items: center; gap: 12px; margin: 0; border-radius: 0; padding: 8px 12px; background: #0a2c22; }
.title { flex: 1; text-align: left; font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { min-width: 44px; min-height: 44px; font-size: 20px; padding: 6px 10px; }
.menudrop { position: absolute; top: 100%; left: 8px; z-index: 20; background: #071f19; border: 1px solid #2c5f50; border-radius: 12px; padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); }
.menudrop button { width: 100%; border: none; background: transparent; text-align: left; }
.menudrop button:active { background: #17493c; }
button { touch-action: manipulation; font-size: 16px; min-height: 44px; padding: 10px 14px; border-radius: 12px; border: 1px solid #2c5f50; background: #17493c; color: #fff; }
button:active { transform: scale(0.97); background: #1f6352; }
button.primary { background: #e0a100; border-color: #a87600; color: #221a00; font-weight: 700; }
button.big { width: 100%; min-height: 52px; font-size: 18px; }
button:disabled { opacity: 0.45; }
main { flex: 1; overflow-y: auto; contain: strict; padding: 60px 12px calc(96px + env(safe-area-inset-bottom)); }
body.nofoot main { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
body.nofoot #view-room { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
body.nofoot #table { flex: 1; min-height: 0; display: flex; flex-direction: column; }
footer { position: fixed; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #0a2c22; border-top: 1px solid #2c5f50; z-index: 10; }
body.nofoot footer { display: none; }
footer button { flex: none; width: 100%; }
.foothint { font-size: 13px; opacity: 0.85; text-align: center; }
body.team main { padding-bottom: calc(190px + env(safe-area-inset-bottom)); }
/* full-screen modal (keep .hidden AFTER .overlay) */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.65); padding: 20px; }
.modal { background: #10493a; border-radius: 16px; padding: 20px; width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }
.modal h2 { margin: 0; font-size: 20px; text-align: left; }
.overlay.top { align-items: flex-start; padding-top: 16dvh; }
.modal input { font-size: 16px; padding: 12px; border-radius: 10px; border: 1px solid #2c5f50; }
.hidden { display: none !important; }
.err { background: #7f1d1d; padding: 10px; border-radius: 10px; margin-bottom: 10px; }
.rooms { display: flex; flex-direction: column; gap: 10px; }
.rooms:empty { display: none; }

/* Team / join screen */
.team { background: #10493a; border-radius: 14px; padding: 10px; margin: 10px 0; }
.team h4 { margin: 0 0 8px; font-size: 14px; }
.tm-seat { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: #0a2c22; margin-top: 6px; }
.tm-seat .avatar { width: 44px; height: 44px; font-size: 22px; flex: none; }
.tm-seat .tname { font-size: 15px; max-width: none; }
.tm-seat .tsub { font-size: 12px; }
.tm-seat.mine { outline: 2px solid #e0a100; }
.tm-seat:disabled { opacity: 0.65; }
.tm-seat > div:last-child { flex: 1; min-width: 0; }
#view-team .tname, #view-team .tsub { text-align: left; }
.room { background: #10493a; border-radius: 14px; padding: 12px; }
.room .rname { font-size: 18px; font-weight: 700; }
.room .rmeta { opacity: 0.85; font-size: 14px; margin-top: 4px; }
.room .rrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.room .rrow .rmeta { margin-top: 0; }
.live { color: #ffd23f; font-weight: 800; }
.livedot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #ffd23f; margin-right: 5px; animation: pulse 1.1s ease-in-out infinite; }
/* Bidding */
#trumpSuits { margin-top: 12px; }

.hint { text-align: center; font-size: 13px; opacity: 0.85; margin-top: 6px; }

/* Table */
.table { margin-top: 4px; display: flex; flex-direction: column; gap: 8px; }
.felt { position: relative; background: radial-gradient(ellipse at center, #1a6b4f 0%, #10493a 70%); border-radius: 18px; flex: 1 1 auto; min-height: 150px; padding: 8px; }
.edge-top { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.edge-bottom { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.edge-left { position: absolute; left: 4px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.edge-right { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.fbacks.horiz { display: flex; }
.fbacks.horiz .bback { margin-left: -22px; }
.fbacks.horiz .bback:first-child { margin-left: 0; }
.fbacks.vert { display: flex; flex-direction: column; }
.fbacks.vert .bback + .bback { margin-top: -34px; }
.bback { position: relative; width: 34px; height: 50px; flex: none; }
.bback svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: #071f19; border: 2px solid #999; border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.pill.turn { border-color: #ffd23f; box-shadow: 0 0 0 2px #ffd23f, 0 0 14px 3px rgba(255, 210, 63, 0.75); animation: pulse 1.1s ease-in-out infinite; }
.pill.dim { opacity: 0.55; }
.bub { position: absolute; z-index: 5; background: #071f19; border: 2px solid #fff; border-radius: 16px; padding: 10px 16px; font-size: 16px; font-weight: 800; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.bub::after { content: ""; position: absolute; border: 8px solid transparent; }
#bubTop { top: 33%; left: 50%; transform: translateX(-50%); }
#bubTop::after { bottom: 100%; left: 50%; transform: translateX(-50%); border-bottom-color: #fff; border-top: none; }
#bubBottom { bottom: 20%; left: 50%; transform: translateX(-50%); }
#bubBottom::after { top: 100%; left: 50%; transform: translateX(-50%); border-top-color: #fff; border-bottom: none; }
#bubLeft { left: 14%; top: 52%; transform: translateY(-50%); max-width: 130px; }
#bubLeft::after { left: 100%; top: 50%; transform: translateY(-50%); border-left-color: #fff; border-right: none; }
#bubRight { right: 14%; top: 52%; transform: translateY(-50%); max-width: 130px; }
#bubRight::after { right: 100%; top: 50%; transform: translateY(-50%); border-right-color: #fff; border-left: none; }
.avatar { position: relative; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; background: #071f19; border: 3px solid var(--seat, #999); }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px #ffd23f, 0 0 26px 8px rgba(255, 210, 63, 0.9); } }
.avatar .badge { position: absolute; right: -6px; bottom: -6px; font-size: 16px; background: #071f19; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; }
.tname { font-size: 12px; font-weight: 700; text-align: center; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tname .you, .pill .you, .you { background: #e0a100; color: #221a00; border-radius: 6px; padding: 0 4px; font-size: 10px; margin-left: 3px; }
.tsub { font-size: 11px; opacity: 0.9; text-align: center; min-height: 14px; }

.tcenter { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -58%); width: 190px; height: 150px; }
.played { position: absolute; width: 62px; }
.played .cdot { width: 10px; height: 10px; border-radius: 50%; margin: 2px auto 0; }
.played.p-top { left: 50%; top: 0; transform: translateX(-50%); }
.played.p-bottom { left: 50%; bottom: 0; transform: translateX(-50%); }
.played.p-left { left: 0; top: 50%; transform: translateY(-50%); }
.played.p-right { right: 0; top: 50%; transform: translateY(-50%); }
.played.pending { width: 62px; height: 90px; border: 2px dashed #7d8b87; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 22px; color: #aeb8b4; }

.panel { background: #10493a; border-radius: 12px; padding: 10px; }
.bidrow { display: flex; gap: 8px; margin-top: 8px; }
.bidrow button { flex: 1; }
.suits { display: flex; gap: 8px; margin-top: 8px; }
.suits button { flex: 1; font-size: 30px; min-height: 60px; }
.meldgrid { font-size: 13px; }

/* Cards with SVG faces + text fallback underneath */
.card { position: relative; width: 52px; height: 75px; border-radius: 8px; background: #fff; overflow: hidden; border: 2px solid #222; flex: none; }
/* Cards: simple high-legibility faces (corner index + big center) */
.card .ctext { position: absolute; top: 2px; left: 4px; font-size: 15px; font-weight: 800; color: #111; }
.card .ctext.red { color: #b91c1c; }
.card .cface { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.card .cface .crank { font-size: 24px; font-weight: 800; color: #111; line-height: 1.05; }
.card .cface .csuit { font-size: 32px; line-height: 1; color: #111; }
.card .cface.red .crank, .card .cface.red .csuit { color: #b91c1c; }
.card.trump { border-color: #e0a100; }
.card.legal { outline: 3px solid #22c55e; opacity: 1; }
.card.dim { opacity: 0.35; filter: grayscale(0.6); }
.card.sel { border-color: #38bdf8; transform: translateY(-10px); position: relative; z-index: 1; box-shadow: 0 0 0 2px #38bdf8, 0 6px 16px rgba(56, 189, 248, 0.6); }
.card.new { border-color: #fff; transform: translateY(-10px); position: relative; z-index: 1; box-shadow: 0 0 0 2px #fff, 0 6px 16px rgba(255, 255, 255, 0.55); }
.card.trickcard { width: 62px; height: 90px; }
.hand { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; }
.frow { display: flex; }
.frow.spread { justify-content: center; gap: 8px; }
.frow.spread > button.cardbtn { margin-left: 0; }
.frow > button.cardbtn { flex: 0 0 auto; width: calc((100% + 170px) / 6); width: min(calc((100% + 170px) / 6), calc((20dvh - 4px) * 0.69)); margin-left: -34px; padding: 0; border: none; background: none; min-height: 0; min-width: 0; }
.frow > button.cardbtn:first-child { margin-left: 0; }
.frow .card { width: 100%; height: auto; aspect-ratio: 169.075 / 244.64; }
.frow .card .ctext { font-size: 17px; }
.frow .card .cface .crank { font-size: 30px; }
.frow .card .cface .csuit { font-size: 40px; }
.mgroup { margin-bottom: 8px; }
.mgroup:last-child { margin-bottom: 0; }
.mhead { font-size: 13px; margin-bottom: 4px; }
.mfan { display: flex; flex-wrap: wrap; }
.card.mini { width: 30px; height: 44px; flex: none; }
.mfan .card + .card { margin-left: -18px; }
.card.mini .ctext { font-size: 9px; top: 1px; left: 2px; }
.card.mini .cface .crank { font-size: 12px; }
.card.mini .cface .csuit { font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button { flex: 1; }
.phase { font-weight: 700; font-size: 13px; opacity: 0.85; }
