:root {
  --paper: #EDE8DD; --app: #FBF9F4; --ink: #232838; --muted: #5C6170; --icon: #9297A6;
  --line: #E5E0D4; --card: #FFFFFF; --card-line: #E9E4D9;
  --accent: #1E7B4F; --accent-soft: #E3F1E9; --red: #C43A31; --gold: #C0871B; --blue: #2B6CB0;
  --felt: #1F6B45; --felt-dark: #17553A;
  --good-bg: #E7F1EA; --good-ink: #24603F; --gold-bg: #FBF0DC; --gold-ink: #8A5B12; --bad-bg: #F7E5E3; --bad-ink: #8F2A23;
  --shadow: rgba(35,40,56,0.14);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0F1117; --app: #14201A; --ink: #E9E7DF; --muted: #A3A7B3; --icon: #6E7486;
    --line: #2A3A31; --card: #1B2A22; --card-line: #2E4036;
    --accent: #3FA372; --accent-soft: #1E3A2C; --red: #E06055; --gold: #DCA843; --blue: #6FA8DC;
    --felt: #1A4D33; --felt-dark: #143C28;
    --good-bg: #1E2F26; --good-ink: #8FCFAA; --gold-bg: #332A18; --gold-ink: #E0B96A; --bad-bg: #3A2523; --bad-ink: #F0A099;
    --shadow: rgba(0,0,0,0.5);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--app); color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 16px; line-height: 1.5;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
a { color: var(--accent); font-weight: 600; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 900; }
.topbar .right { display: flex; align-items: center; gap: 10px; }
.chip { background: var(--accent-soft); color: var(--accent); padding: 6px 12px; border-radius: 99px; font-size: 13px; font-weight: 600; border: none; cursor: pointer; }

.screen { flex: 1; padding: 16px; }
.hidden { display: none !important; }
h2 { font-size: 20px; margin: 6px 0 10px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

.btn { display: flex; align-items: center; justify-content: center; gap: 8px; border: none; border-radius: 12px; padding: 13px 16px; font-size: 15px; font-weight: 600; cursor: pointer; width: 100%; background: var(--accent); color: #fff; }
.bi { width: 18px; height: 18px; flex: 0 0 auto; }
.btn:active { transform: scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--card-line); }
.btn.small { width: auto; padding: 9px 14px; font-size: 13px; border-radius: 10px; }
.btn.gold { background: var(--gold-ink); color: var(--app); }
.btn.red { background: var(--red); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
#scSignin input { max-width: 280px; width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--card-line); background: var(--card); color: var(--ink); font-size: 15px; }
.sep { color: var(--muted); font-size: 13px; margin: 6px 0 2px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .row input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--card-line); background: var(--app); color: var(--ink); font-size: 15px; }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; font-size: 14px; }
.switch input { width: 20px; height: 20px; }
.segs { display: inline-flex; border: 1px solid var(--card-line); border-radius: 10px; overflow: hidden; }
.segs.wide { display: flex; width: 100%; }
.segs.wide .seg { flex: 1; }
.seg { border: none; background: var(--card); color: var(--muted); padding: 7px 11px; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.seg.on { background: var(--accent); color: #fff; }

.card { background: var(--card); border: 1px solid var(--card-line); border-radius: 14px; padding: 14px; }
.roomcard { background: var(--card); border: 1px solid var(--card-line); border-radius: 12px; padding: 13px 38px 13px 14px; margin: 0 0 10px; cursor: pointer; position: relative; }
.roomcard:hover { border-color: var(--accent); }
.roomcard:active { background: var(--paper); transform: scale(0.995); }
.roomchev { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--accent); }
.roomcard h3 { margin: 0; font-size: 15.5px; font-weight: 700; letter-spacing: -0.01em; }
.rmeta { display: flex; flex-direction: column; gap: 6px; margin-top: 9px; color: var(--muted); font-size: 12.5px; }
.rmeta .l { display: flex; align-items: center; gap: 8px; }
.rmeta b { color: var(--ink); font-weight: 600; }
.mi { width: 13px; height: 13px; flex: 0 0 auto; color: var(--icon); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.badge.live { color: var(--red); }
.badge.lobby { color: var(--blue); }
.badge.done { color: var(--accent); }
.badge.cx, .badge.lock { color: var(--muted); }
.gtag { display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); margin-right: 6px; vertical-align: middle; }
.gtag.mahjong { background: var(--gold-bg); color: var(--gold-ink); }
.pres { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--icon); margin-right: 6px; vertical-align: middle; flex: 0 0 auto; }
.pres.on { background: #22c55e; box-shadow: 0 0 0 2px rgba(34,197,94,0.22); }
.onlinechip { font-size: 12px; font-weight: 700; color: #16a34a; letter-spacing: 0.02em; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.prow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.prow:last-child { border-bottom: none; }
.prow .who { flex: 1; min-width: 0; }
.prow .who small { display: block; color: var(--muted); font-size: 11.5px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; overflow: hidden; font-size: 13px; }
.pill { font-size: 10px; font-weight: 700; letter-spacing: 0.05em; padding: 3px 9px; border-radius: 99px; background: var(--good-bg); color: var(--good-ink); }
.pill.pending, .pill.muted { background: transparent; color: var(--muted); border: 1px solid var(--card-line); }
.pill.bad { background: var(--bad-bg); color: var(--bad-ink); }
.uname { color: var(--muted); font-weight: 600; font-size: 0.86em; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--card-line); border-radius: 12px; padding: 10px 12px; }
.stat .v { font-weight: 800; font-size: 20px; } .stat .k { font-size: 11px; color: var(--muted); }
.markbtn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--card-line); color: var(--ink); background: transparent; border-radius: 10px; padding: 7px 11px; font-size: 12px; font-weight: 700; cursor: pointer; flex: 0 0 auto; }
.pos { color: var(--good-ink); font-weight: 700; } .neg { color: var(--bad-ink); font-weight: 700; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--app); padding: 11px 18px; border-radius: 10px; font-size: 14px; opacity: 0; transition: all 0.3s; z-index: 100; max-width: 90%; text-align: center; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none; align-items: center; justify-content: center; padding: 24px; z-index: 60; }
.overlay.show { display: flex; }
.modal { background: var(--card); border-radius: 18px; padding: 22px; width: 100%; max-width: 380px; max-height: 90dvh; overflow-y: auto; }

