/* 麻將算台大師 — 象牙牌面 × 翡翠牌背 × 紅中印 */
:root {
  color-scheme: light;
  --paper: #F4EEE2;
  --paper-2: #EBE3D3;
  --tile: #FFFDF7;
  --ink: #1C1A16;
  --ink-2: #514B40;
  --ink-3: #5F5849;
  --line: #DDD3BF;
  --jade: #0E5A49;
  --jade-2: #17775F;
  --jade-soft: #DCEBE3;
  --red: #C33326;
  --red-soft: #F6DED8;
  --gold: #B0832F;
  --win: #0E6B53;
  --lose: #B8352A;
  --r-sm: 10px;
  --r: 16px;
  --r-lg: 24px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-in: cubic-bezier(.55, 0, .75, .2);
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px -12px rgba(40, 30, 10, .18);
  --gutter: clamp(16px, 4vw, 28px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --font-tile: "DFKai-SB", "BiauKai", "標楷體", "Kaiti TC", "STKaiti", "AR PL UKai TW", "Songti TC", "Noto Serif TC", serif;
  --font-serif: "Songti TC", "Noto Serif TC", "Source Han Serif TC", "PMingLiU", serif;
  --font-num: "SF Pro Rounded", "SF Pro Display", -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, #FBF7EE 0%, rgba(251, 247, 238, 0) 60%),
    var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  letter-spacing: .01em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
:focus-visible { outline: 2.5px solid var(--jade-2); outline-offset: 2px; border-radius: 6px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript { padding: 40px var(--gutter); }

/* ---------- layout ---------- */
.app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(var(--safe-t) + 8px) var(--gutter) calc(var(--safe-b) + 24px);
}
.app.is-game { max-width: 600px; padding-bottom: calc(var(--safe-b) + 108px); }
/* 首次載入不淡入（讓首屏立即繪製），之後切換畫面才有過場 */
/* 只用 opacity：transform 會讓裡面 position:fixed 的底部按鈕列跟著頁面跑 */
.ready .view { animation: view-fade .4s var(--ease) backwards; }
@keyframes view-fade { from { opacity: 0; } }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } }

