@font-face { font-family: "Bodoni Moda"; font-weight: 600; font-display: swap; src: url(/fonts/bodoni-moda-600.woff2) format("woff2"); }
@font-face { font-family: "Sign"; font-display: block; src: url(/fonts/sacramento-sign.woff2) format("woff2"); }

:root {
  --ground: #0f1b17; --panel: #142420; --line: #24352e; --ink: #ede7dc; --mute: #a6b7ae;
  /* The lantern ramp: the only emphasis scale (turn, selection, callable, closeness). */
  --l1: rgba(242, 182, 90, .06); --l2: rgba(242, 182, 90, .13); --l3: rgba(242, 182, 90, .24); --l4: rgba(242, 182, 90, .5); --l5: #f2b65a;
  --neon: #ff5fa8; --neon-ink: #ffc2de;
  --dot: #1e5aa8; --bam: #17744a; --crak: #b62f2a; --bone: #fffbf3; --bone2: #efe5d3; --edge: #d8c8ac;
  --sa: #8ab4f8; --sb: #f28b82; --sc: #81c995; /* card colors for suit a, b, c: the printed card's blue, red, green */
  --twmax: 58px; --sw: min(26px, 3.1vw); --xs: 20px;
  --pad-t: max(8px, env(safe-area-inset-top)); --pad-b: max(10px, env(safe-area-inset-bottom));
  --pad-l: max(16px, env(safe-area-inset-left)); --pad-r: max(16px, env(safe-area-inset-right));
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --display: "Bodoni Moda", "Didot", serif;
  --ease: cubic-bezier(.2, .9, .25, 1);
  color-scheme: dark;
}
:root.big { --sw: min(31px, 3.7vw); --xs: 24px; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--ground); color: var(--ink); font: 15px/1.35 var(--ui); -webkit-text-size-adjust: 100%; }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--l5); outline-offset: 2px; }
::selection { background: var(--l4); color: var(--ink); }
.defs { position: absolute; width: 0; height: 0; }

