:root {
  --bg-sky: #e8f5ff;
  --panel: rgba(255, 250, 240, 0.94);
  --panel-solid: #fffaf0;
  --panel-alt: #fdf3dc;
  --border: #d9be92;
  --border-strong: #b88b4a;
  --ink: #3a271d;
  --muted: #7b6251;
  --gold: #f59e0b;
  --gold-dark: #d97706;
  --green: #22a06b;
  --red: #e04848;
  --blue: #2f7ae5;
  --purple: #7c4dff;
  --shadow: 0 10px 26px rgba(64, 42, 22, 0.16);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #9bd7ff 0%, #eaf6ff 55%, #fff5da 100%);
  overflow: hidden;
  user-select: none;
}

#app {
  width: 100%;
  height: 100%;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  transition: transform 0.1s ease, filter 0.15s ease, box-shadow 0.15s ease;
}

button:hover:not(:disabled) {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--border);
  box-shadow: 0 2px 0 var(--border);
}

.btn-primary {
  background: linear-gradient(180deg, #fbbf24 0%, #f59e0b 100%);
  color: #3a2007;
  border-color: #c27803;
  box-shadow: 0 3px 0 #b45309;
}

.btn-green {
  background: linear-gradient(180deg, #34d399 0%, #10b981 100%);
  color: #063928;
  border-color: #059669;
  box-shadow: 0 3px 0 #047857;
}

.btn-red {
  background: linear-gradient(180deg, #f87171 0%, #ef4444 100%);
  color: #fff;
  border-color: #dc2626;
  box-shadow: 0 3px 0 #b91c1c;
}

.btn-blue {
  background: linear-gradient(180deg, #60a5fa 0%, #3b82f6 100%);
  color: #fff;
  border-color: #2563eb;
  box-shadow: 0 3px 0 #1d4ed8;
}

.btn-purple {
  background: linear-gradient(180deg, #a78bfa 0%, #7c3aed 100%);
  color: #fff;
  border-color: #6d28d9;
  box-shadow: 0 3px 0 #5b21b6;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
}

/* ---------------- Title Screen ---------------- */

.title-screen {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 20px 24px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.title-header {
  width: 100%;
  max-width: 1120px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 16px 22px;
  box-shadow: var(--shadow);
}

.title-brand h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.02em;
  color: #b45309;
  text-shadow: 0 2px 0 #fde68a;
}

.title-brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.title-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.setup-box {
  width: 100%;
  max-width: 1120px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 18px 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.pill-group {
  display: inline-flex;
  background: var(--panel-alt);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 4px;
}

.pill-btn {
  padding: 5px 12px;
  border-radius: 7px;
  font-weight: 700;
  font-size: 13px;
  background: transparent;
  color: var(--muted);
}

.pill-btn.active {
  background: var(--gold);
  color: #3a2007;
}

.slots-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.slot-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: #fff;
  border: 2px solid var(--border);
  cursor: pointer;
}

.slot-card.active {
  border-color: var(--gold-dark);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
  background: #fffbeb;
}

.slot-card img {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.slot-meta {
  min-width: 0;
}

.slot-meta .slot-role {
  font-size: 11px;
  font-weight: 800;
  color: var(--muted);
}

.slot-meta .slot-name {
  font-size: 15px;
  font-weight: 800;
}

.chars-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.char-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  background: #fff;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.char-card:hover {
  transform: translateY(-2px);
  border-color: var(--gold-dark);
}

.char-card.picked {
  border-color: var(--gold-dark);
  background: #fffdf2;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.2);
}

.char-card img {
  width: 78px;
  height: 78px;
  border-radius: 12px;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.char-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.char-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.char-name {
  font-size: 16px;
  font-weight: 800;
}

.el-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
}

.char-perk {
  font-size: 12px;
  font-weight: 700;
  color: #b45309;
}

.char-stats {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ---------------- Game Layout ---------------- */

.game-shell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 52px;
  flex-shrink: 0;
  background: var(--panel);
  border-bottom: 2px solid var(--border);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stage-pill {
  padding: 4px 11px;
  border-radius: 999px;
  background: var(--panel-alt);
  border: 1.5px solid var(--border);
  font-weight: 800;
  font-size: 13px;
}

.turn-pill {
  padding: 4px 11px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 13px;
  border: 1.5px solid rgba(0, 0, 0, 0.15);
}

.main-area {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 268px 1fr 290px;
  gap: 10px;
  padding: 10px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
}

.card-box {
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: 0 4px 12px rgba(70, 45, 20, 0.09);
}

.box-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: #8c5a2b;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Player Roster Cards */
.roster-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 12px;
  background: #fff;
  border: 2px solid var(--border);
  opacity: 0.84;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
}

.roster-card.active {
  opacity: 1;
  border-width: 3px;
  border-color: var(--active-color, var(--gold-dark));
  background: #fffdf3;
  box-shadow: 0 0 0 3px var(--active-glow, rgba(245, 158, 11, 0.28)), 0 6px 14px rgba(70, 45, 20, 0.14);
}

.turn-badge {
  margin-left: auto;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.03em;
  background: #f59e0b;
  color: #3a2007;
  white-space: nowrap;
  flex-shrink: 0;
  animation: pulseBadge 1.4s ease-in-out infinite;
}

.seat-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 900;
  color: #fff;
  background: #475569;
  border: 1px solid rgba(0, 0, 0, 0.18);
  white-space: nowrap;
  flex-shrink: 0;
}

.seat-badge.ai {
  background: #64748b;
}

.merc-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 8px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  font-size: 11px;
  font-weight: 700;
  color: #78350f;
}

.merc-chip img {
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

@keyframes pulseBadge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.roster-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.roster-top img {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}

.roster-name-row {
  flex: 1;
  min-width: 0;
}

.roster-name {
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 5px;
}

.sub-hero-name {
  font-size: 10.5px;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.roster-sub {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
}

.bar-track {
  height: 8px;
  background: #eadfce;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.bar-hp { background: linear-gradient(90deg, #34d399, #10b981); }
.bar-hp.low { background: linear-gradient(90deg, #fb7185, #ef4444); }
.bar-mp { background: linear-gradient(90deg, #60a5fa, #3b82f6); }

.roster-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
}

.frag-pips {
  display: flex;
  gap: 4px;
}

.frag-pip {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  background: #f1e6d2;
  opacity: 0.4;
}

.frag-pip.got {
  background: #fef08a;
  border: 1.5px solid #d97706;
  opacity: 1;
}

/* Board Viewport */
.board-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 18px;
  overflow: hidden;
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
  background: #cdeaff;
}

.board-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.tile-tip {
  position: absolute;
  top: 10px;
  left: 10px;
  max-width: 315px;
  background: rgba(255, 250, 240, 0.96);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 8px 12px;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  z-index: 25;
}

.tile-tip-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 4px;
}

.tile-tip-desc {
  font-size: 11.5px;
  color: var(--muted);
}

.title-logo-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
}

.title-logo-svg,
.wait-logo-svg,
.stage-logo-svg {
  flex: none;
  display: block;
}

.stage-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 6px;
}

.map-legend-pop {
  position: absolute;
  top: 46px;
  right: 10px;
  width: min(350px, calc(100% - 20px));
  max-height: calc(100% - 110px);
  overflow-y: auto;
  background: rgba(255, 250, 240, 0.97);
  border: 2px solid var(--border-strong);
  border-radius: 14px;
  padding: 11px 13px;
  box-shadow: var(--shadow);
  z-index: 32;
}

.legend-title {
  font-weight: 900;
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--ink);
}

.legend-subtitle {
  font-weight: 800;
  font-size: 11.5px;
  margin: 10px 0 6px;
  color: var(--muted);
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  min-width: 0;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3.5px;
  border: 1.5px solid #3b2824;
  flex: none;
}

.legend-penalties {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.plot-tip-owner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 9px;
  background: #fffdf8;
  border: 2px solid var(--border);
  margin: 3px 0;
}

.plot-tip-owner img {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex: none;
}

.plot-tip-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.plot-penalty-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1.8px solid;
  font-weight: 800;
  font-size: 11px;
}

.penalty-tier-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  margin: 8px 0;
}

.penalty-tier-chip {
  padding: 6px 4px;
  border-radius: 9px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  background: var(--tier-bg);
  color: var(--tier-text);
  border: 1.8px solid var(--tier-border);
  opacity: 0.55;
}

.penalty-tier-chip.active {
  opacity: 1;
  transform: translateY(-1px);
  box-shadow: 0 0 0 2px #3b2824, 0 4px 10px rgba(0, 0, 0, 0.16);
}

.penalty-tier-chip.next {
  opacity: 0.88;
  border-style: dashed;
}

.cam-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 5px;
}

.action-dock {
  position: absolute;
  bottom: 12px;
  left: 14px;
  right: 14px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.dock-bar {
  pointer-events: auto;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  background: rgba(255, 250, 240, 0.96);
  border: 2.5px solid var(--border-strong);
  border-radius: 16px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
}

.dock-who {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 4px;
  border-radius: 999px;
  background: var(--panel-alt);
  border: 2px solid var(--border);
  font-weight: 800;
  font-size: 13px;
}

.dock-who img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
}

.fork-bar {
  gap: 6px;
  padding: 6px 10px;
}

.fork-steps {
  font-size: 12px;
  font-weight: 800;
  color: #78350f;
  background: var(--panel-alt);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
}

.fork-opt-btn {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  font-size: 12.5px;
  white-space: nowrap;
}

.fork-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3b2824;
  color: #fde047;
  font-size: 10.5px;
  font-weight: 900;
  flex: none;
}