.topbar {
  display: flex; align-items: center; gap: 8px;
  min-height: 56px;
  margin: 0 calc(var(--gutter) * -1) 8px;
  padding: 0 calc(var(--gutter) - 8px);
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
}
.topbar h1, .topbar .title { flex: 1; margin: 0; font-size: 17px; font-weight: 650; text-align: center; letter-spacing: .04em; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%;
  color: var(--ink); transition: background-color .2s, transform .35s var(--ease-spring);
}
.icon-btn:active { transform: scale(.88); background: var(--paper-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.ghost { visibility: hidden; }

/* ---------- home ---------- */
.hero { padding: clamp(20px, 7vh, 64px) 0 clamp(20px, 4vh, 36px); text-align: center; }
.brand-mark {
  width: 76px; height: 96px; margin: 0 auto 22px; border-radius: 14px;
  background: var(--tile); display: grid; place-items: center;
  box-shadow: 0 7px 0 var(--jade), 0 7px 0 1px rgba(0,0,0,.06), 0 22px 30px -16px rgba(14, 90, 73, .55);
  transform: rotate(-6deg);
  animation: tile-drop .9s var(--ease-spring) both;
}
.brand-mark svg { width: 44px; height: 52px; }
@keyframes tile-drop { from { opacity: 0; transform: translateY(-30px) rotate(-18deg); } }
.hero h1 {
  margin: 0; font-family: var(--font-serif); font-weight: 900;
  font-size: clamp(34px, 9vw, 46px); line-height: 1.1; letter-spacing: .12em;
}
.hero p { margin: 10px 0 0; color: var(--ink-2); font-size: 15px; letter-spacing: .08em; }

.card {
  background: var(--tile); border-radius: var(--r); box-shadow: var(--shadow);
  border: 1px solid rgba(221, 211, 191, .6);
}
.resume {
  display: block; width: 100%; text-align: left; padding: 18px 20px; margin-bottom: 14px;
  transition: transform .4s var(--ease-spring), box-shadow .3s;
}
.resume:active { transform: scale(.98); }
.resume .label { font-size: 12px; font-weight: 600; letter-spacing: .14em; color: var(--jade-2); }
.resume .meta { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.resume .names { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; }
.resume .names div { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.resume .names b { display: block; font-size: 15px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px; border-radius: 14px;
  font-weight: 650; font-size: 16px; letter-spacing: .06em;
  transition: transform .35s var(--ease-spring), background-color .2s, box-shadow .2s, opacity .2s;
  -webkit-user-select: none; user-select: none;
}
.btn:active { transform: scale(.96); }
.btn[disabled] { opacity: .38; pointer-events: none; }
.btn-primary { background: var(--jade); color: #fff; box-shadow: 0 4px 0 #0A3F33, 0 12px 20px -10px rgba(14, 90, 73, .6); }
.btn-primary:active { transform: translateY(3px) scale(.98); box-shadow: 0 1px 0 #0A3F33; }
.btn-red { background: var(--red); color: #fff; box-shadow: 0 4px 0 #8C2219; }
.btn-red:active { transform: translateY(3px) scale(.98); box-shadow: 0 1px 0 #8C2219; }
.btn-soft { background: var(--paper-2); color: var(--ink); }
.btn-line { border: 1.5px solid var(--line); background: var(--tile); color: var(--ink); }
.btn-block { width: 100%; }
.btn svg { width: 20px; height: 20px; }

.home-actions { display: grid; gap: 12px; }
.menu-list { margin-top: 24px; overflow: hidden; }
.menu-list a, .menu-list button {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px 18px;
  color: inherit; text-decoration: none; text-align: left;
  border-top: 1px solid var(--paper-2); transition: background-color .2s;
}
.menu-list > :first-child { border-top: 0; }
.menu-list a:active, .menu-list button:active { background: var(--paper); }
.menu-list .mi-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--jade-soft); color: var(--jade); }
.menu-list .mi-icon svg { width: 20px; height: 20px; }
.menu-list .mi-text { flex: 1; }
.menu-list .mi-text small { display: block; color: var(--ink-3); font-size: 12.5px; }
.menu-list .chev { color: var(--ink-3); width: 18px; height: 18px; }
.foot-note { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 28px; letter-spacing: .06em; }

/* ---------- forms ---------- */
.section-title { font-size: 13px; font-weight: 650; letter-spacing: .16em; color: var(--ink-2); margin: 26px 4px 10px; display: flex; align-items: center; justify-content: space-between; }
.section-title .link { color: var(--jade-2); letter-spacing: .04em; font-weight: 600; font-size: 13.5px; padding: 6px 4px; }
.field-group { padding: 4px 0; }
.field { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-top: 1px solid var(--paper-2); min-height: 58px; }
.field:first-child { border-top: 0; }
.field label, .field .flabel { flex: 1; font-size: 15.5px; }
.field .hint { display: block; font-size: 12.5px; color: var(--ink-3); }
.seat-badge {
  width: 34px; height: 42px; flex: none; border-radius: 7px; display: grid; place-items: center;
  background: var(--tile); font-family: var(--font-serif); font-weight: 900; font-size: 19px; color: var(--jade);
  box-shadow: inset 0 0 0 1px var(--line), 0 3px 0 var(--jade);
}
.seat-badge.is-dealer { color: var(--red); }
.text-input {
  flex: 1; min-width: 0; height: 44px; border: 0; background: transparent; font-size: 17px; font-weight: 600; outline: none;
}
.text-input::placeholder { color: var(--ink-3); font-weight: 400; }
.stepper { display: inline-flex; align-items: center; gap: 2px; background: var(--paper); border-radius: 12px; padding: 3px; }
.stepper button { width: 38px; height: 38px; border-radius: 9px; font-size: 20px; font-weight: 500; transition: transform .3s var(--ease-spring), background-color .2s; }
.stepper button:active { transform: scale(.85); background: var(--paper-2); }
.stepper input, .stepper output {
  width: 64px; text-align: center; border: 0; background: transparent; font: 650 17px var(--font-num); font-variant-numeric: tabular-nums; outline: none;
}
.stepper.sm input, .stepper.sm output { width: 34px; }
.stepper.sm button { width: 34px; height: 34px; }
.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background-color .25s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.2); transition: transform .4s var(--ease-spring); }
.switch input:checked + span { background: var(--jade-2); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2.5px solid var(--jade-2); outline-offset: 2px; }
.name-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 2px 0; }
.name-chip { padding: 7px 14px; border-radius: 99px; background: var(--tile); border: 1px solid var(--line); font-size: 14px; transition: transform .3s var(--ease-spring), opacity .2s; }
.name-chip:active { transform: scale(.92); }
.name-chip[disabled] { opacity: .35; }
.sticky-cta { position: sticky; bottom: 0; padding: 16px 0 calc(var(--safe-b) + 8px); margin-top: 18px; background: linear-gradient(to top, var(--paper) 70%, transparent); }

/* ---------- game table ---------- */
.game-head { text-align: center; }
.game-head .round-name { font-family: var(--font-serif); font-weight: 900; font-size: 19px; letter-spacing: .14em; }
.game-head .round-sub { font-size: 12px; color: var(--ink-3); letter-spacing: .1em; font-weight: 500; }

.table {
  display: grid;
  grid-template-columns: 1fr minmax(84px, 112px) 1fr;
  grid-template-areas: "s2 s2 s2" "s3 core s1" "s0 s0 s0";
  gap: 12px 10px;
  align-items: center;
  margin: 8px 0 4px;
}
.seat {
  position: relative; width: 100%;
  padding: 14px 10px 12px; border-radius: var(--r);
  background: var(--tile); text-align: center;
  box-shadow: inset 0 0 0 1px rgba(221, 211, 191, .8), 0 6px 0 var(--jade), 0 16px 22px -14px rgba(14, 90, 73, .55);
  transition: transform .45s var(--ease-spring), box-shadow .25s;
}
.seat.is-dealer { box-shadow: inset 0 0 0 2.5px var(--red), 0 6px 0 var(--jade), 0 16px 22px -14px rgba(14, 90, 73, .55); }
.seat:active { transform: translateY(4px); box-shadow: inset 0 0 0 1px rgba(221, 211, 191, .8), 0 2px 0 var(--jade), 0 6px 10px -8px rgba(14, 90, 73, .5); }
.seat[data-pos="0"] { grid-area: s0; }
.seat[data-pos="1"] { grid-area: s1; }
.seat[data-pos="2"] { grid-area: s2; }
.seat[data-pos="3"] { grid-area: s3; }
.seat[data-pos="0"], .seat[data-pos="2"] { width: clamp(132px, 42%, 210px); justify-self: center; }
.seat .wind {
  position: absolute; top: 8px; left: 9px;
  font-family: var(--font-serif); font-weight: 900; font-size: 14px; color: var(--jade-2); line-height: 1;
}
.seat .name, .seat .total, .seat .stats-mini { display: block; }
.seat .name { font-weight: 700; font-size: 16px; line-height: 1.3; padding: 0 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .total { font-size: clamp(20px, 6vw, 26px); font-weight: 700; line-height: 1.2; margin-top: 4px; transition: color .3s; }
.seat .stats-mini { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; letter-spacing: .04em; }
.pos { color: var(--win); }
.neg { color: var(--lose); }
.zero { color: var(--ink-3); }
.seal {
  position: absolute; top: -9px; right: 6px;   /* 別凸出卡片：右邊那家貼著畫面邊，凸出去會被 .game-main 的 clip 切掉 */
  min-width: 30px; height: 30px; padding: 0 6px; border-radius: 8px;
  display: grid; place-items: center;
  background: var(--red); color: #fff;
  font: 900 15px/1 var(--font-serif);
  box-shadow: 0 3px 8px -2px rgba(195, 51, 38, .6);
  transform: rotate(8deg);
  animation: seal-in .55s var(--ease-spring) both;
}
.seal small { font: 700 10px/1 var(--font); display: block; margin-top: 1px; }
@keyframes seal-in { from { opacity: 0; transform: rotate(8deg) scale(1.8); } }
.delta-pop {
  position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
  font: 800 16px var(--font-num); pointer-events: none; white-space: nowrap;
  animation: delta-pop 1.6s var(--ease) forwards;
}
@keyframes delta-pop {
  0% { opacity: 0; transform: translate(-50%, 14px) scale(.8); }
  18% { opacity: 1; transform: translate(-50%, 0) scale(1.05); }
  70% { opacity: 1; transform: translate(-50%, -6px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -18px); }
}

.core {
  grid-area: core; aspect-ratio: 1; width: 100%; border-radius: 50%;
  position: relative; display: grid; place-items: center; text-align: center;
  background: radial-gradient(circle at 35% 30%, var(--jade-2), var(--jade) 70%);
  color: #F2EBDA;
  box-shadow: inset 0 2px 0 rgba(255,255,255,.12), inset 0 -6px 14px rgba(0,0,0,.25), 0 10px 22px -10px rgba(14, 90, 73, .7);
}
.core .c-wind { font: 900 clamp(22px, 7vw, 30px)/1 var(--font-serif); letter-spacing: .04em; }
.core .c-hand { font-size: 11px; letter-spacing: .2em; opacity: .8; margin-top: 4px; }
.core .pointer {
  position: absolute; inset: 0; pointer-events: none;
  transition: transform .9s var(--ease-spring);
}
.core .pointer::before {
  content: ""; position: absolute; left: 50%; bottom: -3px; transform: translateX(-50%);
  border: 8px solid transparent; border-top: 10px solid var(--red); border-bottom: 0;
}

.action-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 12px var(--gutter) calc(var(--safe-b) + 12px);
  background: linear-gradient(to top, var(--paper) 72%, rgba(244, 238, 226, 0));
}
.action-bar .inner { max-width: calc(600px - 2 * var(--gutter)); margin: 0 auto; display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; }
.action-bar .btn { padding: 0 4px; letter-spacing: .02em; white-space: nowrap; }
.sq { width: 48px; padding: 0 !important; }

.log { margin-top: 18px; }
.log-item { display: flex; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--paper-2); align-items: flex-start; }
.log-item:first-child { border-top: 0; }
.log-no { font: 700 12px/1 var(--font-num); color: var(--ink-3); width: 26px; padding-top: 4px; flex: none; }
.log-main { flex: 1; min-width: 0; }
.log-title { font-weight: 650; font-size: 15px; }
.log-title .tai { color: var(--red); }
.log-sub { font-size: 12.5px; color: var(--ink-3); margin-top: 1px; }
.log-cols { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 4px; text-align: center; }
.log-cols > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.log-d { margin-top: 7px; font: 700 15px/1.25 var(--font-num); }
.log-d .zero { color: var(--ink-3); opacity: .5; font-weight: 600; }
.log-run { margin-top: 2px; font: 600 12px/1.3 var(--font-num); color: var(--ink-3); }
.log-head { display: flex; gap: 12px; padding: 9px 16px 8px; border-top: 1px solid var(--paper-2); background: var(--tile); font-size: 12px; font-weight: 700; color: var(--ink-2); }
.log-head:first-child { border-top: 0; border-radius: var(--r) var(--r) 0 0; }
.log-head .log-cols { flex: 1; min-width: 0; }
.sheet .log-head, .end-log .log-head { position: sticky; top: 0; z-index: 1; }   /* 長列表往下滑，名字一直在上面 */
.end-log .log-head { top: 56px; }   /* 結算頁上面還有固定的標題列 */
.empty { text-align: center; padding: 28px 16px; color: var(--ink-3); font-size: 14px; }

/* ---------- sheet ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(28, 26, 22, .38); opacity: 0; transition: opacity .35s var(--ease); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 600px; margin: 0 auto; max-height: 92dvh;
  display: flex; flex-direction: column;
  background: var(--tile); border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: 0 -10px 40px -10px rgba(0,0,0,.25);
  transform: translateY(105%); transition: transform .5s var(--ease);
}
.sheet-root.open .backdrop { opacity: 1; }
.sheet-root.open .sheet { transform: none; }
.sheet-root.closing .sheet { transition: transform .3s var(--ease-in); }
.sheet-handle { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 9px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; padding: 6px 10px 6px 20px; flex: none; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 18px; font-weight: 700; letter-spacing: .04em; }
.sheet-body { overflow-y: auto; padding: 4px 20px 16px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet-foot { flex: none; padding: 12px 20px calc(var(--safe-b) + 14px); border-top: 1px solid var(--paper-2); background: var(--tile); }

.step-label { font-size: 12.5px; font-weight: 650; letter-spacing: .16em; color: var(--ink-3); margin: 16px 0 8px; }
.pick-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pick {
  position: relative; min-height: 64px; padding: 8px 4px; border-radius: 12px;
  background: var(--paper); text-align: center; font-weight: 650; font-size: 15px;
  transition: transform .35s var(--ease-spring), background-color .2s, color .2s, box-shadow .2s;
  overflow: hidden; text-overflow: ellipsis;
}
.pick small { display: block; font-size: 11px; font-weight: 500; color: var(--ink-3); transition: color .2s; }
.pick:active { transform: scale(.94); }
.pick[aria-pressed="true"] { background: var(--jade); color: #fff; box-shadow: 0 3px 0 #0A3F33; }
.pick[aria-pressed="true"] small { color: rgba(255,255,255,.75); }
.pick.red[aria-pressed="true"] { background: var(--red); box-shadow: 0 3px 0 #8C2219; }
.pick[disabled] { opacity: .3; pointer-events: none; }
.how-grid { display: grid; grid-template-columns: 1fr 3fr; gap: 8px; }
.how-grid .pick-grid { grid-template-columns: repeat(3, 1fr); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 13px; border-radius: 11px;
  background: var(--paper); font-size: 15px; font-weight: 600;
  transition: transform .35s var(--ease-spring), background-color .2s, color .2s;
}
.chip i { font-style: normal; font: 700 12px var(--font-num); color: var(--ink-3); transition: color .2s; }
.chip:active { transform: scale(.92); }
.chip[aria-pressed="true"] { background: var(--jade); color: #fff; }
.chip[aria-pressed="true"] i { color: rgba(255,255,255,.75); }
.chip.auto { background: var(--jade-soft); color: var(--jade); pointer-events: none; }
.chip.auto i { color: var(--jade-2); }
.chip.big[aria-pressed="true"] { background: var(--red); }
.flower-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.flower-row .field { border: 0; background: var(--paper); border-radius: 12px; padding: 6px 6px 6px 14px; min-height: 52px; }
.flower-row .stepper { background: var(--tile); }

.preview {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; align-items: center;
  margin-bottom: 12px;
}
.preview .big-tai { grid-row: span 2; font: 800 40px/1 var(--font-num); color: var(--red); }
.preview .big-tai small { font: 700 15px var(--font); margin-left: 2px; }
.preview .pay-list { font-size: 13px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 2px 12px; }
.preview .pay-list b { color: var(--lose); font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.preview .gain { font-size: 14px; font-weight: 650; }
.preview .gain b { color: var(--win); font-family: var(--font-num); }

/* ---------- end / stats ---------- */
.rank-list { padding: 4px 0; }
.rank { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-top: 1px solid var(--paper-2); }
.rank:first-child { border-top: 0; }
.rank-no { width: 30px; height: 38px; border-radius: 6px; flex: none; display: grid; place-items: center; font: 900 16px var(--font-serif); background: var(--paper); color: var(--ink-2); box-shadow: 0 3px 0 var(--line); }
.rank:first-child .rank-no { background: var(--red); color: #fff; box-shadow: 0 3px 0 #8C2219; }
.rank-name { flex: 1; font-weight: 700; font-size: 16px; }
.rank-name small { display: block; font-weight: 400; font-size: 12.5px; color: var(--ink-3); }
.rank-amt { font: 800 20px var(--font-num); font-variant-numeric: tabular-nums; }
.transfer { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--paper-2); font-size: 15px; }
.transfer:first-child { border-top: 0; }
.transfer .arrow { color: var(--ink-3); }
.transfer .amt { margin-left: auto; font: 700 16px var(--font-num); }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--paper-2); border-radius: 12px; overflow: hidden; margin-top: 10px; }
.stat-grid div { background: var(--tile); padding: 10px 8px; text-align: center; }
.stat-grid b { display: block; font: 750 18px var(--font-num); font-variant-numeric: tabular-nums; }
.stat-grid span { font-size: 11.5px; color: var(--ink-3); letter-spacing: .06em; }
.player-stat { padding: 16px 18px; margin-bottom: 12px; }
.player-stat .ps-head { display: flex; align-items: baseline; gap: 10px; }
.player-stat .ps-head h3 { margin: 0; font-size: 18px; flex: 1; }
.player-stat .ps-head .num { font-weight: 800; font-size: 20px; }

