:root {
  --bg: #141b42;
  --panel: rgba(24, 26, 32, 0.94);
  --panel-2: #20232b;
  --line: rgba(255, 255, 255, 0.09);
  --text: #eceef2;
  --muted: #9aa1ad;
  --tile-surface: linear-gradient(#f6f3ea, #f6f3ea); /* 牌身材質（由設定切換） */
  --gold: #f7c04a;
  --gold-2: #ffd77a;
  --teal: #7fd3c3;
  --red: #ff6b6b;
  --blue: #7da7ff;
  --radius: 12px;
  --font: "Noto Sans TC", system-ui, sans-serif;
  --serif: "Noto Serif TC", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); }
button { font-family: inherit; }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.screen { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .45s ease; }
.screen.show { opacity: 1; }
.screen.show > * { pointer-events: auto; }
.hidden { display: none !important; }

/* ---------- 載入 ---------- */
#loading { display: grid; place-content: center; justify-items: center; gap: 14px; background: var(--bg); color: var(--muted); z-index: 50; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #2a2d35; border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 按鈕 ---------- */
.btn {
  min-width: 220px; padding: 11px 22px; border-radius: 9px; font-size: calc(16px * var(--fs)); font-weight: 700; letter-spacing: .12em;
  cursor: pointer; border: 1px solid transparent; transition: transform .15s, background .2s, border-color .2s, box-shadow .2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--gold); color: #2a1d00; box-shadow: 0 6px 22px rgba(247, 192, 74, .22); }
.btn-primary:hover { background: var(--gold-2); }
.btn-ghost { background: rgba(255, 255, 255, .04); color: var(--text); border-color: rgba(255, 255, 255, .14); }
.btn-ghost:hover { border-color: rgba(255, 255, 255, .3); }
.btn-outline { background: rgba(0, 0, 0, .25); color: var(--text); border-color: var(--gold); }
.btn-outline:hover { background: rgba(247, 192, 74, .1); }
.btn-sm { min-width: 0; padding: 8px 18px; font-size: calc(14px * var(--fs)); letter-spacing: .06em; }

