:root {
  --bg-table: #0d1114;
  --bg-panel: #161b20;
  --bg-card: #1c2228;
  --border-subtle: #2c353d;
  --border-strong: #3e4a54;

  /* 5-Color K1C Tabletop Palette */
  --k1c-charcoal: #1f262b;
  --k1c-ash: #6e787d;
  --k1c-ivory: #f4f4f0;
  --k1c-yellow: #f5c71a;
  --k1c-orange: #f07b1e;

  --text-main: #eef1f3;
  --text-muted: #98a4ad;
  --accent-cyan: #38bdf8;
  --accent-green: #34d399;
  --accent-red: #ef4444;

  --cell-size: 46px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: radial-gradient(circle at 50% 25%, #171e24 0%, #0b0e11 75%);
  color: var(--text-main);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.mt-20 {
  margin-top: 20px;
}

/* Compact System Header (~44px, quiet chrome) */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 44px;
  padding: 0 16px;
  background: #14191e;
  border-bottom: 1px solid rgba(238, 241, 243, 0.08);
  position: sticky;
  top: 0;
  z-index: 40;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-emblem {
  display: flex;
  align-items: center;
}

.brand-title {
  font-family: 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  font-size: 0.98rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--k1c-ivory);
  white-space: nowrap;
}

.ver-badge {
  display: inline-block;
  background: rgba(245, 199, 26, 0.16);
  color: var(--k1c-yellow);
  font-family: system-ui, sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
}

.header-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  padding-left: 10px;
  border-left: 1px solid rgba(238, 241, 243, 0.1);
  white-space: nowrap;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-sep {
  width: 1px;
  height: 18px;
  background: rgba(238, 241, 243, 0.1);
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 3px;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 6px;
}

.speed-control input[type="range"] {
  width: 60px;
  accent-color: var(--k1c-yellow);
  cursor: pointer;
}

.speed-label {
  color: var(--text-main);
  font-weight: 500;
  min-width: 40px;
  font-variant-numeric: tabular-nums;
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-main);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-xs {
  padding: 3px 9px;
  font-size: 0.75rem;
  border-radius: 6px;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.79rem;
}

.btn-swap-dice {
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  background: #2b3844;
  border: 2px solid var(--k1c-yellow);
  color: var(--k1c-yellow);
}

.btn-swap-dice:hover:not(:disabled) {
  background: rgba(245, 199, 26, 0.16);
}

.btn-lg {
  padding: 12px 28px;
  font-size: 1rem;
}

.btn-primary {
  background: #27323c;
  border-color: var(--border-strong);
}

.btn-primary:hover:not(:disabled) {
  background: #32404d;
}

.btn-secondary {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text-muted);
}

.btn-secondary:hover:not(:disabled) {
  color: var(--text-main);
  border-color: #5b6b78;
}

.btn-gold {
  background: var(--k1c-yellow);
  color: var(--k1c-charcoal);
  font-weight: 700;
}

.btn-gold:hover:not(:disabled) {
  background: #ffd438;
}

.btn-orange {
  background: var(--k1c-orange);
  color: #fff;
  font-weight: 700;
}

.btn-orange:hover:not(:disabled) {
  background: #fb8c34;
}

.btn-cyan {
  background: #0284c7;
  color: #fff;
}

.btn-cyan:hover:not(:disabled) {
  background: #0ea5e9;
}

.btn-danger {
  background: #b91c1c;
  color: #fff;
}

/* Setup Screen */
.setup-screen {
  max-width: 1140px;
  margin: 22px auto;
  padding: 0 20px;
}

.setup-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 26px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.setup-header h2 {
  font-family: 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  font-size: 1.55rem;
  color: var(--k1c-yellow);
  margin-bottom: 6px;
}

.setup-header p {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 26px;
  margin-top: 22px;
}

@media (max-width: 820px) {
  .setup-grid {
    grid-template-columns: 1fr;
  }
}

.setup-section h3 {
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.mode-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.mode-card {
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 11px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.mode-card input {
  display: none;
}

.mode-card.selected {
  border-color: var(--k1c-yellow);
  background: rgba(245, 199, 26, 0.08);
}

.mode-title {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--k1c-ivory);
}

.mode-meta {
  font-size: 0.71rem;
  color: var(--k1c-yellow);
  margin: 3px 0 4px;
  font-weight: 600;
}

.mode-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.32;
}

.wall-mode-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toggle-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.87rem;
}