.fork-arrow {
  font-size: 12px;
  font-weight: 900;
  color: #78350f;
}

/* Turn Handoff Overlay (Multi-Human Hot-Seat) */
.handoff-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 16, 10, 0.62);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 55;
}

.handoff-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel-solid);
  border: 4px solid var(--gold-dark);
  border-radius: 24px;
  padding: 24px 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}

.handoff-card img {
  width: 96px;
  height: 96px;
  border-radius: 20px;
  border: 3px solid var(--border-strong);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.16);
}

.handoff-title {
  font-size: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #b45309;
}

.handoff-who {
  font-size: 24px;
  font-weight: 900;
  display: flex;
  align-items: center;
  gap: 8px;
}

.handoff-sub {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

/* Inn Tabs, Poker Card & Friendship Hearts */
.modal-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--panel-alt);
  padding-bottom: 8px;
}

.modal-tab {
  padding: 6px 11px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 800;
  background: var(--panel-alt);
  color: var(--muted);
  border: 1.5px solid var(--border);
}

.modal-tab.active {
  background: var(--gold);
  color: #3a2007;
  border-color: #c27803;
}

.poker-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 66px;
  border-radius: 8px;
  background: #ffffff;
  border: 2px solid #cbd5e1;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
  font-weight: 900;
  font-size: 18px;
  line-height: 1.1;
  flex-shrink: 0;
}

