/* ============================================================
   STOP&GO RPG — 4P Board Game
   Mobile-style glass HUD: the whole play surface is the 3D board,
   with floating bars, a party panel and a bottom action dock.
   ============================================================ */

:root {
  --bg:          #0d1226;
  --bg2:         #141b3d;
  --panel:       rgba(16, 20, 46, .78);
  --panel-solid: #1a2148;
  --panel2:      #232b56;
  --stroke:      rgba(150, 170, 255, .18);
  --stroke-hi:   rgba(170, 190, 255, .38);

  --accent:      #7c5cff;
  --accent2:     #ff5c8a;
  --accent3:     #38e8c0;
  --gold:        #ffc93c;
  --warn:        #ffb020;
  --good:        #46e08a;
  --bad:         #ff5f6d;
  --info:        #4bc8ff;

  --text:        #eef1ff;
  --muted:       #9aa6d8;

  --seat0: #7c5cff;
  --seat1: #ff5c8a;
  --seat2: #38e8c0;
  --seat3: #ffc93c;

  --radius: 16px;
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, .40);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, "Noto Sans Thai", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
#app { width: 100%; min-height: 100vh; }
.hidden { display: none !important; }
.screen { display: none; height: 100vh; }
.screen.active { display: block; }

button { font-family: inherit; cursor: pointer; border: none; color: inherit; }
button:disabled { cursor: not-allowed; }
input { font-family: inherit; }

/* ============================ LOBBY ============================ */
.lobby-bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(1200px 700px at 18% 12%, rgba(124, 92, 255, .30), transparent 62%),
    radial-gradient(1000px 620px at 84% 78%, rgba(56, 232, 192, .18), transparent 60%),
    radial-gradient(800px 500px at 50% 110%, rgba(255, 92, 138, .18), transparent 62%),
    linear-gradient(160deg, #0d1226 0%, #141b3d 55%, #0b1024 100%);
}
.lobby-bg::after {
  content: ""; position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 50% 45%, #000 25%, transparent 78%);
}
.lobby-card {
  position: relative; z-index: 1;
  max-width: 440px; margin: 0 auto; padding: 34px 32px 30px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--stroke);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: cardIn .45s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes cardIn { from { opacity: 0; transform: translateY(18px) scale(.97); } }

.lobby-badge {
  display: inline-block; padding: 4px 14px; margin-bottom: 14px;
  font-size: 11px; font-weight: 800; letter-spacing: 2px;
  color: #0d1226;
  background: linear-gradient(135deg, var(--gold), #ffe08a);
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(255, 201, 60, .35);
}
.lobby-title {
  margin: 0 0 4px; font-size: 40px; font-weight: 900; letter-spacing: 1px;
  background: linear-gradient(135deg, #fff 10%, var(--accent) 55%, var(--accent2) 95%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 34px rgba(124, 92, 255, .35);
}
.lobby-title span { font-size: 24px; vertical-align: super; opacity: .85; }
.lobby-sub { margin: 0 0 22px; color: var(--muted); font-size: 13px; }

.field { text-align: left; margin-bottom: 14px; }
.field label {
  display: block; margin-bottom: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: 1px; color: var(--muted);
}
.field-row { display: flex; gap: 8px; align-items: stretch; }
.field-row input { flex: 1; }
input {
  width: 100%; padding: 12px 14px;
  background: rgba(8, 11, 26, .7);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  color: var(--text); font-size: 15px;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, .22); }
input::placeholder { color: rgba(154, 166, 216, .6); }

.btn {
  padding: 11px 20px; border-radius: 12px;
  font-size: 14px; font-weight: 700; letter-spacing: .3px;
  transition: transform .12s, filter .18s, box-shadow .18s;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), #9d7cff);
  box-shadow: 0 8px 22px rgba(124, 92, 255, .42);
}
.btn-secondary {
  background: rgba(255,255,255,.08);
  border: 1px solid var(--stroke-hi);
  box-shadow: var(--shadow-sm);
}
.btn-lg { width: 100%; padding: 14px; font-size: 16px; }

.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0; color: var(--muted); font-size: 11px; letter-spacing: 2px;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--stroke-hi), transparent);
}

.msg { min-height: 20px; margin-top: 10px; color: var(--warn); font-size: 13px; font-weight: 600; }

.room-info {
  margin-top: 18px; padding: 14px;
  background: rgba(8, 11, 26, .55);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  text-align: left;
}
.room-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.room-label { font-size: 11px; letter-spacing: 2px; color: var(--muted); font-weight: 700; }
.room-code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 18px; font-weight: 800; color: var(--gold);
  text-shadow: 0 0 14px rgba(255, 201, 60, .45);
}
#playerList { list-style: none; padding: 0; margin: 0 0 12px; }
#playerList li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 0; font-size: 13px;
  border-bottom: 1px solid rgba(140,160,255,.10);
}
#playerList li:last-child { border-bottom: none; }
#playerList li::before {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  background: var(--seat0); box-shadow: 0 0 8px currentColor;
}
#playerList li:nth-child(2)::before { background: var(--seat1); }
#playerList li:nth-child(3)::before { background: var(--seat2); }
#playerList li:nth-child(4)::before { background: var(--seat3); }
#startBtn { width: 100%; }

/* ============================ GAME SHELL ============================
   The 3D board fills the entire viewport; every UI block floats above
   it like a mobile game HUD. */