.hist-item { display: block; width: 100%; text-align: left; padding: 14px 18px; border-top: 1px solid var(--paper-2); transition: background-color .2s; }
.hist-item:first-child { border-top: 0; }
.hist-item:active { background: var(--paper); }
.hist-item .h-date { font-size: 12.5px; color: var(--ink-3); }
.hist-item .h-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; font-size: 13px; }
.hist-item .h-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-item .h-row b { display: block; font: 700 14px var(--font-num); }

.rule-row { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-top: 1px solid var(--paper-2); min-height: 54px; }
.rule-row:first-child { border-top: 0; }
.rule-row span { flex: 1; }
.rule-row small { color: var(--ink-3); font-size: 12px; margin-left: 6px; }
.danger-link { color: var(--lose) !important; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 100px); z-index: 40;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: #F4EEE2; padding: 11px 12px 11px 18px; border-radius: 14px;
  font-size: 14.5px; box-shadow: 0 12px 30px -10px rgba(0,0,0,.4);
  transition: opacity .3s var(--ease), transform .45s var(--ease-spring);
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { color: #8FD3BB; font-weight: 700; padding: 4px 8px; }
.toast:not(:has(button)) { padding-right: 18px; }

/* ---------- landscape phones & wide screens ---------- */
@media (orientation: landscape) and (max-height: 540px), (min-width: 900px) {
  .app.is-game { max-width: 1080px; padding-bottom: calc(var(--safe-b) + 16px); }
  .game-layout {
    display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(280px, 1fr); gap: 0 clamp(16px, 3vw, 36px);
    align-items: start;
  }
  .game-side { position: sticky; top: 64px; display: flex; flex-direction: column; max-height: calc(100dvh - 80px); }
  .game-side .log { flex: 1; overflow-y: auto; margin-top: 0; }
  .action-bar { position: static; background: none; padding: 12px 0 0; order: 2; }
  .action-bar .inner { max-width: none; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .topbar { min-height: 46px; margin-bottom: 0; }
  .table { grid-template-columns: 1fr minmax(64px, 84px) 1fr; gap: 8px; margin: 0; }
  .seat { padding: 10px 8px 8px; box-shadow: inset 0 0 0 1px rgba(221, 211, 191, .8), 0 4px 0 var(--jade); }
  .seat .total { font-size: 19px; }
  .seat .stats-mini { display: none; }
  .core .c-wind { font-size: 20px; }
  .hero { padding: 16px 0; }
  .brand-mark { display: none; }
  .sheet { max-width: 720px; max-height: 96dvh; }
  .sheet-body { padding-top: 0; }
  .step-label { margin: 10px 0 6px; }
  .pick { min-height: 48px; }
  .game-side { top: 52px; max-height: calc(100dvh - 60px); }
  .toast { bottom: calc(var(--safe-b) + 20px); }
}
@media (min-width: 900px) {
  .app { max-width: 720px; }
  .sheet { max-width: 640px; bottom: 50%; border-radius: var(--r-lg); transform: translateY(calc(50% + 60px)); opacity: 0; transition: transform .5s var(--ease), opacity .3s; max-height: 86dvh; }
  .sheet-root.open .sheet { transform: translateY(50%); opacity: 1; }
  .sheet-handle { display: none; }
  .table { grid-template-columns: 1fr 130px 1fr; }
}
@media (max-width: 360px) {
  .table { grid-template-columns: 1fr 76px 1fr; gap: 10px 6px; }
  .pick-grid { gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ---------- v2：規則表單、多響分頁、換位置 ---------- */
.dep[hidden] { display: none; }
.dep > .field { border-top: 1px solid var(--paper-2); padding-left: 28px; }
.seg { display: inline-flex; flex: none; padding: 3px; gap: 2px; border-radius: 12px; background: var(--paper); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span, .seg button {
  display: block; min-width: 64px; padding: 8px 12px; border-radius: 9px; text-align: center;
  font: 650 15px var(--font-num); color: var(--ink-2);
  transition: background-color .25s, color .25s, box-shadow .25s, transform .35s var(--ease-spring);
}
.seg input:checked + span, .seg button[aria-selected="true"] { background: var(--tile); color: var(--jade); box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 4px 10px -6px rgba(14, 90, 73, .5); }
.seg input:focus-visible + span { outline: 2.5px solid var(--jade-2); outline-offset: 1px; }
.seg button:active, .seg label:active span { transform: scale(.95); }
.seg-wide { display: flex; }
.seg-wide button { flex: 1; font-family: var(--font); }
.chip-note { align-self: center; font-size: 12.5px; color: var(--ink-3); margin-left: 4px; font-weight: 500; }
.seat-swap {
  position: relative; display: grid; gap: 10px;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-areas: ". p2 ." "p3 core p1" ". p0 .";
  align-items: center;
}
.seat-swap .pick { min-height: 70px; }
.seat-swap .pick.is-dealer:not([aria-pressed="true"]) { box-shadow: inset 0 0 0 2px var(--red); }
.seat-swap-core { grid-area: core; justify-self: center; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--jade-soft); color: var(--jade); }
.seat-swap-core svg { width: 22px; height: 22px; }
.seat-swap .pick[aria-pressed="true"] { animation: wiggle .5s var(--ease-spring); }
@keyframes wiggle { 30% { transform: scale(1.06) rotate(-2deg); } 60% { transform: scale(1.02) rotate(1.5deg); } }

/* ---------- v3：直接輸入台數、詐胡 ---------- */
.quick-tai { display: grid; grid-template-columns: 60px 1fr 60px; align-items: center; gap: 10px; padding: 6px; border-radius: 16px; background: var(--paper); }
.quick-tai button { height: 56px; border-radius: 12px; background: var(--tile); font-size: 26px; box-shadow: 0 2px 0 var(--line); transition: transform .3s var(--ease-spring); }
.quick-tai button:active { transform: scale(.9); }
.quick-tai output { text-align: center; font: 800 44px/1 var(--font-num); color: var(--red); }
.quick-tai output small { font: 700 16px var(--font); margin-left: 3px; color: var(--ink-2); }
.quick-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.quick-grid .pick { min-height: 44px; padding: 0; font: 700 16px var(--font-num); }

/* ---------- v4：拖移換位 ---------- */
.seat-swap .pick { touch-action: none; -webkit-user-select: none; user-select: none; cursor: grab; }
.seat-swap .pick.dragging { position: relative; z-index: 3; cursor: grabbing; transition: none; box-shadow: 0 18px 32px -12px rgba(28, 26, 22, .45); }
.seat-swap .pick.drop-target { background: var(--jade-soft); box-shadow: inset 0 0 0 2.5px var(--jade-2); transform: scale(.96); }
.seat-swap .pick.just-swapped { animation: swap-in .5s var(--ease-spring); }
.seat-swap.tap .pick { touch-action: manipulation; cursor: pointer; }   /* 開新局只用點的，頁面要能捲 */
#newSeats .pick:not([aria-pressed="true"]) { background: var(--tile); box-shadow: var(--shadow); border: 1px solid rgba(221, 211, 191, .6); }
#newSeats .seat-swap .pick.is-dealer:not([aria-pressed="true"]) { box-shadow: inset 0 0 0 2px var(--red), var(--shadow); }
@keyframes swap-in { from { transform: scale(.8); opacity: .4; } }

/* ---------- v5：新手友善 ---------- */
.lead { margin: -2px 4px 10px; font-size: 13.5px; color: var(--ink-2); line-height: 1.55; }
.field .flabel .hint, .field label .hint { font-size: 12.5px; }
.more-rules { margin-top: 26px; }
.more-rules > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-radius: var(--r); background: var(--tile); box-shadow: var(--shadow);
  font-weight: 700; font-size: 16px; transition: transform .35s var(--ease-spring);
}
.more-rules > summary::-webkit-details-marker { display: none; }
.more-rules > summary:active { transform: scale(.98); }
.more-rules > summary span { flex: 1; }
.more-rules > summary small { display: block; font-weight: 400; font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.more-rules > summary .chev { width: 20px; height: 20px; color: var(--ink-3); transform: rotate(90deg); transition: transform .35s var(--ease); }
.more-rules[open] > summary .chev { transform: rotate(-90deg); }
.more-rules[open] > :not(summary) { animation: view-in .45s var(--ease) both; }

.coach-tip {
  margin: 4px auto 10px; width: fit-content; padding: 8px 16px; border-radius: 99px;
  background: var(--ink); color: #F4EEE2; font-size: 14.5px; letter-spacing: .04em;
  animation: tip-bob 2.4s var(--ease) infinite;
}
.coach-tip b { color: #FFD99A; font-weight: 700; }
@keyframes tip-bob { 50% { transform: translateY(-3px); } }
.table.coach .seat::after {
  content: ""; position: absolute; inset: -4px; border-radius: calc(var(--r) + 4px); pointer-events: none;
  border: 2px solid var(--jade-2); opacity: 0; animation: seat-ping 2.4s var(--ease) infinite;
}
.table.coach .seat[data-pos="1"]::after { animation-delay: .6s; }
.table.coach .seat[data-pos="2"]::after { animation-delay: 1.2s; }
.table.coach .seat[data-pos="3"]::after { animation-delay: 1.8s; }
@keyframes seat-ping { 0% { opacity: .9; transform: scale(.97); } 60%, 100% { opacity: 0; transform: scale(1.06); } }

.sq { flex-direction: column; gap: 1px; }
.sq svg { width: 19px !important; height: 19px !important; }
.sq small { font-size: 11px; font-weight: 650; letter-spacing: .04em; line-height: 1; }

.step-q { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; margin: 20px 0 10px; font-size: 17px; font-weight: 750; letter-spacing: .02em; scroll-margin-top: 8px; }
.step-q:first-child { margin-top: 8px; }
.step-q i { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--jade); color: #fff; font: 800 14px var(--font-num); font-style: normal; flex: none; }
.step-q small { flex-basis: 100%; padding-left: 36px; margin-top: -2px; font-size: 13px; font-weight: 400; color: var(--ink-3); }

.help-card { display: flex; align-items: center; gap: 8px; padding: 16px 18px; margin-bottom: 14px; text-decoration: none; color: var(--ink); background: #FFF6DE; border-color: #EBD9A6; font-size: 15px; }
.help-card b { color: var(--red); margin-right: 4px; }
.help-card .chev { margin-left: auto; color: var(--ink-3); width: 18px; height: 18px; }
.howto { padding: 20px 18px 8px; }
.howto h2 { margin: 0 0 14px; font-family: var(--font-serif); font-weight: 900; font-size: 22px; letter-spacing: .08em; }
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 14px; padding: 0 0 16px; }
.steps li i { width: 34px; height: 42px; flex: none; border-radius: 8px; display: grid; place-items: center; background: var(--tile); font: 900 18px var(--font-serif); font-style: normal; color: var(--red); box-shadow: inset 0 0 0 1px var(--line), 0 4px 0 var(--jade); }
.steps li b { font-size: 17px; }
.steps li p { margin: 3px 0 0; color: var(--ink-2); font-size: 16px; line-height: 1.65; }
.faq .qa { border-top: 1px solid var(--paper-2); }
.faq .qa:first-child { border-top: 0; }
.qa summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 16px 18px; font-weight: 650; font-size: 16.5px; }
.qa summary::-webkit-details-marker { display: none; }
.qa summary .chev { margin-left: auto; width: 18px; height: 18px; color: var(--ink-3); transform: rotate(90deg); transition: transform .3s var(--ease); flex: none; }
.qa[open] summary .chev { transform: rotate(-90deg); }
.qa p { margin: -4px 18px 16px; color: var(--ink-2); font-size: 16px; line-height: 1.7; }

/* ===== v10：點紀錄修改 ===== */
.log-item.editable { cursor: pointer; transition: background .2s var(--ease); -webkit-tap-highlight-color: transparent; }
.log-item.editable:hover, .log-item.editable:active { background: var(--paper-2); }
.log-item.editable:focus-visible { outline: 2px solid var(--ink-2); outline-offset: -2px; }
.log-edited { color: var(--red); font-weight: 600; }
.log-hint { font-size: 12px; font-weight: 500; color: var(--ink-3); margin-left: 8px; letter-spacing: 0; }
.edit-what { font-weight: 700; font-size: 15px; margin: 0 2px 4px; }
.edit-sum { font: 600 13.5px/1.5 var(--font-num); margin: 10px 2px 0; color: var(--win); }
.edit-sum.warn { color: var(--red); }
.edit-note { font-size: 12.5px; color: var(--ink-3); margin: 4px 2px 0; }

/* ===== v11：中途換人 ===== */
.left-tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 6px; background: var(--paper-2); color: var(--ink-2); font-size: 11px; font-weight: 600; vertical-align: 2px; letter-spacing: .04em; }

/* ===== v12：我的預設 ===== */
.pref-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

/* ===== v13：下面還有內容的提示 ===== */
.sheet-body.more-below::after {
  content: '往下滑還有 ▾'; position: sticky; bottom: 0; display: block; height: 44px; margin: -44px -20px 0;
  padding-top: 18px; text-align: center; font-size: 12.5px; font-weight: 600; color: var(--ink-2); letter-spacing: .08em;
  background: linear-gradient(to bottom, rgba(255, 253, 247, 0), var(--tile) 60%); pointer-events: none;
  animation: more-in .3s var(--ease) both;
}
@keyframes more-in { from { opacity: 0; } }
.multi-box { margin-top: 18px; padding: 2px 12px 12px; border-radius: var(--r); background: var(--paper); border: 1px dashed var(--paper-2); }

/* ===== v14：本將／累計 ===== */
.score-mode { display: flex; justify-content: center; width: 100%; margin: 0 0 10px; }
.score-mode .seg button { padding: 0 18px; }
.score-mode .seg small { margin-left: 4px; font-size: 11px; font-weight: 500; opacity: .7; }
.seat .alt-total { font-size: 11px; color: var(--ink-3); margin-top: 1px; white-space: nowrap; letter-spacing: 0; }
.core .c-east { margin-top: 5px; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .16); font-size: 11px; letter-spacing: .04em; white-space: nowrap; }
.core .c-east b { font-weight: 700; }

/* ===== v15：旋轉視角 ===== */
.score-mode { position: relative; }
.rot-btn { position: absolute; right: 0; top: 50%; transform: translateY(-50%); display: inline-flex; align-items: center; gap: 4px; height: 36px; padding: 0 10px; border: 0; border-radius: 10px; background: var(--paper); color: var(--ink-2); font: 600 12.5px/1 inherit; cursor: pointer; transition: transform .2s var(--ease), background .2s; }
.rot-btn svg { width: 16px; height: 16px; }
.rot-btn:active { transform: translateY(-50%) scale(.92); background: var(--paper-2); }
@media (max-width: 380px) { .rot-btn span { display: none; } }
.game-main { overflow-x: clip; }   /* 旋轉動畫時桌子轉斜，別撐出橫向捲軸 */


/* ===== v17：紀錄只顯示最近幾筆 ===== */
.log-more { display: flex; align-items: center; justify-content: center; gap: 4px; width: 100%; min-height: 50px; border: 0; border-top: 1px solid var(--paper-2); background: none; color: var(--win); font: 600 14px/1 inherit; letter-spacing: .04em; cursor: pointer; }
.log-more svg { width: 16px; height: 16px; }
.log-more:active { background: var(--paper-2); }


/* ===== v18：房間 ===== */
.menu-btn { position: relative; }
.menu-btn .dot { position: absolute; top: 6px; right: 6px; width: 11px; height: 11px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 2px var(--bg, #fff); animation: dot-pulse 1.6s cubic-bezier(.22,1,.36,1) infinite; }
@keyframes dot-pulse { 50% { transform: scale(1.25); } }
.view-tip .link { font: inherit; font-weight: 700; color: var(--win); background: none; border: 0; padding: 4px 2px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.room-code { text-align: center; font: 800 44px/1 var(--font-serif); letter-spacing: .14em; color: var(--ink); padding: 18px 0 6px; font-variant-numeric: tabular-nums; }
.member-list { padding: 4px 14px; }
.member { display: flex; align-items: center; gap: 8px; min-height: 54px; border-bottom: 1px solid var(--line); }
.member:last-child { border-bottom: 0; }
.m-name { flex: 1; min-width: 0; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-name small { font-weight: 400; color: var(--ink-3); margin-left: 2px; }
.m-role { flex: none; font-size: 12px; font-weight: 650; padding: 4px 8px; border-radius: 99px; background: var(--tile); color: var(--ink-3); }
.m-role.r-host { background: var(--gold); color: #fff; }
.m-role.r-editor { background: var(--win); color: #fff; }
.m-ask { flex: none; font-size: 12px; font-weight: 700; color: var(--red); }
.m-acts { flex: none; display: flex; align-items: center; gap: 4px; }
.m-acts .btn { height: 36px; min-height: 36px; padding: 0 12px; font-size: 13px; }
.m-kick { width: 40px; height: 40px; border: 0; border-radius: 10px; background: none; color: var(--ink-3); display: grid; place-items: center; cursor: pointer; }
.m-kick svg { width: 16px; height: 16px; }
.code-input { display: block; width: 100%; height: 64px; border: 1.5px solid var(--line); border-radius: 14px; background: var(--tile); text-align: center; font: 800 32px/1 var(--font-serif); letter-spacing: .22em; text-indent: .22em; color: var(--ink); font-variant-numeric: tabular-nums; }
.code-input:focus { outline: none; border-color: var(--win); box-shadow: 0 0 0 3px color-mix(in srgb, var(--win) 22%, transparent); }


/* ===== v19：前面各將、房號 ===== */
.jiang-list { padding: 2px 14px; margin-bottom: 18px; }
.jiang-row { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--paper-2); }
.jiang-row:last-child { border-bottom: 0; }
.jiang-row > b { font: 800 14px/1 var(--font-serif); color: var(--ink-2); letter-spacing: .04em; }
.jr-cells { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.jr-cells span { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.jr-cells small { font-size: 11.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.jr-cells em { font-style: normal; font-size: 13.5px; font-weight: 700; }
.jr-east { grid-column: 2; margin-top: 4px; font-size: 11.5px; color: var(--ink-3); }
.room-tag { position: absolute; left: 0; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 4px 2px; border: 0; background: none; color: var(--ink-2); cursor: pointer; text-align: left; transition: transform .2s var(--ease); }
.room-tag small { font-size: 10.5px; color: var(--ink-3); letter-spacing: .08em; }
.room-tag b { font-size: 13px; font-weight: 800; letter-spacing: .02em; color: var(--win); }
.room-tag:active { transform: translateY(-50%) scale(.94); }
/* 頂部小字只佔一行（東錢看牌桌中間的「東錢」），太長就省略 */
.game-head { min-width: 0; }
.game-head .round-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 360px) { .game-head .round-sub { letter-spacing: .01em; } }
.room-tag.pending b { color: var(--ink-3); font-weight: 600; letter-spacing: 0; }


/* ===== v20：雲端備份 ===== */
.cloud-card { padding: 16px; }
.cloud-card > p:first-child { margin: 0 0 12px; font-size: 13.5px; color: var(--ink-2); line-height: 1.6; }
.backup-code { text-align: center; font: 800 21px/1 var(--font-serif); letter-spacing: .08em; color: var(--ink); padding: 14px 0; border-radius: 12px; background: var(--paper); margin-bottom: 12px; font-variant-numeric: tabular-nums; word-break: break-all; }
.backup-input { font-size: 20px; letter-spacing: .06em; text-indent: 0; text-transform: uppercase; }


/* ===== v21：聽牌計算機 ===== */
.mj { --w: 32px; position: relative; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; width: var(--w); height: calc(var(--w) * 1.36); border-radius: 6px; background: linear-gradient(180deg, #FFFDF7, var(--tile)); box-shadow: inset 0 0 0 1px var(--line), 0 3px 0 var(--jade); line-height: 1; user-select: none; flex: none; }
.mj b { font: 900 calc(var(--w) * .52)/1 var(--font-tile); color: #1E2F4F; }
.mj i { font: 900 calc(var(--w) * .4)/1 var(--font-tile); font-style: normal; margin-top: 1px; }
.mj-萬 i { color: var(--red); }
.mj .mj-face { width: 86%; height: 86%; display: block; }
.mj-筒 i { color: #2F5E8C; }
.mj-條 i { color: var(--win); }
/* 字牌照實體牌：粗楷體、風牌深藍、中紅、發綠，白板是藍框 */
.mj-z b { font-size: calc(var(--w) * .76); -webkit-text-stroke: calc(var(--w) * .012) currentColor; }
.mj-中 b { color: #C8261B; }
.mj-發 b { color: #12704F; }
.mj-白 .mj-face { width: 78%; height: 78%; }
.calc-hand { display: flex; flex-wrap: wrap; gap: 8px 5px; padding: 14px 12px 16px; min-height: 76px; align-items: center; }
.calc-hand .mj { --w: 30px; cursor: pointer; transition: transform .25s cubic-bezier(.22,1,.36,1); }
.calc-hand .mj[data-fresh] { animation: mj-in .32s cubic-bezier(.22,1,.36,1); }
.calc-hand .mj:active { transform: translateY(2px) scale(.94); }
@keyframes mj-in { from { opacity: 0; transform: translateY(-6px) scale(.9); } }
.calc-empty { color: var(--ink-3); font-size: 13.5px; width: 100%; text-align: center; }
.calc-melds { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 4px 0; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.calc-melds small { display: block; font-size: 11.5px; font-weight: 400; color: var(--ink-3); margin-top: 2px; }
.calc-hint { min-height: 1.6em; margin: 14px 4px 0; font-size: 13.5px; color: var(--ink-3); line-height: 1.6; }
.calc-hint b { color: var(--ink); }
.calc-out { margin-top: 14px; padding: 14px; border-radius: 16px; background: var(--paper); }
.calc-out > b, .co-head b { display: block; font: 800 17px/1.2 var(--font-serif); color: var(--win); letter-spacing: .04em; }
.calc-out > small, .co-head small { display: block; margin-top: 4px; font-size: 12.5px; color: var(--ink-3); }
.calc-out.none > b { color: var(--ink-2); }
.calc-out.win { background: var(--win); text-align: center; }
.calc-out.win > b { color: #fff; font-size: 22px; }
.calc-out.win > small { color: rgba(255,255,255,.8); }
.co-tiles { display: flex; flex-wrap: wrap; gap: 10px 8px; margin-top: 10px; }
.co-wait { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; }
.co-wait small { font-size: 11px; font-weight: 700; color: var(--ink-2); }
.co-wait.dead { opacity: .4; }
.co-row { display: grid; grid-template-columns: auto auto 1fr auto; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.co-row:first-of-type { margin-top: 8px; }
.co-row .co-tiles { margin-top: 0; gap: 6px; }
.co-row .mj { --w: 26px; }
.co-drop { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; color: var(--red); }
.co-arrow { font-size: 12px; color: var(--ink-3); }
.co-left { font-size: 12px; font-weight: 700; color: var(--win); white-space: nowrap; }
.calc-tip { font-size: 11.5px; color: var(--ink-3); }
.calc-pal { padding: 10px 8px; display: grid; gap: 8px; }
.pal-row { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 4px; }
.pal-btn { position: relative; display: grid; place-items: center; padding: 2px 0 4px; border: 0; background: none; cursor: pointer; border-radius: 8px; transition: transform .2s cubic-bezier(.22,1,.36,1), opacity .2s; }
.pal-btn .mj { --w: min(34px, 8.6vw); }
.pal-btn:active:not(:disabled) { transform: scale(.9); }
.pal-btn:disabled { opacity: .35; cursor: default; }
.pal-btn em { position: absolute; top: -8px; right: -5px; z-index: 1; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 99px; background: var(--ink); color: #fff; font: 700 11px/17px var(--font); font-style: normal; text-align: center; box-shadow: 0 0 0 2px var(--tile); }
@media (min-width: 560px) { .pal-btn .mj { --w: 40px; } .calc-hand .mj { --w: 34px; } }

/* ===== v22：拍照辨識手牌 ===== */
.calc-scan { display: flex; align-items: center; gap: 12px; width: 100%; margin: 4px 0 6px; padding: 14px 16px; border: 1.5px dashed var(--jade); border-radius: 18px; background: var(--paper); color: var(--ink); text-align: left; font: inherit; cursor: pointer; transition: transform .25s cubic-bezier(.22,1,.36,1), background .25s cubic-bezier(.22,1,.36,1); }
.calc-scan:active:not(:disabled) { transform: scale(.98); }
.calc-scan:disabled { cursor: progress; }
.cs-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: var(--jade); color: #fff; flex: none; }
.cs-text { font-size: 15px; font-weight: 700; }
.cs-text small { display: block; margin-top: 3px; font-size: 12px; font-weight: 400; color: var(--ink-3); }
.cs-spin { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: cs-spin .8s linear infinite; }
@keyframes cs-spin { to { transform: rotate(360deg); } }
.calc-check { margin: 8px 4px 0; padding: 8px 12px; border-radius: 12px; background: color-mix(in srgb, var(--jade) 12%, transparent); font-size: 12.5px; line-height: 1.5; color: var(--ink-2); }
@media (prefers-reduced-motion: reduce) { .cs-spin { animation-duration: 2s; } }
/* 還沒放牌：拍照辨識放大成主要按鈕 */
.calc-scan.hero { flex-direction: column; justify-content: center; gap: 14px; margin-bottom: 14px; padding: 28px 18px 24px; text-align: center; border: 0; background: var(--jade); color: #fff; box-shadow: 0 5px 0 #0A3F33, 0 16px 26px -14px rgba(14, 90, 73, .7); }
.calc-scan.hero:active:not(:disabled) { transform: translateY(3px) scale(.99); box-shadow: 0 2px 0 #0A3F33; }
.calc-scan.hero .cs-icon { width: 64px; height: 64px; border-radius: 18px; background: rgba(255, 255, 255, .16); }
.calc-scan.hero .cs-icon svg { width: 34px; height: 34px; }
.calc-scan.hero .cs-text { font-size: 19px; letter-spacing: .04em; }
.calc-scan.hero .cs-text small { margin-top: 6px; font-size: 13.5px; letter-spacing: 0; color: rgba(255, 255, 255, .82); }
.nw { white-space: nowrap; }

/* ===== v23：多場進行中的牌局 ===== */
.resume-list { display: grid; gap: 12px; margin-bottom: 14px; }
.resume-list .resume { position: relative; padding: 0; margin: 0; }
.resume-open { display: block; width: 100%; padding: 18px 60px 18px 20px; border: 0; background: none; font: inherit; color: inherit; text-align: left; cursor: pointer; border-radius: inherit; }
.resume-del { position: absolute; top: 4px; right: 4px; width: 48px; height: 48px; color: var(--ink-2); opacity: 1; transition: opacity .25s cubic-bezier(.22,1,.36,1), color .25s cubic-bezier(.22,1,.36,1); }
.resume-del:hover, .resume-del:focus-visible { opacity: 1; color: var(--red); }
.resume-del svg { width: 20px; height: 20px; }
.nowrap { white-space: nowrap; }

/* ===== v24：備份碼提醒、AI 揭露 ===== */
.backup-warn { margin-top: 8px !important; padding: 8px 12px; border-radius: 12px; background: var(--red-soft); color: var(--red); font-size: 12.5px !important; line-height: 1.55; }
.calc-ai-note { margin: 0 4px 10px; font-size: 11.5px; line-height: 1.55; color: var(--ink-3); }
.calc-ai-note a { color: var(--jade-2); }
.gbtn { display: flex; justify-content: center; min-height: 44px; align-items: center; color: var(--ink-3); font-size: 13px; text-align: center; }
.acct-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.acct-row .mi-text small { display: block; color: var(--ink-3); font-size: 12.5px; word-break: break-all; }
.acct-g { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--jade-soft); color: var(--jade); font: 800 18px/1 var(--font-serif); }
.cloud-card .acct-row + p { margin: 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.6; }
.home-top { display: flex; justify-content: flex-end; min-height: 44px; margin-bottom: -44px; position: relative; z-index: 1; }
.acct-chip { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 44px; border-radius: 22px; text-decoration: none; color: var(--jade); transition: transform .2s var(--ease-spring); }
.acct-chip:active { transform: scale(.94); }
.acct-chip .acct-g { width: 36px; height: 36px; font-size: 16px; }
.acct-chip.login { padding: 0 16px; background: var(--tile); border: 1px solid var(--line); font-size: 14px; font-weight: 650; letter-spacing: .06em; }
a.foot-note { display: block; text-decoration: none; }
.gbtn { overflow: hidden; }
.gone-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px auto 0; max-width: 520px; }
.gone { display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 14px; background: var(--tile); border: 1px dashed var(--line); font-size: 14px; }
.gone-tag { padding: 1px 7px; border-radius: 6px; background: var(--paper-2); color: var(--ink-2); font-size: 11px; font-weight: 600; letter-spacing: .04em; }
.gone-name { color: var(--ink); }
.gone .stats-mini { font-size: 11.5px; color: var(--ink-3); letter-spacing: .04em; }
.gone-total { font-weight: 700; font-size: 16px; }
@media (orientation: landscape) and (max-height: 540px) { .gone-list { margin-top: 6px; } .gone { padding: 4px 10px; font-size: 13px; } .gone .stats-mini { display: none; } }
.rules-view { box-shadow: none; background: var(--paper); }
.rules-view .rule-row { min-height: 44px; padding: 6px 14px; font-size: 14.5px; }
.rule-val { color: var(--ink); font-weight: 650; text-align: right; }
.ended-tag { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 6px; background: var(--paper-2); color: var(--ink-2); font-size: 11px; font-weight: 600; letter-spacing: .04em; vertical-align: 1px; }
.recent-ended { margin-bottom: 4px; }

/* ===== v51：點座位直接記胡牌，其他動作放最上面一列 ===== */
.hu-alt { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 2px 0 4px; padding: 10px 12px; border-radius: 14px; background: var(--paper); }
.hu-alt span { flex: 1 0 100%; font-size: 13px; color: var(--ink-3); }
.hu-alt button { flex: 1; min-height: 44px; padding: 0 10px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--tile); color: var(--red); font: inherit; font-size: 14.5px; font-weight: 700; cursor: pointer; transition: transform .2s cubic-bezier(.22,1,.36,1); }
.hu-alt button[data-k="sub"] { color: var(--ink); }
.hu-alt button:active { transform: scale(.96); }
@media (min-width: 480px) { .hu-alt span { flex: 0 0 auto; margin-right: 4px; } }
.room-tag.offline small { color: var(--red); letter-spacing: .02em; }
.room-tag.offline b { color: var(--ink-3); }

/* 牌友檔案 */
.ps-link { display: block; color: inherit; text-decoration: none; transition: transform .25s var(--ease); }
.ps-link:active { transform: scale(.985); }
.ps-link .ps-head svg { width: 18px; height: 18px; color: var(--ink-3); align-self: center; }
.ps-alias { margin-left: 8px; padding: 2px 7px; border-radius: 99px; background: var(--paper-2); color: var(--ink-3); font-size: 11px; font-weight: 600; vertical-align: 2px; }
.ps-sub { margin: 4px 0 0; color: var(--ink-3); font-size: 13px; }
.spark { display: block; width: 100%; height: 64px; margin: 12px 0 4px; overflow: visible; }
.spark-zero { stroke: var(--paper-2); stroke-width: 1; stroke-dasharray: 3 3; }
.spark-line { fill: none; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; stroke: var(--ink-3); }
.spark-line.pos, .spark-dot.pos { stroke: var(--win); fill: var(--win); }
.spark-line.neg, .spark-dot.neg { stroke: var(--red); fill: var(--red); }
.spark-line.pos, .spark-line.neg { fill: none; }
.vs-list { padding: 0; overflow: hidden; }
.vs-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 16px; border-top: 1px solid var(--paper-2); color: inherit; text-decoration: none; }
.vs-row:first-child { border-top: 0; }
.vs-row:active { background: var(--paper-2); }
.vs-name { flex: 1; min-width: 0; font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-name small { display: block; font-weight: 500; font-size: 12px; color: var(--ink-3); margin-top: 1px; }
.vs-money { flex: none; font-weight: 750; font-size: 15px; font-variant-numeric: tabular-nums; }

/* LINE 登入按鈕（LINE 品牌綠） */
.line-login { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 44px; border-radius: 99px; background: #06C755; color: #fff; font-weight: 700; font-size: 15px; text-decoration: none; box-shadow: none; }
.line-login:active { background: #05A847; transform: scale(.98); }
.line-mark { padding: 3px 6px; border-radius: 6px; background: #fff; color: #06C755; font: 900 11px/1 var(--font); letter-spacing: .02em; }
.acct-g.line { background: #06C755; color: #fff; }
/* 認領座位 */
.me-tag { display: inline-block; font: 700 11px/1 var(--font); font-style: normal; color: #fff; background: var(--jade); padding: 3px 5px; border-radius: 6px; margin-right: 5px; vertical-align: 2px; }
.m-seat { color: var(--jade) !important; font-weight: 650 !important; margin-left: 6px !important; }
.ps-me { border: 1.5px solid var(--jade); }
.pick:disabled { opacity: .5; }
/* 營運統計 */
.adm-note { font-size: 12px; color: var(--ink-3); margin: 10px 2px 0; line-height: 1.6; }
.adm-table { padding: 6px 14px; }
.adm-table table { width: 100%; border-collapse: collapse; }
.adm-table th, .adm-table td { padding: 10px 4px; border-bottom: 1px solid var(--line); text-align: right; font-size: 14px; }
.adm-table tr:last-child th, .adm-table tr:last-child td { border-bottom: 0; }
.adm-table thead th { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.adm-table tbody th { text-align: left; font-weight: 650; }
.adm-table td { font: 700 15px var(--font-num); font-variant-numeric: tabular-nums; }
.adm-chart { display: block; width: 100%; height: auto; overflow: visible; }
.adm-chart rect { fill: var(--jade-2, var(--jade)); opacity: .55; }
.adm-chart rect.is-today { opacity: 1; fill: var(--jade); }
.adm-chart .adm-base { stroke: var(--line); }
.adm-chart text { font-size: 10px; fill: var(--ink-3); }
.adm-code { display: block; padding: 10px 12px; border-radius: 10px; background: var(--paper); font: 600 12px/1.5 ui-monospace, monospace; word-break: break-all; user-select: all; }