/* ---------- Buttons ---------- */
.btn { min-height: 44px; min-width: 44px; padding: 0 16px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: 600 17px/1 var(--ui); border: 1px solid rgba(237, 231, 220, .2); background: rgba(237, 231, 220, .04); transition: transform .1s ease-out, background .15s; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--l5); color: #1d1408; border: 0; box-shadow: 0 2px 0 #b98431, 0 8px 16px rgba(0, 0, 0, .4); }
.btn.mahjong { background: var(--neon); color: #2a0718; border: 0; box-shadow: 0 2px 0 #b8336f, 0 8px 16px rgba(0, 0, 0, .4); }
.btn:disabled { opacity: .38; pointer-events: none; }
.btn.primary:disabled { opacity: 1; background: transparent; color: var(--mute); border: 1px solid var(--l4); box-shadow: none; }
.btn.icon { padding: 0; width: 44px; }

/* ---------- Tiles ---------- */
.t { position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; flex: none;
  width: var(--tw, 46px); height: calc(var(--tw, 46px) * 1.34); border-radius: calc(var(--tw, 46px) * .15);
  background: linear-gradient(var(--bone), var(--bone2)); box-shadow: inset 0 -3px 0 var(--edge), 0 2px 0 #b5a385, 0 6px 12px rgba(0, 0, 0, .4);
  font: 800 calc(var(--tw, 46px) * .52)/1 var(--ui); font-style: normal; color: #1c2a24; transition: transform .16s var(--ease); }
.t::after { flex: none; }
.d { color: var(--dot); }
.d::after { content: ""; width: .44em; height: .44em; border-radius: 50%; border: .1em solid var(--dot); background: radial-gradient(var(--crak) 0 30%, transparent 36%); }
.b { color: var(--bam); }
.b::after { content: ""; width: .19em; height: .56em; border-radius: .1em; background: linear-gradient(var(--bam) 0 44%, #0c4a30 44% 56%, var(--bam) 56%); }
.c { color: var(--crak); }
.c::after { content: "萬"; font: 700 .42em/1 "PingFang SC", "Hiragino Sans", sans-serif; }
.w::after { content: attr(data-h); font: 600 .42em/1 "PingFang SC", "Hiragino Sans", sans-serif; color: #56635c; }
.r, .g { font-family: "PingFang SC", "Hiragino Sans", sans-serif; font-weight: 700; }
.r { color: var(--crak); font-size: calc(var(--tw, 46px) * .56); } .g { color: var(--bam); font-size: calc(var(--tw, 46px) * .5); }
.o::before { content: ""; width: 58%; height: 60%; border: .1em solid var(--dot); border-radius: .08em; }
.j { color: #a11a55; font-size: calc(var(--tw, 46px) * .28); font-weight: 900; letter-spacing: .02em; line-height: 1.05; text-align: center; }
.f svg { width: 66%; height: 50%; }
.s { --tw: var(--sw); box-shadow: inset 0 -2px 0 var(--edge), 0 1px 0 #b5a385, 0 3px 5px rgba(0, 0, 0, .35); }
.xs { --tw: var(--xs); }
.s.j { font-size: calc(var(--tw) * .55); }
.t.sel { transform: translateY(-14%); outline: 2px solid var(--l5); outline-offset: 1px; }
.t.hint { outline: 2px dashed var(--l5); outline-offset: 2px; }
.t.new::before { content: ""; position: absolute; top: 4%; right: 6%; width: 7px; height: 7px; border-radius: 50%; background: var(--l5); }
.t.last { outline: 2px solid var(--l5); outline-offset: 1px; }
.t.off { opacity: .45; }
button.t:active { transform: translateY(-6%) scale(.98); }

/* ---------- Home ---------- */
.home { position: fixed; inset: 0; display: grid; grid-template-columns: 1.15fr 1fr; align-items: center; gap: 24px;
  padding: var(--pad-t) var(--pad-r) var(--pad-b) var(--pad-l); background: radial-gradient(70% 60% at 30% 95%, var(--l3), transparent 70%), var(--ground); }
.sign { font: 400 clamp(44px, 9.5vw, 92px)/1.05 "Sign", cursive; color: var(--neon-ink); text-shadow: 0 0 4px rgba(255, 95, 168, .9), 0 0 16px rgba(255, 95, 168, .55), 0 0 34px rgba(255, 95, 168, .3); }
.home .tag { margin-top: 18px; max-width: 30ch; color: var(--mute); font-size: 16px; }
.home .menu { display: flex; flex-direction: column; gap: 12px; max-width: 340px; width: 100%; justify-self: end; }
.home .menu .btn { width: 100%; justify-content: space-between; }
.home .menu .btn small { font: 500 13px var(--ui); color: inherit; opacity: .75; }
.home .stats { color: var(--mute); font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.home .stand { color: var(--mute); font-size: 12px; margin-top: 14px; }

/* ---------- Table ---------- */
.table { position: fixed; inset: 0; display: grid; gap: 6px 14px; padding: var(--pad-t) var(--pad-r) var(--pad-b) var(--pad-l);
  grid-template-columns: minmax(92px, 15%) minmax(0, 1fr) minmax(92px, 15%); grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "head head head" "left pool right" "bar bar bar" "rack rack rack"; }
.head { grid-area: head; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: start; gap: 12px; }
.bar { grid-area: bar; display: flex; gap: 12px; align-items: center; min-width: 0; }
.lantern { position: fixed; left: 0; top: 0; width: 560px; height: 220px; margin: -110px 0 0 -280px; pointer-events: none; border-radius: 50%;
  background: radial-gradient(closest-side, var(--l3), var(--l2) 55%, transparent); transition: opacity .3s; z-index: 0; }
.table > * { position: relative; z-index: 1; }
.tl { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tl .sign { font-size: 27px; line-height: 1; white-space: nowrap; }
.sign.unlit { color: rgba(255, 194, 222, .4); text-shadow: none; }
.top { justify-self: center; text-align: center; }
.tr { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.tr .btn { flex: none; }
.left { grid-area: left; align-self: start; }
.right { grid-area: right; align-self: start; text-align: right; }
.right .row { justify-content: flex-end; }
.pool-wrap { grid-area: pool; display: flex; flex-direction: column; justify-content: center; min-height: 0; }
.pool { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; align-content: flex-start; overflow: hidden; padding: 4px; }
.wallct { margin-top: 6px; text-align: center; color: var(--mute); font-size: 12px; font-variant-numeric: tabular-nums; }
.name { font: 600 22px/1 var(--display); color: var(--ink); opacity: .82; transition: opacity .3s; }
.seat.on .name { opacity: 1; color: #fff3dc; }
.exps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.top .exps { justify-content: center; }
.exp { display: flex; gap: 2px; }
.talk { position: fixed; z-index: 25; max-width: 220px; padding: 8px 12px; border-radius: 12px; background: var(--bone); color: #1c2a24;
  font: 600 13px/1.3 var(--ui); box-shadow: 0 8px 18px rgba(0, 0, 0, .45); white-space: normal; }
.talk.enter { animation: talk-in .25s var(--ease); }
.talk[hidden], .toast[hidden] { display: none; }
@keyframes talk-in { from { opacity: 0; translate: 0 4px; } }

.pin { position: relative; display: inline-flex; align-items: center; min-height: 44px; min-width: 0; max-width: 100%; padding: 0 12px; font: 600 13px/1.2 var(--ui); color: var(--ink); white-space: nowrap; }
.pin .pl { overflow: hidden; text-overflow: ellipsis; }
.pin svg { position: absolute; inset: 4px -4px; width: calc(100% + 8px); height: calc(100% - 8px); overflow: visible; fill: none; stroke: var(--l5); stroke-width: 1.6; stroke-linecap: round; }
.pin.none { color: var(--mute); }
.pin.none svg { stroke: var(--line); stroke-dasharray: 3 4; }

.coach { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 8px 14px; border-radius: 12px; background: rgba(20, 36, 32, .82); border: 1px solid var(--line); min-width: 0; }
.coach:empty { visibility: hidden; }
.coach .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--l5); }
.coach .msg { font-size: 15px; line-height: 1.3; min-width: 0; }
.coach .msg b { font-weight: 600; }
.coach .rule { display: block; font: 600 12px/1.3 var(--ui); color: var(--ink); opacity: .75; margin-bottom: 2px; }
.coach .meta { margin-left: auto; flex: none; font-size: 12px; color: var(--mute); }
.coach .x { margin-left: auto; flex: none; }
.coach.note { border-color: var(--l4); }
.acts { flex: none; display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.rack-row { grid-area: rack; display: flex; align-items: flex-end; gap: 12px; min-width: 0; }
.mine { display: flex; gap: 6px; flex: none; }
.rack-wrap { flex: 1; min-width: 0; container-type: inline-size; }
.rack { display: flex; gap: 4px; justify-content: center; padding-top: 10px; }
.rack .t { --tw: min(var(--twmax), calc((100cqw - (var(--n) - 1) * 4px) / var(--n))); touch-action: none; }
.rack-row.on .t { background: linear-gradient(#fff6e2, #f2e0bf); }
.t.press { transform: translateY(-10%); }
.t.fly { transition: none; pointer-events: none; }
.t.drag { transition: none; z-index: 5; box-shadow: inset 0 -3px 0 var(--edge), 0 16px 24px rgba(0, 0, 0, .5); }

/* Portrait: the same table, stacked. */
@media (max-aspect-ratio: 4/5) {
  .table { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "head head" "left right" "pool pool" "bar bar" "rack rack"; }
  .head { grid-template-columns: minmax(0, 1fr); }
  .head .top { order: 3; }
  .bar { flex-direction: column; align-items: stretch; }
  .tl .sign { font-size: 24px; }
  .rack { flex-wrap: wrap; max-width: 100cqw; }
  .rack .t { --tw: min(var(--twmax), calc((100cqw - 6 * 4px) / 7)); }
  .acts { justify-content: stretch; } .acts .btn { flex: 1; }
  .home { grid-template-columns: 1fr; align-content: center; text-align: center; }
  .home .tag { margin-inline: auto; } .home .menu { justify-self: center; }
  :root { --sw: min(26px, 6.4vw); }
}

/* ---------- Sheets ---------- */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(5, 10, 8, .55); }
.scrim.enter { animation: fade .2s ease-out; }
.sheet { position: fixed; z-index: 21; top: 0; right: 0; bottom: 0; width: min(560px, 66vw); display: flex; flex-direction: column;
  padding: var(--pad-t) var(--pad-r) 0 20px; background: #12201c; border-left: 1px solid var(--line); box-shadow: -20px 0 40px rgba(0, 0, 0, .45); }
.sheet.enter { animation: slide .3s var(--ease); }
@media (max-aspect-ratio: 4/5) { .sheet { width: 100vw; padding-left: var(--pad-l); } }
@keyframes slide { from { transform: translateX(100%); } }
@keyframes fade { from { opacity: 0; } }
.sheet header { display: flex; align-items: center; gap: 12px; min-height: 52px; flex: none; }
.sheet h2 { font: 600 24px/1.1 var(--display); }
.sheet header .btn { margin-left: auto; }
.sheet .body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(var(--pad-b) + 12px); flex: 1; }
.sheet .sub { color: var(--mute); font-size: 13px; margin-bottom: 8px; }
.sec { margin: 18px 0 6px; font: 700 12px/1 var(--ui); color: var(--mute); text-transform: uppercase; letter-spacing: .08em; }
.hand { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 18px; min-height: 52px; border-radius: 12px; text-align: left; position: relative; }
.hand:active { background: var(--l1); }
.hand.pinned { background: rgba(237, 231, 220, .06); }
.hand .pat { font: 700 17px/1.25 var(--ui); letter-spacing: .04em; font-variant-numeric: tabular-nums; flex: 1; min-width: 0; }
.pat .pa { color: var(--sa); } .pat .pb { color: var(--sb); } .pat .pc { color: var(--sc); } .pat .pn { color: var(--ink); }
.hand .note { display: block; font: 500 12px/1.3 var(--ui); color: var(--mute); letter-spacing: 0; margin-top: 2px; }
.hand .val { flex: none; text-align: right; font: 600 13px/1.3 var(--ui); color: var(--mute); font-variant-numeric: tabular-nums; }
.hand .away { display: block; color: var(--ink); }
.hand .away.near { color: var(--l5); }
.hand.dead .pat { text-decoration: line-through; text-decoration-color: var(--mute); opacity: .5; }
.hand .circle { position: absolute; inset: 1px; width: calc(100% - 2px); height: calc(100% - 2px); overflow: visible; fill: none; stroke: var(--l5); stroke-width: 1.5; stroke-linecap: round; vector-effect: non-scaling-stroke; pointer-events: none; }
.rules li { list-style: none; padding: 12px 0; border-bottom: 1px solid var(--line); }
.rules h3 { font: 600 17px/1.3 var(--ui); }
.rules p { color: var(--mute); font-size: 14px; margin-top: 4px; }
.rules .dots { display: flex; gap: 5px; margin-top: 8px; }
.rules .dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.rules .dots i.on { background: var(--l5); }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.opt .seg { display: flex; gap: 4px; }
.opt .seg .btn { min-height: 36px; padding: 0 12px; font-size: 14px; }
.opt .seg .btn.on { background: var(--l2); border-color: var(--l4); }

/* ---------- End of game ---------- */
.end { position: fixed; inset: 0; z-index: 30; display: grid; grid-template-columns: 1fr 1fr; gap: 28px; align-items: center;
  padding: var(--pad-t) var(--pad-r) var(--pad-b) var(--pad-l); background: radial-gradient(70% 60% at 25% 100%, var(--l2), transparent 70%), #0d1714; }
.end.enter { animation: fade .3s ease-out; }
.end .sign.big { font-size: clamp(40px, 6.4vw, 64px); white-space: nowrap; padding-bottom: .22em; }
.end .sign.on { animation: flicker 1.2s steps(1) both; }
@keyframes flicker { 0% { opacity: 0; } 8% { opacity: 1; } 12% { opacity: .2; } 18% { opacity: 1; } 24% { opacity: .35; } 30%, 100% { opacity: 1; } }
.end h2 { font: 600 28px/1.15 var(--display); margin-top: 10px; }
.end .what { color: var(--mute); margin-top: 6px; }
.end .line { font: 600 17px/1.3 var(--display); color: var(--neon-ink); margin-top: 10px; }
.end .won { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 14px; }
.end .won .t { --tw: 26px; }
.end .review h3 { font: 600 17px/1.3 var(--ui); }
.end .review .score { color: var(--mute); font-size: 14px; margin: 4px 0 12px; }
.end .review li { list-style: none; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.end .review li .rule { display: block; color: var(--mute); font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.end .btns { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
@media (max-aspect-ratio: 4/5) { .end { grid-template-columns: 1fr; align-content: center; overflow-y: auto; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--pad-b) + 90px); transform: translateX(-50%); z-index: 40; padding: 10px 16px; border-radius: 12px;
  background: var(--bone); color: #1c2a24; font-weight: 600; box-shadow: 0 8px 18px rgba(0, 0, 0, .45); animation: talk-in .25s var(--ease); }

@media (prefers-reduced-motion: reduce) {
  .lantern { transition: opacity .3s; }
  .sheet.enter, .talk.enter, .toast { animation: fade .2s ease-out; }
  .end .sign.on { animation: fade .4s ease-out; }
  .t, .btn { transition: none; }
}