.toggle-chip input {
  accent-color: var(--k1c-yellow);
}

.hint-text {
  font-size: 0.77rem;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.4;
}

.player-count-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.count-btn {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 8px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.count-btn.active {
  background: rgba(245, 199, 26, 0.12);
  border-color: var(--k1c-yellow);
  color: var(--k1c-yellow);
}

.player-slots {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.player-slot-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 12px;
}

.slot-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  flex-shrink: 0;
}

.slot-name-input {
  flex: 1;
  background: #12171b;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.87rem;
}

.slot-type-toggle {
  display: flex;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
}

.slot-type-btn {
  background: #14191e;
  border: none;
  color: var(--text-muted);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.slot-type-btn.active.human {
  background: #0284c7;
  color: #fff;
}

.slot-type-btn.active.bot {
  background: var(--k1c-orange);
  color: #fff;
}

.setup-footer {
  margin-top: 24px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

/* Main Game Arena */
.game-arena {
  display: grid;
  grid-template-columns: 292px minmax(520px, 1fr) 300px;
  gap: 14px;
  padding: 12px 16px;
  max-width: 1580px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 1220px) {
  .game-arena {
    grid-template-columns: 260px 1fr;
  }
  .right-panel {
    grid-column: 1 / -1;
  }
}

.left-panel,
.right-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 12px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 700;
}

.win-req-badge {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.74rem;
  background: rgba(245, 199, 26, 0.14);
  color: var(--k1c-yellow);
  padding: 2px 8px;
  border-radius: 6px;
}

/* Player Boards (Ash Grey 3D-printed aesthetic) */
.player-boards-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-board {
  background: #232a30;
  border: 2px solid #353f47;
  border-radius: 12px;
  padding: 9px 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.player-board.active-turn {
  border-color: var(--active-color, var(--k1c-yellow));
  box-shadow: 0 0 0 1px var(--active-color, var(--k1c-yellow)), 0 8px 20px rgba(0, 0, 0, 0.4);
}

.pb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}

.pb-identity {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.pb-pawn-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid #111;
  flex-shrink: 0;
}

.pb-name {
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pb-tags {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pb-tag {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  background: #161b20;
  color: var(--text-muted);
}

.pb-tag.bot {
  color: var(--k1c-orange);
}

.pb-tag.skip {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.pb-top-tray {
  background: #171c21;
  border: 1px solid #323c44;
  border-radius: 8px;
  padding: 6px;
  min-height: 38px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  margin-bottom: 6px;
}

.pb-tray-empty {
  font-size: 0.72rem;
  color: #65727c;
  width: 100%;
  text-align: center;
}

.inv-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.inv-chip.relic {
  background: var(--k1c-ivory);
  color: var(--k1c-charcoal);
  border-color: var(--k1c-yellow);
}

.inv-chip.key {
  background: var(--k1c-yellow);
  color: var(--k1c-charcoal);
}

.inv-chip.map {
  background: #223743;
  color: #7dd3fc;
  border-color: #38bdf8;
}

.inv-chip.clickable {
  cursor: pointer;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.45);
}

.inv-chip.clickable:hover {
  transform: scale(1.04);
}

.pb-tool-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.tool-slot {
  height: 44px;
  background: #151a1e;
  border: 1px dashed #3d4852;
  border-radius: 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  position: relative;
  font-size: 0.67rem;
  color: #5b6771;
}

.tool-slot.filled {
  background: var(--k1c-yellow);
  color: var(--k1c-charcoal);
  border: 1px solid #d4a70c;
  font-weight: 700;
}

.tool-slot.filled.clickable {
  cursor: pointer;
  box-shadow: 0 0 0 2px #38bdf8;
}

.tool-slot-badge {
  position: absolute;
  top: -5px;
  right: -4px;
  background: var(--k1c-charcoal);
  color: var(--k1c-yellow);
  border: 1px solid var(--k1c-yellow);
  border-radius: 4px;
  font-size: 0.58rem;
  padding: 0 3px;
  font-weight: 800;
}

/* Center Stage & Unified Command HUD */
.center-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.command-hud {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid rgba(238, 241, 243, 0.1);
  border-radius: 12px;
  padding: 8px 14px;
  min-height: 60px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

/* HUD Segment 1: Dice */
.hud-dice {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 14px;
  border-right: 1px solid rgba(238, 241, 243, 0.08);
}

.hud-swap-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #222a32;
  border: 1px solid rgba(245, 199, 26, 0.45);
  color: var(--k1c-yellow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.hud-swap-btn:hover:not(:disabled) {
  background: rgba(245, 199, 26, 0.16);
}

.hud-swap-btn:disabled {
  opacity: 0.25;
  cursor: default;
  border-color: rgba(238, 241, 243, 0.1);
  color: var(--text-muted);
}

.d12-die {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border: 1px solid rgba(0, 0, 0, 0.35);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.d12-die.swappable {
  cursor: pointer;
}

.d12-die.swappable:hover {
  transform: translateY(-1px);
}

.d12-die.muted {
  opacity: 0.42;
}

.d12-die.rolling {
  animation: diceTumble 0.35s ease;
}

@keyframes diceTumble {
  0% { transform: translateY(-6px) rotate(-14deg) scale(0.92); }
  50% { transform: translateY(1px) rotate(8deg) scale(1.05); }
  100% { transform: translateY(0) rotate(0) scale(1); }
}

.d12-die.light {
  background: var(--k1c-yellow);
  color: var(--k1c-charcoal);
}

.d12-die.steps {
  background: var(--k1c-ivory);
  color: var(--k1c-charcoal);
}

.d12-num {
  font-size: 1rem;
  line-height: 1;
}

.d12-tag {
  font-size: 0.5rem;
  text-transform: uppercase;
  font-weight: 700;
  opacity: 0.78;
}

/* HUD Segment 2: Active Status & Context Actions */
.hud-center {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  flex-wrap: nowrap;
}

.hud-status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.hud-status-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.hud-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-sub {
  font-size: 0.77rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  white-space: nowrap;
}

/* HUD Segment 3: Compact Castle Victory Progress */
.hud-castle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 14px;
  border-left: 1px solid rgba(238, 241, 243, 0.08);
  white-space: nowrap;
}

.hud-castle.flash {
  animation: hudFlash 0.6s ease;
}

@keyframes hudFlash {
  0%, 100% { background: transparent; }
  50% { background: rgba(245, 199, 26, 0.14); border-radius: 8px; }
}

.castle-req-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.castle-req-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.castle-req-item.ok {
  color: var(--accent-green);
  font-weight: 600;
}

.castle-req-dot {
  opacity: 0.35;
}

.castle-won-readout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--k1c-yellow);
}

/* Tabletop + Architectural Castle Gate + Board */
.tabletop-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  max-width: 100%;
  overflow: auto;
}

.board-assembly {
  position: relative;
  display: inline-block;
}

/* Architectural Stone Castle Gate attached flush at the 2 threshold cells */
.castle-arch {
  position: absolute;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: linear-gradient(180deg, #2c353d 0%, #1c2228 100%);
  border: 2px solid #566370;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.65);
  cursor: pointer;
  padding: 2px 6px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.castle-arch:hover {
  border-color: var(--k1c-yellow);
}

.castle-arch.gate-ready {
  border-color: var(--accent-green);
  background: linear-gradient(180deg, #1b3b30 0%, #132821 100%);
  box-shadow: 0 0 14px rgba(52, 211, 153, 0.45);
}

.castle-arch.gate-won {
  border-color: var(--k1c-yellow);
  background: linear-gradient(180deg, #3a3118 0%, #221d10 100%);
}

.castle-arch.side-W,
.castle-arch.side-E {
  flex-direction: column;
  padding: 6px 2px;
}

.castle-bastion {
  width: 8px;
  height: 16px;
  background: #4b5763;
  border: 1px solid #14191d;
  border-radius: 2px;
  flex-shrink: 0;
}

.castle-arch.side-W .castle-bastion,
.castle-arch.side-E .castle-bastion {
  width: 16px;
  height: 8px;
}

.castle-throne-bay {
  flex: 1;
  height: 22px;
  min-width: 24px;
  background: #101519;
  border: 1px solid #3c4752;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.castle-arch.side-W .castle-throne-bay,
.castle-arch.side-E .castle-throne-bay {
  width: 22px;
  min-height: 24px;
  height: auto;
}

.castle-arch.gate-ready .castle-throne-bay {
  border-color: var(--accent-green);
  background: rgba(52, 211, 153, 0.15);
}

.castle-arch.gate-won .castle-throne-bay {
  border-color: var(--k1c-yellow);
  background: rgba(245, 199, 26, 0.14);
}

/* Grid Frame (Charcoal #1F262B base) */
.board-frame {
  background: #14191d;
  border: 6px solid #262e35;
  border-radius: 10px;
  padding: 5px;
  box-shadow: 0 20px 55px rgba(0, 0, 0, 0.65);
  position: relative;
}

.board-grid {
  position: relative;
  display: grid;
  gap: 5px;
  background: #0a0d10;
  padding: 5px;
  border-radius: 5px;
}

/* Quadrant Seam Guides (C4 symmetry visual hint - subtle, under walls) */
.quad-seam-v {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  border-left: 1px dashed rgba(245, 199, 26, 0.14);
  transform: translateX(-0.5px);
  pointer-events: none;
  z-index: 1;
}

.quad-seam-h {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 0;
  border-top: 1px dashed rgba(245, 199, 26, 0.14);
  transform: translateY(-0.5px);
  pointer-events: none;
  z-index: 1;
}

/* Open Gate Breach in Board Border */
.castle-gate-breach {
  position: absolute;
  z-index: 9;
  background: linear-gradient(135deg, rgba(245, 199, 26, 0.45), rgba(52, 211, 153, 0.28));
  border: 2px solid var(--k1c-yellow);
  border-radius: 4px;
  box-shadow: 0 0 12px rgba(245, 199, 26, 0.45);
  pointer-events: none;
}

.castle-gate-breach.unlocked {
  background: linear-gradient(135deg, rgba(52, 211, 153, 0.78), rgba(245, 199, 26, 0.55));
  border-color: #ecfdf5;
  box-shadow: 0 0 18px rgba(52, 211, 153, 0.85);
}

.threshold-badge {
  position: absolute;
  top: 1px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  color: var(--k1c-yellow);
  border: 1px solid var(--k1c-yellow);
  border-radius: 3px;
  font-size: 9px;
  font-weight: 900;
  line-height: 1.1;
  padding: 0 3px;
  letter-spacing: 0.02em;
  pointer-events: none;
  z-index: 5;
  white-space: nowrap;
}

.board-cell.compact-cells .threshold-badge {
  font-size: 6.5px;
  padding: 0 2px;
  max-width: calc(100% - 2px);
}

/* Cells & Tiles */
.board-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 5px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.board-cell.closed {
  background: linear-gradient(145deg, #252d33 0%, #1a2025 100%);
  border: 1px solid #313b44;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), inset 0 -2px 4px rgba(0, 0, 0, 0.45);
}

.board-cell.closed::after {
  content: '';
  width: 34%;
  height: 34%;
  border: 1px solid rgba(110, 120, 125, 0.24);
  transform: rotate(45deg);
  border-radius: 2px;
}

.board-cell.start-cell {
  background: radial-gradient(circle, #2a333b 0%, #1c2228 80%);
  border: 1px solid #485560;
}

.board-cell.open-empty {
  background: var(--k1c-ash);
  border: 1px solid #828e94;
}

.board-cell.open-useful {
  background: var(--k1c-yellow);
  border: 1px solid #ffd84d;
  color: var(--k1c-charcoal);
}

.board-cell.open-trap {
  background: var(--k1c-orange);
  border: 1px solid #ff9744;
  color: var(--k1c-ivory);
}

.board-cell.open-relic {
  background: var(--k1c-ivory);
  border: 2px solid var(--k1c-yellow);
  color: var(--k1c-charcoal);
}

.board-cell.just-flipped {
  animation: tileFlipIn 0.35s ease;
}

@keyframes tileFlipIn {
  0% { transform: scaleX(0.15); filter: brightness(1.4); }
  100% { transform: scaleX(1); filter: brightness(1); }
}

/* Highlights on cells */
.board-cell.castle-threshold {
  box-shadow: inset 0 0 0 2px var(--k1c-yellow), 0 0 8px rgba(245, 199, 26, 0.35);
}

.board-cell.ray-reach-hint {
  box-shadow: inset 0 0 0 2px rgba(245, 199, 26, 0.42);
}

.board-cell.map-reach-hint {
  box-shadow: inset 0 0 0 2px rgba(56, 189, 248, 0.42);
}

.board-cell.ray-preview {
  box-shadow: inset 0 0 0 3px var(--k1c-yellow), 0 0 12px rgba(245, 199, 26, 0.72);
  z-index: 3;
}

.board-cell.map-preview {
  box-shadow: inset 0 0 0 3px var(--accent-cyan), 0 0 12px rgba(56, 189, 248, 0.72);
  z-index: 3;
}

.board-cell.valid-step {
  box-shadow: inset 0 0 0 3px var(--accent-green), 0 0 12px rgba(52, 211, 153, 0.55);
  cursor: pointer;
  z-index: 4;
}

.board-cell.valid-step:hover {
  transform: scale(1.06);
}

.board-cell.valid-jump {
  box-shadow: inset 0 0 0 3px var(--accent-cyan), 0 0 12px rgba(56, 189, 248, 0.65);
  cursor: pointer;
  z-index: 4;
}

.jump-badge {
  position: absolute;
  bottom: 1px;
  left: 50%;
  transform: translateX(-50%);
  background: #0284c7;
  color: #fff;
  font-size: 0.55rem;
  font-weight: 800;
  padding: 0 4px;
  border-radius: 3px;
  z-index: 6;
  pointer-events: none;
}

.cell-tooltip-tag {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  opacity: 0.75;
}

/* Directional Light Arrows overlaid cleanly inside neighboring cell center */
.dir-arrow-btn {
  position: absolute;
  border-radius: 50%;
  background: rgba(11, 16, 23, 0.94);
  border: 2px solid var(--k1c-yellow);
  color: var(--k1c-yellow);
  font-weight: 900;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 15;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.75);
  transition: transform 0.12s ease, background 0.12s ease;
  padding: 0;
}

.dir-arrow-count {
  position: absolute;
  bottom: -5px;
  right: -5px;
  background: var(--k1c-yellow);
  color: #0b0f14;
  font-size: 9px;
  font-weight: 900;
  padding: 0 3px;
  border-radius: 4px;
  border: 1px solid #0b0f14;
  line-height: 1.15;
  pointer-events: none;
}

.dir-arrow-btn.map-mode .dir-arrow-count {
  background: var(--accent-cyan);
}

.dir-arrow-btn.map-mode {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.dir-arrow-btn:hover {
  transform: scale(1.18);
  background: var(--k1c-yellow);
  color: var(--k1c-charcoal);
}

.dir-arrow-btn.map-mode:hover {
  background: var(--accent-cyan);
  color: #082f49;
}

/* Castle Enter Floating Button on Threshold */
.castle-enter-btn {
  position: absolute;
  z-index: 16;
  background: var(--accent-green);
  color: #052e16;
  border: 2px solid #ecfdf5;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 0.7rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.65);
  white-space: nowrap;
}

/* Floating Diagonal Loot Pickup Pill */
.floating-pickup-btn {
  position: absolute;
  z-index: 18;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #1b242c 0%, #0f151a 100%);
  border: 2px solid var(--k1c-yellow);
  color: var(--k1c-yellow);
  font-size: 0.75rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.85), 0 0 12px rgba(245, 199, 26, 0.35);
  animation: pickupPopIn 0.12s ease-out;
}

.floating-pickup-btn:hover {
  background: var(--k1c-yellow);
  color: var(--k1c-charcoal);
  transform: translateY(-1px);
}

@keyframes pickupPopIn {
  from { opacity: 0; transform: scale(0.88); }
  to { opacity: 1; transform: scale(1); }
}

/* Segmented Pegged Walls — bold high-contrast stone ridges */
.wall-layer {
  position: absolute;
  inset: 5px;
  pointer-events: none;
  z-index: 9;
}

.wall-segment {
  position: absolute;
  background: linear-gradient(180deg, #F1F5F9 0%, #CBD5E1 100%);
  border: none;
  border-radius: 3px;
  box-shadow: 0 0 0 1.5px #05070A, 0 2px 5px rgba(0, 0, 0, 0.85);
}

.wall-segment.orient-v {
  background: linear-gradient(90deg, #F1F5F9 0%, #CBD5E1 100%);
}

.wall-segment::after {
  content: '';
  position: absolute;
  background: rgba(15, 23, 42, 0.32);
  border-radius: 1px;
}

.wall-segment.orient-h::after {
  top: 25%;
  bottom: 25%;
  left: 42%;
  right: 42%;
}

.wall-segment.orient-v::after {
  left: 25%;
  right: 25%;
  top: 42%;
  bottom: 42%;
}

.wall-segment.pickaxe-selectable {
  pointer-events: auto;
  cursor: pointer;
  background: var(--accent-cyan);
  border-color: #e0f2fe;
  box-shadow: 0 0 12px var(--accent-cyan);
  z-index: 14;
}

.wall-segment.pickaxe-selected {
  background: var(--k1c-yellow);
  border-color: #fff;
  box-shadow: 0 0 14px var(--k1c-yellow);
}

/* Interactive Edge Targets (Wall Setup & Pickaxe) */
.edge-hitbox {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  z-index: 12;
  border-radius: 3px;
  transition: background 0.1s;
}

.edge-hitbox.pickaxe-target {
  background: rgba(52, 211, 153, 0.45);
  border: 1px dashed var(--accent-green);
}

.edge-hitbox.pickaxe-target:hover {
  background: rgba(52, 211, 153, 0.85);
}

.wall-preview {
  position: absolute;
  border-radius: 3px;
  pointer-events: none;
  z-index: 13;
}

.wall-preview.valid {
  background: rgba(52, 211, 153, 0.78);
  border: 1px solid #a7f3d0;
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.7);
}

.wall-preview.invalid {
  background: rgba(239, 68, 68, 0.72);
  border: 1px solid #fecaca;
}

/* Pawns */
.pawn-token {
  position: absolute;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
  transition: left 0.2s ease, top 0.2s ease, transform 0.2s ease;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.75));
}

.pawn-token.active-pawn {
  z-index: 11;
  transform: scale(1.13);
}

.pawn-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--k1c-yellow);
  animation: ringPulse 1.5s infinite;
}

@keyframes ringPulse {
  0%, 100% { opacity: 0.9; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(1.15); }
}

/* Toast Banner */
.toast-banner {
  position: fixed;
  top: 118px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 24, 39, 0.96);
  border: 1px solid var(--k1c-yellow);
  color: var(--k1c-ivory);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65);
  z-index: 60;
  white-space: nowrap;
  pointer-events: none;
  max-width: min(92vw, 640px);
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Right Panel: Stats & Log */
.stats-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid rgba(238, 241, 243, 0.08);
  border-radius: 8px;
  padding: 6px 8px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.stat-val {
  font-size: 1rem;
  font-weight: 800;
  color: var(--k1c-ivory);
}

.stat-lbl {
  font-size: 0.67rem;
  color: var(--text-muted);
}

.event-log {
  max-height: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}

.log-entry {
  font-size: 0.78rem;
  line-height: 1.38;
  padding: 6px 8px;
  border-radius: 7px;
  background: #1a2026;
  border-left: 3px solid #475569;
  color: #dce3e8;
}

.log-entry.kind-dice { border-left-color: var(--k1c-ivory); }
.log-entry.kind-light { border-left-color: var(--k1c-yellow); }
.log-entry.kind-loot { border-left-color: var(--accent-green); }
.log-entry.kind-trap { border-left-color: var(--k1c-orange); background: rgba(240, 123, 30, 0.08); }
.log-entry.kind-combat { border-left-color: #f43f5e; background: rgba(244, 63, 94, 0.09); }
.log-entry.kind-relic { border-left-color: #c084fc; }
.log-entry.kind-dark { border-left-color: #64748b; color: #94a3b8; }
.log-entry.kind-victory { border-left-color: var(--k1c-yellow); background: rgba(245, 199, 26, 0.15); font-weight: 700; }
.log-entry.kind-map, .log-entry.kind-tool { border-left-color: var(--accent-cyan); }

.log-round {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-right: 5px;
  font-weight: 700;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 11, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}

.modal-card {
  background: var(--bg-panel);
  border: 2px solid var(--border-strong);
  border-radius: 16px;
  padding: 22px 24px;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75);
  max-height: 88vh;
  overflow-y: auto;
}

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

.modal-title {
  font-family: 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  font-size: 1.25rem;
  color: var(--k1c-yellow);
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 0.88rem;
  color: #d4dce2;
  line-height: 1.48;
  margin-bottom: 16px;
}

.modal-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.choice-tile-btn {
  background: var(--bg-card);
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.85rem;
}

.choice-tile-btn:hover {
  border-color: var(--k1c-yellow);
  background: #242c33;
}

.combat-arena {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  background: #12171b;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.fighter-card {
  text-align: center;
}

.fighter-name {
  font-weight: 700;
  margin-bottom: 6px;
}

.fighter-roll {
  font-size: 2rem;
  font-weight: 900;
  color: var(--k1c-yellow);
}

.fighter-bonus {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.vs-badge {
  font-weight: 900;
  color: var(--k1c-orange);
  font-size: 1.1rem;
}

.rules-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  margin-top: 8px;
}

.rules-table th,
.rules-table td {
  border-bottom: 1px solid var(--border-subtle);
  padding: 6px 8px;
  text-align: left;
}

.rules-table th {
  color: var(--k1c-yellow);
}

/* =========================================================================
   MULTIPLAYER LOBBY, WAITING ROOM & NETWORK INDICATORS
   ========================================================================= */

.net-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(238, 241, 243, 0.06);
  color: var(--text-muted);
  border: 1px solid rgba(238, 241, 243, 0.1);
}

.net-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.net-badge.connected {
  color: var(--accent-green);
  border-color: rgba(52, 211, 153, 0.3);
  background: rgba(52, 211, 153, 0.08);
}

.net-badge.reconnecting {
  color: var(--k1c-yellow);
  border-color: rgba(245, 199, 26, 0.3);
}

.net-badge.offline {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
}

.setup-top-row {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(238, 241, 243, 0.08);
}

.setup-mode-tabs {
  display: inline-flex;
  gap: 6px;
  background: #12171b;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 4px;
}

.lobby-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.lobby-tab-btn.active {
  background: var(--k1c-yellow);
  color: var(--k1c-charcoal);
}

.mp-profile-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-card);
  border: 1px solid rgba(238, 241, 243, 0.08);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.mp-name-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.mp-name-input {
  width: 200px;
}

.mp-profile-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.mp-profile-hint.warn {
  color: var(--k1c-orange);
}

.lobby-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 22px;
  align-items: start;
}

@media (max-width: 860px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

.lobby-browser-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.lobby-browser-head h3 {
  margin-bottom: 0;
}

.lobby-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.room-search-input {
  flex: 1 1 180px;
}

.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
}

.filter-toggle input {
  accent-color: var(--k1c-yellow);
}

.status-filter-tabs {
  display: inline-flex;
  background: #12171b;
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 2px;
}

.filter-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
}

.filter-btn.active {
  background: #27323c;
  color: var(--text-main);
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}

.rooms-empty {
  background: #12171b;
  border: 1px dashed var(--border-subtle);
  border-radius: 10px;
  padding: 20px 16px;
  text-align: center;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.room-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
}

.room-card.joined {
  border-color: rgba(52, 211, 153, 0.45);
}

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

.room-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--k1c-ivory);
}

