:root {
  --bg: #0f3d2e; --felt: #1c5c44; --card: #fff; --ink: #14211c; --muted: #b7cfc4;
  --accent: #f2c14e; --danger: #d9534f; --panel: #10281f; --red: #c62828;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.4 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: #eef5f1; -webkit-tap-highlight-color: transparent; }
header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: var(--panel); }
.brand { font-weight: 700; letter-spacing: .5px; }
.right { display: flex; gap: 8px; align-items: center; }
.badge { background: var(--accent); color: var(--ink); padding: 2px 8px; border-radius: 10px; font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); display: inline-block; }
.dot.on { background: #4caf50; }
main { max-width: 720px; margin: 0 auto; padding: 12px; }
.card { background: var(--panel); border-radius: 12px; padding: 16px; margin-bottom: 12px; }
h1, h2, h3 { margin: 0 0 12px; }
label { display: block; margin: 8px 0; }
label span { display: block; font-size: 13px; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; }
label.check span { display: inline; color: inherit; }
input, select, button { font: inherit; border-radius: 8px; border: 1px solid #365; padding: 10px 12px; background: #fff; color: var(--ink); }
input, select { width: 100%; }
input[type=checkbox], input[type=file] { width: auto; }
label.check { justify-content: flex-start; }
label.check span { flex: 1; text-align: left; }
select#lang { width: auto; padding: 4px 6px; }
.row { display: flex; gap: 8px; margin: 10px 0; }
.row input { flex: 1; }
button { cursor: pointer; background: #dfe9e4; }
button.primary { background: var(--accent); font-weight: 700; }
button.small { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
.muted { color: var(--muted); font-size: 13px; }
a { color: var(--accent); word-break: break-all; }
.players { list-style: none; padding: 0; margin: 8px 0; }
.players li { padding: 8px 10px; background: #183a2e; border-radius: 8px; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; }
fieldset { border: 1px solid #365; border-radius: 8px; margin: 10px 0; }
legend { color: var(--muted); }

/* game */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 13px; }
.topbar > div:last-child { white-space: nowrap; }
#table { position: relative; margin-top: 24px; background: radial-gradient(ellipse at center, #2a7a5a 0%, var(--felt) 70%); border-radius: 50% / 40%;
  border: 6px solid #5a3b1e; min-height: 320px; padding: 10px; box-shadow: inset 0 0 40px rgba(0,0,0,.4); }
#seats { position: absolute; inset: 0; }
.seat { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 1px; transform: translate(-50%, -50%); text-align: center; background: rgba(0,0,0,.35); border-radius: 10px; padding: 4px 8px; min-width: 88px; font-size: 13px; }
.seat.turn { outline: 3px solid var(--accent); box-shadow: 0 0 12px var(--accent); }
.seat.off { opacity: .5; }
.seat .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.seat .bt { color: var(--accent); }
.seat .dl { position: absolute; top: -8px; right: -8px; background: #fff; color: var(--ink); border-radius: 50%; width: 20px; height: 20px; font-size: 11px; line-height: 20px; font-weight: 700; }
#trickArea { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
#trickArea .pc.tcard { position: absolute; transform: translate(-50%, -50%); transition: left .35s cubic-bezier(.2,.8,.3,1), top .35s cubic-bezier(.2,.8,.3,1), transform .35s ease, opacity .3s ease; will-change: left, top, transform; }
#status { text-align: center; font-weight: 700; margin-top: 8px; min-height: 1.4em; color: var(--accent); }

/* cards */
.pc { position: relative; display: inline-block; width: 52px; height: 74px; background: var(--card); color: var(--ink);
  border-radius: 6px; border: 1px solid #9aa; box-shadow: 0 2px 4px rgba(0,0,0,.4); user-select: none; font-weight: 700; }
.pc .ix { position: absolute; top: 3px; left: 4px; line-height: 1; font-size: 14px; text-align: center; }
.pc .ix i { display: block; font-style: normal; font-size: 12px; }
.pc .ix.r { top: auto; left: auto; bottom: 3px; right: 4px; transform: rotate(180deg); }
.pc .pip { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 30px; }
.pc.sH, .pc.sD { color: var(--red); }
body.four .pc.sD { color: #1e5bc6; }
body.four .pc.sC { color: #1f7a3a; }
.pc.small { width: 40px; height: 56px; }
.pc.small .ix { font-size: 11px; } .pc.small .ix i { font-size: 10px; } .pc.small .pip { font-size: 22px; }
.pc.mini { display: inline-block; width: auto; height: auto; padding: 2px 6px; font-size: 14px; }
body.big .pc { width: 66px; height: 94px; } body.big .pc .ix { font-size: 18px; } body.big .pc .ix i { font-size: 15px; } body.big .pc .pip { font-size: 38px; }
body.big #hand { gap: 6px; }
.backs { display: flex; margin-top: 2px; justify-content: center; }
.back { width: 14px; height: 20px; border-radius: 3px; background: repeating-linear-gradient(45deg, #b23a3a 0 3px, #8f2727 3px 6px); border: 1px solid #fff; box-shadow: 0 1px 2px rgba(0,0,0,.5); }
#hand { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; margin-top: 14px; min-height: 80px; }
#hand .pc { cursor: pointer; transition: transform .15s; }
#hand .pc.legal { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--accent); }
#hand .pc.dim { opacity: .45; cursor: default; }
#bidBox { margin-top: 12px; text-align: center; font-weight: 700; }
#bidButtons { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
#bidButtons button { min-width: 42px; }
#bidButtons button.forb { text-decoration: line-through; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 6px 4px; border-bottom: 1px solid #365; text-align: center; }
th:first-child, td:first-child { text-align: left; }
td.pos { color: #8fdc9a; } td.neg { color: #f28b82; }
#roundEnd { margin-top: 12px; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 12px; z-index: 10; }
.overlay .card { width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column; }
.scroll { overflow: auto; max-height: 70vh; margin-bottom: 8px; }
#chat { margin-top: 12px; background: var(--panel); border-radius: 12px; padding: 8px; }
#chatLog { max-height: 120px; overflow: auto; font-size: 13px; }
#chatLog b { color: var(--accent); }
#chatForm { display: flex; gap: 6px; margin-top: 6px; }
#chatForm input { flex: 1; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--danger); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 20; }
@media (min-width: 600px) { #table { min-height: 440px; } .seat { min-width: 110px; font-size: 14px; } .pc.small { width: 52px; height: 74px; } .pc.small .ix { font-size: 14px; } .pc.small .ix i { font-size: 12px; } .pc.small .pip { font-size: 30px; } }
@media (max-width: 480px) { .pc { width: 44px; height: 64px; font-size: 14px; } .pc .s { font-size: 18px; } #table { min-height: 280px; } }

/* stage 2/3 additions */
.icon { background: none; border: none; color: #fff; font-size: 18px; padding: 2px 4px; }
.avatar-btn { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.08); border: none; color: #fff; padding: 3px 8px 3px 3px; border-radius: 20px; max-width: 140px; }
.avatar-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.avatar-btn img, .avatar-xs { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; vertical-align: middle; background: #2a7a5a; }
.avatar-s { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.5); background: #2a7a5a; margin-top: -20px; }
.seat.turn .avatar-s { border-color: var(--accent); }
.avatar-lg { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; border: 3px solid var(--accent); background: #2a7a5a; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button { flex: 1; background: #183a2e; color: #eef5f1; border-color: #365; }
.tabs button.on { background: var(--accent); color: var(--ink); font-weight: 700; }
form button { margin-top: 6px; }
.tables .tbl { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; background: #183a2e; border-radius: 8px; margin-bottom: 6px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 700; padding: 6px 0; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stat { background: #183a2e; border-radius: 8px; padding: 8px; text-align: center; }
.stat .v { font-size: 20px; font-weight: 700; color: var(--accent); }
.stat .k { font-size: 12px; color: var(--muted); }
.scroll-x { overflow-x: auto; }
tr.lnk { cursor: pointer; }
tr.lnk:hover td { background: rgba(255,255,255,.05); }
#toast.ok { background: #2e7d32; }
#pEdit form { border-top: 1px solid #365; padding-top: 8px; margin-top: 8px; }
@keyframes deal { from { transform: translateY(-140px) rotate(-8deg); opacity: 0; } to { transform: none; opacity: 1; } }
#hand .pc.deal { animation: deal .4s cubic-bezier(.2,.8,.3,1) both; }
#hand .pc.legal.deal { animation-fill-mode: backwards; }
#hand .pc.played { opacity: 0; transform: translateY(-60px) scale(.8); transition: all .25s ease; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 12px var(--accent); } 50% { box-shadow: 0 0 22px 4px var(--accent); } }
.seat.turn { animation: pulse 1.6s ease-in-out infinite; }

/* stage 3 additions */
.linkbtn { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 6px 0; margin-left: 8px; }
.accent { color: var(--accent); }
.clock { font-weight: 700; color: var(--accent); margin-left: 6px; }
.clock.urgent { color: #f28b82; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .3; } }
.bubble { position: absolute; bottom: 100%; left: 50%; transform: translate(-50%, -6px); background: #fff; color: var(--ink); padding: 4px 8px; border-radius: 10px; font-size: 12px; max-width: 160px; white-space: normal; box-shadow: 0 2px 6px rgba(0,0,0,.4); z-index: 5; }
.bubble::after { content: ''; position: absolute; top: 100%; left: 50%; margin-left: -5px; border: 5px solid transparent; border-top-color: #fff; }
.invite { position: fixed; top: 60px; left: 50%; transform: translateX(-50%); background: var(--accent); color: var(--ink); padding: 10px 14px; border-radius: 12px; z-index: 30; display: flex; gap: 8px; align-items: center; box-shadow: 0 4px 16px rgba(0,0,0,.5); max-width: 92vw; }
.lt { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 12px; }
.ltc { text-align: center; font-size: 12px; padding: 4px; border-radius: 8px; }
.ltc.win { background: rgba(242,193,78,.25); outline: 2px solid var(--accent); }
#spectatorBar { text-align: center; margin-bottom: 6px; }
#inviteBox { margin: 6px 0 10px; }
#inviteBox button { margin: 2px; }
#adminTables .tbl { font-size: 13px; }