.poker-card.red {
  color: #dc2626;
}

.poker-card.black {
  color: #0f172a;
}

.heart-bar {
  width: 110px;
  height: 8px;
  background: #f3e8e8;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #f5c2c7;
}

.heart-fill {
  height: 100%;
  background: linear-gradient(90deg, #fb7185, #e11d48);
  border-radius: 999px;
}

.battle-ticker {
  padding: 6px 10px;
  border-radius: 9px;
  background: #fffbeb;
  border: 1.5px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: #78350f;
}

.battle-shortcuts {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-top: 2px;
}

.dock-drawer {
  pointer-events: auto;
  background: var(--panel-solid);
  border: 2px solid var(--border-strong);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  max-width: min(560px, 100%);
  width: max-content;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Right Panel: Quest + Log */
.quest-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quest-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 9px;
  background: #fff;
  border: 1.5px solid var(--border);
  font-size: 12px;
}

.quest-row.done {
  background: #ecfdf5;
  border-color: #6ee7b7;
}

.log-box {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.log-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  line-height: 1.4;
}

.log-entry {
  padding: 4px 7px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.72);
  border-left: 3px solid var(--border);
}

/* ---------------- Modals ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(34, 22, 14, 0.52);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}

.modal-card {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--panel-solid);
  border: 3px solid var(--border-strong);
  border-radius: 20px;
  padding: 18px 20px;
  box-shadow: 0 20px 50px rgba(30, 18, 8, 0.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-card.wide {
  max-width: 640px;
}

.board-wrap .modal-backdrop,
.board-wrap .handoff-backdrop {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 12px;
  z-index: 40;
}

.board-wrap .modal-card {
  max-height: calc(100% - 8px);
  max-width: min(560px, 100%);
}

.board-wrap .modal-card.wide {
  max-width: min(640px, 100%);
}

.board-wrap .handoff-backdrop {
  z-index: 55;
}

.board-wrap .modal-card {
  max-height: calc(100% - 8px);
  max-width: min(580px, calc(100% - 8px));
}

.board-wrap .modal-card.wide {
  max-width: min(640px, calc(100% - 8px));
}

.board-wrap .handoff-card {
  max-height: calc(100% - 12px);
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 2px solid var(--panel-alt);
  padding-bottom: 8px;
}

.modal-header h2 {
  margin: 0;
  font-size: 19px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1.5px solid var(--border);
}

.modal-row-info {
  flex: 1;
  min-width: 0;
}

.modal-row-title {
  font-weight: 800;
  font-size: 14px;
}

.modal-row-desc {
  font-size: 12px;
  color: var(--muted);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 6px;
  border-top: 2px solid var(--panel-alt);
}

/* Battle Modal */
.battle-stage {
  width: 100%;
  border-radius: 14px;
  border: 2px solid var(--border);
  overflow: hidden;
  background: #e0f2fe;
}