.room-card-meta {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.room-lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(238, 241, 243, 0.06);
  color: var(--text-muted);
}

.room-lock-badge.locked {
  color: var(--k1c-yellow);
  background: rgba(245, 199, 26, 0.12);
}

.create-party-card {
  background: #14191e;
  border: 1px solid rgba(238, 241, 243, 0.08);
  border-radius: 12px;
  padding: 14px 16px;
}

.create-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.form-field .player-count-tabs {
  margin-bottom: 0;
}

.wall-mode-inline {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toggle-chip.compact {
  padding: 7px 10px;
  font-size: 0.8rem;
}

.create-submit-btn {
  margin-top: 4px;
  width: 100%;
}

/* Waiting Room */
.waiting-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(238, 241, 243, 0.08);
}

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

.waiting-title-wrap h2 {
  font-family: 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  font-size: 1.25rem;
  color: var(--k1c-ivory);
}

.waiting-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.waiting-seats {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.seat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 9px 12px;
}

.seat-row.is-me {
  border-color: rgba(245, 199, 26, 0.45);
}

.seat-identity {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.seat-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-main);
}

.seat-name.open {
  color: var(--text-muted);
  font-weight: 400;
}

.seat-badges {
  display: flex;
  align-items: center;
  gap: 5px;
}

.pb-tag.you {
  background: rgba(245, 199, 26, 0.16);
  color: var(--k1c-yellow);
}

.pb-tag.host {
  background: rgba(56, 189, 248, 0.16);
  color: var(--accent-cyan);
}

.pb-conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #475569;
  display: inline-block;
}

.pb-conn-dot.online {
  background: var(--accent-green);
}

.waiting-config {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #14191e;
  border: 1px solid rgba(238, 241, 243, 0.08);
  border-radius: 10px;
  padding: 12px 14px;
}

.waiting-config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.83rem;
}

.waiting-config-row span {
  color: var(--text-muted);
}

.waiting-start-wrap {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.waiting-wait-note {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-align: center;
  padding: 10px;
  background: #14191e;
  border-radius: 8px;
}