.center { min-height: 80dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; padding: 24px; }
.brandmark { display: flex; gap: 6px; }
.bm-tile { width: 46px; height: 62px; border-radius: 8px; background: var(--card); border: 2px solid var(--gold); color: var(--accent); font-weight: 900; font-size: 28px; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 10px var(--shadow); }
.bm-tile.red { color: var(--red); transform: rotate(6deg); }

/* ---------- table screen ---------- */
.seatstrip { display: grid; grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 8px; margin-bottom: 10px; }
.seat { background: var(--card); border: 1px solid var(--card-line); border-radius: 12px; padding: 8px 10px; font-size: 12.5px; position: relative; min-width: 0; }
.seat.me { border-color: var(--accent); }
.seat.turn { box-shadow: 0 0 0 2px var(--gold); }
.seat .nm { font-weight: 700; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .st { color: var(--muted); font-size: 11.5px; margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; }
.seat .tag { font-size: 9.5px; font-weight: 800; letter-spacing: 0.05em; padding: 1px 6px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.seat .tag.gold { background: var(--gold-bg); color: var(--gold-ink); }
.seat .tag.red { background: var(--bad-bg); color: var(--bad-ink); }
.seat .tag.muted { background: transparent; color: var(--muted); border: 1px solid var(--card-line); }
.seat.empty { border-style: dashed; color: var(--muted); display: flex; align-items: center; justify-content: center; min-height: 54px; }

.felt { background: var(--felt); border-radius: 16px; padding: 12px; color: #fff; box-shadow: inset 0 0 0 4px var(--felt-dark); }
.felt .lbl { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.8; margin-bottom: 4px; }
.felt .note { font-size: 12.5px; opacity: 0.95; margin: 6px 0 0; min-height: 18px; }
.opps { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.opp { background: rgba(0,0,0,0.18); border-radius: 10px; padding: 7px 9px; }
.opp .hd { display: flex; align-items: center; justify-content: space-between; font-size: 12.5px; font-weight: 700; gap: 6px; }
.opp .hd small { font-weight: 600; opacity: 0.85; }
.melds { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.meld { display: flex; gap: 2px; padding: 3px; border-radius: 8px; background: rgba(255,255,255,0.08); border: 1px dashed transparent; }
.meld.tap { cursor: pointer; border-color: var(--gold); }
.meld.tap:hover { background: rgba(255,255,255,0.18); }
.centerrow { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 6px 0 10px; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.95; }
.pile.tap { cursor: pointer; }
.pile.tap:hover .pcard, .pile.tap:hover .tile { transform: translateY(-3px); }
.myarea { margin-top: 8px; }
.hand { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; padding: 6px 2px; }

/* playing cards */
.pcard { width: 44px; height: 62px; border-radius: 6px; background: #fff; color: #1b1f2a; border: 1px solid #c9c4b8; display: flex; flex-direction: column; justify-content: space-between; padding: 3px 4px; font-weight: 800; font-size: 14px; line-height: 1; cursor: default; user-select: none; position: relative; transition: transform 0.12s; box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.pcard .s { font-size: 18px; align-self: flex-end; }
.pcard.redsuit { color: var(--red); }
.pcard.sm { width: 30px; height: 42px; font-size: 11px; padding: 2px 3px; border-radius: 4px; }
.pcard.sm .s { font-size: 12px; }
.pcard.tap { cursor: pointer; }
.pcard.sel { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--gold), 0 6px 12px rgba(0,0,0,0.35); }
.pcard.back { background: repeating-linear-gradient(45deg, #2B6CB0 0 4px, #245b95 4px 8px); border-color: #1d4a7a; }
.pcard.back.sm { width: 30px; height: 42px; }

/* mahjong tiles */
.tile { width: 40px; height: 56px; border-radius: 6px; background: #FBF8EE; color: #1b1f2a; border: 1px solid #c9c4b8; border-bottom-width: 4px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; line-height: 1; cursor: default; user-select: none; transition: transform 0.12s; box-shadow: 0 1px 3px rgba(0,0,0,0.25); }
.tile .n { font-size: 17px; }
.tile .g { font-size: 15px; margin-top: 2px; }
.tile .g.cjk { font-size: 18px; }
.tile.bamboo { color: #1E7B4F; } .tile.chars { color: #C43A31; } .tile.dots { color: #2B6CB0; }
.tile.wind { color: #1b1f2a; } .tile.dragon-red { color: #C43A31; } .tile.dragon-green { color: #1E7B4F; } .tile.dragon-white { color: #2B6CB0; }
.tile.flower { color: #8a3fb0; background: #F6EEFB; }
.tile.sm { width: 26px; height: 36px; border-bottom-width: 3px; }
.tile.sm .n { font-size: 11px; } .tile.sm .g { font-size: 10px; } .tile.sm .g.cjk { font-size: 12px; }
.tile.tap { cursor: pointer; }
.tile.sel { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--gold), 0 6px 12px rgba(0,0,0,0.35); }
.tile.last { box-shadow: 0 0 0 3px var(--red); }
.tile.back { background: #2F7D52; border-color: #1f5f3c; }
.river { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; min-height: 36px; max-height: 120px; overflow-y: auto; padding: 4px; background: rgba(0,0,0,0.15); border-radius: 10px; }
.exposed { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.eset { display: flex; gap: 1px; padding: 2px; border-radius: 6px; background: rgba(255,255,255,0.1); }
.eset.concealed .tile { opacity: 0.85; }

.actionbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; position: sticky; bottom: 8px; background: var(--card); border: 1px solid var(--card-line); border-radius: 14px; padding: 10px; box-shadow: 0 6px 20px var(--shadow); z-index: 5; }
.actionbar .btn { flex: 1 1 30%; padding: 11px 8px; font-size: 14px; }
.actionbar .hint { flex: 1 1 100%; text-align: center; font-size: 12.5px; color: var(--muted); }
.actionbar .hint.hot { color: var(--red); font-weight: 700; }
.countdown { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--gold-ink); }

.result h3 { margin: 0 0 6px; font-size: 18px; color: var(--accent); }
.result .payouts { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; margin: 8px 0; }
.result .payouts div { display: flex; justify-content: space-between; }
.reveal { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.reveal .rv { font-size: 12.5px; }
.reveal .rv b { display: block; margin-bottom: 3px; }
.reveal .rv .hand { justify-content: flex-start; padding: 2px 0; gap: 3px; }

.chatlist { background: var(--app); border: 1px solid var(--card-line); border-radius: 12px; padding: 8px; height: 130px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.chatlist .m { font-size: 12.5px; } .chatlist .m b { font-weight: 700; }
.chatlist .chatt { color: var(--muted); font-size: 10.5px; margin-left: 4px; white-space: nowrap; }
.chatinput { display: flex; gap: 6px; }
.chatinput input { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--card-line); background: var(--app); color: var(--ink); }
.chatinput button { border: none; background: var(--accent); color: #fff; border-radius: 10px; padding: 0 16px; font-weight: 600; }
.reacts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.reacts button { border: 1px solid var(--card-line); background: var(--card); color: var(--ink); border-radius: 99px; padding: 5px 10px; font-size: 12.5px; cursor: pointer; }
details.card summary { cursor: pointer; font-weight: 700; font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
  .pcard, .tile { transition: none; }
}
