:root {
  --bg: #0b1016; --panel: rgba(16, 22, 31, .82); --panel-solid: #141b26; --text: #f1ece2; --dim: #8f9aab; --line: rgba(255, 220, 160, .14);
  --gold: #f2c14e; --gold2: #ffdf8a; --danger: #e05a4f; --ok: #5fd39a; --catch: #ff7a59; --ice: #7deeff;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif; overflow-x: hidden; }
.hidden { display: none !important; }
button { background: linear-gradient(#34445b, #263344); color: var(--text); border: 1px solid #4a5d78; border-radius: 8px; padding: 9px 16px; font-size: 15px; font-family: inherit; cursor: pointer; box-shadow: 0 2px 0 #0008; transition: transform .08s, filter .15s; }
button:hover:not(:disabled) { filter: brightness(1.18); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .35; cursor: not-allowed; }
button.primary, button.big { background: linear-gradient(#ffd877, #e0a83a); color: #2a1a05; border-color: #ffe7a8; font-weight: 900; text-shadow: 0 1px 0 #fff6; }
button.big { font-size: 19px; padding: 12px 34px; }
button.danger { background: linear-gradient(#7a2f2a, #5a221e); border-color: var(--danger); }
button.warn { background: linear-gradient(#8a5a14, #6b4510); border-color: var(--gold); }
button.ghost { background: transparent; box-shadow: none; }
.dim { color: var(--dim); }
.ok { color: var(--ok); }

/* ---------- 開局畫面 ---------- */
#setup { position: relative; }
body:has(#game.hidden) { background: radial-gradient(ellipse at 50% 30%, #2a2033 0%, #0b1016 60%), #0b1016; }
.panel.center { max-width: 540px; margin: 8vh auto; padding: 34px 30px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; text-align: center; backdrop-filter: blur(6px); box-shadow: 0 20px 60px #000a, inset 0 1px 0 #ffffff14; }
h1 { font-family: "Noto Serif TC", serif; font-weight: 900; font-size: 44px; margin: 0 0 6px; background: linear-gradient(#fff3c4, #f2c14e 55%, #b07a1e); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 3px 0 #3a2508) drop-shadow(0 0 18px #f2c14e55); letter-spacing: 4px; }
h1 small { display: block; font-family: "Noto Sans TC", sans-serif; font-size: 14px; letter-spacing: 6px; color: var(--ice); -webkit-text-fill-color: var(--ice); filter: drop-shadow(0 0 6px #3de0ff); font-weight: 700; margin-top: 4px; }
.sub, .note { color: var(--dim); font-size: 14px; }
.form { display: flex; gap: 22px; justify-content: center; margin: 20px 0; flex-wrap: wrap; }
.form select, .form input, .join input, .linkrow input { margin-left: 8px; padding: 8px 10px; font-size: 16px; background: #0b1118; color: var(--text); border: 1px solid #3a4a60; border-radius: 8px; font-family: inherit; }
.modes { display: flex; gap: 12px; justify-content: center; align-items: center; margin: 8px 0 18px; flex-wrap: wrap; }
.join { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }
.join input { width: 120px; text-transform: uppercase; text-align: center; letter-spacing: 4px; margin-left: 0; }
.hint-join { width: 100%; color: var(--gold); margin: 0 0 4px; }
.code { color: var(--gold); letter-spacing: 8px; font-family: monospace; text-shadow: 0 0 12px #f2c14e88; }
.linkrow { display: flex; gap: 8px; margin-bottom: 10px; }
.linkrow input { flex: 1; font-size: 13px; margin-left: 0; }
.lobby-list { list-style: none; padding: 0; margin: 10px 0 18px; text-align: left; }
.lobby-list li { padding: 8px 10px; border-bottom: 1px solid var(--line); }

/* ---------- 遊戲版面 ---------- */
#game { position: relative; height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; gap: 18px; align-items: center; padding: 8px 16px; background: linear-gradient(#141b26ee, #0e141ccc); border-bottom: 1px solid var(--line); flex-wrap: wrap; z-index: 3; font-size: 14px; }
#hand-no { font-weight: 900; color: var(--gold); font-size: 16px; letter-spacing: 1px; }
.speed input { vertical-align: middle; }
.main { display: flex; gap: 0; flex: 1; min-height: 0; }
.table-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.table { position: relative; flex: 1; min-height: 420px; overflow: hidden; }

/* 3D 場景層：低解析度渲染 → pixelated 放大；上下帶狀模糊＝移軸微縮感 */
#scene3d, #scene3d-blur, .grade { position: absolute; inset: 0; }
#scene3d canvas { width: 100% !important; height: 100% !important; image-rendering: pixelated; display: block; }
#scene3d-blur { pointer-events: none; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); -webkit-mask-image: linear-gradient(#000 0%, #0000 30%, #0000 72%, #000 100%); mask-image: linear-gradient(#000 0%, #0000 30%, #0000 72%, #000 100%); }
/* 調色：暗部偏青、亮部偏暖＋暗角 */
.grade { pointer-events: none; background:
  radial-gradient(ellipse at 50% 48%, transparent 45%, rgba(0, 6, 14, .72) 100%),
  linear-gradient(rgba(30, 80, 110, .16), rgba(255, 170, 80, .06)); mix-blend-mode: normal; }

#felt-ui { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 2; pointer-events: none; }
.board { display: flex; gap: 6px; filter: drop-shadow(0 6px 8px #0009); }
.pot { position: relative; font-size: 17px; font-weight: 900; background: rgba(8, 12, 18, .72); color: var(--gold2); padding: 4px 16px 4px 10px; border-radius: 16px; border: 1px solid #f2c14e55; display: flex; align-items: center; gap: 6px; box-shadow: 0 0 16px #f2c14e33; }
.chip-ico { width: 16px; height: 16px; border-radius: 50%; background: repeating-conic-gradient(#e0483f 0 30deg, #fff 30deg 45deg); box-shadow: inset 0 0 0 3px #e0483f, 0 1px 0 #0008; }
.card { width: 62px; height: 87px; border-radius: 5px; background: #fff; box-shadow: 0 3px 8px #000a; }
.card.small { width: 42px; height: 59px; }
.card.back { background: repeating-linear-gradient(45deg, #7a1c2b 0 4px, #9c2738 4px 8px); border: 3px solid #f6efe2; box-shadow: inset 0 0 0 2px #c79b3a, 0 3px 8px #000a; }
.card.slot { background: rgba(255, 255, 255, .05); border: 1px dashed rgba(255, 240, 200, .25); box-shadow: none; }
.card.deal { animation: deal .38s cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes deal { from { transform: translateY(-40px) rotateY(90deg) scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }

#seats { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.seat { position: absolute; transform: translate(-50%, -50%); width: 196px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px 7px 8px; text-align: center; font-size: 13px; backdrop-filter: blur(4px); box-shadow: 0 8px 20px #0009; transition: box-shadow .2s, border-color .2s, left .3s, top .3s; }
.seat .avatar { position: absolute; left: -14px; top: -14px; width: 40px; height: 40px; image-rendering: pixelated; border-radius: 8px; border: 2px solid #000; box-shadow: 0 0 0 1px #f2c14e66, 0 3px 6px #000a; }
.seat.me { border-color: #6c9cf0aa; box-shadow: 0 0 0 1px #6c9cf055, 0 8px 20px #0009; }
.seat.acting { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), 0 0 22px #f2c14e88; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 2px var(--gold), 0 0 34px #f2c14ecc; } }
.seat.folded { opacity: .42; filter: grayscale(.6); }
.seat.frozen { opacity: .5; }
.seat .name { font-weight: 700; font-size: 14px; margin-bottom: 3px; padding-left: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .cards { display: flex; gap: 4px; justify-content: center; min-height: 59px; align-items: center; }
.seat .stats { margin-top: 3px; }
.seat .stats.small { font-size: 11px; color: var(--dim); }
.seat .bet { position: absolute; left: 50%; bottom: -24px; transform: translateX(-50%); background: linear-gradient(#ffe08a, #e8b13f); color: #2a1a05; font-weight: 900; padding: 1px 10px; border-radius: 10px; white-space: nowrap; box-shadow: 0 2px 6px #0008; }
.seat .escrow { font-size: 11px; color: var(--catch); }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 8px; background: #33445a; margin-left: 2px; font-weight: 400; }
.tag.dealer { background: #fff; color: #000; font-weight: 900; }
.tag.lock { background: #8a3424; box-shadow: 0 0 8px #ff7a5988; }
.tag.caught { background: #5c2a6b; box-shadow: 0 0 8px #b06bff88; }
.tag.fire { background: #9a5a00; box-shadow: 0 0 8px #ffb34788; }

.actions { position: relative; z-index: 3; background: linear-gradient(#141b26f0, #0e141cf0); border-top: 1px solid var(--line); padding: 10px 14px; }
.actions .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.actions input[type=number] { width: 92px; padding: 8px; font-size: 15px; background: #0b1118; color: var(--text); border: 1px solid #3a4a60; border-radius: 8px; }
.hint { font-size: 14px; margin-bottom: 6px; text-align: center; }
.declare { font-size: 14px; color: var(--gold); }

.side { width: 330px; background: linear-gradient(#121924, #0d131b); border-left: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; z-index: 3; }
.side h3 { margin: 0 0 6px; font-size: 15px; color: var(--gold); }
#log { overflow-y: auto; flex: 1; font-size: 13px; line-height: 1.55; }
.log-line { padding: 2px 0; border-bottom: 1px solid #ffffff08; }
.log-line.hand { color: var(--gold); font-weight: 700; margin-top: 6px; }
.log-line.street { color: #8fd3ff; }
.log-line.catch { color: var(--catch); font-weight: 700; }
.log-line.allin { color: #ffb347; font-weight: 700; }
.log-line.settle { color: #cfe8d5; }
.log-line.sys { color: #b9a8ff; }
.log-line.dim { color: var(--dim); }

/* ---------- 特效層 ---------- */
#fx-layer { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 20; image-rendering: pixelated; }
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 19; opacity: 0; mix-blend-mode: screen; }
#flash.on { animation: flash .35s ease-out; }
@keyframes flash { 0% { opacity: .55; } 100% { opacity: 0; } }
#game.shaking { animation: shake .42s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  10%, 90% { transform: translate(calc(var(--shake) * -.25), 0) rotate(-.2deg); }
  20%, 80% { transform: translate(calc(var(--shake) * .5), calc(var(--shake) * .25)); }
  30%, 50%, 70% { transform: translate(calc(var(--shake) * -1), 0) rotate(.3deg); }
  40%, 60% { transform: translate(var(--shake), calc(var(--shake) * -.25)); }
}
.banner { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.6); z-index: 21; pointer-events: none; opacity: 0; font-size: 30px; font-weight: 900; padding: 10px 28px; border-radius: 14px; white-space: nowrap; background: rgba(8, 10, 16, .82); border: 2px solid var(--gold); color: #fff; text-shadow: 0 2px 0 #000; box-shadow: 0 0 40px #f2c14e66; transition: none; }
.banner.show { animation: bannerIn 1.6s cubic-bezier(.2, .9, .3, 1.1) forwards; }
.banner.catch { border-color: var(--ice); box-shadow: 0 0 40px #3de0ff88; }
.banner.fire { border-color: #ff9a3d; box-shadow: 0 0 40px #ff7a2a99; }
.banner.lose { border-color: #b06bff; box-shadow: 0 0 40px #8a3bc299; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(.96); }
}

/* ---------- 視窗 ---------- */
.modal { position: fixed; inset: 0; background: #000b; display: flex; align-items: center; justify-content: center; z-index: 30; backdrop-filter: blur(3px); }
.modal .box { background: var(--panel-solid); border: 1px solid #f2c14e55; border-radius: 14px; padding: 22px; max-width: 480px; margin: 16px; line-height: 1.65; box-shadow: 0 20px 60px #000c, 0 0 30px #f2c14e22; }
.modal .box.wide { max-width: 660px; }
.modal h2 { font-family: "Noto Serif TC", serif; color: var(--gold); margin-top: 0; }
.modal .row { display: flex; gap: 12px; justify-content: flex-end; margin-top: 16px; }
table.rank { width: 100%; border-collapse: collapse; }
table.rank th, table.rank td { padding: 7px; border-bottom: 1px solid var(--line); text-align: center; }
table.rank tr:nth-child(2) td { color: var(--gold2); font-weight: 900; }

.drawer { position: fixed; right: 12px; top: 56px; width: 380px; max-width: calc(100vw - 24px); max-height: 80vh; overflow-y: auto; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; padding: 14px 18px; z-index: 25; font-size: 14px; line-height: 1.65; box-shadow: 0 8px 30px #000a; }
.credit { font-size: 12px; color: var(--dim); }
.credit a { color: #8fb8ff; }

/* ---------- 手機 ---------- */
@media (max-width: 900px) {
  #game { height: auto; min-height: 100vh; }
  .main { flex-direction: column; }
  .table { min-height: 72vh; }
  .side { width: auto; height: 220px; border-left: 0; border-top: 1px solid var(--line); }
  .seat { width: 128px; font-size: 10.5px; padding: 4px 5px; }
  .seat .avatar { width: 28px; height: 28px; left: -9px; top: -9px; }
  .seat .name { font-size: 11.5px; padding-left: 14px; }
  .seat .cards { min-height: 42px; }
  .seat .stats.small { display: none; }
  .card { width: 40px; height: 56px; }
  .card.small { width: 30px; height: 42px; }
  .banner { font-size: 20px; padding: 8px 16px; }
  h1 { font-size: 34px; }
  .topbar { gap: 10px; font-size: 12px; padding: 6px 10px; flex-wrap: nowrap; }
  .topbar .speed { font-size: 0; }
  .topbar .speed input { width: 64px; }
  .topbar > * { white-space: nowrap; }
  #hand-no { font-size: 14px; }
  .topbar button { padding: 5px 10px; font-size: 13px; }
  .actions { position: sticky; bottom: 0; padding: 8px; }
  .actions .row { gap: 6px; }
  .actions button { padding: 9px 12px; }
  .actions input[type=number] { width: 70px; }
}

/* 回合倒數 */
.timer { position: relative; height: 16px; background: #0008; border: 1px solid #ffffff22; border-radius: 8px; overflow: hidden; margin: 2px auto 8px; max-width: 520px; }
.timer .fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #3de0ff, #5fd39a); }
.timer.urgent .fill { background: linear-gradient(90deg, #ff5d5d, #ffb347); animation: blink .5s steps(2) infinite; }
.timer span { position: relative; display: block; text-align: center; font-size: 11px; line-height: 16px; font-weight: 700; text-shadow: 0 1px 0 #000; }
@keyframes blink { 50% { opacity: .55; } }
