:root {
  --felt: #1f5a3c;
  --felt-dark: #14402a;
  --ink: #f4efe1;
  --muted: #b9cbbf;
  --accent: #e8b84a;
  --danger: #e05d4f;
  --tile-face: #fffdf4;
  --tile-edge: #d9cfb2;
  --tw: clamp(18px, calc((100vw - 40px) / 18), 46px); /* 自己手牌的寬度 */
  --sw: clamp(14px, calc(var(--tw) * 0.62), 26px); /* 小牌的寬度 */
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 40%, var(--felt), var(--felt-dark));
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; }
[hidden] { display: none !important; }

/* ---------- 大廳 ---------- */
.panel-page {
  max-width: 420px;
  margin: 0 auto;
  padding: 48px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
h1 { font-size: 2.2rem; margin: 0; text-align: center; }
h2 { margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0; text-align: center; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); }
input, select {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #3c7a57;
  background: #0f3322;
  color: var(--ink);
  font-size: 1.05rem;
}
.row { display: flex; gap: 8px; }
.row input { flex: 1; text-transform: uppercase; letter-spacing: 0.2em; }
.or { text-align: center; color: var(--muted); font-size: 0.9rem; }

button {
  padding: 10px 16px;
  border-radius: 10px;
  border: 0;
  background: #e9e2cc;
  color: #1d2a22;
  font-weight: 700;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); }