.battle-stage canvas {
  display: block;
  width: 100%;
  height: auto;
}

.battle-hud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.fighter-box {
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.battle-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.battle-subgrid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: var(--panel-alt);
  border-radius: 10px;
}

.podium-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff;
  border: 2px solid var(--border);
}

.podium-row.first {
  background: #fef9c3;
  border-color: var(--gold-dark);
}

.toast-banner {
  position: fixed;
  top: 64px;
  right: 18px;
  background: #1e293b;
  color: #fef08a;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
  z-index: 60;
  box-shadow: var(--shadow);
}

/* ---------------- Online Lobby & Waiting Room ---------------- */

.form-input {
  padding: 7px 11px;
  border-radius: 9px;
  border: 2px solid var(--border);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
}

.form-input:focus {
  outline: none;
  border-color: var(--gold-dark);
}

.online-grid {
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 16px;
}

.sub-panel {
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sub-panel h3 {
  margin: 0;
  font-size: 15px;
  color: #8c5a2b;
}

.room-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 11px;
  background: var(--panel);
  border: 1.5px solid var(--border);
}

.room-id-pill {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0.08em;
  padding: 4px 11px;
  border-radius: 10px;
  background: #fef3c7;
  border: 2px solid #d97706;
  color: #78350f;
}

.waiting-layout {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr;
  gap: 14px;
}

.char-card.taken {
  opacity: 0.48;
  cursor: not-allowed;
}

.chat-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 220px;
}

.chat-log {
  flex: 1;
  min-height: 150px;
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 8px;
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 12.5px;
}

.chat-row {
  padding: 4px 7px;
  border-radius: 7px;
  background: #fff;
}

.error-banner {
  padding: 8px 12px;
  border-radius: 10px;
  background: #fee2e2;
  border: 2px solid #ef4444;
  color: #991b1b;
  font-weight: 700;
  font-size: 13px;
}

