/* Family Mahjong — visual system v2 */
:root {
  --felt: #0a3a28; --felt2: #14603f; --felt-deep: #072a1d;
  --ink: #f5f1e4; --muted: #9fbcad; --faint: rgba(255,255,255,.08);
  --gold: #f3c24f; --gold-ink: #2b2006; --red: #d23b33; --win: #ff5a4f;
  --tile: #fffcf2; --tile2: #f1e9d2; --tile-edge: #e2d6b6; --tile-back: #1f8f5f; --tile-back2: #16734b;
  --hw: min(44px, calc((100vw - 24px) / 9.5));   /* hand tiles: two rows in portrait */
  --rw: 23px;                                     /* discard tiles */
  --sw: 16px;                                     /* others' melds */
  --r: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--felt-deep); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif; }
body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
#app { min-height: 100%;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 .07 0'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>"),
    radial-gradient(120% 80% at 50% 38%, var(--felt2) 0%, var(--felt) 55%, var(--felt-deep) 100%); }
button { font: inherit; color: inherit; border: 0; cursor: pointer; background: none; }
button:active { transform: scale(.97); }
input, select { font: inherit; }
.en { font-size: .72em; opacity: .72; font-weight: 400; }
.muted { color: var(--muted); font-size: 14px; }
.pos { color: #74e7a2; } .neg { color: #ff8f86; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #5ad17a; margin-right: 4px; }
.dot.off { background: #777; }

/* ---------------- pages: home / join / lobby ---------------- */
.page { max-width: 460px; margin: 0 auto; padding: calc(22px + env(safe-area-inset-top)) 16px calc(36px + env(safe-area-inset-bottom)); }
.hero { text-align: center; margin: 10px 0 22px; }
.hero h1 { font-size: 38px; margin: 14px 0 2px; letter-spacing: 4px; font-family: "Songti TC", "Noto Serif TC", serif; font-weight: 900;
  background: linear-gradient(#ffe8a3, var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); margin: 0; font-size: 14px; }
.hero .tiles { display: flex; gap: 4px; justify-content: center; --tw: 40px; }
.hero .tiles .t:nth-child(1) { transform: rotate(-10deg) translateY(6px); } .hero .tiles .t:nth-child(2) { transform: rotate(-5deg) translateY(1px); }
.hero .tiles .t:nth-child(4) { transform: rotate(5deg) translateY(1px); } .hero .tiles .t:nth-child(5) { transform: rotate(10deg) translateY(6px); }
.card { background: rgba(0,0,0,.24); border: 1px solid var(--faint); border-radius: 18px; padding: 16px; margin-bottom: 14px; backdrop-filter: blur(2px); }
.card h2 { margin: 0 0 8px; font-size: 18px; }
label.field { display: block; margin: 10px 0; color: var(--muted); font-size: 14px; }
label.field input, label.field select { display: block; width: 100%; margin-top: 6px; padding: 13px 14px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.07); color: var(--ink); font-size: 17px; outline: none; }
label.field input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(243,194,79,.2); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.btn { display: block; width: 100%; padding: 15px; border-radius: 14px; background: linear-gradient(#ffd46a, var(--gold)); color: var(--gold-ink);
  font-weight: 800; font-size: 17px; margin-top: 12px; box-shadow: 0 3px 0 #b88a1f, 0 6px 14px rgba(0,0,0,.3); }
.btn.secondary { background: rgba(255,255,255,.1); color: var(--ink); box-shadow: none; font-weight: 700; }
.btn.small { padding: 9px 13px; font-size: 14px; width: auto; display: inline-block; margin: 0; box-shadow: none; }
.btn:disabled { opacity: .45; }
details summary { color: var(--muted); cursor: pointer; padding: 8px 0; }
.code { font-size: 34px; letter-spacing: 8px; font-weight: 900; text-align: center; margin: 2px 0; font-variant-numeric: tabular-nums; }
.linkrow { display: flex; gap: 8px; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }

/* Lobby: seats arranged around a little table */
.lobby-table { display: grid; grid-template-columns: 1fr 1.25fr 1fr; grid-template-rows: auto auto auto; gap: 8px; align-items: center; justify-items: center; margin: 4px 0 6px; }
.lobby-table .felt { grid-area: 2 / 2; width: 100%; aspect-ratio: 1; border-radius: 18px; display: grid; place-items: center; text-align: center;
  background: radial-gradient(circle at 50% 40%, #1b7a50, #0d4a31); box-shadow: inset 0 0 0 6px #5a3b22, inset 0 0 0 8px #2d1d10, 0 8px 18px rgba(0,0,0,.4); }
.lobby-table .felt small { display: block; color: #cfe7da; font-size: 11px; }
.lobby-table .felt b { font-size: 20px; letter-spacing: 3px; }
.lseat { display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; width: 100%; min-width: 0; }
.lseat.s0 { grid-area: 3 / 2; } .lseat.s1 { grid-area: 2 / 3; } .lseat.s2 { grid-area: 1 / 2; } .lseat.s3 { grid-area: 2 / 1; }
.lseat .nm { font-weight: 700; font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lseat .st { font-size: 11px; color: var(--muted); }
.lseat .av { width: 54px; height: 54px; box-shadow: 0 0 0 3px rgba(255,255,255,.15); }
.lseat.mine .av { box-shadow: 0 0 0 3px var(--gold); }
.lseat .empty { width: 54px; height: 54px; border-radius: 50%; border: 2px dashed rgba(255,255,255,.3); display: grid; place-items: center; color: var(--muted); font-size: 22px; }
.lseat .mini-btns { display: flex; gap: 4px; }
.lseat .mini-btns button { font-size: 11px; padding: 4px 8px; border-radius: 8px; background: rgba(255,255,255,.1); }

/* ---------------- tiles: ivory face on a green back ---------------- */
.t { --tw: var(--hw); position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; flex: none;
  width: var(--tw); height: calc(var(--tw) * 1.34); border-radius: calc(var(--tw) * .16); color: #222; font-weight: 700; line-height: 1;
  background: linear-gradient(170deg, var(--tile) 55%, var(--tile2));
  box-shadow: inset 0 calc(var(--tw) * -.05) 0 var(--tile-edge), 0 calc(var(--tw) * .07) 0 var(--tile-back), 0 calc(var(--tw) * .07 + 2px) 4px rgba(0,0,0,.35);
  margin-bottom: calc(var(--tw) * .07); }
.t svg { width: 88%; height: 84%; margin-bottom: 5%; }
.t .n { font-size: calc(var(--tw) * .5); font-family: "Songti TC", "Noto Serif TC", "PMingLiU", serif; }
.t .s { font-size: calc(var(--tw) * .44); color: var(--red); font-family: "Songti TC", "Noto Serif TC", serif; margin-top: 2%; }
.t .h { font-size: calc(var(--tw) * .7); font-family: "Songti TC", "Noto Serif TC", "PMingLiU", serif; margin-bottom: 6%; }
.t .h.red { color: var(--red); } .t .h.green { color: #1b7a3a; }
.t .white { width: 60%; height: 62%; border: calc(var(--tw) * .07) solid #2c6fbb; border-radius: 3px; margin-bottom: 6%; }
.t .fl { font-size: calc(var(--tw) * .56); color: #8e3fa8; font-family: "Songti TC", "Noto Serif TC", serif; margin-bottom: 6%; }
.t .fl.p { color: #c9531a; }
.t .fn { position: absolute; top: 4%; right: 9%; font-size: calc(var(--tw) * .26); color: #666; }
.t.back { background: linear-gradient(160deg, #2bb57c, var(--tile-back)); box-shadow: inset 0 calc(var(--tw) * -.05) 0 var(--tile-back2), 0 calc(var(--tw) * .07) 0 var(--tile-edge), 0 calc(var(--tw) * .07 + 2px) 4px rgba(0,0,0,.35); }
.t.sm { --tw: var(--sw); } .t.rv { --tw: var(--rw); } .t.lg { --tw: 54px; }
.t.last { box-shadow: 0 0 0 2px var(--gold), 0 0 10px rgba(243,194,79,.8), 0 calc(var(--tw) * .07) 0 var(--tile-back); }
.t.dim { filter: brightness(.9); }
.t.fresh { animation: drop .35s cubic-bezier(.2,1.4,.4,1); }
@keyframes drop { from { transform: translateY(-14px) scale(1.35); opacity: .2; } to { transform: none; opacity: 1; } }

/* ---------------- table ---------------- */
.table { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.topbar { display: flex; align-items: center; gap: 6px; padding: 7px 8px; font-size: 13px; background: linear-gradient(rgba(0,0,0,.45), rgba(0,0,0,.2)); }
.topbar .pill { display: inline-flex; align-items: center; gap: 4px; padding: 4px 9px; border-radius: 999px; background: rgba(255,255,255,.08); white-space: nowrap; }
.topbar .pill b { color: var(--gold); }
.topbar .grow { flex: 1; display: flex; gap: 6px; overflow: hidden; }
.iconbtn { width: 34px; height: 30px; border-radius: 10px; background: rgba(255,255,255,.1); font-size: 15px; display: grid; place-items: center; flex: none; }
.timer { display: none; }

.board { display: grid; grid-template-columns: 74px 1fr 74px; grid-template-rows: auto 1fr; min-height: 0; gap: 6px; padding: 6px 6px 4px; }
.north { grid-column: 1 / 4; display: flex; align-items: center; gap: 8px; min-width: 0; }
.north .melds { flex: 1; min-width: 0; }
.side { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 0; min-width: 0; }
.melds { display: flex; flex-wrap: wrap; gap: 2px 4px; align-items: flex-end; }
.meld { display: inline-flex; gap: 0; }
.side .melds { justify-content: center; }

/* Seat card: the person, not the wind */
.seatcard { position: relative; display: flex; align-items: center; gap: 7px; padding: 5px 9px 5px 5px; border-radius: 999px; background: rgba(0,0,0,.28);
  border: 1px solid var(--faint); transition: background .2s, box-shadow .2s; min-width: 0; }
.side .seatcard { flex-direction: column; gap: 2px; padding: 6px 4px 5px; border-radius: 16px; width: 100%; }
.seatcard .ava { position: relative; flex: none; }
.seatcard .av { width: 34px; height: 34px; box-shadow: 0 0 0 2px rgba(255,255,255,.15); }
.seatcard .badge { position: absolute; bottom: -3px; right: -5px; font-size: 9px; font-weight: 800; background: var(--red); color: #fff; border-radius: 6px; padding: 1px 3px; box-shadow: 0 0 0 2px var(--felt); }
.seatcard .wind { position: absolute; top: -4px; left: -5px; font-size: 10px; font-weight: 800; background: #0008; color: var(--gold); border-radius: 6px; padding: 0 3px; }
.seatcard .who { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; align-items: flex-start; }
.side .seatcard .who { align-items: center; }
.seatcard .nm { font-weight: 700; font-size: 13px; max-width: 86px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .seatcard .nm { max-width: 64px; font-size: 12px; }
.seatcard .sc { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.seatcard .cnt { font-size: 10px; color: var(--muted); display: inline-flex; align-items: center; gap: 2px; }
.seatcard .cnt i { display: inline-block; width: 7px; height: 10px; border-radius: 2px; background: var(--tile-back); }
.seatcard .doing { display: none; font-size: 10px; font-weight: 800; }
.seatcard.off .av { filter: grayscale(1) opacity(.6); }
.seatcard.bot .nm::after { content: " 電腦"; font-size: 9px; font-weight: 400; color: var(--muted); }
.discarding .seatcard:not(.active) { opacity: .62; }
.seatcard.active { background: linear-gradient(#ffd66d, var(--gold)); color: var(--gold-ink); border-color: #fff4; box-shadow: 0 0 16px rgba(243,194,79,.75); opacity: 1; }
.seatcard.active .sc, .seatcard.active .cnt { display: none; }
.seatcard.active .doing { display: block; }
.seatcard.active .av { box-shadow: 0 0 0 2px var(--gold-ink); animation: bob 1s ease-in-out infinite alternate; }
.seatcard.active.bot .nm::after { color: #6b5418; }
@keyframes bob { to { transform: translateY(-2px) scale(1.05); } }

/* Discards: each player's pond in front of them */
.pond { display: flex; flex-wrap: wrap; gap: 2px; align-content: flex-start; padding: 4px; border-radius: 10px; background: rgba(0,0,0,.14); min-height: calc(var(--rw) * 1.34 + 10px); }
.center { display: flex; flex-direction: column; min-height: 0; gap: 6px; }
.center .pond { justify-content: center; }
.side .pond { display: grid; grid-template-columns: repeat(3, var(--rw)); justify-content: center; width: 100%; flex: 1; min-height: 0; overflow: hidden; }

/* Centre dial: whose turn, the countdown, and the tile on offer */
.mid { flex: 1; display: grid; place-items: center; min-height: 120px; }
.dial { display: flex; flex-direction: column; align-items: center; gap: 5px; text-align: center; }
.ringwrap { position: relative; width: 96px; height: 96px; display: grid; place-items: center; }
.ring { position: absolute; inset: 0; border-radius: 50%; --p: 100%;
  background: conic-gradient(var(--gold) var(--p), rgba(255,255,255,.1) 0);
  -webkit-mask: radial-gradient(circle, transparent 64%, #000 65%); mask: radial-gradient(circle, transparent 64%, #000 65%); transition: --p .25s linear; }
.ring.urgent { background: conic-gradient(var(--win) var(--p), rgba(255,255,255,.1) 0); }
.ringwrap .av { width: 66px; height: 66px; }
.ringwrap .t.lg { --tw: 46px; margin: 0; }
.pointer { position: absolute; inset: -12px; transition: transform .45s cubic-bezier(.3,1.4,.5,1); pointer-events: none; }
.pointer::before { content: ""; position: absolute; left: 50%; top: 0; transform: translateX(-50%); border: 8px solid transparent; border-bottom: 11px solid var(--gold); border-top: 0;
  filter: drop-shadow(0 0 4px rgba(243,194,79,.9)); }
.secs { position: absolute; bottom: -6px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 800; background: var(--felt-deep); border: 1px solid var(--gold);
  color: var(--gold); border-radius: 999px; padding: 0 6px; font-variant-numeric: tabular-nums; }
.secs.urgent { border-color: var(--win); color: var(--win); }
.dial .caption { font-size: 14px; font-weight: 800; }
.dial .caption small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); }
.dial .lastd { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dial .lastd .t { --tw: 26px; }
.dial.mine .caption { color: var(--gold); font-size: 16px; }

/* Me */
.me { padding: 6px 6px 8px; background: linear-gradient(rgba(0,0,0,.05), rgba(0,0,0,.32)); border-top: 1px solid var(--faint); transition: background .25s; }
.me .bar { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.me .bar .seatcard { flex: none; }
.me .bar .melds { flex: 1; min-width: 0; justify-content: flex-end; }
.me .bar .melds .t { --tw: min(24px, calc((100vw - 150px) / 12)); }
.myturn .me { background: linear-gradient(rgba(243,194,79,.08), rgba(243,194,79,.24)); box-shadow: inset 0 3px 0 var(--gold); }
.yourturn { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 auto 2px; padding: 6px 16px; border-radius: 999px; width: fit-content;
  background: linear-gradient(#ffd66d, var(--gold)); color: var(--gold-ink); font-weight: 900; font-size: 15px; box-shadow: 0 0 16px rgba(243,194,79,.7); animation: glow 1.1s infinite alternate; }
.yourturn .en { font-size: 11px; }
@keyframes glow { from { box-shadow: 0 0 5px rgba(243,194,79,.5); } to { box-shadow: 0 0 20px rgba(243,194,79,1); } }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 4px 0 2px; }
.actions:empty { display: none; }
.act { min-width: 68px; padding: 9px 14px 8px; border-radius: 16px; font-size: 21px; font-weight: 900; color: #fff; line-height: 1.05;
  background: linear-gradient(#4b8ad6, #2d62ad); box-shadow: 0 4px 0 #1d4078, 0 8px 16px rgba(0,0,0,.35); }
.act .en { display: block; font-size: 10px; opacity: .85; font-weight: 600; }
.act.hu { background: linear-gradient(#ff6b5f, #c9261d); box-shadow: 0 4px 0 #7d1510, 0 0 22px rgba(255,90,79,.8); animation: pulse .8s infinite alternate; min-width: 88px; }
.act.pass { background: rgba(255,255,255,.16); box-shadow: 0 4px 0 rgba(0,0,0,.3); }
.act.chi { display: inline-flex; gap: 1px; align-items: center; padding: 7px 10px; background: linear-gradient(#3fae74, #2b8656); box-shadow: 0 4px 0 #1b5c39, 0 8px 16px rgba(0,0,0,.35); }
.act.chi .t { --tw: 24px; margin-left: 1px; }
.act.go { background: linear-gradient(#ffd66d, var(--gold)); color: var(--gold-ink); box-shadow: 0 4px 0 #b88a1f, 0 8px 16px rgba(0,0,0,.35); }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.07); } }
.hint { text-align: center; font-size: 12px; color: var(--muted); min-height: 18px; display: flex; gap: 4px; justify-content: center; align-items: center; flex-wrap: wrap; margin: 2px 0; }
.hand { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 4px 2px; padding-top: 12px; max-width: calc(var(--hw) * 9 + 24px); margin: 0 auto; }
.hand .t { transition: transform .14s ease, box-shadow .14s; }
.hand .t.sel { transform: translateY(-12px); box-shadow: 0 0 0 2px var(--gold), 0 calc(var(--tw) * .07) 0 var(--tile-back), 0 12px 16px rgba(0,0,0,.45); }
.hand .t.drawn { animation: slidein .3s ease-out; }
@keyframes slidein { from { transform: translateX(26px); opacity: 0; } to { transform: none; opacity: 1; } }
.hand .gap { width: calc(var(--hw) * .3); flex: none; }
.hand .t .ting { position: absolute; top: 1px; left: 1px; font-size: 9px; background: var(--red); color: #fff; border-radius: 4px; padding: 1px 2px; font-family: system-ui; z-index: 1; }
.myturn .hand .t { cursor: pointer; }
.spectate { text-align: center; color: var(--muted); font-size: 13px; padding: 6px; }

/* ---------------- sheets ---------------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; z-index: 20; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: linear-gradient(#17463a, #0f3327); width: 100%; max-width: 520px; max-height: 90dvh; overflow: auto; border-radius: 22px 22px 0 0;
  padding: 10px 16px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 30px rgba(0,0,0,.5); animation: rise .28s cubic-bezier(.2,1.2,.4,1); }
.sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.25); margin: 0 auto 10px; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { margin: 16px 0 6px; font-size: 15px; color: var(--muted); font-weight: 700; }
table.tai, table.scores { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tai td, table.scores td, table.scores th { padding: 7px 4px; border-bottom: 1px solid var(--faint); }
table.tai td:last-child, table.scores td.num, table.scores th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.scores td .av { width: 24px; height: 24px; margin-right: 6px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; background: rgba(0,0,0,.25); padding: 4px; border-radius: 12px; }
.tabs button { flex: 1; padding: 8px 4px; border-radius: 9px; font-size: 13px; }
.tabs button.on { background: var(--gold); color: var(--gold-ink); font-weight: 800; }
.taiedit { display: grid; grid-template-columns: 1fr 64px; gap: 6px 8px; align-items: center; font-size: 14px; }
.taiedit input { width: 64px; padding: 6px; border-radius: 8px; border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.07); color: var(--ink); text-align: center; }

/* Result */
.res-hero { text-align: center; padding: 4px 0 8px; }
.res-hero .ava { position: relative; display: inline-block; }
.res-hero .av { width: 78px; height: 78px; box-shadow: 0 0 0 4px var(--gold), 0 0 30px rgba(243,194,79,.8); }
.res-hero .crown { position: absolute; top: -22px; left: 50%; transform: translateX(-50%) rotate(-8deg); line-height: 0; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }
.res-hero h2 { margin: 8px 0 0; font-size: 26px; color: var(--gold); }
.res-hero .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.res-hero .big { display: inline-flex; align-items: baseline; gap: 10px; margin-top: 8px; padding: 6px 16px; border-radius: 999px; background: rgba(0,0,0,.25); }
.res-hero .big b { font-size: 30px; color: var(--gold); } .res-hero .big span { font-size: 18px; font-weight: 800; }
.res-hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 6px; margin: 10px 0 4px; padding: 10px 6px; border-radius: 14px; background: rgba(0,0,0,.2); }
.res-hand .set { display: inline-flex; gap: 1px; }
.res-hand .t { --tw: min(28px, calc((100vw - 64px) / 18)); }
.res-hand .t.win { box-shadow: 0 0 0 2px var(--win), 0 0 12px rgba(255,90,79,.9), 0 calc(var(--tw) * .07) 0 var(--tile-back); }
.res-hand .lbl { width: 100%; text-align: center; font-size: 11px; color: var(--muted); }
.taichips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0; }
.taichip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: rgba(243,194,79,.14); border: 1px solid rgba(243,194,79,.35); font-size: 14px; }
.taichip b { color: var(--gold); } .taichip .en { font-size: 10px; }
.pays { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.standings { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 4px; }
.standing { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 14px; background: rgba(0,0,0,.2); }
.standing .av { width: 34px; height: 34px; }
.standing .nm { flex: 1; font-weight: 700; } .standing .nm small { color: var(--muted); font-weight: 400; }
.standing .d { font-weight: 800; min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; }
.standing .tot { color: var(--muted); min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }
.standing.winner { background: rgba(243,194,79,.16); box-shadow: inset 0 0 0 1px rgba(243,194,79,.4); }
.standing .medal { font-size: 20px; width: 24px; text-align: center; }
.waiting { text-align: center; color: var(--muted); font-size: 13px; margin-top: 6px; }

#toast { position: fixed; left: 50%; top: calc(12px + env(safe-area-inset-top)); transform: translateX(-50%); background: #1b1b1b; color: #fff;
  padding: 10px 16px; border-radius: 12px; z-index: 50; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.4); max-width: 90vw; }
.banner { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); font-size: 72px; font-weight: 900; pointer-events: none; z-index: 30;
  font-family: "Songti TC", "Noto Serif TC", serif; color: #ffe38a; -webkit-text-stroke: 2px #7a4b00; text-shadow: 0 6px 20px rgba(0,0,0,.7); animation: pop .95s ease-out forwards; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.3) rotate(-8deg); } 30% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(3deg); }
  75% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -62%) scale(1); } }
.confetti { position: fixed; top: -12px; width: 8px; height: 12px; z-index: 40; pointer-events: none; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate(var(--dx), 105vh) rotate(var(--rot)); } }

/* ---------------- guide & coaching ---------------- */
.guide h3 { margin: 18px 0 6px; }
.guide h4 { margin: 14px 0 6px; color: var(--gold); }
.gitem { background: rgba(0,0,0,.2); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.gitem p { margin: 4px 0 6px; font-size: 14px; color: #dfe9e2; }
.gh { display: flex; align-items: center; gap: 8px; }
.gh b { flex: 1; }
.gh .tai { color: var(--gold); font-weight: 800; white-space: nowrap; }
.pill { font-size: 11px; background: var(--red); color: #fff; border-radius: 6px; padding: 2px 6px; }
.ex { display: flex; flex-wrap: wrap; gap: 4px 5px; align-items: flex-end; }
.ex .set { display: inline-flex; gap: 1px; }
.exrow { margin-top: 5px; align-items: center; }
.exlabel { font-size: 11px; color: var(--muted); margin-right: 2px; }
.ex .t.gx { --tw: min(22px, calc((100vw - 90px) / 17.5)); }
.ex .t.win { outline: 2px solid var(--red); outline-offset: 0; }
.ex .arrow { margin: 0 8px; color: var(--gold); font-weight: 800; align-self: center; }
.exnote { font-size: 11px; color: var(--muted); margin-top: 4px; }
.winmark { color: #ff8a80; }
.wchip { display: inline-flex; align-items: flex-end; gap: 1px; margin: 0 3px; }
.wchip i { font-style: normal; font-size: 11px; color: var(--gold); }
.wchip.dead { opacity: .45; }
.coach { display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px; }
.cnote { font-size: 11px; color: var(--muted); margin-left: 4px; }
.hint .t { --tw: 20px; }


/* ---------------- avatars & picker ---------------- */
.av { flex: none; display: inline-block; vertical-align: middle; border-radius: 50%; }
.field-label { color: var(--muted); font-size: 14px; margin: 12px 0 6px; }
.picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pick { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 2px 5px; border-radius: 12px;
  background: rgba(255,255,255,.06); border: 2px solid transparent; font-size: 11px; color: var(--ink); }
.pick.on { border-color: var(--gold); background: rgba(242,193,78,.16); box-shadow: 0 0 10px rgba(242,193,78,.4); }
.pick.taken { opacity: .35; filter: grayscale(1); }
.pick i { position: absolute; top: 4px; right: 4px; font-style: normal; font-size: 9px; background: #000a; color: #fff; border-radius: 4px; padding: 1px 3px; }

/* ---------------- landscape phones ---------------- */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --hw: min(40px, calc((100vw - 60px) / 18)); --rw: 19px; --sw: 14px; }
  .topbar { padding: 4px 8px; }
  .board { grid-template-columns: 120px 1fr 120px; gap: 4px; padding: 4px 6px 2px; }
  .north { justify-content: center; }
  .side .seatcard { flex-direction: row; border-radius: 999px; padding: 3px 8px 3px 3px; }
  .side .seatcard .who { align-items: flex-start; }
  .side .seatcard .av, .seatcard .av { width: 28px; height: 28px; }
  .side .pond { grid-template-columns: repeat(5, var(--rw)); }
  /* Centre: the two ponds stacked on the left, the dial on the right. */
  .center { display: grid; grid-template-columns: 1fr auto; grid-template-rows: 1fr 1fr; gap: 4px; }
  .center > .pond:first-child { grid-area: 1 / 1; } .center > .mid { grid-area: 1 / 2 / 3 / 3; min-height: 0; padding: 0 4px; }
  .center > .pond:last-child { grid-area: 2 / 1; }
  .ringwrap { width: 64px; height: 64px; } .ringwrap .av { width: 44px; height: 44px; } .ringwrap .t.lg { --tw: 32px; }
  .dial .caption { font-size: 12px; } .dial .caption small { display: none; } .dial .lastd { display: none; }
  /* Me: one row of card + actions, then the hand in a single row. */
  .me { display: grid; grid-template-columns: auto 1fr auto; align-items: center; column-gap: 8px; padding: 3px 8px 4px; }
  .me .yourturn { display: none; }
  .me .bar { grid-column: 1; min-height: 0; } .me .bar .melds { justify-content: flex-start; } .me .bar .melds .t { --tw: 18px; }
  .me .actions { grid-column: 2; margin: 0; justify-content: flex-end; }
  .me .hint { grid-column: 3; justify-content: flex-end; font-size: 11px; max-width: 240px; }
  .me .hand { grid-column: 1 / 4; max-width: none; flex-wrap: nowrap; padding-top: 8px; }
  .me .hand::before { content: ""; }
  .act { min-width: 54px; padding: 5px 10px 4px; font-size: 17px; border-radius: 12px; }
  .act .en { font-size: 9px; }
  .act.chi .t { --tw: 18px; }
  .myturn .me { box-shadow: inset 0 2px 0 var(--gold); }
}
.seat { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: rgba(255,255,255,.06); }
.seat .nm { flex: 1; font-weight: 600; }

.standing .medal i { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-style: normal; font-size: 12px; font-weight: 900; color: #3a2a00; }
.medal .m1 { background: linear-gradient(#ffe38a, #e0a92c); } .medal .m2 { background: linear-gradient(#f2f2f2, #b8c0c8); } .medal .m3 { background: linear-gradient(#f0c09a, #b9763f); }
.medal .m4 { background: rgba(255,255,255,.12); color: var(--muted); }
.drawtiles { display: flex; justify-content: center; gap: 4px; align-items: flex-end; --tw: 34px; }
.pond:empty { background: transparent; }
.iconbtn svg { display: block; }
.north .seatcard .who { display: grid; grid-template-columns: auto auto; column-gap: 8px; align-items: baseline; }
.north .seatcard .nm { grid-column: 1 / 3; }

.me .seatcard.active { background: rgba(0,0,0,.28); color: var(--ink); box-shadow: 0 0 0 2px var(--gold); }
.me .seatcard.active .doing { display: none; } .me .seatcard.active .sc { display: inline; }
.res-hand .set + .set { margin-left: 2px; }

/* A chow's eaten tile sits in the middle, tinted and dropped slightly so everyone sees what was taken. */
.t.eaten { background: linear-gradient(170deg, #fff1c4 55%, #f3dc98); transform: translateY(2px); }

/* ---------------- easy-read tiles (per phone) ---------------- */
.t .num, .t .suit { display: none; }
.s0 { --suit: #c62828; } .s1 { --suit: #1f5fa8; } .s2 { --suit: #1b7a3a; }
/* Hand-size tiles: a bold number on top, the picture shrunk underneath. */
.easy .t .num { display: block; font: 900 calc(var(--tw) * .46)/1 system-ui, sans-serif; color: var(--suit); order: -1; margin-top: 3%; }
.easy .t:has(.num) { justify-content: flex-start; }
.easy .t:has(.num) svg { height: 58%; width: 80%; margin: 0; }
.easy .t:has(.num) .n { font-size: calc(var(--tw) * .3); } .easy .t:has(.num) .s { font-size: calc(var(--tw) * .3); margin-top: 1%; }
/* Small tiles (discards, sets, examples) become a big number over the suit character. */
.easy .t.rv svg, .easy .t.sm svg, .easy .t.gx svg, .easy .melds .t svg, .easy .res-hand .t svg { display: none; }
.easy .t.rv .n, .easy .t.rv .s, .easy .t.sm .n, .easy .t.sm .s, .easy .melds .t .n, .easy .melds .t .s, .easy .res-hand .t .n, .easy .res-hand .t .s { display: none; }
.easy .t.rv .num, .easy .t.sm .num, .easy .melds .t .num, .easy .res-hand .t .num, .easy .t.gx .num {
  position: static; background: none; padding: 0; font-size: calc(var(--tw) * .72); }
.easy .t.rv .suit, .easy .t.sm .suit, .easy .melds .t .suit, .easy .res-hand .t .suit, .easy .t.gx .suit {
  display: block; font-style: normal; font-weight: 800; font-size: calc(var(--tw) * .36); color: var(--suit); margin-top: 1px; }
.easy .t.gx .n, .easy .t.gx .s { display: none; }
/* Slightly bigger discards; honours in bold. */
.easy { --rw: 25px; --sw: 19px; }
.easy .t .h { font-weight: 900; }
@media (orientation: landscape) and (max-height: 520px) { .easy { --rw: 21px; } }

/* Toggle switches */
.prefs { display: grid; gap: 8px; }
.toggle { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border-radius: 14px; background: rgba(255,255,255,.07); text-align: left; }
.toggle .knob { flex: none; width: 46px; height: 28px; border-radius: 999px; background: rgba(255,255,255,.2); position: relative; transition: background .2s; }
.toggle .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; }
.toggle.on .knob { background: #3fae74; } .toggle.on .knob::after { transform: translateX(18px); }
.toggle b { display: block; font-size: 16px; } .toggle small { color: var(--muted); font-size: 12px; }