.game-shell {
  position: relative;
  height: 100vh;
  width: 100%;
  min-width: 100%;
  background:
    radial-gradient(1100px 640px at 50% 8%, rgba(124, 92, 255, .20), transparent 62%),
    radial-gradient(900px 560px at 12% 88%, rgba(56, 232, 192, .12), transparent 60%),
    linear-gradient(170deg, #0d1226, #101634 60%, #0a0e20);
}

/* ---------------- Floating top bar ---------------- */
.top-bar {
  position: absolute; top: 12px; left: 12px; right: 12px;
  z-index: 60;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 8px 14px;
  background: rgba(10, 14, 32, .55);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  pointer-events: none;
}
.top-left, .top-right { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.top-right { justify-content: flex-end; }
.top-center { flex: 0 1 auto; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--stroke);
  white-space: nowrap;
  pointer-events: auto;
}
.chip-room { font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--gold); }
.chip-scene {
  background: linear-gradient(135deg, rgba(56,232,192,.28), rgba(124,92,255,.26));
  border-color: rgba(56,232,192,.5);
  color: #d9fff2;
}
.chip-surrender {
  cursor: pointer;
  background: rgba(255, 95, 109, .18);
  border-color: rgba(255, 95, 109, .55);
  color: #ffc9ce;
  font-family: inherit;
}
.chip-surrender:hover { background: rgba(255, 95, 109, .34); color: #fff; }
.chip-surrender.is-armed {
  background: linear-gradient(135deg, #ff5f6d, #ff8f98);
  border-color: transparent;
  color: #2a0509;
  font-weight: 900;
  animation: armedPulse .7s ease-in-out infinite alternate;
}
@keyframes armedPulse { to { filter: brightness(1.18); } }

/* Leave the room / back to the lobby */
.chip-leave {
  cursor: pointer;
  background: rgba(140, 170, 255, .16);
  border-color: rgba(140, 170, 255, .5);
  color: #cfe0ff;
  font-family: inherit;
}
.chip-leave:hover { background: rgba(140, 170, 255, .32); color: #fff; }

/* Upgrade + log buttons in the top bar */
.chip-upgrade, .chip-log {
  cursor: pointer; font-family: inherit;
  background: rgba(56, 232, 192, .16);
  border-color: rgba(56, 232, 192, .5);
  color: #b8ffe9;
}
.chip-upgrade:hover, .chip-log:hover { background: rgba(56, 232, 192, .3); color: #fff; }
.chip-upgrade.has-points {
  background: linear-gradient(135deg, #2fd39b, #52efc0);
  border-color: transparent; color: #06251b; font-weight: 900;
  animation: armedPulse .8s ease-in-out infinite alternate;
}
.chip-upgrade .up-badge {
  display: inline-block; margin-left: 5px;
  min-width: 16px; padding: 0 4px;
  border-radius: 999px; font-size: 9.5px; font-weight: 900;
  background: #06251b; color: #52efc0;
}

/* Floating CRITICAL! tag for critical hits */
.crit-float {
  position: absolute; z-index: 12;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: 15px; font-weight: 900; letter-spacing: 1.2px;
  color: #ffe066;
  text-shadow: 0 0 12px rgba(255, 201, 60, .95), 0 2px 4px rgba(0,0,0,.85);
  animation: critPop 1.15s cubic-bezier(.2,.9,.3,1.3) forwards;
}
@keyframes critPop {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); }
  18% { opacity: 1; transform: translate(-50%, -60%) scale(1.18); }
  70% { opacity: 1; transform: translate(-50%, -110%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(.92); }
}
.dmg-popup.crit { font-size: 18px; font-weight: 900; }
.battle-log .blocked { color: #9fb4e8; }

/* Trap tag floating above a trap tile */
.hud-label.trap-tag {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 9.5px; font-weight: 900;
  color: #fff;
  background: rgba(8, 11, 26, .86);
  border: 1px solid var(--trap-color, #ff8f3c);
  box-shadow: 0 0 12px color-mix(in srgb, var(--trap-color, #ff8f3c) 60%, transparent);
  pointer-events: none;
  white-space: nowrap;
}
.hud-label.trap-tag .trap-own { color: var(--trap-color, #ff8f3c); }

/* ---------- Turn countdown ---------- */
.turn-timer-bar {
  position: absolute; top: 52px; left: 50%; transform: translateX(-50%);
  z-index: 62;
  width: min(320px, 46vw); height: 7px;
  border-radius: 999px;
  background: rgba(8, 11, 26, .72);
  border: 1px solid var(--stroke);
  pointer-events: none;
}
.turn-timer-bar > i {
  display: block; height: 100%; width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #38e8c0, #7cffdc);
  transition: width .2s linear, background .3s;
}
/* The seconds readout sits outside the track, so the track must not clip. */
.turn-timer-bar > span {
  position: absolute; right: -52px; top: -8px;
  font-size: 11px; font-weight: 900; color: #eaf3ff;
  min-width: 42px; padding: 2px 7px;
  border-radius: 999px;
  background: rgba(8, 11, 26, .9);
  border: 1px solid var(--stroke);
  text-align: center;
  letter-spacing: .3px;
}
.turn-timer-bar.is-urgent > i { background: linear-gradient(90deg, #ff5f6d, #ff9aa3); }
.turn-timer-bar.is-urgent > span { color: #ffb3ba; }
.turn-timer-bar.is-mine { border-color: rgba(255, 201, 60, .55); }
.chip-turn .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--good); box-shadow: 0 0 10px var(--good);
  animation: pulseDot 1.5s ease-in-out infinite;
}
@keyframes pulseDot { 50% { opacity: .35; transform: scale(.8); } }
.chip-phase {
  background: linear-gradient(135deg, rgba(124,92,255,.34), rgba(255,92,138,.30));
  border-color: var(--stroke-hi);
  letter-spacing: 1.4px; font-size: 10.5px;
}
.status-pill {
  padding: 6px 16px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  text-align: center;
}

/* ---------------- Stage (full-screen board area) ---------------- */
.stage {
  position: fixed; inset: 0;
  overflow: hidden;
  padding: 0;
}
/* Soft vignette so the HUD reads like a mobile game full-screen. */
.stage::after {
  content: ""; position: absolute; inset: 0; z-index: 5;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 55%, rgba(4, 6, 18, .42) 100%);
}
.board {
  position: absolute; inset: 0;
  background: #070b18;
}
/* The board canvas must always fill its container */
.board > canvas {
  position: absolute; inset: 0;
  width: 100% !important; height: 100% !important; display: block;
  z-index: 1;
}

/* Live HUD nameplate above every token: name + HP + SP bars */
.hud-label {
  position: absolute; z-index: 9;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: pointer;
  text-align: center;
  font-weight: 800;
  font-size: 10.5px;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,.9), 0 0 8px rgba(0,0,0,.6);
  white-space: nowrap;
  transition: left .4s cubic-bezier(.2,.9,.3,1), top .4s cubic-bezier(.2,.9,.3,1);
  padding: 2px 6px 3px;
  border-radius: 9px;
  background: rgba(8, 11, 26, .62);
  border: 1px solid rgba(255,255,255,.10);
}
.hud-label .hud-name { opacity: .96; }
.hud-label.is-self { border-color: rgba(124, 92, 255, .75); }
.hud-label .hud-bars {
  display: flex; flex-direction: column; gap: 2px; margin-top: 2px;
}
.hud-label .hud-bar {
  position: relative;
  width: 46px; height: 4px; margin: 0 auto;
  border-radius: 3px;
  background: rgba(0,0,0,.62);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.10);
}
.hud-label .hud-bar > i {
  position: absolute; inset: 0 auto 0 0;
  display: block; height: 100%;
  border-radius: 3px;
  transition: width .35s ease;
}
.hud-label .hud-bar.hp > i { background: linear-gradient(90deg, #ff5f6d, #ff9aa3); }
.hud-label .hud-bar.sp > i { background: linear-gradient(90deg, #7c5cff, #a58cff); }
.hud-label.dead { filter: grayscale(.9) opacity(.6); }

/* Monster level badge + HP bar floating above each monster */
.hud-label.monster {
  z-index: 10;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.hud-label.monster .hud-lv {
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10px; font-weight: 900; letter-spacing: .5px;
  color: #fff;
  background: rgba(8, 11, 26, .82);
  border: 1px solid rgba(255, 255, 255, .28);
  box-shadow: 0 2px 8px rgba(0,0,0,.55);
}
.hud-label.monster .hud-bar {
  position: relative;
  width: 52px; height: 6px; margin: 0 auto;
  border-radius: 4px;
  background: rgba(0,0,0,.72);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22), 0 2px 6px rgba(0,0,0,.5);
}
.hud-label.monster .hud-bar > i {
  position: absolute; inset: 0 auto 0 0;
  display: block; height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #ff3d5f, #ff8f6b);
  transition: width .35s ease;
}
.hud-label.monster[data-tier="low"] .hud-lv { border-color: #63e6a0; color: #b6ffd8; }
.hud-label.monster[data-tier="mid"] .hud-lv { border-color: #ffa53c; color: #ffd9a3; }
.hud-label.monster[data-tier="high"] .hud-lv { border-color: #ff4d6d; color: #ffc0cb; }

/* ---------- Focused profile (top centre) ---------- */
.focus-profile {
  position: absolute; top: 60px; left: 50%; transform: translateX(-50%);
  z-index: 68;
  min-width: 272px; max-width: min(430px, 54vw);
  padding: 10px 14px 11px;
  background: linear-gradient(160deg, rgba(30, 26, 62, .94), rgba(13, 17, 38, .94));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--stroke-hi);
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.08);
  animation: focusIn .28s cubic-bezier(.2,.9,.3,1.3);
  pointer-events: auto;
}
@keyframes focusIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-12px) scale(.96); }
}
.fp-head { display: flex; align-items: center; gap: 9px; margin-bottom: 7px; }
.fp-badge {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 900; color: #0d1226;
  background: linear-gradient(135deg, #ffe08a, var(--gold));
  box-shadow: 0 4px 14px rgba(255,201,60,.35);
}
.fp-badge.monster { background: linear-gradient(135deg, #ff8fa3, var(--bad)); color: #2a0509; }
.fp-name { font-size: 14px; font-weight: 900; line-height: 1.15; }
.fp-sub { font-size: 10px; color: var(--muted); font-weight: 700; }
.fp-close {
  margin-left: auto; width: 22px; height: 22px; border-radius: 7px;
  background: rgba(255,255,255,.08); font-size: 11px; line-height: 1;
  flex: 0 0 auto;
}
.fp-close:hover { background: rgba(255,95,109,.3); }
.fp-bar-row { display: flex; align-items: center; gap: 7px; margin: 3px 0; }
.fp-bar-row .lbl { width: 20px; font-size: 9px; font-weight: 900; color: var(--muted); }
.fp-bar-row .val { font-size: 10px; font-weight: 800; min-width: 58px; }
.fp-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 7px; }
.fp-stats div {
  background: rgba(0,0,0,.32); border-radius: 6px;
  padding: 3px 2px; text-align: center;
  font-size: 8.5px; font-weight: 800; color: var(--muted);
}
.fp-stats b { display: block; color: var(--text); font-size: 10px; }
.fp-skills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
/* One puck per skill: the 3D icon plus its level, nothing else. */
.fp-skill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px 2px 3px; border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(160,180,255,.18);
}
.fp-skill .sk-icon, .fp-skill .icon3d { width: 18px; height: 18px; }
.fp-skill b { font-size: 9.5px; font-weight: 900; color: var(--gold); letter-spacing: .3px; }
.fp-skill.off { opacity: .42; }
.fp-skill.off b { color: var(--muted); }

/* Skill hover tooltip: what it does now + what the next level would add. */
.skill-tip {
  position: fixed; z-index: 90;
  width: 240px; max-width: 42vw;
  padding: 9px 11px 10px;
  background: rgba(16, 20, 44, .97);
  border: 1px solid rgba(150, 170, 255, .35);
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0,0,0,.55);
  pointer-events: none;
  font-size: 10.5px; color: var(--text);
}
.skill-tip.hidden { display: none; }
.skill-tip .st-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 900; margin-bottom: 5px;
}
.skill-tip .st-head .icon3d { width: 20px; height: 20px; }
.skill-tip .st-head b {
  margin-left: auto; font-size: 9.5px; color: #06251b;
  background: linear-gradient(135deg, #2fd39b, #52efc0);
  padding: 1px 7px; border-radius: 999px;
}
.skill-tip .st-row { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.skill-tip .st-row b { color: var(--gold); }
.skill-tip .st-now { margin-top: 6px; color: #d7e2ff; line-height: 1.45; }
.skill-tip .st-next {
  margin-top: 5px; padding-top: 5px;
  border-top: 1px dashed rgba(150,170,255,.28);
  color: #b8ffe9; line-height: 1.45;
}

/* While the 3D chooser is open, dim the DOM nameplates so the cards read clearly. */
body.choosing .hud-label { opacity: .18; pointer-events: none; }

/* ---------- Target-selection hint ---------- */
.target-hint {
  position: absolute; left: 50%; bottom: calc(var(--dock-h, 0px) + 22px);
  transform: translateX(-50%);
  z-index: 66;
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 12px; font-weight: 800;
  color: #0d1226;
  background: linear-gradient(135deg, #ffe08a, var(--gold));
  box-shadow: 0 10px 28px rgba(255,201,60,.42);
  animation: hintPulse 1.5s ease-in-out infinite;
  pointer-events: none;
  white-space: nowrap;
}
@keyframes hintPulse {
  50% { box-shadow: 0 10px 34px rgba(255,201,60,.72); }
}
/* While picking, valid targets glow so it is obvious what can be clicked. */
.hud-label.targetable {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  animation: targetablePulse 1.1s ease-in-out infinite;
}
@keyframes targetablePulse {
  50% { outline-color: rgba(255,201,60,.25); }
}


/* ---------------- Floating party panel (left edge) ---------------- */
.player-rail {
  position: absolute; left: 12px; top: 76px;
  bottom: calc(var(--dock-h, 0px) + 18px);
  width: 244px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
  /* The rail itself never scrolls: each panel below scrolls on its own so the
     profile, status and skill lists never scroll away from each other. */
  overflow: hidden;
  padding-right: 2px;
}
/* One scrollable panel inside the rail. flex-basis 0 + min-height 0 lets the
   four panels share the height predictably. */
.rail-panel {
  pointer-events: auto;
  display: flex; flex-direction: column;
  flex: 1 1 0; min-height: 0;
}
.rail-panel > .hub-body,
.rail-panel > .pc-scroll {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  scrollbar-width: thin;
}
/* The profile card holds identity + vitals and scrolls on its own too. */
#selfProfile { flex: 0 1 auto; max-height: 42%; overflow-y: auto; scrollbar-width: thin; }
#selfProfile::-webkit-scrollbar { width: 5px; }
#selfProfile::-webkit-scrollbar-thumb { background: rgba(150,170,255,.34); border-radius: 3px; }
#statusCard  { flex: 1 1 0; min-height: 84px; }
#skillCard   { flex: 1.6 1 0; min-height: 96px; }
#itemCard    { flex: 1 1 0; min-height: 64px; max-height: 26%; }
.rail-panel > .hub-body::-webkit-scrollbar { width: 5px; }
.rail-panel > .hub-body::-webkit-scrollbar-thumb {
  background: rgba(150,170,255,.34); border-radius: 3px;
}
/* The old rail-card sizing is gone: each panel now uses .rail-panel (own
   scrollbar). Kept as a no-op base so existing markup still renders. */
.rail-card {
  pointer-events: auto;
  min-height: 0;
}
/* Inside the rail every card manages its own scroll (see .rail-panel). */
.hub-spacer { pointer-events: none; }
.hub-tag {
  float: right;
  padding: 1px 7px; border-radius: 999px;
  font-size: 9px; font-weight: 900; letter-spacing: 0;
  background: linear-gradient(135deg, #2fd39b, #52efc0);
  color: #06251b;
}
.hub-tag.hidden { display: none; }

/* An encounter is waiting for this player's choice: pulse the panel so the
   Fight / Flee buttons are impossible to miss (จบตา is disabled by design). */
.hub-card--skills.needs-choice {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 201, 60, .28), 0 12px 30px rgba(255, 201, 60, .22);
  animation: needsChoicePulse 1.4s ease-in-out infinite alternate;
}
@keyframes needsChoicePulse {
  to { box-shadow: 0 0 0 5px rgba(255, 201, 60, .10), 0 14px 34px rgba(255, 201, 60, .34); }
}

/* ---------------- Status upgrade rows (inside the profile card) ------- */
.up-head-row {
  display: flex; align-items: center; justify-content: space-between;
  margin: 7px 0 4px;
  padding-top: 6px;
  border-top: 1px solid rgba(140,160,255,.18);
  font-size: 9px; font-weight: 900; letter-spacing: .8px;
  color: var(--muted); text-transform: uppercase;
}
.sp-pill {
  padding: 1px 7px; border-radius: 999px;
  font-size: 9px; font-weight: 900; letter-spacing: 0;
  background: rgba(255,255,255,.09); color: var(--muted);
}
.sp-pill.has { background: linear-gradient(135deg, #2fd39b, #52efc0); color: #06251b; }
.up-stats { display: flex; flex-direction: column; gap: 2px; }
.up-stat-row {
  display: grid;
  grid-template-columns: 34px 34px 1fr 22px;
  align-items: center; gap: 4px;
  padding: 1px 0;
}
.up-stat-row .us-label { font-size: 9.5px; font-weight: 900; color: var(--text); }
.up-stat-row .us-val  { font-size: 9.5px; font-weight: 800; color: var(--gold); text-align: right; }
.up-stat-row .us-hint { font-size: 8.5px; color: #7f8cb4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-stat-row .us-plus {
  width: 20px; height: 20px; padding: 0; border-radius: 6px;
  font-size: 13px; font-weight: 900; line-height: 1;
  background: linear-gradient(160deg, #2fd39b, #14a37a);
  color: #04231a; border: none; cursor: pointer;
}
.up-stat-row .us-plus:disabled { opacity: .25; cursor: default; }
.corner-card.has-points { border-color: var(--accent3, #38e8c0); }

/* ---------------- Skill rows (left rail) ---------------- */
.skill-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px;
  align-items: stretch;
}
.skill-row > button:first-child { min-width: 0; }
.sk-up {
  flex: 0 0 auto;
  min-width: 34px; padding: 0 7px;
  border-radius: 10px;
  font-family: inherit; font-size: 10.5px; font-weight: 900;
  background: rgba(255,255,255,.08);
  border: 1px solid var(--stroke);
  color: var(--muted);
  cursor: pointer;
}
.sk-up.can {
  background: linear-gradient(160deg, #2fd39b, #14a37a);
  border-color: transparent; color: #04231a;
}
.sk-up:disabled { opacity: .3; cursor: default; }

.corner-card {
  position: relative;
  width: 100%;
  flex: 0 0 auto;
  padding: 9px 12px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  font-size: 10.5px;
  pointer-events: auto;
  transition: border-color .25s, box-shadow .25s;
}
.corner-card:empty { display: none; }
.corner-card.is-self {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 12px 34px rgba(124, 92, 255, .38);
}
.corner-card.is-active {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 12px 34px rgba(255, 201, 60, .28);
}

.pc-name {
  display: flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 12px; margin-bottom: 2px;
}
.pc-name .badge {
  margin-left: auto; padding: 1px 7px; border-radius: 999px;
  font-size: 9px; font-weight: 800; letter-spacing: 1px;
  background: rgba(255,255,255,.12); color: var(--muted);
}
.pc-meta { color: var(--muted); font-size: 9.5px; margin-bottom: 4px; }
.pc-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.pc-row .lbl { width: 20px; font-size: 9px; font-weight: 800; color: var(--muted); }
.pc-row .val { font-size: 10.5px; font-weight: 700; min-width: 46px; }
.bar {
  flex: 1; height: 7px; border-radius: 4px;
  background: rgba(0,0,0,.45); overflow: hidden;
  border: 1px solid rgba(255,255,255,.07);
}
.bar > div {
  height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--good), #7cf5b4);
  transition: width .35s cubic-bezier(.2,.9,.3,1);
}
.bar.sp > div { background: linear-gradient(90deg, var(--accent), #a58cff); }
.pc-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; margin-top: 5px;
}
.pc-stat {
  padding: 3px 2px; border-radius: 5px; text-align: center;
  background: rgba(0,0,0,.32); font-size: 8.5px; font-weight: 700;
  color: var(--muted);
}
.pc-stat b { display: block; color: var(--text); font-size: 9.5px; }
.pc-dead {
  margin-top: 5px; padding: 2px 0; border-radius: 6px; text-align: center;
  background: rgba(255,95,109,.18); color: var(--bad);
  font-weight: 800; font-size: 9.5px; letter-spacing: 1px;
}

/* ---------------- Right action column ---------------- */
.action-hub {
  position: absolute; right: 12px; top: 74px;
  bottom: calc(var(--dock-h, 0px) + 14px);
  width: 264px; z-index: 55;
  display: grid;
  /* dice · orbs · battle/log (fills the rest) */
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
  pointer-events: none;
  min-height: 0;
}

/* Dice + result */
.hub-dice {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  background: linear-gradient(160deg, rgba(38, 30, 74, .82), rgba(18, 22, 48, .82));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 201, 60, .30);
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(0,0,0,.42), inset 0 1px 0 rgba(255,255,255,.10);
}
.dice3d {
  width: 54px; height: 54px;
  perspective: 340px;
  position: relative;
  flex: 0 0 auto;
}
.cube {
  width: 54px; height: 54px; position: relative;
  transform-style: preserve-3d;
  /* Start from an explicit transform so the very first roll also animates
     (transitioning from `none` is not interpolated and would snap). */
  transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
  /* the JS sets the final transform; the transition is the tumble */
  transition: transform 1.05s cubic-bezier(.22, .72, .18, 1);
  will-change: transform;
}
.face {
  --pip: #1a2040;
  position: absolute; width: 54px; height: 54px;
  border-radius: 11px;
  background-color: #f6f8ff;
  background-repeat: no-repeat;
  background-size: 26% 26%;
  background-image: radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%);
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,.95),
    inset 0 -8px 14px rgba(96, 116, 186, .22),
    inset 0 8px 12px rgba(255,255,255,.75);
  backface-visibility: hidden;
}
/* Pip layouts */
.f1 { background-position: 50% 50%; }
.f2 { background-position: 27% 27%, 73% 73%;
      background-image:
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%); }
.f3 { background-position: 25% 25%, 50% 50%, 75% 75%;
      background-image:
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%); }
.f4 { background-position: 27% 27%, 73% 27%, 27% 73%, 73% 73%;
      background-image:
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%); }
.f5 { background-position: 27% 27%, 73% 27%, 50% 50%, 27% 73%, 73% 73%;
      background-image:
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%); }
.f6 { background-position: 27% 24%, 27% 50%, 27% 76%, 73% 24%, 73% 50%, 73% 76%;
      background-image:
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%),
        radial-gradient(circle at center, var(--pip) 0 58%, transparent 60%); }
/* Face placement (opposite faces total 7) */
.f1 { transform: translateZ(27px); }
.f6 { transform: rotateX(180deg) translateZ(27px); }
.f2 { transform: rotateY(90deg) translateZ(27px); }
.f5 { transform: rotateY(-90deg) translateZ(27px); }
.f3 { transform: rotateX(-90deg) translateZ(27px); }
.f4 { transform: rotateX(90deg) translateZ(27px); }

/* soft shadow under the die */
.dice-shadow {
  position: absolute; left: 50%; bottom: -9px;
  width: 44px; height: 10px; transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(0,0,0,.55), transparent 70%);
  pointer-events: none;
}
.hub-dice.is-rolling .cube { filter: drop-shadow(0 6px 12px rgba(255,201,60,.35)); }
.hub-dice.is-rolling .dice-shadow { opacity: .5; }
/* Tactile bounce while the die tumbles: reads clearly even on a slow GPU
   where the 3D rotation itself is hard to follow. */
@keyframes diceBounce {
  from { transform: translateY(0) scale(1); }
  to   { transform: translateY(-6px) scale(1.07); }
}
.hub-dice.is-rolling .dice3d { animation: diceBounce .15s ease-in-out infinite alternate; }
@keyframes dicePulse { from { opacity: .5; } to { opacity: 1; } }
.hub-dice.is-rolling .dice-readout small { animation: dicePulse .45s ease-in-out infinite alternate; }

.dice-readout {
  flex: 1;
  font-size: 12px; font-weight: 800; color: var(--muted);
  letter-spacing: .4px;
  text-align: center;
  min-height: 18px;
  transition: color .2s;
}
.dice-readout b {
  display: block;
  font-size: 26px; line-height: 1.05;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 201, 60, .55);
}
.dice-readout small { font-size: 10px; font-weight: 700; opacity: .8; letter-spacing: 1px; }
.dice-readout.has-result { color: var(--muted); }

/* Roll / end turn orbs */
.hub-actions {
  pointer-events: auto;
  display: flex; align-items: center; justify-content: center;
  gap: 14px;
  padding: 10px 8px;
  background: rgba(14, 18, 42, .55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--stroke);
  border-radius: 18px;
}
.orb {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 84px; height: 84px; border-radius: 50%;
  font-weight: 800; color: #fff;
  border: 3px solid rgba(255,255,255,.35);
  transition: transform .14s cubic-bezier(.2,.9,.3,1.4), filter .2s, opacity .2s, box-shadow .2s;
}
.orb-glyph { font-size: 28px; line-height: 1; filter: drop-shadow(0 3px 7px rgba(0,0,0,.5)); }
.orb-text { font-size: 11px; letter-spacing: 1.5px; margin-top: 3px; }
.orb-roll {
  background: radial-gradient(circle at 34% 26%, #ffb3d2, var(--accent2) 50%, #c62a5c 100%);
  box-shadow: 0 14px 34px rgba(255, 92, 138, .58), inset 0 -9px 20px rgba(0,0,0,.30);
}
.orb-end {
  width: 70px; height: 70px;
  background: radial-gradient(circle at 34% 26%, #b3a6ff, var(--accent) 50%, #4a2ec9 100%);
  box-shadow: 0 12px 28px rgba(124, 92, 255, .52), inset 0 -7px 18px rgba(0,0,0,.30);
}
.orb:hover:not(:disabled) { transform: scale(1.08) translateY(-3px); filter: brightness(1.12); }
.orb:active:not(:disabled) { transform: scale(.96); }
.orb:disabled { opacity: .45; filter: grayscale(.55) brightness(.75); }
.orb.is-pulse { animation: orbPulse 1.7s ease-in-out infinite; }
@keyframes orbPulse {
  50% { box-shadow: 0 16px 46px rgba(255, 92, 138, .78), inset 0 -9px 20px rgba(0,0,0,.30), 0 0 0 10px rgba(255,92,138,.12); }
}

/* Skill / item cards in the action column */
.hub-card {
  pointer-events: auto;
  display: flex; flex-direction: column; min-height: 0;
  padding: 8px 10px 10px;
  background: rgba(14, 18, 42, .70);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
/* Categories are compact and scroll internally: no percentage heights,
   because a percentage max-height against an auto grid row is unreliable. */
.hub-card--skills { max-height: min(360px, 42vh); }
/* Inside the left rail the cards stretch with the rail instead of the old
   fixed heights that were tuned for the right column. */
.player-rail .hub-card--skills,
.player-rail .hub-card--items { max-height: none; }
.hub-spacer { pointer-events: none; }
.hub-title {
  flex: 0 0 auto;
  font-size: 9.5px; font-weight: 800; letter-spacing: 1.4px;
  color: var(--muted); text-transform: uppercase;
  margin-bottom: 6px;
}
.hub-body { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; min-height: 0; }
.hub-body::-webkit-scrollbar { width: 5px; }
.hub-body::-webkit-scrollbar-thumb { background: rgba(150,170,255,.3); border-radius: 3px; }

/* ---------------- Battle HUD ---------------- */
/* The battle box is always visible at the bottom of the action column: while a
   fight runs it carries the fight header + HP bar, and underneath it always
   holds the full game log. */
.battle-hud {
  pointer-events: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}
.battle-hud-inner {
  display: flex; flex-direction: column; gap: 6px;
  min-height: 0;
  flex: 1 1 auto;
  padding: 9px 11px;
  background: rgba(20, 24, 50, .80);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--stroke-hi);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.40);
}
.battle-hud.is-fighting .battle-hud-inner {
  background: rgba(36, 16, 30, .86);
  border-color: rgba(255, 122, 150, .45);
}
.battle-hud-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.battle-hud-head h3 { margin: 0; font-size: 11px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.battle-live { font-size: 9.5px; font-weight: 800; color: var(--gold); white-space: nowrap; }
.battle-close {
  width: 22px; height: 22px; border-radius: 7px;
  background: rgba(255,255,255,.08); font-size: 11px; line-height: 1;
}
.battle-close:hover { background: rgba(255,95,109,.25); }
.battle-bar { height: 8px; flex: 0 0 auto; }
.battle-bar > div { background: linear-gradient(90deg, var(--bad), #ff9aa3); }
/* The log fills the rest of the box and scrolls on its own. */
.battle-log {
  flex: 1 1 auto;
  min-height: 70px;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 10.5px; line-height: 1.5;
  display: flex; flex-direction: column; gap: 2px;
  padding-right: 2px;
}
.battle-log::-webkit-scrollbar { width: 5px; }
.battle-log::-webkit-scrollbar-thumb { background: rgba(150,170,255,.3); border-radius: 3px; }
.battle-log .log-line { color: #d7e2ff; word-break: break-word; }
.battle-log .log-line .log-time { color: #6d7ba6; font-size: 9.5px; margin-right: 5px; }
.battle-log .log-line.k-combat { color: #ffc7cf; }
.battle-log .log-line.k-trap { color: #ffd9a3; }
.battle-log .log-line.k-item { color: #c9f3ff; }
.battle-log .log-line.k-turn { color: #9fb4e8; }
.battle-log .log-line.k-stat { color: #b8ffe9; }
.battle-log .log-line.k-death { color: #ff9aa3; font-weight: 800; }
.battle-log .log-line.k-game { color: #ffe9a8; font-weight: 800; }
.battle-log .log-empty { color: var(--muted); font-size: 10.5px; }
.damage-floats { position: relative; height: 22px; flex: 0 0 auto; }
.dmg-popup {
  position: absolute; font-weight: 800; font-size: 17px;
  animation: floatUp .85s forwards; pointer-events: none;
}
@keyframes floatUp { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-34px); } }

/* ---------------- Bottom bar (retired) ----------------
   Stat points are now spent inside the profile card and skills inside the skill
   list, so the bottom dock no longer exists. `--dock-h` stays for layout. */
.hint { color: var(--muted); font-size: 11px; }

/* Skills live in the left rail: stack them as full-width buttons. */
.hub-skills {
  display: flex; flex-direction: column; gap: 6px;
  align-items: stretch;
}
.hub-skills button {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: 10px;
  font-size: 11px; font-weight: 700;
  text-align: left;
  color: var(--text);
  background: rgba(24, 31, 66, .88);
  border: 1px solid var(--stroke-hi);
  box-shadow: var(--shadow-sm);
  transition: transform .12s, filter .18s, opacity .18s;
}
.hub-skills button:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.18); }
.hub-skills button:disabled { opacity: .38; }
.hub-skills button .sk-lv {
  flex: 0 0 auto;
  padding: 1px 7px; border-radius: 999px;
  font-size: 9px; font-weight: 900;
  background: rgba(0,0,0,.35);
  color: var(--gold);
}
.hub-skills button.is-primary {
  background: linear-gradient(135deg, rgba(124,92,255,.9), rgba(157,124,255,.9));
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(124, 92, 255, .45);
}
.hub-skills button.is-danger {
  background: linear-gradient(135deg, rgba(255,92,138,.92), rgba(255,133,173,.92));
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(255, 92, 138, .40);
}
.hub-skills button.is-good {
  background: linear-gradient(135deg, #2fd39b, #52efc0);
  border-color: transparent; color: #06251b;
  box-shadow: 0 6px 18px rgba(56, 232, 192, .38);
}
.hub-skills button.is-good .sk-lv { background: rgba(255,255,255,.45); color: #06251b; }
/* Locked skills: dim, dashed, and only clickable when a stat point is free. */
.hub-skills button.is-locked {
  background: rgba(255,255,255,.05);
  border: 1px dashed rgba(255, 201, 60, .55);
  color: #ffd977;
  box-shadow: none;
  opacity: .95;
}
.hub-skills button.is-locked:hover:not(:disabled) {
  background: rgba(255, 201, 60, .18);
  border-color: var(--gold);
}

/* Encounter / initiative note shown in place of the skill buttons */
.init-note {
  width: 100%;
  padding: 8px 10px; margin-bottom: 2px;
  text-align: center; font-size: 11px; line-height: 1.55;
  color: var(--text);
  background: rgba(24, 31, 66, .95);
  border: 1px solid var(--gold);
  border-radius: 10px;
  box-shadow: 0 8px 26px rgba(255, 201, 60, .22);
  animation: popIn .35s cubic-bezier(.2,.9,.3,1.35);
}
.init-note b { color: var(--gold); font-size: 14px; }
/* Compact variant used during a fight: two short lines instead of a banner. */
.init-note.compact {
  padding: 5px 8px; font-size: 9.5px; line-height: 1.45;
  text-align: left; box-shadow: none;
}
.init-note.compact b { font-size: 11px; }
.hub-skills .sk-name { flex: 1 1 auto; min-width: 0; }
.hub-skills button .sk-icon { flex: 0 0 auto; }

/* ---------- 3D icon puck (skills + items) ---------- */
.icon3d {
  --tint: #8fa8d8;
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  flex: 0 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 24%, rgba(255,255,255,.92) 0 11%, rgba(255,255,255,.30) 34%, rgba(255,255,255,0) 58%),
    linear-gradient(158deg, var(--tint) 0%, rgba(10, 14, 30, .72) 128%);
  box-shadow:
    inset 0 2px 2px rgba(255,255,255,.6),
    inset 0 -4px 7px rgba(0,0,0,.55),
    0 3px 7px rgba(0,0,0,.55);
  transform: translateZ(0);
}
.icon3d::before {
  /* Specular ring + a soft bounce light from below = rounded 3D puck. */
  content: "";
  position: absolute; inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 118%, rgba(255,255,255,.45) 0 26%, transparent 58%);
  pointer-events: none;
}
.icon3d::after {
  content: "";
  position: absolute; inset: 1px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,.42);
  pointer-events: none;
}
.icon3d-face {
  position: relative; z-index: 1;
  width: 70%; height: 70%;
  display: flex; align-items: center; justify-content: center;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.55));
}
.icon3d-face svg { width: 100%; height: 100%; display: block; }
/* Bigger puck for the item cards. */
.item-card .icon3d { width: 34px; height: 34px; }
.hub-skills button:hover:not(:disabled) .icon3d,
.item-card:hover:not(:disabled) .icon3d {
  transform: translateY(-1px) scale(1.06);
  transition: transform .14s;
}

/* Encounter choice buttons carry icons too. */
.hub-skills button.has-icon {
  justify-content: flex-start; gap: 10px;
}
.hub-skills button.has-icon .sk-name { flex: 1 1 auto; font-size: 12px; }

/* The player's own dice roll when a fight / flee needs deciding. */
.encounter-roll {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 10px; border-radius: 14px;
  font-family: inherit; font-size: 14px; font-weight: 900; letter-spacing: .4px;
  color: #22130a;
  background: linear-gradient(160deg, #ffe9a8 0%, #ffc93c 46%, #f59f00 100%);
  border: 1px solid #ffe08a;
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,.85),
    inset 0 -3px 8px rgba(150,80,0,.45),
    0 10px 24px rgba(255, 201, 60, .45),
    0 0 0 3px rgba(255, 201, 60, .14);
  cursor: pointer;
  animation: rollPulse 1.1s ease-in-out infinite alternate;
}
.encounter-roll .er-die {
  font-size: 20px;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.35));
  animation: dieWiggle 1.1s ease-in-out infinite;
}
@keyframes rollPulse { to { filter: brightness(1.1); box-shadow: inset 0 2px 0 rgba(255,255,255,.9), 0 14px 30px rgba(255,201,60,.6); } }
@keyframes dieWiggle { 50% { transform: rotate(-14deg) translateY(-1px); } }
.encounter-roll:disabled { opacity: .55; animation: none; cursor: default; }


.init-who { font-weight: 800; color: var(--good); letter-spacing: .5px; }
@keyframes popIn { from { opacity: 0; transform: scale(.9); } }
.hub-skills button.is-locked:disabled { opacity: .45; }

/* Items in the narrow right column: stacked icon cards. */
.item-list { display: flex; flex-direction: column; gap: 6px; }
.item-list button {
  width: 100%;
  display: flex; align-items: center; gap: 9px;
  text-align: left;
  padding: 6px 9px; border-radius: 10px; font-size: 11px; font-weight: 700;
  color: var(--text);
  background: rgba(255,255,255,.07); border: 1px solid var(--stroke);
  transition: background .15s, border-color .15s, transform .12s;
}
.item-list button:hover:not(:disabled) { background: rgba(255,201,60,.18); border-color: var(--gold); transform: translateY(-1px); }
.item-list button:disabled { opacity: .4; }
.item-list .item-name { flex: 1 1 auto; min-width: 0; }
.item-list .none { color: var(--muted); font-size: 11px; }

/* Legacy stat-grid classes (the bottom dock is retired). */

/* ---------------- Target picker ---------------- */
#targetPicker {
  position: fixed; inset: 0; z-index: 1200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5, 8, 20, .70); backdrop-filter: blur(6px);
}
#targetPicker > div {
  min-width: 260px; padding: 20px 24px;
  background: var(--panel-solid);
  border: 1px solid var(--stroke-hi);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
#targetPicker button {
  display: block; width: 100%;
  margin-top: 8px; padding: 10px 14px; border-radius: 11px;
  font-size: 13px; font-weight: 700;
  background: rgba(255,255,255,.08); border: 1px solid var(--stroke);
}
#targetPicker button:hover { background: rgba(124,92,255,.30); border-color: var(--accent); }

/* ---------------- Toast ---------------- */
.toast-container {
  position: fixed; top: 74px; left: 50%; transform: translateX(-50%);
  z-index: 1300;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
  max-width: 92vw;
}
.toast {
  padding: 10px 16px; border-radius: 12px;
  font-size: 12px; font-weight: 700;
  background: rgba(26, 33, 72, .95);
  border: 1px solid var(--stroke-hi);
  border-left: 3px solid var(--accent);
  box-shadow: var(--shadow-md);
  animation: toastIn .25s cubic-bezier(.2,.9,.3,1.3);
  max-width: 340px;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } }
.toast.is-bad { border-left-color: var(--bad); }
.toast.is-good { border-left-color: var(--good); }

/* Liveness banner: shown while the client is reconnecting after a dead socket. */
.conn-banner {
  position: fixed; left: 50%; top: 12px; transform: translateX(-50%);
  z-index: 1600;
  padding: 8px 16px; border-radius: 999px;
  font-size: 12px; font-weight: 800;
  background: rgba(180, 40, 60, .95); color: #fff;
  border: 1px solid rgba(255, 255, 255, .35);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .45);
}
.conn-banner.hidden { display: none; }

/* ---------------- Game over ---------------- */
#gameOverBanner {
  position: fixed; inset: 0; z-index: 1500;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5, 8, 20, .84); backdrop-filter: blur(8px);
  animation: fadeIn .4s;
}
@keyframes fadeIn { from { opacity: 0; } }
#gameOverBanner > div {
  padding: 36px 52px; text-align: center;
  background: linear-gradient(150deg, #232b56, #1a2148);
  border: 1px solid var(--gold);
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,.7), 0 0 60px rgba(255,201,60,.18);
  animation: cardIn .5s cubic-bezier(.2,.9,.3,1.25);
}
#gameOverBanner .go-title {
  font-size: 38px; font-weight: 900; letter-spacing: 4px;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(255, 201, 60, .55);
  margin-bottom: 8px;
}
#gameOverBanner .go-winner { font-size: 22px; font-weight: 800; color: var(--good); }
#gameOverBanner .go-why { margin: 6px 0 20px; color: var(--muted); font-size: 13px; }
#gameOverBanner .go-actions { display: flex; gap: 12px; justify-content: center; }
#gameOverBanner .go-actions .btn { min-width: 130px; }

/* ---------------- Encounter dice duel ---------------- */
.dice-duel {
  position: fixed; inset: 0; z-index: 900;
  display: flex; align-items: center; justify-content: center;
  background: rgba(6, 9, 22, .52);
  backdrop-filter: blur(3px);
  animation: fadeIn .18s;
}
.dd-card {
  min-width: 320px;
  padding: 18px 26px 20px;
  border-radius: 22px;
  background: linear-gradient(155deg, rgba(38, 46, 88, .97), rgba(20, 25, 52, .97));
  border: 1px solid rgba(255, 201, 60, .45);
  box-shadow: 0 26px 70px rgba(0, 0, 0, .65), 0 0 50px rgba(255, 201, 60, .14);
  text-align: center;
  animation: cardIn .32s cubic-bezier(.2, .9, .3, 1.25);
}
.dd-title {
  font-size: 12px; font-weight: 900; letter-spacing: 2.4px;
  color: var(--gold); margin-bottom: 14px; text-transform: uppercase;
}
.dd-row { display: flex; align-items: center; justify-content: center; gap: 18px; }
.dd-side { width: 118px; }
.dd-name {
  font-size: 12px; font-weight: 800; color: #e8eeff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 8px;
}
.dd-stage {
  height: 86px; display: flex; align-items: center; justify-content: center;
  perspective: 460px;
}
.dd-cube {
  width: 72px; height: 72px; position: relative;
  transform-style: preserve-3d;
  transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
  transition: transform 1s cubic-bezier(.22, .72, .18, 1);
  will-change: transform;
}
.dd-cube .face {
  width: 72px; height: 72px; border-radius: 15px;
  background-size: 24% 24%;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .95),
    inset 0 -10px 16px rgba(96, 116, 186, .24),
    inset 0 10px 14px rgba(255, 255, 255, .8);
}
.dd-cube .f1 { transform: translateZ(36px); }
.dd-cube .f6 { transform: rotateX(180deg) translateZ(36px); }
.dd-cube .f2 { transform: rotateY(90deg) translateZ(36px); }
.dd-cube .f5 { transform: rotateY(-90deg) translateZ(36px); }
.dd-cube .f3 { transform: rotateX(-90deg) translateZ(36px); }
.dd-cube .f4 { transform: rotateX(90deg) translateZ(36px); }
.dd-cube.is-enemy .face {
  --pip: #3a1220;
  background-color: #ffd9e2;
  box-shadow:
    inset 0 0 0 1px rgba(255, 220, 230, .95),
    inset 0 -10px 16px rgba(180, 60, 90, .22),
    inset 0 10px 14px rgba(255, 255, 255, .8);
}
.dd-vs {
  font-size: 13px; font-weight: 900; letter-spacing: 1.4px;
  color: rgba(255, 255, 255, .55);
}
.dd-value {
  margin-top: 8px;
  font-size: 26px; font-weight: 900; color: #fff;
  text-shadow: 0 0 18px rgba(255, 201, 60, .45);
}
.dd-outcome {
  margin-top: 12px; min-height: 22px;
  font-size: 13.5px; font-weight: 800; color: #ffe9a8;
}
.dd-outcome.bad { color: #ff9aa3; }
.dd-outcome.good { color: #8affc1; }

/* ---------------- Responsive ---------------- */
@media (max-width: 1180px) {
  .player-rail { width: 186px; }
  .action-hub { width: 224px; }
}
@media (max-width: 900px) {
  .top-bar { padding: 7px 12px; }
  .status-pill { font-size: 11px; padding: 5px 12px; }
  .chip { font-size: 10.5px; padding: 4px 10px; }
  .player-rail {
    width: 148px; left: 8px; top: 70px;
    bottom: calc(var(--dock-h, 74px) + 12px);
    gap: 7px;
  }
  .corner-card { padding: 7px 10px; }
  .pc-stats { display: none; }
  .pc-name { font-size: 11px; }
  .action-hub { right: 8px; top: 68px; width: 186px; gap: 6px;
               grid-template-rows: auto auto minmax(0, 1fr); }
  .hub-dice { padding: 8px 10px; gap: 8px; }
  .dice3d, .cube, .face { width: 44px; height: 44px; }
  .f1 { transform: translateZ(22px); }
  .f6 { transform: rotateX(180deg) translateZ(22px); }
  .f2 { transform: rotateY(90deg) translateZ(22px); }
  .f5 { transform: rotateY(-90deg) translateZ(22px); }
  .f3 { transform: rotateX(-90deg) translateZ(22px); }
  .f4 { transform: rotateX(90deg) translateZ(22px); }
  .dice-readout b { font-size: 20px; }
  .orb { width: 66px; height: 66px; }
  .orb-end { width: 56px; height: 56px; }
  .orb-glyph { font-size: 22px; }
  .orb-text { font-size: 9.5px; }
  .hub-skills button { font-size: 10px; padding: 6px 8px; }
  .battle-hud { min-height: 0; }
  .dock { bottom: 6px; left: 6px; right: 6px; padding: 6px 10px; }
}