button.win { background: var(--danger); color: #fff; }
button.pass { background: #8aa395; }
button.link { background: none; color: var(--muted); text-decoration: underline; font-weight: 400; }

.code { color: var(--accent); letter-spacing: 0.15em; }
.invite { background: #0f3322; padding: 12px; border-radius: 10px; color: var(--muted); }
.invite-link { display: block; color: var(--accent); word-break: break-all; margin-top: 6px; font-family: ui-monospace, monospace; }
.invite-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.invite-row .invite-link { flex: 1; min-width: 0; margin-top: 0; }
.copy-btn { flex: none; white-space: nowrap; }
.seats { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.seats li { background: #0f3322; padding: 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; }
.seats li.me { outline: 2px solid var(--accent); }
.seats .wind { color: var(--accent); font-weight: 700; }
.seats em { font-style: normal; font-size: 0.8rem; background: #2d6e4a; padding: 1px 6px; border-radius: 6px; }
.seats .empty { color: #6f8f7c; }

/* ---------- 牌 ---------- */
.tile {
  --w: var(--tw);
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: var(--w);
  height: calc(var(--w) * 1.36);
  margin: 0 1px 3px 0;
  background: linear-gradient(var(--tile-face), #f1ead4);
  border-radius: calc(var(--w) * 0.14);
  box-shadow: 0 calc(var(--w) * 0.06) 0 var(--tile-edge), 0 calc(var(--w) * 0.1) 4px rgba(0, 0, 0, 0.35);
  color: #222;
  line-height: 1;
  font-weight: 800;
  user-select: none;
  vertical-align: bottom;
  transition: transform 0.12s;
}
.tile b { font-size: calc(var(--w) * 0.52); }
.tile i { font-style: normal; font-size: calc(var(--w) * 0.4); margin-top: 2px; }
.tile.m i { color: #c0392b; }
.tile.p i { color: #1f5fa8; }
.tile.s i { color: #1e8449; }
.tile.z b { font-size: calc(var(--w) * 0.66); }
.tile.red b { color: #c0392b; }
.tile.green b { color: #1e8449; }
.tile.white b { color: transparent; width: 58%; height: 62%; border: 2px solid #1f5fa8; border-radius: 3px; }
.tile.flower b { color: #8e44ad; font-size: calc(var(--w) * 0.6); }
.tile.back { background: linear-gradient(#3aa069, #23744a); box-shadow: 0 calc(var(--w) * 0.06) 0 #e8dfc4, 0 calc(var(--w) * 0.1) 4px rgba(0, 0, 0, 0.35); }
.tile.sm { --w: var(--sw); }
.tile.dim { filter: brightness(0.85); }
.tile.last { box-shadow: 0 0 0 2px var(--accent), 0 0 10px var(--accent); }
.tile.win-tile { box-shadow: 0 0 0 3px var(--danger), 0 0 10px var(--danger); }

/* ---------- 牌桌 ---------- */
#screen-game { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: flex-end; justify-content: center; padding: 8px 12px 0; }
.board {
  /* S = 牌桌邊長，桌上所有東西都按比例縮放 */
  --S: min(calc(100vw - 24px), calc(100dvh - var(--tw) * 1.9 - 100px));
  position: relative;
  flex: none;
  width: var(--S);
  height: var(--S);
  background: radial-gradient(circle, #2a7550, #1a5236 75%);
  border-radius: calc(var(--S) * 0.03);
  box-shadow: inset 0 0 0 calc(var(--S) * 0.01) #6b4423, 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: max(10px, calc(var(--S) * 0.022));
}
.layer { position: absolute; inset: 0; }
.layer .tile { --w: calc(var(--S) * 0.029); margin: 0 0 2px 0; }

/* 中央牌牆 */
.wall-seg {
  position: absolute;
  left: 29%;
  width: 42%;
  top: calc(71% - var(--S) * 0.036);
  height: calc(var(--S) * 0.032);
  display: flex;
  gap: 1px;
}
.stack {
  flex: 1;
  border-radius: 2px;
  background: linear-gradient(#3aa069, #23744a);
  box-shadow: 0 2px 0 #e8dfc4, 0 3px 3px rgba(0, 0, 0, 0.3);
}
.stack.single { transform: scaleY(0.75); transform-origin: bottom; }
.stack.gone { visibility: hidden; }

/* 打出的牌：放在牌牆和自己之間 */
.river {
  position: absolute;
  left: 29%;
  width: 42%;
  top: calc(71% + var(--S) * 0.01);
  height: 21%;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
}
.river .tile { --w: calc(var(--S) * 0.038); }

/* 吃碰槓和手牌：靠桌邊 */
.melds-row {
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: calc(var(--S) * 0.058);
  display: flex;
  justify-content: center;
  align-items: flex-end;
}
.layer.me .melds-row { bottom: calc(var(--S) * 0.015); }
.melds-row .meld { margin: 0 calc(var(--S) * 0.008); }
.hand-row {
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: calc(var(--S) * 0.006);
  display: flex;
  justify-content: center;
  align-items: flex-end;
}
.hand-row .tile { --w: calc(var(--S) * 0.033); margin: 0; }

/* 每個人右手邊的角落放名字、分數、花牌（文字轉正方便閱讀） */
.corner { position: absolute; right: 0; bottom: 0; width: 16%; height: 16%; padding: 4px; }
.corner-in {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-align: center;
  line-height: 1.15;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
}
.corner.active .corner-in { outline: 2px solid var(--accent); background: rgba(232, 184, 74, 0.18); }
.corner .wind { background: var(--ink); color: var(--felt-dark); border-radius: 4px; padding: 0 4px; font-weight: 800; }
.corner .pname { font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.corner.active .pname { color: var(--accent); }
.corner .score { color: var(--muted); font-variant-numeric: tabular-nums; }
.corner .badge { margin-left: 3px; }
.corner .flowers { justify-content: center; }
.corner .flowers .tile { --w: calc(var(--S) * 0.022); margin: 0; }
.badge { background: var(--danger); color: #fff; border-radius: 4px; padding: 0 4px; font-size: 0.85em; }
.badge.off { background: #6c7a72; }

.center-info {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(var(--S) * 0.33);
  height: calc(var(--S) * 0.33);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}
.round { font-size: 1.3em; font-weight: 800; color: var(--accent); }
.wall { color: var(--muted); }
.wall b { color: var(--ink); }
.log { list-style: none; padding: 0 6px; margin: 6px 0 0; color: var(--muted); max-width: 100%; }
.log li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log li:first-child { color: var(--ink); font-weight: 700; }
.tile.last { box-shadow: 0 0 0 2px var(--accent), 0 0 8px var(--accent); }

/* 自己的手牌 */
.my-hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: calc(var(--tw) * 0.45) 16px 6px;
  min-height: calc(var(--tw) * 1.9 + 6px);
}
.my-hand .tile { cursor: pointer; }
.my-hand .tile.sel { transform: translateY(-30%); }
.gap { display: inline-block; width: calc(var(--tw) * 0.4); }
.meld { display: inline-flex; }
.melds, .flowers { display: flex; flex-wrap: wrap; align-items: flex-end; }
.flowers .tile { margin-right: 1px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  min-height: 64px;
  background: rgba(0, 0, 0, 0.25);
}
.actions .hint { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.actions button { min-width: 64px; font-size: 1.05rem; }

/* ---------- 結算 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.card {
  background: #183f2b;
  border-radius: 16px;
  padding: 20px;
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.card h2 { text-align: center; color: var(--accent); }
.card h2 small { display: block; color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.card h3 { text-align: center; margin: 0; }
.win-hand { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; gap: 4px; }
.win-hand .tile { --w: clamp(16px, 5.4vw, 30px); }
.card .flowers { justify-content: center; }
.tai { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.tai li { display: flex; justify-content: space-between; background: #0f3322; padding: 6px 10px; border-radius: 8px; }
.tai b { color: var(--accent); }
.scores { width: 100%; border-collapse: collapse; }
.scores th, .scores td { padding: 6px; text-align: center; border-bottom: 1px solid #2d5e43; }
.scores th { color: var(--muted); font-weight: 400; }
.scores tr.me td { color: var(--accent); }
.plus { color: #7fe0a0; }
.minus { color: #ff8b7e; }

.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 20;
  max-width: calc(100% - 32px);
}
.offline {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 6px;
  z-index: 20;
}

/* ---------- 特效 ---------- */
.tile.drop { animation: drop 0.35s cubic-bezier(0.2, 1.4, 0.5, 1); }
@keyframes drop {
  from { transform: translateY(-120%) scale(1.8) rotate(-12deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.tile.slide-in { animation: slide-in 0.3s ease-out; }
@keyframes slide-in {
  from { transform: translateX(80%) translateY(-30%); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.my-hand .tile { transition: transform 0.12s; }
@media (hover: hover) {
  .my-hand.turn .tile:hover:not(.sel) { transform: translateY(-12%); }
}
.my-hand.turn { filter: drop-shadow(0 0 10px rgba(232, 184, 74, 0.55)); }
.corner.active .corner-in { animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow {
  from { box-shadow: 0 0 0 rgba(232, 184, 74, 0); }
  to { box-shadow: 0 0 18px rgba(232, 184, 74, 0.8); }
}
.actions button.win { animation: pulse 0.7s ease-in-out infinite alternate; }
@keyframes pulse {
  from { transform: scale(1); box-shadow: 0 0 0 rgba(224, 93, 79, 0); }
  to { transform: scale(1.12); box-shadow: 0 0 18px rgba(224, 93, 79, 0.9); }
}

.fx-callout {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-weight: 900;
  color: #ffe08a;
  -webkit-text-stroke: 2px #7a2a10;
  text-shadow: 0 4px 0 #7a2a10, 0 8px 18px rgba(0, 0, 0, 0.6);
  animation: stamp 1.4s ease-out forwards;
}
.fx-callout.big {
  color: #fff3b0;
  -webkit-text-stroke: 3px #b3261e;
  text-shadow: 0 5px 0 #b3261e, 0 0 30px #ffcf4a, 0 10px 30px rgba(0, 0, 0, 0.6);
  animation: stamp-big 2.2s ease-out forwards;
}
.fx-callout.small {
  color: #f6d6ff;
  -webkit-text-stroke: 1px #5b1f73;
  text-shadow: 0 2px 0 #5b1f73, 0 4px 10px rgba(0, 0, 0, 0.5);
}
@keyframes stamp {
  0% { scale: 3; rotate: -18deg; opacity: 0; }
  14% { scale: 0.9; rotate: -6deg; opacity: 1; }
  22% { scale: 1.06; }
  30% { scale: 1; }
  75% { opacity: 1; translate: 0 0; }
  100% { opacity: 0; translate: 0 -40%; scale: 1.1; }
}
@keyframes stamp-big {
  0% { scale: 4; rotate: 20deg; opacity: 0; }
  12% { scale: 0.85; rotate: -4deg; opacity: 1; }
  20% { scale: 1.08; rotate: 2deg; }
  28% { scale: 1; rotate: 0; }
  40%, 60% { scale: 1.04; }
  50%, 70% { scale: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; scale: 1.3; }
}

.fx-bubble {
  position: fixed;
  z-index: 31;
  pointer-events: none;
  max-width: 220px;
  padding: 8px 12px;
  border-radius: 14px;
  background: #fff;
  color: #222;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  animation: bubble-in 0.35s cubic-bezier(0.2, 1.6, 0.5, 1);
  transition: opacity 0.3s, scale 0.3s;
}
.fx-bubble.out { opacity: 0; scale: 0.6; }
/* 依角落決定泡泡往哪邊長 */
.fx-bubble.p0 { transform: translate(-100%, -120%); border-bottom-right-radius: 2px; transform-origin: bottom right; }
.fx-bubble.p1 { transform: translate(-100%, 40%); border-top-right-radius: 2px; transform-origin: top right; }
.fx-bubble.p2 { transform: translate(0, 40%); border-top-left-radius: 2px; transform-origin: top left; }
.fx-bubble.p3 { transform: translate(0, -120%); border-bottom-left-radius: 2px; transform-origin: bottom left; }
@keyframes bubble-in {
  from { scale: 0; opacity: 0; }
  to { scale: 1; opacity: 1; }
}

.fx-canvas { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 25; }
/* 結算視窗要在彩帶下面才看得到彩帶 */
.modal { z-index: 20; }

.board-wrap.shake { animation: shake 0.45s; }
.board-wrap.shake-big { animation: shake-big 0.8s; }
@keyframes shake {
  0%, 100% { transform: none; }
  20% { transform: translate(-6px, 3px) rotate(-0.6deg); }
  40% { transform: translate(5px, -4px) rotate(0.5deg); }
  60% { transform: translate(-4px, 2px); }
  80% { transform: translate(3px, -1px); }
}
@keyframes shake-big {
  0%, 100% { transform: none; }
  10% { transform: translate(-14px, 6px) rotate(-1.5deg) scale(1.02); }
  25% { transform: translate(12px, -8px) rotate(1.2deg); }
  40% { transform: translate(-10px, 4px) rotate(-0.8deg); }
  55% { transform: translate(8px, -3px) rotate(0.5deg); }
  70% { transform: translate(-4px, 2px); }
  85% { transform: translate(2px, -1px); }
}

.hud { position: fixed; top: 10px; right: 10px; display: flex; gap: 6px; z-index: 15; }
.hud button { width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 1.3rem; background: rgba(0, 0, 0, 0.35); }
.chat-panel {
  position: fixed;
  top: 62px;
  right: 10px;
  z-index: 16;
  width: min(260px, calc(100vw - 20px));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(10, 35, 22, 0.95);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: bubble-in 0.2s ease-out;
}
.chat-panel button { font-size: 0.85rem; padding: 8px 6px; }

@media (prefers-reduced-motion: reduce) {
  .fx-callout, .fx-bubble, .tile.drop, .tile.slide-in, .board-wrap.shake, .board-wrap.shake-big,
  .corner.active .corner-in, .actions button.win { animation-duration: 0.01s !important; animation-iteration-count: 1 !important; }
}

/* =====================================================================
   科技 Q 版主題：霓虹、全息、毛玻璃，加上原創 Q 版機器人
   ===================================================================== */
:root {
  --felt-dark: #070b1f;
  --ink: #e8f4ff;
  --muted: #8fa6c8;
  --accent: #2ef2ff;
  --pink: #ff4fd8;
  --yellow: #ffd23f;
  --danger: #ff3d7f;
  --panel: rgba(12, 20, 48, 0.68);
  --line: rgba(46, 242, 255, 0.35);
  --tile-edge: #a9b8d8;
}
body {
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 79, 216, 0.22), transparent 40%),
    radial-gradient(circle at 85% 20%, rgba(46, 242, 255, 0.2), transparent 45%),
    radial-gradient(circle at 50% 100%, rgba(80, 60, 255, 0.35), transparent 60%),
    #060a1c;
  background-attachment: fixed;
}
.screen { position: relative; z-index: 1; }

/* ---------- 背景：格線地板、飄浮麻將、掃描線 ---------- */
.cyber-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.grid-floor {
  position: absolute;
  left: -50%;
  right: -50%;
  bottom: -5%;
  height: 55%;
  background-image:
    linear-gradient(rgba(46, 242, 255, 0.45) 1px, transparent 1px),
    linear-gradient(90deg, rgba(46, 242, 255, 0.45) 1px, transparent 1px);
  background-size: 60px 60px;
  transform: perspective(380px) rotateX(64deg);
  transform-origin: top center;
  -webkit-mask-image: linear-gradient(to top, #000 25%, transparent 95%);
  mask-image: linear-gradient(to top, #000 25%, transparent 95%);
  animation: grid-move 2.4s linear infinite;
  transition: opacity 0.6s;
}
@keyframes grid-move { to { background-position: 0 60px, 0 0; } }
.float-tiles { position: absolute; inset: 0; transition: opacity 0.6s; }
.floater {
  position: absolute;
  bottom: -90px;
  opacity: 0.55;
  filter: drop-shadow(0 0 10px rgba(46, 242, 255, 0.7));
  animation: float-up var(--dur) linear infinite;
  animation-delay: var(--delay);
}
.floater .tile { --w: var(--size); }
@keyframes float-up {
  from { transform: translateY(0) rotate(0deg); }
  to { transform: translateY(-125vh) rotate(calc(var(--spin) * 360deg)); }
}
.scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 3px);
}
body[data-screen="game"] .grid-floor { opacity: 0.15; }
body[data-screen="game"] .float-tiles { opacity: 0; }

/* ---------- Q 版機器人 ---------- */
.robot { display: block; overflow: visible; }
.robot .antenna { fill: var(--c); filter: drop-shadow(0 0 5px var(--c)); animation: antenna 1.4s ease-in-out infinite alternate; }
.robot .ear { fill: var(--c); }
.robot .core { fill: var(--c); filter: drop-shadow(0 0 6px var(--c)); animation: antenna 2s ease-in-out infinite alternate; }
.robot .eye { fill: var(--c); filter: drop-shadow(0 0 4px var(--c)); transform-box: fill-box; transform-origin: center; animation: blink 4.2s infinite; }
.robot .eye-line, .robot .mouth { stroke: var(--c); stroke-width: 4; fill: none; stroke-linecap: round; filter: drop-shadow(0 0 3px var(--c)); }
.robot .mouth-fill { fill: var(--c); filter: drop-shadow(0 0 4px var(--c)); }
.robot .blush { fill: #ff7bbd; opacity: 0.75; }
.robot .tear { fill: #6fd3ff; animation: tear 1s ease-in infinite; }
.robot .bot-body { transform-box: fill-box; transform-origin: 50% 100%; }
.robot.mood-happy .bot-body { animation: hop 0.5s ease-in-out infinite alternate; }
.robot.mood-sad .bot-body { animation: sulk 2.4s ease-in-out infinite; }
.robot.mood-think .antenna { animation-duration: 0.4s; }
@keyframes antenna { from { opacity: 0.55; } to { opacity: 1; } }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.1); } }
@keyframes tear { from { transform: translateY(0); opacity: 1; } to { transform: translateY(10px); opacity: 0; } }
@keyframes hop { from { transform: translateY(0) scaleY(1); } to { transform: translateY(-6%) scaleY(1.03); } }
@keyframes sulk { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg) translateY(2%); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }

/* ---------- 首頁 ---------- */
.panel-page { padding-top: 28px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hero-bots { display: flex; align-items: flex-end; justify-content: center; gap: 4px; margin-bottom: -6px; }
.hero-main { width: 150px; animation: bob 2.6s ease-in-out infinite; filter: drop-shadow(0 0 22px rgba(46, 242, 255, 0.45)); }
.hero-side { width: 78px; animation: bob 2.2s ease-in-out infinite; }
.hero-side:last-child { animation-delay: -1.1s; }
.neon-title {
  position: relative;
  margin: 0;
  font-size: clamp(48px, 13vw, 78px);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 18px var(--accent), 0 0 42px var(--accent), 0 0 90px #2e7bff;
  animation: flicker 6s infinite;
}
.neon-title::before,
.neon-title::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  text-shadow: none;
  opacity: 0.85;
  clip-path: inset(0 0 100% 0);
}
.neon-title::before { color: var(--pink); animation: glitch-a 3.2s infinite steps(1); }
.neon-title::after { color: var(--accent); animation: glitch-b 3.2s infinite steps(1); }
@keyframes glitch-a {
  0%, 86%, 100% { clip-path: inset(0 0 100% 0); transform: none; }
  88% { clip-path: inset(8% 0 62% 0); transform: translate(-7px, -2px); }
  92% { clip-path: inset(55% 0 18% 0); transform: translate(6px, 1px); }
}
@keyframes glitch-b {
  0%, 87%, 100% { clip-path: inset(0 0 100% 0); transform: none; }
  89% { clip-path: inset(40% 0 35% 0); transform: translate(7px, 2px); }
  93% { clip-path: inset(70% 0 5% 0); transform: translate(-5px, 0); }
}
@keyframes flicker {
  0%, 18%, 22%, 62%, 64%, 100% { opacity: 1; }
  20%, 63% { opacity: 0.55; }
}
.tagline {
  margin: 0;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.95rem;
  letter-spacing: 0.25em;
  color: var(--accent);
  text-align: center;
  text-shadow: 0 0 8px rgba(46, 242, 255, 0.7);
}
.tagline span { display: block; margin-top: 4px; letter-spacing: 0.1em; color: var(--muted); text-shadow: none; font-size: 0.85rem; }

.glass-card,
.room-page .invite,
.room-page .seats li,
.card {
  background: var(--panel);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  box-shadow: 0 0 30px rgba(46, 242, 255, 0.12), inset 0 0 24px rgba(46, 242, 255, 0.05);
}
.glass-card { display: flex; flex-direction: column; gap: 14px; padding: 20px; border-radius: 20px; animation: breathe 4s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 24px rgba(46, 242, 255, 0.12), inset 0 0 24px rgba(46, 242, 255, 0.05); }
  50% { box-shadow: 0 0 42px rgba(255, 79, 216, 0.22), inset 0 0 24px rgba(46, 242, 255, 0.08); }
}

input, select {
  background: rgba(4, 8, 26, 0.85);
  border: 1px solid rgba(46, 242, 255, 0.3);
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(46, 242, 255, 0.2), 0 0 18px rgba(46, 242, 255, 0.35); }
input::placeholder { color: #5d7398; }

button {
  position: relative;
  overflow: hidden;
  background: rgba(46, 242, 255, 0.08);
  color: var(--accent);
  border: 1px solid rgba(46, 242, 255, 0.55);
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
}
button:not(:disabled):hover { box-shadow: 0 0 16px rgba(46, 242, 255, 0.5); background: rgba(46, 242, 255, 0.16); }
button:not(:disabled):active { transform: scale(0.96); }
button.primary {
  background: linear-gradient(90deg, var(--accent), #6c8bff 55%, var(--pink));
  color: #071022;
  border: 0;
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: 0 0 20px rgba(46, 242, 255, 0.45);
}
/* 按鈕上掃過的一道光 */
button.primary::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -60%;
  width: 40%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.7), transparent);
  transform: skewX(-20deg);
  animation: shine 3.2s ease-in-out infinite;
}
@keyframes shine { 0%, 60% { left: -60%; } 100% { left: 130%; } }
button.win { background: linear-gradient(90deg, var(--danger), var(--pink)); color: #fff; border: 0; }
button.pass { background: rgba(143, 166, 200, 0.12); color: var(--muted); border-color: rgba(143, 166, 200, 0.4); }
button.link { border: 0; background: none; color: var(--muted); }
button.link:hover { box-shadow: none; background: none; color: var(--accent); }
.or { color: var(--muted); }

/* ---------- 房間 ---------- */
.room-page h2 { text-align: center; }
.code { color: var(--pink); text-shadow: 0 0 12px var(--pink); font-family: ui-monospace, Menlo, monospace; }
.room-page .invite { border-radius: 14px; }
.invite-link { color: var(--accent); }
.room-page .seats li { border-radius: 14px; padding: 8px 12px; transition: transform 0.2s; }
.room-page .seats li.me { outline: 2px solid var(--accent); box-shadow: 0 0 22px rgba(46, 242, 255, 0.35); }
.room-page .seats li.vacant { opacity: 0.55; }
.seats .wind { color: var(--accent); text-shadow: 0 0 8px var(--accent); }
.seats em { background: rgba(255, 79, 216, 0.2); border: 1px solid rgba(255, 79, 216, 0.5); color: #ffc2f1; }
.robot.mini { width: 40px; flex: none; }

/* ---------- 牌桌：全息桌面 ---------- */
.board {
  background:
    radial-gradient(circle at 50% 50%, rgba(46, 242, 255, 0.14), transparent 55%),
    linear-gradient(rgba(46, 242, 255, 0.06) 1px, transparent 1px) 0 0 / calc(var(--S) / 24) calc(var(--S) / 24),
    linear-gradient(90deg, rgba(46, 242, 255, 0.06) 1px, transparent 1px) 0 0 / calc(var(--S) / 24) calc(var(--S) / 24),
    linear-gradient(160deg, #0d1a45, #070d28 70%);
  border-radius: calc(var(--S) * 0.04);
  box-shadow:
    0 0 0 2px rgba(46, 242, 255, 0.75),
    0 0 26px rgba(46, 242, 255, 0.45),
    0 0 90px rgba(255, 79, 216, 0.18),
    inset 0 0 70px rgba(46, 242, 255, 0.12);
  animation: rim 5s ease-in-out infinite;
}
@keyframes rim {
  0%, 100% { box-shadow: 0 0 0 2px rgba(46, 242, 255, 0.75), 0 0 26px rgba(46, 242, 255, 0.45), 0 0 90px rgba(255, 79, 216, 0.18), inset 0 0 70px rgba(46, 242, 255, 0.12); }
  50% { box-shadow: 0 0 0 2px rgba(255, 79, 216, 0.75), 0 0 30px rgba(255, 79, 216, 0.4), 0 0 90px rgba(46, 242, 255, 0.22), inset 0 0 70px rgba(255, 79, 216, 0.1); }
}

/* 牌背與牌牆：深藍電路板，中間一顆發光核心 */
.tile.back,
.stack {
  background:
    radial-gradient(circle at 50% 45%, rgba(46, 242, 255, 0.85) 0 9%, rgba(46, 242, 255, 0.25) 10% 16%, transparent 18%),
    repeating-linear-gradient(45deg, rgba(46, 242, 255, 0.1) 0 2px, transparent 2px 6px),
    linear-gradient(160deg, #26408f, #0c1647);
  border: 1px solid rgba(46, 242, 255, 0.45);
}
.tile.back { box-shadow: 0 calc(var(--w) * 0.06) 0 rgba(46, 242, 255, 0.45), 0 0 6px rgba(46, 242, 255, 0.3); }
.stack { box-shadow: 0 2px 0 rgba(46, 242, 255, 0.5), 0 0 5px rgba(46, 242, 255, 0.35); }

.tile { background: linear-gradient(170deg, #ffffff, #e9eefb); }
.tile.last { box-shadow: 0 0 0 2px var(--accent), 0 0 12px var(--accent); }
.tile.win-tile { box-shadow: 0 0 0 3px var(--pink), 0 0 14px var(--pink); }

.corner-in {
  background: rgba(8, 14, 40, 0.78);
  border: 1px solid rgba(46, 242, 255, 0.25);
  border-radius: 12px;
}
.corner.active .corner-in { outline: 2px solid var(--accent); background: rgba(46, 242, 255, 0.12); }
.corner-row { display: flex; align-items: center; justify-content: center; gap: 4%; width: 100%; }
.robot.avatar { width: 42%; flex: none; }
.who { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.corner .wind { background: var(--accent); color: #061028; box-shadow: 0 0 8px var(--accent); }
.corner.active .pname { color: var(--accent); text-shadow: 0 0 8px var(--accent); }

/* 中央全息面板，有一道掃描線 */
.center-info {
  overflow: hidden;
  background: rgba(8, 20, 54, 0.62);
  border: 1px solid rgba(46, 242, 255, 0.4);
  box-shadow: inset 0 0 24px rgba(46, 242, 255, 0.18), 0 0 18px rgba(46, 242, 255, 0.2);
  border-radius: 12px;
}
.center-info::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 30%;
  top: -30%;
  background: linear-gradient(to bottom, transparent, rgba(46, 242, 255, 0.18), transparent);
  animation: scan 3.5s linear infinite;
  pointer-events: none;
}
@keyframes scan { to { top: 100%; } }
.round { color: var(--accent); text-shadow: 0 0 10px var(--accent); letter-spacing: 0.06em; }
.wall b { color: var(--yellow); text-shadow: 0 0 8px rgba(255, 210, 63, 0.7); }

.my-hand {
  background: linear-gradient(to bottom, transparent, rgba(46, 242, 255, 0.08));
  border-bottom: 1px solid rgba(46, 242, 255, 0.35);
}
.my-hand.turn { filter: drop-shadow(0 0 12px rgba(46, 242, 255, 0.6)); }
.actions { background: rgba(5, 9, 26, 0.88); border-top: 1px solid rgba(46, 242, 255, 0.2); }

/* ---------- 結算 ---------- */
.modal { background: rgba(3, 6, 20, 0.6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.card { background: rgba(10, 18, 46, 0.88); border-radius: 20px; }
.card h2 { color: #fff; text-shadow: 0 0 10px var(--accent), 0 0 30px var(--accent); }
.result-cast { display: flex; align-items: flex-end; justify-content: center; gap: 8px; }
.robot.winner { width: 110px; filter: drop-shadow(0 0 18px rgba(46, 242, 255, 0.55)); }
.robot.loser { width: 58px; }
.tai li { background: rgba(46, 242, 255, 0.06); border: 1px solid rgba(46, 242, 255, 0.18); }
.tai b { color: var(--yellow); }
.scores th, .scores td { border-bottom-color: rgba(46, 242, 255, 0.15); }
.scores tr.me td { color: var(--accent); }

/* ---------- 特效配色換成霓虹 ---------- */
.fx-callout {
  color: #fff;
  -webkit-text-stroke: 2px var(--pink);
  text-shadow: 0 0 10px var(--pink), 0 0 28px var(--accent), 0 6px 0 #5a1680;
}
.fx-callout.big {
  color: #fff;
  -webkit-text-stroke: 3px var(--accent);
  text-shadow: 0 0 14px var(--accent), 0 0 40px var(--pink), 0 7px 0 #1b2f8a;
}
.fx-bubble { background: #f4f8ff; border: 2px solid var(--accent); box-shadow: 0 0 18px rgba(46, 242, 255, 0.5); }
.hud button { background: var(--panel); border: 1px solid var(--line); }
.chat-panel { background: rgba(8, 14, 40, 0.94); border: 1px solid var(--line); }
.toast { background: rgba(8, 14, 40, 0.95); border: 1px solid var(--line); }

@media (prefers-reduced-motion: reduce) {
  .grid-floor, .floater, .neon-title, .neon-title::before, .neon-title::after, .glass-card, .board,
  .center-info::after, button.primary::after, .robot *, .hero-main, .hero-side { animation: none !important; }
}
.robot.avatar { width: 34%; }
.badge.ai { background: rgba(46, 242, 255, 0.2); color: var(--accent); border: 1px solid rgba(46, 242, 255, 0.5); }
.fx-bubble { width: max-content; max-width: min(220px, 60vw); }
.who > div:first-child { white-space: nowrap; }
/* 手機上牌桌角落太小，只留文字 */
@media (max-width: 600px) {
  .robot.avatar { display: none; }
  .who { align-items: center; }
  .badge { font-size: 0.75em; padding: 0 3px; }
}

/* =====================================================================
   牌桌畫面：太空站觀景窗
   ===================================================================== */
.space-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; opacity: 0; transition: opacity 0.8s; background: #02030c; }
body[data-screen="game"] .space-bg { opacity: 1; }
body[data-screen="game"] .cyber-bg { opacity: 0; }
.cyber-bg { transition: opacity 0.8s; }
#starfield { position: absolute; inset: 0; width: 100%; height: 100%; }
.nebula {
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(ellipse at 20% 30%, rgba(157, 123, 255, 0.28), transparent 45%),
    radial-gradient(ellipse at 80% 70%, rgba(255, 79, 216, 0.18), transparent 45%),
    radial-gradient(ellipse at 60% 15%, rgba(46, 242, 255, 0.15), transparent 40%);
  animation: nebula 40s ease-in-out infinite alternate;
}
@keyframes nebula { to { transform: translate(3%, -2%) scale(1.08); } }

/* 行星：有條紋的球體加一圈光環，慢慢自轉 */
.planet { position: absolute; right: 6vw; top: 9vh; width: min(22vw, 220px); aspect-ratio: 1; animation: drift 30s ease-in-out infinite alternate; }
.planet-body {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 30%, rgba(255, 255, 255, 0.55), transparent 35%),
    repeating-linear-gradient(170deg, #ff8ad8 0 8%, #9d7bff 8% 15%, #5a4fd8 15% 22%, #ff6fb4 22% 26%);
  background-size: 100% 100%, 100% 260%;
  box-shadow: inset -24px -16px 40px rgba(5, 0, 30, 0.85), 0 0 60px rgba(157, 123, 255, 0.5);
  animation: spin-bands 18s linear infinite;
}
@keyframes spin-bands { to { background-position: 0 0, 0 260%; } }
.planet-ring {
  position: absolute;
  left: -38%;
  right: -38%;
  top: 40%;
  height: 22%;
  border-radius: 50%;
  border: 3px solid rgba(46, 242, 255, 0.7);
  box-shadow: 0 0 14px rgba(46, 242, 255, 0.6), inset 0 0 10px rgba(46, 242, 255, 0.5);
  transform: rotate(-16deg);
}
.planet-ring.back { clip-path: inset(0 0 50% 0); }
.planet-ring.front { clip-path: inset(50% 0 0 0); z-index: 1; }
.moon {
  position: absolute;
  left: 8vw;
  bottom: 18vh;
  width: min(6vw, 56px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #a9b8d8 45%, #3b4670);
  box-shadow: 0 0 24px rgba(169, 184, 216, 0.5);
  animation: drift 22s ease-in-out infinite alternate-reverse;
}
@keyframes drift { to { transform: translate(-18px, 14px); } }

/* 觀景窗的金屬框、螺絲和標籤 */
.window-frame {
  position: absolute;
  inset: 0;
  border: 10px solid #1a2140;
  border-radius: 28px;
  box-shadow:
    inset 0 0 0 2px rgba(46, 242, 255, 0.45),
    inset 0 0 40px rgba(46, 242, 255, 0.18),
    0 0 0 2px #0a0f24;
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.05) 0 10%, transparent 10% 60%, rgba(255, 255, 255, 0.03) 60% 63%, transparent 63%);
}
.bolt { position: absolute; width: 12px; height: 12px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #c9d6f2, #4a5680); box-shadow: 0 0 6px rgba(46, 242, 255, 0.6); }
.bolt.tl { left: 10px; top: 10px; }
.bolt.tr { right: 10px; top: 10px; }
.bolt.bl { left: 10px; bottom: 10px; }
.bolt.br { right: 10px; bottom: 10px; }
.frame-label {
  position: absolute;
  top: -9px;
  padding: 0 10px;
  font: 600 11px/18px ui-monospace, Menlo, monospace;
  letter-spacing: 0.15em;
  color: var(--accent);
  background: #1a2140;
  border-radius: 0 0 8px 8px;
  text-shadow: 0 0 6px var(--accent);
}
.frame-label.left { left: 40px; }
.frame-label.right { right: 40px; }
.frame-label i { font-style: normal; color: var(--yellow); margin-left: 8px; }

/* 快流局：紅色警報燈 */
.alert-light { position: absolute; inset: 0; opacity: 0; transition: opacity 0.5s; }
body[data-alert="1"] .alert-light {
  opacity: 1;
  background: radial-gradient(ellipse at 50% -10%, rgba(255, 40, 80, 0.5), transparent 60%);
  animation: alarm 1s ease-in-out infinite;
}
body[data-alert="1"] .frame-label.right { color: #ff6b8a; text-shadow: 0 0 8px #ff3d7f; animation: alarm 1s infinite; }
body[data-alert="1"] .window-frame { box-shadow: inset 0 0 0 2px rgba(255, 61, 127, 0.7), inset 0 0 50px rgba(255, 61, 127, 0.3), 0 0 0 2px #0a0f24; }
@keyframes alarm { 50% { opacity: 0.35; } }

/* 聽牌：觀景窗邊緣變成青色脈動 */
body[data-tenpai="1"] .window-frame { animation: tenpai-pulse 0.9s ease-in-out infinite; }
@keyframes tenpai-pulse { 50% { box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 70px rgba(46, 242, 255, 0.4), 0 0 0 2px #0a0f24; } }

#screen-game { padding: 14px; }
#screen-game .actions { border-radius: 0 0 18px 18px; }

/* ---------- 資訊面板 ---------- */
.game-info {
  display: none;
  background: var(--panel);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 0 24px rgba(46, 242, 255, 0.15);
  font-size: 0.85rem;
}
.gi-title { font-weight: 800; color: var(--accent); text-shadow: 0 0 8px var(--accent); display: flex; align-items: baseline; gap: 8px; }
.gi-title small { color: var(--muted); font-weight: 400; text-shadow: none; }
.gi-rank { list-style: none; margin: 6px 0; padding: 0; display: grid; gap: 4px; }
.gi-rank li { display: flex; align-items: center; gap: 6px; padding: 2px 6px; border-radius: 8px; }
.gi-rank li.me { background: rgba(46, 242, 255, 0.12); outline: 1px solid rgba(46, 242, 255, 0.4); }
.gi-rank .medal { width: 1.4em; text-align: center; color: var(--muted); }
.gi-rank .robot.mini { width: 24px; }
.gi-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gi-rank b { font-variant-numeric: tabular-nums; color: var(--yellow); }
.gi-meta { color: var(--muted); }
/* 直式螢幕：面板放在牌桌上方，排成兩欄 */
@media (orientation: portrait) {
  .game-info { display: block; margin: 34px 0 0; }
  .gi-rank { grid-template-columns: 1fr 1fr; }
}
/* 寬螢幕：面板放在左上角 */
@media (orientation: landscape) and (min-width: 1000px) and (min-height: 600px) {
  .game-info { display: block; position: fixed; left: 28px; top: 36px; width: 220px; z-index: 2; }
}

/* ---------- 手牌工具列與拖曳 ---------- */
.hand-tools { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 26px; margin-top: 4px; }
.tenpai-hint { color: var(--muted); font-size: 0.9rem; }
.tenpai-hint b { color: var(--yellow); text-shadow: 0 0 8px rgba(255, 210, 63, 0.7); margin: 0 2px; }
button.small { padding: 4px 12px; font-size: 0.85rem; border-radius: 999px; }
.my-hand { padding-top: calc(var(--tw) * 0.35); }
.my-hand.manual .tile { cursor: grab; touch-action: none; }
.my-hand .tile.dragging { opacity: 0.25; }
.drag-ghost { position: fixed; z-index: 40; pointer-events: none; margin: 0; transform: scale(1.15) rotate(-4deg); box-shadow: 0 12px 24px rgba(0, 0, 0, 0.5), 0 0 16px var(--accent); }
/* 打掉就聽牌的牌：頂端一顆亮點 */
.tile.ting::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 50%;
  width: 7px;
  height: 7px;
  margin-left: -3.5px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 8px var(--yellow);
  animation: antenna 0.8s ease-in-out infinite alternate;
}

/* ---------- 設定面板 ---------- */
.settings-panel { grid-template-columns: 1fr; gap: 10px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; font-weight: 700; cursor: pointer; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 46px; height: 26px; border-radius: 999px; background: rgba(143, 166, 200, 0.3); position: relative; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.2s; }
.switch-row input:checked + .switch { background: var(--accent); box-shadow: 0 0 12px rgba(46, 242, 255, 0.6); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--pink); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg button.on { background: var(--accent); color: #061028; }
.seg.disabled { opacity: 0.4; pointer-events: none; }
.hint-small { margin: 0; color: var(--muted); font-size: 0.8rem; }

/* ---------- 開局動畫 ---------- */
.intro {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle, rgba(10, 20, 60, 0.75), rgba(2, 3, 12, 0.85));
  animation: fade-in 0.3s ease-out;
  cursor: pointer;
}
@keyframes fade-in { from { opacity: 0; } }
.intro-stage { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
.intro-bot { width: 120px; animation: bob 1s ease-in-out infinite; }
.dice-row { display: flex; gap: 14px; }
.die {
  width: 46px;
  height: 46px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  background: linear-gradient(145deg, #fff, #dfe6f7);
  border-radius: 10px;
  box-shadow: 0 6px 0 #9fb3d9, 0 0 18px rgba(46, 242, 255, 0.6);
  animation: roll 0.8s cubic-bezier(.3,.6,.4,1) both;
  animation-delay: calc(var(--i) * 0.08s);
}
.die i { border-radius: 50%; }
.die i.pip { background: #1b2340; }
.die i.pip.red { background: #e0263a; }
@keyframes roll {
  0% { transform: translateY(-160px) rotate(-540deg) scale(0.6); opacity: 0; }
  60% { transform: translateY(10px) rotate(20deg) scale(1.05); opacity: 1; }
  80% { transform: translateY(-6px) rotate(-6deg); }
  100% { transform: none; }
}
.intro-title { font-size: clamp(36px, 9vw, 64px); font-weight: 900; color: #fff; text-shadow: 0 0 10px var(--accent), 0 0 40px var(--accent); animation: stamp 2.6s ease-out both 0.7s; }
.intro-sub { color: var(--muted); font-size: 1.05rem; animation: fade-in 0.4s both 0.9s; }
.intro-skip { color: #5d7398; font-size: 0.8rem; margin-top: 8px; }
.tile.back.flying { position: fixed; z-index: 36; --w: 22px; margin: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .nebula, .planet, .planet-body, .moon, .die, .intro-title, .intro-bot, .alert-light, .window-frame { animation: none !important; }
}
/* 加了觀景窗框、資訊列和手牌工具列後，牌桌要再縮一點 */
.board { --S: min(calc(100vw - 52px), calc(100dvh - var(--tw) * 1.9 - 170px)); }
.board-wrap { padding-top: 24px; }
.hud { top: 22px; right: 24px; }
.chat-panel { top: 74px; right: 24px; }
.frame-label.right { right: 200px; }
@media (max-width: 700px) {
  .frame-label.right { display: none; }
  .frame-label.left { left: 24px; }
  .game-info { margin-top: 70px; }
}

/* 房間規則設定 */
.rules-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 14px; width: 100%; }
.rules-form .switch-row { grid-column: 1 / -1; font-weight: 400; }
.rules-form select:disabled, .rules-form input:disabled + .switch { opacity: 0.55; cursor: default; }

/* 倒數計時 */
.countdown {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid var(--accent); color: var(--accent); font-weight: 800; font-variant-numeric: tabular-nums;
}
.countdown.urgent { border-color: var(--danger); color: var(--danger); animation: pulse 0.5s ease-in-out infinite alternate; }

.tenpai-hint .passed { color: var(--danger); margin-left: 6px; }

/* 戰績、回放 */
.sheet { z-index: 25; }
.card.wide { width: min(760px, calc(100vw - 32px)); }
.table-scroll { overflow-x: auto; width: 100%; }
.scores.history td, .scores.history th { white-space: nowrap; font-size: 0.85rem; padding: 5px 6px; }
.scores tr.total td { font-weight: 800; border-bottom: 0; }
.row-links { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.game-info #btn-history { margin-top: 6px; width: 100%; }
body[data-replay="1"] .actions { border-top-color: var(--yellow); }

/* 金幣、場次、台數表 */
.wallet-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); }
.wallet-row b { color: var(--yellow); font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.seat-coins { margin-left: auto; color: var(--yellow); font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.seat-coins.short { color: var(--danger); }
.level-note { grid-column: 1 / -1; text-align: left; font-size: 0.85rem; }
.level-note .warn { color: var(--danger); }
.tai-btn { grid-column: 1 / -1; justify-self: start; }
.tai-table td, .tai-table th { text-align: left; font-size: 0.85rem; padding: 5px 8px; }
.tai-table .tai-group th { color: var(--accent); font-weight: 800; padding-top: 12px; }
.tai-table .tai-n { white-space: nowrap; color: var(--yellow); }
.tai-table .tai-desc { color: var(--muted); }
.next-in { font-weight: 400; font-size: 0.85em; margin-left: 4px; }