/* ---------- 首頁 ---------- */
#home { background-color: var(--site-bg-color); background-image: var(--site-bg); background-position: center; background-size: cover; background-repeat: no-repeat; color: var(--site-ink); }
#home::before { content: ""; position: absolute; inset: 14px; border: 1px solid rgba(112, 86, 55, .25); pointer-events: none; }
.logo { position: absolute; top: 30px; left: 36px; display: flex; align-items: center; gap: 14px; }
.logo-mark { width: 56px; height: 56px; flex: none; transform: rotate(-3deg); }
.logo-mark svg { display: block; width: 100%; height: 100%; }
.logo-frame { fill: #a44135; stroke: #84392f; stroke-width: 1; }
.logo-seal-border { fill: none; stroke: #f5e8ce; stroke-width: .8; }
.logo-link { fill: none; stroke: #f5e8ce; stroke-width: 3; stroke-linecap: square; stroke-linejoin: miter; }
.logo-node { fill: #f5e8ce; stroke: #a44135; stroke-width: 1; }
.logo h1 { margin: 0; font-family: var(--serif); font-size: calc(32px * var(--fs)); font-weight: 900; letter-spacing: .12em; line-height: 1.15; color: #352f29; }
.logo p { margin: 7px 0 0; font-family: var(--serif); font-size: calc(11px * var(--fs)); color: #796d5b; letter-spacing: .22em; }
.home-menu { position: absolute; right: 36px; top: 34px; display: flex; align-items: center; gap: 14px; }
.home-menu .btn { min-width: 150px; font-family: var(--serif); font-weight: 700; letter-spacing: .2em; border-radius: 2px; padding: 12px 22px; box-shadow: 0 3px 10px rgba(68, 42, 26, .06); }
.home-menu .btn-primary { background: #a44135; color: #fff5df; border-color: #84392f; outline: 1px solid rgba(255, 240, 214, .5); outline-offset: -5px; }
.home-menu .btn-primary:hover { background: #8b352c; }
.home-menu .btn-ghost, .home-menu .btn-outline { background: rgba(250, 246, 234, .94); color: #45392d; border-color: #a99a80; }
.home-menu .btn-ghost:hover, .home-menu .btn-outline:hover { background: #fff9ec; border-color: #a44135; color: #913a30; }
#home button:focus-visible { outline: 2px solid #913a30; outline-offset: 4px; }
.home-poem { position: absolute; top: 29%; left: 12%; display: flex; flex-direction: row-reverse; align-items: flex-start; gap: 24px; pointer-events: none; }
.home-poem p { margin: 0; writing-mode: vertical-rl; font-family: var(--serif); font-weight: 900; font-size: calc(clamp(28px, 3.5vw, 48px) * var(--fs)); letter-spacing: .28em; line-height: 1.5; }
.home-poem p:nth-child(2) { margin-top: 54px; color: #665b4c; }
.home-seal { writing-mode: vertical-rl; margin-top: 160px; padding: 8px 5px; border: 1px solid #a44135; color: #a44135; font-family: var(--serif); font-size: calc(14px * var(--fs)); letter-spacing: .2em; }
.home-colophon { position: absolute; left: 38px; bottom: 38px; font-family: var(--serif); font-size: calc(12px * var(--fs)); letter-spacing: .24em; color: #796d5b; }
.home-colophon span { margin: 0 12px; color: #a44135; }
.home-icons { position: absolute; right: 30px; bottom: 28px; display: flex; gap: 6px; padding: 2px 8px; background: rgba(250, 246, 234, .9); border-top: 1px solid #baaa90; border-bottom: 1px solid #baaa90; }
.home-icons button { background: none; border: 0; color: #665746; display: flex; flex-direction: column; align-items: center; gap: 6px; font-family: var(--serif); font-size: calc(12px * var(--fs)); cursor: pointer; padding: 8px 12px; border-radius: 0; transition: color .2s, background .2s; }
.home-icons button:hover { color: #a44135; background: rgba(164, 65, 53, .06); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 760px) {
  #home::before { inset: 8px; }
  .home-poem { top: 34%; left: 10%; gap: 16px; }
  .home-poem p { font-size: calc(30px * var(--fs)); }
  .home-colophon { display: none; }
}
@media (max-height: 580px) {
  .home-poem { display: none; }
}

/* ---------- HUD ---------- */
.hud-info {
  position: absolute; top: 16px; left: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 14px; min-width: 190px; font-size: calc(13px * var(--fs)); color: var(--muted); display: grid; gap: 5px;
}
.hud-info-title { display: flex; justify-content: space-between; gap: 12px; color: var(--text); font-size: calc(13px * var(--fs)); }
.hud-info-title b { color: var(--gold); font-weight: 700; }
.hud-info-row { display: flex; gap: 10px; align-items: baseline; }
.hud-info-row b { color: var(--text); }
#info-streak { color: var(--red); }

.hud-top-right { position: absolute; top: 16px; right: 16px; display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  display: grid; place-items: center; cursor: pointer; transition: color .2s;
}
.icon-btn:hover { color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.badge {
  position: absolute; display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 14px 5px 6px; font-size: calc(13px * var(--fs)); white-space: nowrap; transition: box-shadow .3s, border-color .3s;
}
.badge .dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-family: var(--serif); font-weight: 900; font-size: calc(12px * var(--fs)); color: #1a1a1a; }
.badge .name { font-weight: 700; }
.badge .score { color: var(--muted); font-variant-numeric: tabular-nums; }
.badge .dealer { font-size: calc(11px * var(--fs)); background: var(--red); color: #fff; border-radius: 4px; padding: 0 5px; font-weight: 700; }
.badge .flowers { color: #f2a7b6; font-size: calc(12px * var(--fs)); }
.badge.active { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(247, 192, 74, .18), 0 0 18px rgba(247, 192, 74, .25); }
.badge.seat-0 { left: 8%; bottom: 25%; }
.badge.seat-1 { right: 3%; top: 32%; }
.badge.seat-2 { left: 67%; top: 16px; }
.badge.seat-3 { left: 3%; top: 32%; }

/* 動作按鈕 */
.actions { position: absolute; right: 6%; bottom: 25%; display: flex; gap: 10px; align-items: flex-end; }
.act {
  min-width: 96px; padding: 12px 20px; border-radius: 9px; font-size: calc(18px * var(--fs)); font-weight: 900; letter-spacing: .2em; cursor: pointer;
  border: 1px solid transparent; color: #fff; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); transition: transform .12s, filter .2s;
  animation: pop-in .2s ease-out;
}
.act:hover { transform: translateY(-2px); filter: brightness(1.1); }
.act-win { background: linear-gradient(180deg, #ff7a6b, #e0443c); }
.act-kan { background: linear-gradient(180deg, #a98bff, #7a5ae0); }
.act-pon { background: linear-gradient(180deg, #7eb3ff, #4a7fe0); }
.act-chi { background: linear-gradient(180deg, #5fd6b9, #2ea88b); }
.act-pass { background: rgba(28, 30, 36, .95); border-color: rgba(255, 255, 255, .2); color: var(--text); }
.chi-opts { display: flex; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.chi-opt { display: flex; gap: 2px; padding: 6px; border-radius: 8px; border: 1px solid transparent; background: none; cursor: pointer; }
.chi-opt:hover { border-color: var(--teal); background: rgba(127, 211, 195, .08); }
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } }

.turn-hint { position: absolute; left: 50%; bottom: 25.5%; transform: translateX(-50%); font-size: calc(13px * var(--fs)); color: var(--muted); background: rgba(0,0,0,.35); padding: 4px 12px; border-radius: 999px; }

/* 牌圖（HTML） */
.tile {
  display: inline-block; width: 38px; height: 52px; border-radius: 5px; background: #f6f3ea center / cover no-repeat;
  box-shadow: inset 0 -1px 0 rgba(0,0,0,.08), 0 4px 0 #4fb3a0, 0 5px 6px rgba(0,0,0,.35); flex: none; position: relative;
}
.tile.sm { width: 26px; height: 36px; border-radius: 4px; box-shadow: 0 3px 0 #4fb3a0, 0 4px 4px rgba(0,0,0,.3); }
.tile.lg { width: 46px; height: 63px; }
.tile.hi { outline: 2px solid var(--gold); outline-offset: 2px; }
.tile.down { background: #4fb3a0 !important; }

/* 聽牌提示 */
.wait-box {
  position: absolute; left: 50%; bottom: 27%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; min-width: 150px;
}
.wait-box .label { font-size: calc(12px * var(--fs)); color: var(--muted); }
.wait-box .label b { color: var(--teal); background: rgba(127,211,195,.12); padding: 1px 6px; border-radius: 4px; margin-left: 6px; font-weight: 700; }
.wait-list { display: flex; gap: 12px; }
.wait-item { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: calc(12px * var(--fs)); color: var(--muted); }
.wait-item b { color: var(--text); }
.tenpai-chip { position: absolute; right: 16px; bottom: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: flex; gap: 8px; align-items: center; font-size: calc(12px * var(--fs)); color: var(--gold); }

/* 宣告字幕 */
#announce-layer { position: absolute; inset: 0; pointer-events: none !important; }
.announce {
  position: absolute; transform: translate(-50%, -50%); font-family: var(--serif); font-weight: 900; font-size: calc(46px * var(--fs)); letter-spacing: .15em;
  padding: 6px 34px 6px 42px; color: #fff; background: linear-gradient(90deg, transparent, rgba(0,0,0,.82) 18%, rgba(0,0,0,.82) 82%, transparent);
  text-shadow: 0 2px 12px rgba(0,0,0,.6); animation: announce 1.1s ease-out forwards; white-space: nowrap;
}
.announce.big { font-size: calc(72px * var(--fs)); color: var(--gold-2); animation-duration: 1.6s; }
.announce.small { font-size: calc(26px * var(--fs)); }
@keyframes announce {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.4); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -60%); }
}

/* ---------- 對話框 ---------- */
.modal { position: fixed; inset: 0; background: rgba(6, 7, 10, .55); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 20; padding: 16px; animation: fade .25s; }
@keyframes fade { from { opacity: 0; } }
.modal-card {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px 28px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); animation: rise .3s ease-out;
}
.modal-card.wide { width: min(1080px, 100%); padding: 0; display: flex; flex-direction: column; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
.modal-card h2 { margin: 0 0 18px; font-family: var(--serif); font-weight: 900; font-size: calc(24px * var(--fs)); letter-spacing: .08em; }
.modal-card h3 { margin: 18px 0 8px; font-size: calc(14px * var(--fs)); color: var(--muted); font-weight: 500; letter-spacing: .08em; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 90px; padding: 10px 12px; border-radius: 9px; background: rgba(255,255,255,.03); border: 1px solid var(--line);
  color: var(--text); cursor: pointer; font-size: calc(14px * var(--fs)); display: grid; gap: 2px; text-align: center; transition: border-color .2s, background .2s;
}
.seg button small { color: var(--muted); font-size: calc(11px * var(--fs)); }
.seg button.on { border-color: var(--gold); background: rgba(247, 192, 74, .08); }
.swatch { width: 18px; height: 18px; border-radius: 5px; display: inline-block; vertical-align: -4px; margin-right: 6px; border: 1px solid rgba(255,255,255,.2); }

.rule-table { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; font-size: calc(14px * var(--fs)); }
.rule-table div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 6px 2px; }
.rule-table b { color: var(--gold); font-weight: 700; }
.prose { font-size: calc(14px * var(--fs)); line-height: 1.8; color: #cfd3da; }
.prose p { margin: 0 0 10px; }
kbd { background: #2a2d35; border-radius: 4px; padding: 1px 6px; font-size: calc(12px * var(--fs)); }

/* ---------- 結算 ---------- */
.res-head { display: flex; justify-content: space-between; align-items: center; padding: 22px 28px 0; }
.res-title { font-family: var(--serif); font-size: calc(30px * var(--fs)); font-weight: 900; letter-spacing: .12em; }
.res-who { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px 5px 6px; font-size: calc(14px * var(--fs)); }
.res-hand { display: flex; justify-content: center; align-items: flex-end; gap: 3px; flex-wrap: wrap; padding: 28px 28px 22px; border-bottom: 1px solid var(--line); }
.res-hand .gap { width: 14px; }
.res-hand .win-bracket { display: flex; align-items: center; gap: 6px; margin-left: 22px; color: var(--gold); font-size: calc(34px * var(--fs)); font-weight: 300; }
.res-body { display: grid; grid-template-columns: 1.3fr 1fr; gap: 28px; padding: 22px 28px; }
.res-items { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; align-content: start; }
.res-item { display: flex; justify-content: space-between; background: rgba(255,255,255,.03); border-radius: 6px; padding: 8px 12px; font-size: calc(14px * var(--fs)); }
.res-item span:last-child { color: var(--muted); }
.res-item.note { opacity: .6; }
.res-score { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.res-points { font-size: calc(64px * var(--fs)); font-weight: 900; color: var(--gold); letter-spacing: .02em; font-variant-numeric: tabular-nums; line-height: 1; }
.res-sub { color: var(--muted); font-size: calc(14px * var(--fs)); }
.res-rank { background: #4a3a14; color: var(--gold-2); border-radius: 7px; padding: 5px 16px; font-weight: 700; letter-spacing: .1em; }
.res-deltas { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 0 28px 4px; }
.res-delta { background: rgba(255,255,255,.03); border-radius: 8px; padding: 8px 12px; display: flex; justify-content: space-between; font-size: calc(13px * var(--fs)); }
.res-delta .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.res-delta .v.plus { color: var(--teal); }
.res-delta .v.minus { color: var(--red); }
.res-foot { display: flex; justify-content: space-between; align-items: center; padding: 16px 28px 20px; margin-top: 10px; border-top: 1px solid var(--line); gap: 12px; }
.res-flowers { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: calc(12px * var(--fs)); }

.rank-list { display: grid; gap: 8px; }
.rank-row { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center; background: rgba(255,255,255,.03); border-radius: 9px; padding: 10px 14px; }
.rank-row .n { font-size: calc(22px * var(--fs)); font-weight: 900; color: var(--muted); }
.rank-row.first .n { color: var(--gold); }
.rank-row .s { font-variant-numeric: tabular-nums; font-weight: 700; }

@media (max-width: 900px) {
  .home-menu { left: 32px; right: 32px; top: 116px; }
  .home-menu .btn { flex: 1; min-width: 0; }
}

@media (max-width: 760px) {
  .home-menu { right: 16px; left: 16px; top: 108px; flex-wrap: wrap; gap: 10px; }
  .home-menu .btn { flex: 1 1 120px; padding: 11px 14px; }
  .btn { min-width: 0; width: 100%; }
  .logo { left: 16px; top: 18px; }
  .home-icons { left: 0; right: 0; justify-content: center; }
  .res-body { grid-template-columns: 1fr; }
  .res-deltas { grid-template-columns: 1fr 1fr; }
  .rule-table { grid-template-columns: 1fr; }
  .hud-info { transform: scale(.85); transform-origin: top left; }
  .badge { font-size: calc(11px * var(--fs)); }
  .act { min-width: 64px; padding: 10px 12px; font-size: calc(15px * var(--fs)); }
}
/* ---------- 會員帳號 ---------- */
.account-bar { position: absolute; right: 36px; top: 100px; }
.account-bar button { border: 1px solid #aa9276; background: rgba(250,246,234,.95); color: #813b31; padding: 8px 18px; font-family: var(--serif); cursor: pointer; }
#auth-dialog { box-sizing: border-box; width: min(420px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 30px; border: 1px solid var(--site-line); border-radius: 4px; background: var(--site-dialog); color: var(--site-ink); box-shadow: 0 24px 80px #0005; }
#auth-dialog::backdrop { background: rgba(32,26,23,.55); backdrop-filter: blur(3px); }
#auth-dialog h2 { font-family: var(--site-display); margin: 12px 0 22px; letter-spacing: .12em; }
.auth-brand { font-size: calc(12px * var(--fs)); color: var(--site-muted); letter-spacing: .1em; }
#auth-dialog button { cursor: pointer; border: 1px solid var(--site-line); padding: 10px 14px; background: var(--site-input); color: var(--site-ink); font-size: calc(14px * var(--fs)); border-radius: 2px; }
#auth-dialog .auth-close { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; font-size: calc(24px * var(--fs)); padding: 4px 10px; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 20px; }
.auth-tabs button { flex: 1; }
#auth-dialog .auth-tabs [aria-pressed="true"], #auth-dialog .auth-primary { background: var(--site-primary); color: var(--site-primary-ink); border-color: var(--site-primary); }
#auth-form { display: grid; gap: 16px; }
#auth-form label { font-size: calc(14px * var(--fs)); }
#auth-form input { box-sizing: border-box; display: block; width: 100%; margin-top: 7px; padding: 11px; border: 1px solid var(--site-line); border-radius: 2px; background: var(--site-input); color: var(--site-ink); font: inherit; }
#auth-dialog :focus-visible { outline: 2px solid var(--site-accent); outline-offset: 3px; }
#auth-dialog .auth-text { background: transparent; border: 0; color: var(--site-accent); padding-left: 0; }
.auth-divider { display: flex; align-items: center; gap: 12px; color: var(--site-muted); margin: 10px 0 18px; font-size: calc(12px * var(--fs)); }
.auth-divider::before, .auth-divider::after { content: ''; height: 1px; background: var(--site-line-2); flex: 1; }
#auth-google, #auth-logout, #auth-profile { width: 100%; }
#auth-profile { margin: 8px 0 10px; }
#auth-logout { margin-top: 18px; }
.auth-note { font-size: calc(12px * var(--fs)); color: var(--site-muted); line-height: 1.6; }
#auth-status { color: var(--site-accent); font-size: calc(14px * var(--fs)); line-height: 1.7; margin-bottom: 0; }
#auth-identity { overflow-wrap: anywhere; }
#auth-dialog button:disabled { opacity: .55; cursor: wait; }
/* 年齡確認（P0-08）：註冊表單的出生年月與獨立的確認對話框 */
#age-dialog { box-sizing: border-box; width: min(380px, calc(100% - 32px)); padding: 28px; border: 1px solid var(--site-line); border-radius: 4px; background: var(--site-dialog); color: var(--site-ink); box-shadow: 0 24px 80px #0005; }
#age-dialog::backdrop { background: rgba(32,26,23,.55); backdrop-filter: blur(3px); }
#age-dialog h2 { font-family: var(--site-display); margin: 0 0 12px; letter-spacing: .12em; }
#age-form { display: grid; gap: 18px; margin-top: 16px; }
.age-row { display: flex; gap: 10px; margin: 0; padding: 0; border: 0; min-width: 0; }
.age-row legend { font-size: calc(14px * var(--fs)); padding: 0; margin-bottom: 7px; }
.age-row select { flex: 1; min-width: 0; padding: 11px; border: 1px solid var(--site-line); border-radius: 2px; background: var(--site-input); color: var(--site-ink); font: inherit; }
.age-actions { display: flex; gap: 10px; justify-content: flex-end; }
#age-dialog button { cursor: pointer; border: 1px solid var(--site-line); padding: 10px 16px; background: var(--site-input); color: var(--site-ink); font-size: calc(14px * var(--fs)); border-radius: 2px; }
#age-dialog .auth-primary { background: var(--site-primary); color: var(--site-primary-ink); border-color: var(--site-primary); }
#age-dialog :focus-visible { outline: 2px solid var(--site-accent); outline-offset: 3px; }
#age-status { color: var(--site-accent); font-size: calc(14px * var(--fs)); line-height: 1.7; margin-bottom: 0; }
@media (max-width: 900px) { .account-bar { top: 182px; right: 32px; } }
@media (max-width: 760px) { .account-bar { top: 228px; right: 16px; } }
@media (max-height: 400px) { .account-bar { top: auto; bottom: 110px; } }

/* ---------- 吃碰槓特寫 ---------- */
.tile.xl { width: 50px; height: 68px; border-radius: 6px; }
.meld-fx {
  --c: var(--teal); --c2: rgba(127, 211, 195, .45);
  position: absolute; transform: translate(-50%, -50%); display: grid; place-items: center; pointer-events: none;
  animation: meld-life 1.45s ease-out forwards;
}
.meld-pon { --c: var(--blue); --c2: rgba(125, 167, 255, .45); }
.meld-kan { --c: #b89cff; --c2: rgba(184, 156, 255, .5); }
.meld-fx::before {
  content: ""; position: absolute; width: 380px; height: 200px; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, .72), rgba(0, 0, 0, .45) 60%, transparent);
}
.meld-word {
  position: absolute; top: -58px; font-family: var(--serif); font-weight: 900; font-size: calc(64px * var(--fs)); line-height: 1; color: #fff;
  -webkit-text-stroke: 1px var(--c); text-shadow: 0 0 18px var(--c2), 0 4px 14px rgba(0, 0, 0, .7);
  animation: meld-stamp .5s cubic-bezier(.2, 1.6, .4, 1) .38s both;
}
.meld-tiles { position: relative; display: flex; gap: 3px; animation: meld-clack .22s ease-out .4s both; }
.mt { display: block; animation: meld-in .42s cubic-bezier(.25, .9, .35, 1.1) calc(var(--i) * 0.035s) both; }
.mt.taken { animation-duration: .4s; animation-delay: .06s; }
.mt.taken .tile { outline: 2px solid var(--gold); outline-offset: 2px; box-shadow: 0 0 22px rgba(247, 192, 74, .75), 0 4px 0 var(--tile-back, #4fb3a0); }
.meld-kan .meld-tiles { animation-name: meld-clack, meld-shake; animation-duration: .22s, .3s; animation-delay: .4s, .42s; }
.meld-ring {
  position: absolute; width: 120px; height: 120px; border-radius: 50%; border: 3px solid var(--c);
  box-shadow: 0 0 24px var(--c2), inset 0 0 24px var(--c2); opacity: 0; animation: meld-ring .6s ease-out .4s;
}
@keyframes meld-in {
  from { transform: translate(var(--fx), var(--fy)) rotate(var(--fr)) scale(.85); opacity: 0; }
  30% { opacity: 1; }
  to { transform: none; opacity: 1; }
}
@keyframes meld-clack { 0% { transform: scale(1.12); } 50% { transform: scale(.96); } 100% { transform: scale(1); } }
@keyframes meld-shake { 25% { translate: -4px 0; } 50% { translate: 4px 2px; } 75% { translate: -2px -1px; } }
@keyframes meld-ring { from { opacity: 1; transform: scale(.4); } to { opacity: 0; transform: scale(2.6); } }
@keyframes meld-stamp { from { opacity: 0; transform: scale(2.2); } to { opacity: 1; transform: scale(1); } }
@keyframes meld-life { 0%, 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -58%); } }
.meld-fx.still * { animation-duration: 0s !important; animation-delay: 0s !important; }
.meld-fx.still .meld-ring { display: none; }

/* ---------- 胡牌牌型高光 ---------- */
.win-fx {
  --tw: clamp(22px, 3.6vw, 52px);
  position: fixed; inset: 0; z-index: 19; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  padding: 16px; cursor: pointer; overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, rgba(58, 42, 10, .82), rgba(6, 7, 12, .93) 70%);
  animation: fade .35s ease-out;
}
.win-fx.out { opacity: 0; transition: opacity .35s; }
.wf-rays {
  position: absolute; left: 50%; top: 46%; width: 160vmax; height: 160vmax; translate: -50% -50%; pointer-events: none; opacity: 0;
  background: repeating-conic-gradient(from 0deg, rgba(255, 215, 122, .09) 0 6deg, transparent 6deg 18deg);
  mask: radial-gradient(closest-side, #000 10%, transparent 70%); -webkit-mask: radial-gradient(closest-side, #000 10%, transparent 70%);
  animation: wf-rays-in .8s ease-out var(--win-at) forwards, wf-spin 40s linear infinite;
}
.win-fx.grand .wf-rays { background: repeating-conic-gradient(from 0deg, rgba(255, 215, 122, .16) 0 6deg, transparent 6deg 15deg); }
.wf-head { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.wf-title {
  font-family: var(--serif); font-weight: 900; font-size: calc(clamp(48px, 9vw, 96px) * var(--fs)); line-height: 1; letter-spacing: .2em; padding-left: .2em;
  background: linear-gradient(180deg, #fff6d8, var(--gold-2) 45%, #d99a1f); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 18px rgba(247, 192, 74, .45)); animation: meld-stamp .55s cubic-bezier(.2, 1.5, .4, 1) both;
}
.wf-who { display: flex; align-items: center; gap: 8px; font-size: calc(15px * var(--fs)); color: var(--text); animation: rise .4s ease-out .15s both; }
.wf-who .dot { width: 18px; height: 18px; border-radius: 50%; }
.wf-who small { color: var(--muted); font-size: calc(13px * var(--fs)); }

.wf-hand { position: relative; display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: calc(var(--tw) * .36); max-width: 100%; }
.wf-group { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.wf-tiles { display: flex; gap: 2px; perspective: 600px; }
.wf-tile { display: block; animation: wf-flip .5s cubic-bezier(.2, .9, .3, 1.2) var(--d) both; transform-origin: 50% 100%; }
.wf-tile .tile.xl { width: var(--tw); height: calc(var(--tw) * 1.36); border-radius: calc(var(--tw) * .12); }
.wf-group.open .wf-tiles { padding: 3px; border-radius: 8px; background: rgba(255, 255, 255, .05); }
.wf-label {
  font-size: calc(12px * var(--fs)); color: var(--muted); letter-spacing: .12em; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--line);
  animation: fade .3s ease-out calc(var(--d) + .3s) both;
}
.wf-group.open .wf-label { color: #c8b8ff; border-color: rgba(184, 156, 255, .3); }
.wf-group.has-win .wf-label { color: var(--gold-2); border-color: rgba(247, 192, 74, .5); }
.wf-tile.win { position: relative; z-index: 1; animation: wf-flip .5s cubic-bezier(.2, .9, .3, 1.2) var(--d) both, wf-win .7s cubic-bezier(.2, 1.4, .4, 1) var(--win-at) forwards; }
.wf-tile.win .tile { animation: wf-glow 1.6s ease-in-out calc(var(--win-at) + .5s) infinite; }
.wf-tile.win::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: calc(var(--tw) * 3); aspect-ratio: 1; translate: -50% -50%; border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 226, 150, .85), rgba(247, 192, 74, .25) 50%, transparent);
  opacity: 0; pointer-events: none; animation: wf-burst .8s ease-out var(--win-at);
}

.wf-items { position: relative; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 760px; }
.wf-item {
  display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 14px; border-radius: 999px; font-size: calc(14px * var(--fs));
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(247, 192, 74, .25); animation: wf-chip .35s cubic-bezier(.2, 1.4, .4, 1) var(--d) both;
}
.wf-item b { min-width: 24px; text-align: center; background: rgba(247, 192, 74, .18); color: var(--gold-2); border-radius: 999px; padding: 1px 7px; font-variant-numeric: tabular-nums; }
.wf-total { position: relative; display: flex; align-items: baseline; gap: 8px; animation: wf-chip .4s cubic-bezier(.2, 1.4, .4, 1) var(--total-at) both; }
.wf-tai { font-size: calc(clamp(48px, 7vw, 72px) * var(--fs)); font-weight: 900; line-height: 1; color: var(--gold); font-variant-numeric: tabular-nums; text-shadow: 0 0 24px rgba(247, 192, 74, .45); }
.wf-total > span { font-size: calc(20px * var(--fs)); color: var(--muted); }
.wf-rank {
  align-self: center; margin-left: 10px; font-style: normal; font-family: var(--serif); font-weight: 900; font-size: calc(22px * var(--fs)); letter-spacing: .15em;
  color: #fff3d6; background: #a44135; border: 2px solid #ffd77a; border-radius: 6px; padding: 2px 10px 2px 14px; rotate: -8deg;
  animation: meld-stamp .45s cubic-bezier(.2, 1.6, .4, 1) calc(var(--total-at) + .5s) both;
}
.wf-skip { position: absolute; bottom: 22px; font-size: calc(12px * var(--fs)); color: var(--muted); letter-spacing: .2em; animation: fade 1s ease-out 1s both; }

@keyframes wf-flip { from { opacity: 0; transform: translateY(-40px) rotateX(80deg); } to { opacity: 1; transform: none; } }
@keyframes wf-win { 0% { transform: none; } 40% { transform: translateY(-18px) scale(1.25); } 100% { transform: translateY(-8px) scale(1.12); } }
@keyframes wf-glow {
  0%, 100% { outline: 2px solid rgba(247, 192, 74, .9); outline-offset: 3px; filter: drop-shadow(0 0 6px rgba(247, 192, 74, .6)); }
  50% { outline: 2px solid rgba(255, 230, 160, 1); outline-offset: 5px; filter: drop-shadow(0 0 18px rgba(247, 192, 74, .95)); }
}
@keyframes wf-burst { 0% { opacity: 1; transform: scale(.3); } 100% { opacity: 0; transform: scale(1.6); } }
@keyframes wf-chip { from { opacity: 0; transform: translateY(10px) scale(.8); } to { opacity: 1; transform: none; } }
@keyframes wf-rays-in { to { opacity: 1; } }
@keyframes wf-spin { to { rotate: 360deg; } }
.win-fx.still *, .win-fx.still *::after { animation-duration: 0s !important; animation-delay: 0s !important; }
.win-fx.still .wf-rays { opacity: 1; }

@media (max-width: 760px) {
  .tile.xl { width: 38px; height: 52px; }
  .meld-word { font-size: calc(48px * var(--fs)); top: -46px; }
  .win-fx { gap: 16px; }
  .wf-label { font-size: calc(10px * var(--fs)); padding: 0 5px; }
}

/* Fine volume adjustment, including keyboard arrow keys. */
.volume-control { display: flex; align-items: center; gap: 16px; }
.volume-control input { flex: 1; min-width: 0; min-height: 32px; accent-color: var(--gold); cursor: pointer; }
.volume-control output { min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.volume-control input:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.volume-control .btn { flex: none; width: auto; }
.settings-hint { margin: 6px 0 0; font-size: calc(12px * var(--fs)); line-height: 1.7; color: var(--muted); }
.act-ready { background: #287e73; color: #fff5d7; }
.ready-label { color: var(--gold); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; font-size: 11px; }

/* 日本麻將：資訊欄的寶牌指示牌 */
.hud-dora { align-items: center; gap: 4px; }
.hud-dora > span { margin-right: 6px; }

/* 國標麻將番種表 */
.mcr-fans { display: grid; gap: 8px; margin-top: 14px; }
.mcr-fan-row { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: baseline; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.mcr-fan-row > b { color: var(--gold); }
.mcr-fan-row > span { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: calc(13px * var(--fs, 1)); }

/* 美式麻將牌型卡：同色同花色 */
.card-a { color: #e0474c; } .card-b { color: #3fae6a; } .card-c { color: #4f86e8; }
.card-red { color: #e0474c; text-decoration: underline; } .card-green { color: #3fae6a; text-decoration: underline; } .card-soap { color: #9aa6b8; text-decoration: underline; }
.card-line { font-family: "Noto Sans Mono", ui-monospace, monospace; font-weight: 700; letter-spacing: .06em; }
.us-card h3 { margin: 16px 0 6px; }
.us-row { display: grid; grid-template-columns: 1fr 28px 40px; gap: 8px; align-items: baseline; padding: 6px 8px; border-bottom: 1px solid var(--line); border-radius: 6px; }
.us-row small { color: var(--muted); text-align: center; }
.us-row b { color: var(--gold); text-align: right; }
.us-row.is-target { background: rgba(247, 192, 74, .1); }
.card-btn { font-weight: 900; font-family: var(--serif); }
.tenpai-chip .card-line { font-size: 12px; }

/* 國旗：Windows 沒有國旗 emoji，改用只含國旗的 Twemoji 字型（僅國旗字元範圍） */
@font-face {
  font-family: "Twemoji Country Flags";
  src: url("https://cdn.jsdelivr.net/npm/country-flag-emoji-polyfill@0.1.8/dist/TwemojiCountryFlags.woff2") format("woff2");
  unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E007F;
  font-display: swap;
}
.flag { font-family: "Twemoji Country Flags", "Apple Color Emoji", "Noto Color Emoji", sans-serif; font-size: 1.15em; line-height: 1; display: inline-block; vertical-align: -0.12em; }
.badge .flag { margin-left: -2px; }
.country-select, .country-select option { font-family: "Twemoji Country Flags", var(--font); }
.room-seat-id { display: inline-flex; align-items: center; gap: 6px; }