.slot-name-input {
  margin-top: 4px;
  width: 100%;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  outline: none;
}

.slot-name-input:focus {
  border-color: var(--gold-dark);
  background: #fff;
}

.leaderboard-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 2px solid #d97706;
  box-shadow: 0 4px 14px rgba(180, 83, 9, 0.14);
}

.leaderboard-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 11px;
  background: var(--panel);
  border: 1.5px solid var(--border);
}

.leaderboard-row.top1 {
  background: #fefce8;
  border-color: #d97706;
}

.turn-timer-pill {
  background: #ecfeff;
  border-color: #0891b2;
  color: #155e75;
  font-variant-numeric: tabular-nums;
}

.turn-timer-pill.urgent {
  background: #fee2e2;
  border-color: #ef4444;
  color: #991b1b;
  animation: timerPulse 0.8s ease-in-out infinite alternate;
}

@keyframes timerPulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.kick-btn {
  padding: 2px 7px;
  font-size: 10.5px;
  border-radius: 7px;
  margin-left: auto;
}

.btn-delegate-on {
  background: linear-gradient(135deg, #fde68a 0%, #fbbf24 100%);
  border-color: #b45309;
  color: #78350f;
  font-weight: 800;
  animation: delegateGlow 1.5s ease-in-out infinite alternate;
}

@keyframes delegateGlow {
  from { box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.25); }
  to { box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.45); }
}

.delegate-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fef3c7;
  border: 1px solid #d97706;
  color: #92400e;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
}

.roster-emote-slot {
  position: absolute;
  top: -8px;
  right: 8px;
  pointer-events: none;
  z-index: 6;
}

.roster-emote-bubble {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #fffdf7;
  border: 2px solid #3b2824;
  color: #2d1a10;
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.16);
  white-space: nowrap;
  animation: emotePop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes emotePop {
  from { opacity: 0; transform: translateY(4px) scale(0.6); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.emote-box {
  gap: 6px;
}

.emote-toggle-btn {
  padding: 2px 7px;
  font-size: 10.5px;
  border-radius: 7px;
}

.emote-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
}

.emote-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: #fffdf8;
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.emote-btn:hover {
  transform: scale(1.12);
  background: #fef3c7;
  border-color: #d97706;
}

.emote-btn:active {
  transform: scale(0.95);
}

.emote-feed {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 88px;
  overflow-y: auto;
}

.emote-feed-row {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 6px;
  border-radius: 7px;
  background: #fff;
  border: 1px solid var(--border);
  font-size: 11px;
  line-height: 1.25;
}

.emote-sender {
  font-weight: 800;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 78px;
}

.emote-msg-emoji {
  font-size: 14px;
  flex-shrink: 0;
}

.emote-msg-label {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.emote-empty {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 3px 0;
}

.room-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 800;
  white-space: nowrap;
}

.room-status-pill.waiting {
  background: #dcfce7;
  border: 1px solid #16a34a;
  color: #166534;
}

.room-status-pill.playing {
  background: #dbeafe;
  border: 1px solid #2563eb;
  color: #1e40af;
}

.unranked-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1px solid #94a3b8;
  color: #475569;
  font-size: 10px;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
}

@media (max-width: 1080px) {
  .main-area {
    grid-template-columns: 225px 1fr 240px;
  }
  .chars-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .online-grid,
  .waiting-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 10px;
  }
  .main-area {
    grid-template-columns: 1fr;
    grid-template-rows: clamp(380px, 54vh, 500px) max-content max-content;
    align-content: start;
    overflow-y: auto;
  }
  .board-wrap {
    order: -1;
    min-height: 380px;
    height: 100%;
  }
  .sidebar {
    min-height: auto;
    overflow-y: visible;
  }
  .log-box {
    min-height: 200px;
    max-height: 300px;
  }
  .slots-grid,
  .chars-grid {
    grid-template-columns: 1fr;
  }
}
