:root {
  /* Quiet walnut-and-parchment neutral ramp */
  --bg-backdrop: #15100d;
  --surface-0: #1e1510;
  --surface-1: #271b14;
  --surface-2: #32231a;
  --surface-3: #3e2c20;

  --border-subtle: rgba(220, 184, 132, 0.14);
  --border-strong: rgba(220, 184, 132, 0.28);
  --ink: #140d09;

  /* 3 deliberate text roles (WCAG AA >= 4.5:1 on dark walnut) */
  --text-primary: #f4ead9;
  --text-secondary: #d2bfa3;
  --text-muted: #b5a288;

  /* One warm brass accent + restrained semantic tokens */
  --accent: #d9a043;
  --accent-hover: #e5b158;
  --accent-ink: #1d1208;
  --sem-hp: #d14836;
  --sem-fire: #dc5233;
  --sem-dome: #3f9ce0;
  --sem-support: #56ad49;
  --sem-gold: #e6b84c;
  --sem-dust: #79c8ff;

  --ease: cubic-bezier(0.2, 0, 0, 1);
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--bg-backdrop);
  color: var(--text-primary);
  font-family: 'Nunito', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.4;
}

/* Unified high-visibility keyboard focus indicator (game-ui-ux + ui-ux-pro-max) */
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #f5cc6a;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

.num {
  font-variant-numeric: tabular-nums;
}

.ui-ico {
  display: block;
  flex-shrink: 0;
}

.px-ico {
  image-rendering: pixelated;
  object-fit: contain;
}

.tray-tile-img,
.shopkeeper-img,
.thief-portrait-img {
  display: block;
  object-fit: contain;
}

.tray-tile-img {
  width: 100%;
  height: 100%;
}

.ico-slot {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.ico-hp { color: var(--sem-hp); }
.ico-gold { color: var(--sem-gold); width: 22px; height: 22px; }
.ico-dust { color: var(--sem-dust); width: 22px; height: 22px; }

.row-with-ico {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

#app-shell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ==================== ORNATE CARVED WALNUT & BRASS-CORNERED FRAMES ==================== */
.wood-panel {
  position: relative;
  background-color: var(--surface-1);
  background-image:
    linear-gradient(180deg, rgba(28, 17, 11, 0.28) 0%, rgba(18, 11, 7, 0.42) 100%),
    url('./assets/arcade32/tex_wood_dark.jpg?v=mat4');
  background-size: 100% 100%, 220px 220px;
  background-repeat: no-repeat, repeat;
  border-style: solid;
  border-width: 16px;
  border-image-source: url('./assets/arcade32/panel_frame_v2.png?v=mat2');
  border-image-slice: 76 76 76 76;
  border-image-repeat: round;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.65);
}

.rivet {
  display: none;
}

/* ==================== 3-COLUMN DESKTOP LAYOUT ==================== */
#game-frame {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 276px minmax(420px, 1fr) 276px;
  gap: 8px;
  width: 100%;
  max-width: 1244px;
  margin: 0 auto;
  height: 100%;
  padding: 8px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 10px 8px 8px;
  gap: 12px;
  overflow-y: auto;
  z-index: 15;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.drawer-close-btn {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background-color: var(--surface-2);
  color: var(--text-primary);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-title {
  margin: 0;
  font-family: 'Philosopher', Georgia, serif;
  font-size: 17px;
  font-weight: 400;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.section-rule {
  height: 1px;
  background-color: var(--border-subtle);
  flex-shrink: 0;
}

/* ==================== CARVED PLAQUE SECTION HEADERS ==================== */
.plaque-title {
  margin: 0;
  height: 32px;
  padding: 0 14px;
  background-image:
    linear-gradient(180deg, rgba(44, 26, 13, 0.46) 0%, rgba(24, 13, 6, 0.64) 100%),
    url('./assets/arcade32/tex_wood_oak.jpg?v=mat4');
  background-size: 100% 100%, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
  border: 1.5px solid #9c743e;
  border-radius: 7px;
  box-shadow:
    inset 0 1px 0 rgba(250, 224, 166, 0.28),
    inset 0 -2px 0 rgba(18, 10, 6, 0.65),
    0 2px 4px rgba(0, 0, 0, 0.35);
  font-family: 'Philosopher', Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  color: #f6e7c8;
  text-shadow: 0 1px 0 #1b1008;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* ==================== LEFT SIDEBAR ==================== */
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.inv-slot {
  aspect-ratio: 1;
  background-color: #1b120c;
  background-image: linear-gradient(180deg, #19100b 0%, #241710 100%);
  border: 1.5px solid #593d25;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.65);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 4px;
}

.inv-slot.filled {
  box-shadow: inset 0 0 0 1.5px rgba(217, 169, 78, 0.7);
}

.inv-ico {
  width: 100%;
  height: 100%;
  padding: 2px;
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
}
.inv-ico .px-ico {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: auto;
}

.inv-count {
  position: absolute;
  bottom: 3px;
  right: 4px;
  padding: 0 4px;
  border-radius: 4px;
  background-color: rgba(20, 13, 9, 0.9);
  border: 1px solid var(--border-strong);
  font-size: 10px;
  line-height: 1.3;
  font-weight: 700;
  color: #f5e6c8;
}

.spellbook-section {
  flex: 1;
  min-height: 0;
}

/* Open Aged Cream Parchment Grimoire Page */
.grimoire-page {
  background-color: #ebd9b4;
  background-image:
    linear-gradient(180deg, rgba(246, 234, 206, 0.14) 0%, rgba(214, 186, 138, 0.18) 100%),
    url('./assets/arcade32/tex_parchment.jpg?v=mat4');
  background-size: 100% 100%, 192px 192px;
  background-repeat: no-repeat, repeat;
  border: 2px solid #593a1e;
  border-radius: 8px;
  box-shadow:
    inset 0 0 0 2px rgba(132, 88, 44, 0.24),
    inset 0 2px 6px rgba(255, 248, 228, 0.45),
    0 3px 8px rgba(0, 0, 0, 0.35);
  padding: 14px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: #2b1a0e;
}

.chain-seals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1.5px dashed rgba(94, 60, 32, 0.35);
}

.chain-seal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.seal-badge {
  min-width: 34px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  border: 1.5px solid #2b1a0e;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff6e0;
  text-shadow: 0 1px 0 rgba(20, 10, 4, 0.7);
}
.seal-base .seal-badge { background-color: #7c5e3c; }
.seal-mid .seal-badge { background-color: #b04a2b; }
.seal-ult .seal-badge { background-color: #a66a16; }

.seal-tag {
  font-size: 11px;
  font-weight: 700;
  color: #4f3218;
}

.grimoire-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.grimoire-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background-color: rgba(112, 74, 38, 0.14);
  border: 1px solid rgba(94, 60, 32, 0.28);
}

.grimoire-ico {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.grimoire-vals {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.grimoire-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
}

.grimoire-name {
  font-family: 'Philosopher', Georgia, serif;
  font-size: 13px;
  font-weight: 700;
  color: #2b1a0e;
}

.grimoire-lvl {
  font-size: 11px;
  font-weight: 700;
  color: #5e3818;
}

.grimoire-nums {
  font-size: 12px;
  font-weight: 700;
  color: #36200e;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grimoire-keys-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-top: 4px;
  border-top: 1px dashed rgba(94, 60, 32, 0.32);
}

.grimoire-keys-label {
  font-size: 11px;
  font-weight: 700;
  color: #52341a;
  line-height: 1;
}

.grimoire-keys {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.kc {
  min-width: 34px;
  height: 28px;
  padding: 0 8px;
  background-image: linear-gradient(180deg, #4b3423 0%, #322116 100%);
  border: 1.5px solid #7d5b34;
  border-radius: 6px;
  box-shadow:
    inset 0 1px 0 rgba(255, 232, 186, 0.22),
    0 2px 0 #170e08;
  font-family: 'Nunito', sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: #f6e7c8;
  text-shadow: 0 1px 0 #1b1008;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.kc-ico {
  color: #f6e7c8;
}

/* ==================== RIGHT SIDEBAR ==================== */
.arcade-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.arcade-bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.bar-emblem {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bar-frame {
  position: relative;
  flex: 1;
  height: 26px;
  background-color: #19100b;
  border: 2px solid #8f6b3a;
  border-radius: 7px;
  box-shadow:
    inset 0 2px 5px rgba(0, 0, 0, 0.72),
    0 1px 0 rgba(255, 224, 166, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.bar-well {
  position: absolute;
  inset: 2px;
  overflow: hidden;
  border-radius: 4px;
  background-color: #261710;
}

.bar-fill-hp,
.bar-fill-shield {
  height: 100%;
  width: 100%;
  border-radius: 3px;
  transition: width 0.2s var(--ease);
}
.bar-fill-hp {
  background-image: linear-gradient(180deg, #ee624b 0%, #c93424 55%, #8f1d13 100%);
  box-shadow: inset 0 1px 0 rgba(255, 225, 200, 0.35);
}
.bar-fill-shield {
  background-image: linear-gradient(180deg, #6ccbff 0%, #2d84d6 55%, #195496 100%);
  box-shadow: inset 0 1px 0 rgba(220, 245, 255, 0.4);
}

.bar-value {
  position: relative;
  z-index: 2;
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 1px 0 #160c08, 0 0 4px rgba(14, 8, 4, 0.85);
}

/* 2x2 Carved Wooden Resource Tiles */
.stats-grid-2x2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat-tile {
  height: 40px;
  padding: 0 10px;
  background-image: linear-gradient(180deg, #271a12 0%, #1b120c 100%);
  border: 1.5px solid #6b4b2b;
  border-radius: 7px;
  box-shadow:
    inset 0 1px 0 rgba(245, 214, 158, 0.14),
    inset 0 -2px 4px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.stat-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 1px 0 #160c08;
}
.val-gold { color: var(--sem-gold); }
.val-dust { color: var(--sem-dust); }

.waves-section {
  flex: 1;
  min-height: 0;
}

.waves-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.waves-head .plaque-title {
  flex: 1;
}

.wave-meta {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  padding: 2px 6px;
  border-radius: 6px;
  background-color: var(--surface-0);
  border: 1px solid var(--border-strong);
}

.enemy-roster {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
}

.enemy-card {
  min-height: 70px;
  padding: 8px 10px;
  background-image: linear-gradient(180deg, #2c1e15 0%, #1f140e 100%);
  border: 1.5px solid #6b4b2b;
  border-radius: 8px;
  box-shadow:
    inset 0 1px 0 rgba(245, 214, 158, 0.14),
    0 2px 6px rgba(0, 0, 0, 0.35);
  display: grid;
  grid-template-columns: 56px 1fr;
  column-gap: 10px;
  align-items: center;
}

.enemy-portrait-box {
  position: relative;
  width: 56px;
  height: 54px;
  border-radius: 6px;
  background-color: #19100b;
  border: 1px solid #593d25;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.enemy-portrait-img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
}

.enemy-card-count {
  position: absolute;
  bottom: 1px;
  right: 2px;
  padding: 0 4px;
  border-radius: 4px;
  background-color: #18100a;
  border: 1px solid var(--accent);
  font-size: 10px;
  line-height: 1.3;
  font-weight: 700;
  color: var(--accent);
}

.enemy-card-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 0 2px;
}

.enemy-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}

.enemy-card-name {
  font-family: 'Philosopher', Georgia, serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.enemy-trait-badge {
  width: 19px;
  height: 19px;
  border-radius: 4px;
  background-color: rgba(24, 15, 10, 0.85);
  border: 1px solid var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.enemy-card-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.ec-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ==================== CENTER 2D STAGE ==================== */
#center-stage {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 1px var(--border-strong);
  background-color: #1b2633;
  min-height: 0;
}

#stage-canvas-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Restrained Slow-Mo Border Tint */
#slowmo-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s var(--ease);
  box-shadow: inset 0 0 0 3px rgba(98, 200, 245, 0.55), inset 0 0 48px rgba(18, 56, 98, 0.45);
  z-index: 6;
}
#slowmo-vignette.active { opacity: 1; }

/* Top Stage Bar */
#stage-topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 12;
  pointer-events: none;
}

.stage-meta-bar {
  pointer-events: auto;
  min-width: 84px;
  height: 32px;
  padding: 0 14px;
  background-image: linear-gradient(180deg, #4b321f 0%, #301e12 100%);
  border: 1.5px solid #a47b42;
  border-radius: 999px;
  box-shadow:
    inset 0 1px 0 rgba(250, 224, 166, 0.25),
    0 2px 6px rgba(0, 0, 0, 0.45);
  color: #f6e7c8;
  text-shadow: 0 1px 0 #1b1008;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.slowmo-badge {
  min-width: 72px;
  height: 32px;
  padding: 0 12px;
  background-image: linear-gradient(180deg, #1e4b73 0%, #12314f 100%);
  border: 1.5px solid #6ec7f7;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  color: #dff6ff;
  text-shadow: 0 1px 0 #0c1f36;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.topbar-controls {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.stage-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background-color: rgba(28, 19, 14, 0.88);
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.14s var(--ease), transform 0.1s var(--ease);
}
.stage-icon-btn:hover { background-color: var(--surface-3); }
.stage-icon-btn:active { transform: scale(0.96); }
.stage-icon-btn.is-off { color: var(--text-muted); }

.stage-label-btn {
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background-color: rgba(28, 19, 14, 0.88);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease), transform 0.1s var(--ease);
}
.stage-label-btn .ico-slot {
  display: none;
}
.stage-label-btn:hover { background-color: var(--surface-3); }
.stage-label-btn:active { transform: scale(0.97); }
.stage-label-btn.active {
  border-color: var(--accent);
  background-color: var(--surface-3);
}
.stage-label-btn.active .ico-slot { color: var(--accent); }

/* ==================== COMPACT TEST PANEL ==================== */
.test-panel {
  position: fixed;
  top: 56px;
  right: 16px;
  width: min(328px, calc(100vw - 24px));
  max-height: calc(100dvh - 80px);
  overflow-y: auto;
  padding: 12px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.6);
}

.test-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.test-head.dragging {
  cursor: grabbing;
}

.test-title {
  font-family: 'Philosopher', Georgia, serif;
  font-size: 16px;
  color: var(--text-primary);
}

.test-close-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background-color: var(--surface-2);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.14s var(--ease), color 0.14s var(--ease);
}
.test-close-btn:hover { background-color: var(--surface-3); color: var(--text-primary); }

.test-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.test-group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.test-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.test-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.test-btn {
  min-height: 32px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background-color: var(--surface-2);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease), transform 0.1s var(--ease);
}
.test-btn:hover {
  background-color: var(--surface-3);
  border-color: var(--border-strong);
}
.test-btn:active { transform: scale(0.98); }

.test-btn-danger {
  color: #f2a296;
  border-color: rgba(209, 72, 54, 0.35);
}
.test-btn-danger:hover {
  background-color: rgba(209, 72, 54, 0.2);
  border-color: rgba(209, 72, 54, 0.55);
}

.test-btn-span {
  grid-column: 1 / -1;
}

/* ==================== SPRITE SHEET PREVIEW MODAL ==================== */
.sprite-window {
  width: 100%;
  max-width: 920px;
  max-height: 92vh;
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.sprite-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.sprite-live-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background-color: var(--surface-0);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 12px;
}

.sprite-mode-tabs {
  display: flex;
  gap: 8px;
}

.sprite-mode-btn {
  height: 32px;
  padding: 0 14px;
  border: 1.5px solid #6b4b2b;
  border-radius: 7px;
  background-image: linear-gradient(180deg, #3c281b 0%, #2b1c12 100%);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.sprite-mode-btn.active {
  background-image: linear-gradient(180deg, #f3e2be 0%, #dec493 100%);
  border-color: #b5853b;
  color: #241409;
}

#sprite-preview-canvas {
  width: 100%;
  height: 88px;
  display: block;
  background-color: #263529;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
}

.sprite-atlas-wrap {
  overflow-y: auto;
  background-color: var(--surface-0);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sprite-col-headers {
  display: grid;
  grid-template-columns: 88px repeat(7, 1fr);
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
}

.sprite-atlas-body {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 8px;
  align-items: stretch;
}

.sprite-row-labels {
  display: grid;
  grid-template-rows: repeat(7, 1fr);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}
.sprite-row-labels span {
  display: flex;
  align-items: center;
}

.sprite-atlas-img {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  border-radius: 6px;
  background-image:
    linear-gradient(45deg, #241b15 25%, transparent 25%),
    linear-gradient(-45deg, #241b15 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #241b15 75%),
    linear-gradient(-45deg, transparent 75%, #241b15 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #1c1510;
  border: 1px solid var(--border-subtle);
}

/* ==================== WIZARD MENTOR TUTORIAL SCROLL ==================== */
.tutorial-card {
  position: absolute;
  top: 56px;
  left: 16px;
  width: min(304px, calc(100% - 32px));
  min-height: 104px;
  background-image: linear-gradient(180deg, #f4e6c7 0%, #e3cc9d 100%);
  border: 2px solid #593a1e;
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 2px rgba(138, 92, 46, 0.25),
    0 8px 20px rgba(0, 0, 0, 0.55);
  padding: 14px 16px 14px 52px;
  z-index: 22;
  display: flex;
  align-items: center;
}

.tut-wizard-medal {
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  pointer-events: none;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
}
.tut-wizard-medal img {
  display: block;
  width: 60px;
  height: 60px;
  object-fit: contain;
}

.tut-scroll-inner {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tut-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.tut-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tut-gem {
  display: block;
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.tut-skip-btn {
  background: none;
  border: none;
  padding: 2px 4px;
  color: #6b4b2b;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: color 0.14s var(--ease);
}
.tut-skip-btn:hover { color: #2b180b; }

.tut-title {
  font-family: 'Philosopher', Georgia, serif;
  font-size: 16px;
  font-weight: 700;
  color: #24140a;
  line-height: 1.2;
}

.tut-body {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  color: #3f2814;
}

.tut-scroll-inner .primary-btn {
  align-self: flex-start;
  margin-top: 4px;
}

/* Medieval Parchment Wave Banner Scroll */
.wave-banner {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -50%);
  min-width: 210px;
  padding: 10px 28px;
  text-align: center;
  z-index: 16;
  pointer-events: none;
  background-image: linear-gradient(180deg, #f5e7c8 0%, #e2ca9a 100%);
  border: 2px solid #593a1e;
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 2px rgba(138, 92, 46, 0.28),
    0 8px 18px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.wave-banner.wave-banner-tut {
  top: 206px;
  transform: translate(-50%, 0);
}
.wave-banner-sub {
  font-size: 11px;
  font-weight: 700;
  color: #6b4322;
  line-height: 1.1;
  margin-bottom: 1px;
}
.wave-banner-title {
  font-family: 'Philosopher', Georgia, serif;
  font-size: 19px;
  font-weight: 700;
  white-space: nowrap;
  color: #24140a;
  line-height: 1.12;
}

/* Heraldic Circuit Live Preview Pennant Badge */
.circuit-preview-badge {
  position: absolute;
  transform: translate(-50%, -132%);
  z-index: 14;
  pointer-events: none;
  padding: 5px 12px 7px;
  border-radius: 4px 4px 10px 10px;
  border: 2px solid #e6c068;
  font-family: 'Philosopher', Georgia, serif;
  font-size: 13px;
  font-weight: 700;
  color: #fff6e0;
  text-shadow: 0 1px 0 #180c06;
  white-space: nowrap;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.55);
}
.circuit-preview-badge.fire { background-color: #a62818; border-color: #f0be6a; }
.circuit-preview-badge.dome { background-color: #195b9c; border-color: #9ad8ff; }
.circuit-preview-badge.support { background-color: #257022; border-color: #a4eb98; }
.circuit-preview-badge.multi { background-color: #612a94; border-color: #e4bdff; }

/* ==================== BOTTOM 3-TILE TRAY & SHAKE BUTTON ==================== */
#bottom-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--tray-bottom, 18px);
  transform: scale(var(--tray-scale, 1));
  transform-origin: bottom center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 0 12px;
  z-index: 14;
  pointer-events: none;
}

#tile-tray-wrap {
  position: relative;
  display: flex;
  align-items: center;
  pointer-events: auto;
  touch-action: none;
}

.tray-handle {
  width: 10px;
  height: 36px;
  background-color: #46505c;
  border: 2px solid var(--ink);
  border-radius: 4px;
}

#tile-tray {
  width: 288px;
  height: 102px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 17px;
  padding: 15px 46px 33px 44px;
  background-image: url('./assets/arcade32/tray_frame.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  touch-action: none;
}

.tray-slot {
  width: 54px;
  height: 54px;
  border-radius: 4px;
  background-color: transparent;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  cursor: grab;
  touch-action: none;
  transition: transform 0.24s var(--ease), border-color 0.22s var(--ease);
}

.tray-slot:hover {
  border-color: rgba(242, 206, 114, 0.55);
}

.tray-slot.selected {
  border-color: var(--accent);
  background-color: rgba(14, 10, 8, 0.36);
}

.tray-slot.selected .tray-tile-svg-wrap,
.tray-slot.dragging-source .tray-tile-svg-wrap {
  opacity: 0;
  visibility: hidden;
  transform: scale(0.84);
}

.tray-slot.tutorial-target {
  border-color: var(--accent);
}

.tray-slot.dragging-source {
  border-color: var(--accent);
  background-color: rgba(14, 10, 8, 0.36);
}
.tray-slot.targeted-by-thief { border-color: var(--sem-hp); }

.tray-tile-svg-wrap {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.22s var(--ease);
  pointer-events: none;
}

.tray-tile-badge {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(24, 17, 13, 0.94);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  line-height: 1.2;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}

.tray-rotate-hint {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: var(--accent);
  border: 1.5px solid var(--ink);
  color: var(--accent-ink);
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.tray-slot.selected .tray-rotate-hint { display: flex; }

/* Goblin Thief on Tray */
.goblin-thief {
  position: absolute;
  top: -54px;
  left: 50%;
  transform: translateX(-50%);
  width: 72px;
  height: 72px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 25;
}
.goblin-thief.hit-bounce {
  transform: translateX(-50%) scale(0.92);
}

.thief-timer-ring {
  position: absolute;
  inset: -4px;
  pointer-events: none;
}
.thief-timer-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.thief-timer-ring .ring-bg {
  fill: none;
  stroke: rgba(0, 0, 0, 0.45);
  stroke-width: 3.5;
}
.thief-timer-ring .ring-fg {
  fill: none;
  stroke: var(--sem-hp);
  stroke-width: 4;
  stroke-dasharray: 119.4;
  stroke-dashoffset: 0;
  stroke-linecap: round;
}

.thief-hits-badge {
  position: absolute;
  top: -14px;
  background-color: #b8321b;
  color: #fff;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

/* Shake Button (32-Bit Arcade Vortex Medallion) */
.shake-btn {
  pointer-events: auto;
  position: relative;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  background-color: transparent;
  background-image: url('./assets/arcade32/shake_ready.png');
  background-size: 100% 100%;
  image-rendering: pixelated;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s var(--ease), filter 0.14s var(--ease);
}
.shake-btn:hover:not(:disabled) { filter: brightness(1.08); }
.shake-btn:active:not(:disabled) {
  background-image: url('./assets/arcade32/shake_pressed.png');
  transform: scale(0.96);
}
.shake-btn:disabled {
  cursor: not-allowed;
  background-image: url('./assets/arcade32/shake_pressed.png');
  filter: brightness(0.8);
}
.shake-btn.tutorial-target { box-shadow: 0 0 0 2px var(--accent); }

.shake-cd-svg {
  position: absolute;
  inset: -2px;
  width: calc(100% + 4px);
  height: calc(100% + 4px);
  transform: rotate(-90deg);
  pointer-events: none;
}
.shake-cd-svg .cd-track {
  fill: none;
  stroke: rgba(0, 0, 0, 0.25);
  stroke-width: 4;
}
.shake-cd-svg .cd-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-dasharray: 219.9;
  stroke-dashoffset: 0;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.1s linear;
}

.shake-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.shake-cd-text {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 0 #140d09;
}

.shake-label {
  position: absolute;
  bottom: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--surface-0);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 1px 6px;
  white-space: nowrap;
}

.drag-ghost {
  position: fixed;
  width: 58px;
  height: 58px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.55));
  z-index: 60;
}
.drag-ghost.touch-dragging {
  width: 64px;
  height: 64px;
  opacity: 0.92;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.65));
}
.drag-ghost .tray-tile-img {
  transition: transform 0.2s var(--ease);
}

/* ==================== CRISP FORGED GOLD & CARVED WALNUT BUTTONS ==================== */
.primary-btn {
  height: 44px;
  padding: 0 18px;
  border: 2px solid #4a2a0a;
  border-radius: 9px;
  background-image:
    linear-gradient(180deg, rgba(255, 232, 146, 0.32) 0%, rgba(226, 166, 52, 0.24) 55%, rgba(164, 102, 20, 0.42) 100%),
    url('./assets/arcade32/tex_gold_satin.jpg?v=mat4');
  background-size: 100% 100%, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
  box-shadow:
    inset 0 2px 0 rgba(255, 251, 224, 0.78),
    inset 0 -3px 0 #8a5310,
    0 3px 0 #1a0f07,
    0 5px 12px rgba(0, 0, 0, 0.42);
  color: var(--accent-ink);
  text-shadow: 0 1px 0 rgba(255, 244, 198, 0.55);
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: filter 0.14s var(--ease), transform 0.1s var(--ease);
}
.primary-btn:hover:not(:disabled) { filter: brightness(1.07); }
.primary-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow:
    inset 0 2px 4px rgba(64, 34, 6, 0.45),
    0 1px 0 #1a0f07;
}
.primary-btn:disabled {
  background-image: linear-gradient(180deg, #5e4c3a 0%, #443628 100%);
  color: #b8a690;
  text-shadow: none;
  box-shadow: inset 0 -2px 0 #2b2118, 0 2px 0 #160e08;
  opacity: 0.72;
  cursor: not-allowed;
}
.primary-btn.small-primary { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 7px; }
.primary-btn.full-width { width: 100%; }

.chrome-btn {
  height: 38px;
  padding: 0 14px;
  border: 1.5px solid #9c743e;
  border-radius: 8px;
  background-image:
    linear-gradient(180deg, rgba(48, 28, 14, 0.44) 0%, rgba(24, 13, 6, 0.64) 100%),
    url('./assets/arcade32/tex_wood_oak.jpg?v=mat4');
  background-size: 100% 100%, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
  box-shadow:
    inset 0 1px 0 rgba(250, 222, 168, 0.32),
    inset 0 -3px 0 #21140b,
    0 3px 0 #160c07,
    0 4px 10px rgba(0, 0, 0, 0.35);
  color: var(--text-primary);
  text-shadow: 0 1px 2px #140a04;
  font-family: inherit;
  font-size: 13px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: filter 0.14s var(--ease), transform 0.1s var(--ease);
}
.modal-actions .chrome-btn {
  height: 44px;
  padding: 0 18px;
  font-size: 14px;
}
.chrome-btn:hover { filter: brightness(1.1); }
.chrome-btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45), 0 1px 0 #160c07;
}
.chrome-btn.icon-only { width: 38px; padding: 0; }

/* ==================== MODALS & ARMORY SHOP ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(12, 9, 7, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
  overflow-y: auto;
}

#settings-modal {
  z-index: 54;
}

.modal-card {
  border-radius: 14px;
  padding: 20px 22px;
  max-width: 368px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.72);
}

.menu-modal {
  text-align: center;
  align-items: center;
}

.modal-title {
  margin: 0;
  font-family: 'Philosopher', Georgia, serif;
  font-size: 26px;
  font-weight: 700;
  color: #f4d898;
  text-shadow: 0 2px 0 #160c08;
  line-height: 1.1;
}
.modal-desc {
  margin: -4px 0 2px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
}
.menu-stack {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* Armory Window */
.armory-window {
  width: 100%;
  max-width: 868px;
  max-height: 92vh;
  border-radius: 14px;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

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

.shopkeeper-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 220px;
}

.armory-title {
  margin: 0;
  font-family: 'Philosopher', Georgia, serif;
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 1px 0 #160c08;
}

.shopkeeper-quote {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.armory-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.armory-currencies {
  display: flex;
  gap: 8px;
}

.currency-tile {
  min-width: 104px;
  height: 44px;
}
.currency-val {
  font-size: 17px;
  font-weight: 700;
  text-shadow: 0 1px 0 #160c08;
}

.armory-tabs-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 2px solid #1a100a;
  padding-bottom: 0;
}

.armory-tabs {
  display: flex;
  gap: 8px;
  flex: 1;
}

.armory-tab {
  flex: 1;
  max-width: 164px;
  height: 40px;
  padding: 0 12px;
  border: 1.5px solid #6b4b2b;
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  background-image: linear-gradient(180deg, #3c281a 0%, #2a1b11 100%);
  color: var(--text-secondary);
  font-family: 'Philosopher', Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: filter 0.14s var(--ease), background-color 0.14s var(--ease);
}
.armory-tab:hover { filter: brightness(1.08); }
.armory-tab.active {
  background-image: linear-gradient(180deg, #f3e2be 0%, #dfc696 100%);
  border-color: #c29144;
  color: #241409;
  box-shadow: inset 0 1px 0 rgba(255, 250, 232, 0.7);
}
.armory-tab.active .ico-slot { color: #241409; }

.reward-pill {
  height: 32px;
  padding: 0 10px;
  margin-bottom: 6px;
  border-radius: 6px;
  background-color: var(--surface-0);
  border: 1px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.armory-items {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #7c5630 #1b110b;
}
.armory-items::-webkit-scrollbar {
  width: 6px;
}
.armory-items::-webkit-scrollbar-track {
  background: #1b110b;
  border-radius: 4px;
}
.armory-items::-webkit-scrollbar-thumb {
  background: #7c5630;
  border-radius: 4px;
}
.armory-items.gems-layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

/* ==================== 9-GEM STAFF SOCKETS & 3x3 COLLECTION ==================== */
.grimoire-gem-ico {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.grimoire-gem-ico img {
  display: block;
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.staff-sockets-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 14px 10px;
  border-radius: 10px;
  background:
    radial-gradient(ellipse at 50% 56%, rgba(82, 52, 26, 0.34) 0%, rgba(22, 13, 8, 0.92) 74%),
    #19100a;
  border: 2px solid #5e3e23;
  box-shadow:
    inset 0 2px 10px rgba(0, 0, 0, 0.68),
    inset 0 -1px 0 rgba(214, 166, 94, 0.14);
}

.sockets-bar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.sockets-bar-title {
  font-family: 'Philosopher', Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  color: #f3e4c6;
  padding: 3px 10px;
  border-radius: 6px;
  background-color: #2f1f14;
  border: 1px solid #6e4a2b;
  white-space: nowrap;
}

.sockets-hint {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0;
}

.staff-visual-stage {
  position: relative;
  width: 100%;
  max-width: 780px;
  aspect-ratio: 824 / 128;
  margin: 2px auto 0;
}

.staff-bg-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 5px 8px rgba(0, 0, 0, 0.65));
}

.sockets-bar-slots {
  position: absolute;
  inset: 0;
}

.socket-slot-btn {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 7.4%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s var(--ease), border-color 0.14s var(--ease), background-color 0.14s var(--ease);
}
.socket-slot-btn:hover {
  transform: translate(-50%, -50%) scale(1.07);
  border-color: rgba(255, 224, 130, 0.72);
}
.socket-slot-btn.selected {
  border-color: #ffe082;
  background-color: rgba(255, 214, 108, 0.14);
}

.socket-bezel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.socket-bezel img {
  display: block;
  width: 78%;
  height: 78%;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.75));
}

.socket-pos-badge {
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 700;
  color: #e8d8ba;
  background-color: #160e09;
  border: 1px solid #664528;
  border-radius: 4px;
  padding: 1px 7px;
  white-space: nowrap;
  pointer-events: none;
}
.socket-slot-btn.selected .socket-pos-badge {
  border-color: #f0c256;
  color: #ffe399;
}

.socket-swap-btn {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid #966c36;
  background-color: rgba(28, 17, 11, 0.92);
  color: #f0c256;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.14s var(--ease), transform 0.1s var(--ease), border-color 0.14s var(--ease);
}
.socket-swap-btn:hover {
  background-color: #4a311f;
  border-color: #f0c256;
}
.socket-swap-btn:active {
  transform: translate(-50%, -50%) scale(0.92);
}

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

.gems-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.gems-col-head {
  text-align: center;
  font-family: 'Philosopher', Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  color: #f5e6c8;
  background-color: #342216;
  border: 1px solid #75502e;
  border-radius: 6px;
  padding: 4px 10px;
}

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

.gem-mini-card {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 76px;
  padding: 8px 10px;
  border-radius: 8px;
  background-image:
    linear-gradient(180deg, rgba(246, 232, 198, 0.26) 0%, rgba(214, 186, 134, 0.3) 100%),
    url('./assets/arcade32/tex_parchment.jpg?v=mat4');
  background-size: 100% 100%, 180px 180px;
  background-repeat: no-repeat, repeat;
  border: 2px solid #4a2e16;
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 228, 0.55),
    0 2px 5px rgba(0, 0, 0, 0.3);
  transition: filter 0.14s var(--ease), border-color 0.14s var(--ease), transform 0.1s var(--ease);
}
.gem-mini-card.unlocked {
  cursor: pointer;
}
.gem-mini-card.unlocked:hover {
  filter: brightness(1.04);
  border-color: #b8883b;
}
.gem-mini-card.equipped {
  border-color: #f0c256;
}
.gem-mini-card.locked .gem-mini-art img {
  opacity: 0.78;
}

.gem-mini-art {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background-color: #24160e;
  border: 2px solid #593b23;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gem-mini-card.equipped .gem-mini-art {
  border-color: #d9a441;
}
.gem-mini-art img {
  display: block;
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.gem-mini-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gem-mini-name {
  font-family: 'Philosopher', Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  color: #24140a;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gem-mini-pips {
  display: flex;
  align-items: center;
  gap: 2px;
}
.gem-pip {
  width: 12px;
  height: 12px;
  object-fit: contain;
}

.gem-mini-tag {
  font-size: 12px;
  font-weight: 700;
  color: #4a2e16;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gem-mini-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-width: 66px;
}

.gem-slot-pill {
  height: 22px;
  padding: 0 6px;
  border-radius: 5px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.gem-slot-pill.active {
  background-color: #2a6e28;
  border: 1px solid #78d96e;
  color: #f0ffe8;
}
.gem-slot-pill.equip-btn {
  background-color: #4f331c;
  border: 1px solid #a87b3e;
  color: #f7e9cf;
  cursor: pointer;
  transition: background-color 0.14s var(--ease);
}
.gem-slot-pill.equip-btn:hover {
  background-color: #6b4626;
}

.gem-max-pill {
  height: 26px;
  border-radius: 5px;
  background-color: rgba(66, 44, 24, 0.2);
  border: 1px solid rgba(66, 44, 24, 0.35);
  color: #4f341c;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.gem-action-btn {
  height: 34px;
  padding: 0 10px;
  border: 1.5px solid #2c1045;
  border-radius: 7px;
  background-image:
    linear-gradient(180deg, rgba(146, 72, 222, 0.45) 0%, rgba(72, 24, 132, 0.58) 100%),
    url('./assets/arcade32/tex_amethyst.jpg?v=mat4');
  background-size: 100% 100%, cover;
  background-position: center, center;
  background-repeat: no-repeat, no-repeat;
  box-shadow:
    inset 0 1px 0 rgba(235, 206, 255, 0.45),
    inset 0 -2px 0 #3a1466,
    0 2px 0 #1b092e;
  color: #ffffff;
  text-shadow: 0 1px 2px #160524;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: filter 0.14s var(--ease), transform 0.1s var(--ease);
}
.gem-action-btn.compact {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
}
.gem-action-btn:hover:not(:disabled) { filter: brightness(1.09); }
.gem-action-btn:active:not(:disabled) { transform: translateY(1px); }
.gem-action-btn:disabled {
  background-image: linear-gradient(180deg, #5c4b3c 0%, #44372c 100%);
  border-color: #2e2218;
  box-shadow: inset 0 -2px 0 #2a2018;
  color: #d6c5ae;
  text-shadow: 0 1px 0 #1b1008;
  opacity: 0.78;
  cursor: not-allowed;
}

.shop-card {
  background-image:
    linear-gradient(180deg, rgba(36, 22, 14, 0.32) 0%, rgba(20, 12, 8, 0.48) 100%),
    url('./assets/arcade32/tex_wood_dark.jpg?v=mat4');
  background-size: 100% 100%, 160px 160px;
  background-repeat: no-repeat, repeat;
  border: 2px solid #78552e;
  border-radius: 10px;
  box-shadow:
    inset 0 1px 0 rgba(246, 214, 150, 0.16),
    0 4px 10px rgba(0, 0, 0, 0.4);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: space-between;
}

.shop-parchment {
  position: relative;
  background-image:
    linear-gradient(180deg, rgba(246, 232, 198, 0.26) 0%, rgba(214, 186, 134, 0.3) 100%),
    url('./assets/arcade32/tex_parchment.jpg?v=mat4');
  background-size: 100% 100%, 180px 180px;
  background-repeat: no-repeat, repeat;
  border: 1.5px solid #593a1e;
  border-radius: 7px;
  box-shadow: inset 0 1px 0 rgba(255, 248, 228, 0.55);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  flex: 1;
}

.shop-card-name {
  font-family: 'Philosopher', Georgia, serif;
  font-size: 15px;
  font-weight: 700;
  color: #24140a;
  line-height: 1.15;
}

.shop-card-art {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shop-card-art img {
  image-rendering: pixelated;
}

.shop-pips {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}
.shop-pip {
  width: 15px;
  height: 15px;
  object-fit: contain;
}

.shop-card-tag {
  padding: 3px 8px;
  border-radius: 5px;
  background-color: rgba(112, 74, 38, 0.16);
  border: 1px solid rgba(94, 60, 32, 0.28);
  font-size: 12px;
  font-weight: 700;
  color: #3a2310;
  line-height: 1.2;
}

.shop-buy-btn {
  width: 100%;
  height: 40px;
  border: 2px solid #3d230a;
  border-radius: 8px;
  background-image: linear-gradient(180deg, #f7d67a 0%, #e0a63e 56%, #be8022 100%);
  box-shadow:
    inset 0 1.5px 0 rgba(255, 249, 218, 0.7),
    inset 0 -3px 0 #8a5512,
    0 2px 0 #1a0f07;
  color: var(--accent-ink);
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: filter 0.14s var(--ease), transform 0.1s var(--ease);
}
.shop-buy-btn:hover:not(:disabled) { filter: brightness(1.07); }
.shop-buy-btn:active:not(:disabled) { transform: translateY(1px); }
.shop-buy-btn.dust-btn {
  border-color: #2c1045;
  background-image: linear-gradient(180deg, #9d5be0 0%, #7334b8 58%, #54218f 100%);
  box-shadow:
    inset 0 1.5px 0 rgba(235, 206, 255, 0.45),
    inset 0 -3px 0 #3a1466,
    0 2px 0 #1b092e;
  color: #ffffff;
  text-shadow: 0 1px 0 #1c082d;
}
.shop-buy-btn:disabled {
  border-color: #2e2218;
  background-image: linear-gradient(180deg, #5c4b3c 0%, #44372c 100%);
  box-shadow: inset 0 -2px 0 #2a2018;
  color: #d6c5ae;
  text-shadow: 0 1px 0 #1b1008;
  opacity: 0.78;
  cursor: not-allowed;
}

.armory-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}

/* Defeat Modal ("Ворота пали") */
.defeat-window {
  position: relative;
  padding-top: 42px;
  text-align: center;
  align-items: center;
  max-width: 368px;
}

.defeat-crest {
  position: absolute;
  top: -42px;
  left: 50%;
  transform: translateX(-50%);
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.65));
}
.defeat-crest img {
  display: block;
}

.defeat-title {
  margin: 0;
  font-family: 'Philosopher', Georgia, serif;
  font-size: 26px;
  font-weight: 700;
  color: #f4d898;
  text-shadow: 0 2px 0 #160c08;
}

.defeat-scroll {
  width: 100%;
  background-image:
    linear-gradient(180deg, rgba(246, 232, 198, 0.26) 0%, rgba(214, 186, 134, 0.3) 100%),
    url('./assets/arcade32/tex_parchment.jpg?v=mat4');
  background-size: 100% 100%, 180px 180px;
  background-repeat: no-repeat, repeat;
  border: 2px solid #593a1e;
  border-radius: 9px;
  box-shadow:
    inset 0 0 0 2px rgba(138, 92, 46, 0.25),
    inset 0 2px 6px rgba(255, 248, 228, 0.55);
  padding: 16px 20px;
}

.defeat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 16px;
}

.defeat-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #24140a;
}
.defeat-cell-label {
  font-size: 11px;
  font-weight: 700;
  color: #634020;
  line-height: 1.1;
}
.defeat-cell-val {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 17px;
  font-weight: 700;
  color: #24140a;
}
.defeat-cell .ico-slot {
  width: 20px;
  height: 20px;
  color: #4f2f16;
}
.defeat-scroll .val-dust {
  color: #1c5fa3;
}

/* Victory Modal */
.victory-window {
  position: relative;
  padding-top: 44px;
  text-align: center;
  align-items: center;
  max-width: 368px;
}

.vic-stars-row {
  position: absolute;
  top: -32px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.65));
}
.vic-stars-row img {
  display: block;
  width: 48px;
  height: 48px;
  object-fit: contain;
}
.vic-stars-row img.center-star {
  width: 58px;
  height: 58px;
  transform: translateY(-6px);
}

/* ==================== DEDICATED CAMPAIGN ADVENTURE MAP SCREEN ==================== */
.campaign-screen {
  position: fixed;
  inset: 0;
  z-index: 44;
  background-color: #160f0a;
  background-image: radial-gradient(circle at 50% 45%, #2b1d13 0%, #140d09 100%);
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  gap: 10px;
  overflow: hidden;
}

.campaign-topbar {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 6px 14px;
  border-radius: 12px;
  flex-shrink: 0;
}

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

.camp-bar-divider {
  width: 1px;
  height: 34px;
  background: linear-gradient(180deg, rgba(168, 120, 56, 0) 0%, rgba(186, 138, 72, 0.7) 50%, rgba(168, 120, 56, 0) 100%);
  flex-shrink: 0;
}

.camp-title-plaque {
  min-width: 152px;
  height: 38px;
  margin: 0;
  font-size: 15px;
}

.camp-stars-pill {
  height: 38px;
  padding: 0 11px;
  border-radius: 8px;
  background-color: #1c120c;
  border: 1.5px solid #8a6334;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  color: #ffe28a;
}
.camp-stars-pill img {
  display: block;
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.camp-curr-tile {
  min-width: 86px;
  height: 38px;
}

.camp-test-wrap {
  position: relative;
}
.camp-test-menu {
  position: absolute;
  top: 44px;
  right: 0;
  width: 210px;
  padding: 10px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 48;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.65);
}

.campaign-map-viewport {
  flex: 1;
  min-height: 0;
  width: 100%;
  container-type: size;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 2px 0;
}

.campaign-map-board {
  position: relative;
  width: min(100cqw, calc(100cqh * 1.791667));
  height: min(100cqh, calc(100cqw / 1.791667));
  border-radius: 12px;
  overflow: hidden;
  padding: 0;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.72);
}

.campaign-map-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  user-select: none;
}

.campaign-trail-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.campaign-nodes-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
}

.camp-node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: clamp(44px, 5.2vw, 64px);
  height: clamp(44px, 5.2vw, 64px);
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.16s var(--ease), filter 0.16s var(--ease);
}
.camp-node.is-boss {
  width: clamp(54px, 6.2vw, 76px);
  height: clamp(54px, 6.2vw, 76px);
}
.camp-node:hover {
  transform: translate(-50%, -50%) scale(1.1);
  z-index: 8;
}
.camp-node.selected {
  transform: translate(-50%, -50%) scale(1.12);
  z-index: 9;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #f5cc6a, 0 4px 12px rgba(0, 0, 0, 0.55);
}
.camp-node.locked {
  filter: saturate(0.6) brightness(0.88);
}
.camp-node.locked.selected {
  filter: saturate(0.75) brightness(0.98) drop-shadow(0 0 6px rgba(210, 180, 130, 0.6));
}

.camp-node-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
}

.camp-node-num {
  position: relative;
  z-index: 2;
  font-family: 'Philosopher', Georgia, serif;
  font-size: clamp(16px, 1.9vw, 23px);
  font-weight: 700;
  color: #fff6e0;
  text-shadow: 0 2px 0 #160c07, 0 0 4px rgba(0, 0, 0, 0.8);
  line-height: 1;
}
.camp-node.locked .camp-node-num {
  color: #a8a29c;
}

.camp-node-pointer {
  position: absolute;
  top: -15px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 10px solid #ffe066;
  filter: drop-shadow(0 2px 2px #140b06);
  pointer-events: none;
}

.camp-node-stars {
  position: absolute;
  bottom: -11px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 1px 4px;
  border-radius: 6px;
  background-color: rgba(20, 13, 9, 0.88);
  border: 1px solid #6b4b28;
  pointer-events: none;
}
.camp-node-stars img {
  display: block;
  width: 12px;
  height: 12px;
  object-fit: contain;
}

/* Bottom Compact Centered Mission Dock */
.campaign-detail-bar {
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px;
  border-radius: 12px;
  flex-shrink: 0;
}

.camp-detail-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.camp-detail-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.camp-lvl-badge {
  padding: 2px 8px;
  border-radius: 5px;
  background-color: #1a110b;
  border: 1px solid #c99642;
  color: #ffe28a;
  font-size: 12px;
  font-weight: 700;
}

.camp-lvl-name {
  margin: 0;
  font-family: 'Philosopher', Georgia, serif;
  font-size: 19px;
  font-weight: 700;
  color: #f7ebd2;
  text-shadow: 0 1px 0 #160c08;
  white-space: nowrap;
}

.camp-biome-tag {
  padding: 2px 8px;
  border-radius: 5px;
  background-color: #362316;
  border: 1px solid #6e4a2b;
  color: #d9c3a0;
  font-size: 11px;
  font-weight: 700;
}

.camp-detail-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
}

.camp-detail-stars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.camp-detail-stars img {
  display: block;
  width: 17px;
  height: 17px;
  object-fit: contain;
}

.camp-meta-sep { color: #6e5236; }
.camp-reward-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.camp-detail-enemies {
  display: flex;
  align-items: center;
  gap: 10px;
}

.camp-group-label {
  font-size: 11px;
  font-weight: 700;
  color: #b89d7a;
  line-height: 1;
}

.camp-enemies-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.camp-enemy-ico {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  background-color: #1f140d;
  border: 1px solid #664528;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.camp-enemy-ico img {
  display: block;
  width: 32px;
  height: 32px;
  object-fit: contain;
  image-rendering: pixelated;
}

.camp-play-btn {
  min-width: 138px;
  height: 46px;
  font-size: 15px;
}

/* ==================== MAIN MENU & SETTINGS MODAL ==================== */
.main-menu-screen {
  position: fixed;
  inset: 0;
  z-index: 46;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background-color: #160f0a;
  overflow-y: auto;
}

.main-menu-backdrop {
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(ellipse at 50% 44%, rgba(16, 10, 6, 0.52) 0%, rgba(12, 8, 5, 0.88) 82%),
    url('./assets/battle_bg_hibit.png');
  background-size: cover;
  background-position: 62% center;
  pointer-events: none;
}

.main-menu-wrap {
  position: relative;
  z-index: 2;
  width: min(368px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.menu-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
}

.menu-emblem-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.65));
}

.menu-crystal-main {
  display: block;
  width: 44px;
  height: auto;
  object-fit: contain;
}

.menu-gem-side {
  display: block;
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.menu-title {
  margin: 0;
  font-family: 'Philosopher', Georgia, serif;
  font-size: clamp(32px, 6vw, 42px);
  font-weight: 700;
  color: #f8e9c6;
  line-height: 1.05;
  text-shadow: 0 3px 0 #180e08, 0 6px 16px rgba(0, 0, 0, 0.72);
  letter-spacing: 0.01em;
}

.menu-progress-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  border-radius: 999px;
  background-color: rgba(24, 15, 10, 0.88);
  border: 1.5px solid #96703c;
  color: #f3e4c6;
  font-size: 13px;
  font-weight: 700;
}

.menu-prog-star {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #ffe28a;
}
.menu-prog-star img {
  display: block;
  width: 15px;
  height: 15px;
  object-fit: contain;
}

.main-menu-panel {
  width: 100%;
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.72);
}

.menu-btn {
  width: 100%;
  height: 46px;
  font-size: 15px;
}

/* Settings Modal */
.settings-window {
  max-width: 396px;
  gap: 14px;
}

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

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

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 6px 12px;
  border-radius: 8px;
  background-color: #1c130d;
  border: 1px solid #523620;
}

.settings-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.settings-toggle,
.settings-action-btn {
  min-width: 80px;
  height: 34px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid #75502e;
  background-color: #362417;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease);
}
.settings-toggle:hover,
.settings-action-btn:hover { background-color: #4a311f; }
.settings-toggle.on {
  background-color: #296b27;
  border-color: #74d46a;
  color: #f0ffe8;
}
.settings-toggle.off {
  background-color: #2c1d14;
  border-color: #5c3f28;
  color: var(--text-muted);
}
.settings-action-btn.danger {
  border-color: rgba(209, 72, 54, 0.55);
  color: #ff9c8c;
}
.settings-action-btn.danger.confirm {
  background-color: #8f2619;
  border-color: #ff8c78;
  color: #fff2ed;
}

.settings-slider-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-slider {
  width: 112px;
  accent-color: #d9a043;
  cursor: pointer;
  outline: none;
}
.settings-slider:focus-visible {
  outline: 2px solid #d9a043;
  outline-offset: 2px;
  border-radius: 4px;
}

.settings-vol-val {
  min-width: 36px;
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: #ffe28a;
}

/* ==================== MOBILE TOPBAR & RESPONSIVE <= 1024px ==================== */
#mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: max(4px, env(safe-area-inset-top)) 8px 4px;
  background-color: #2f1d13;
  background-image: linear-gradient(180deg, rgba(96, 62, 36, 0.45) 0%, rgba(28, 17, 11, 0.72) 100%);
  border-bottom: 2px solid #96723f;
  box-shadow: inset 0 -1px 0 #180e08;
  z-index: 30;
  gap: 8px;
}

.mobile-quick-stats {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
}
.mq-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.mobile-right-actions {
  display: flex;
  gap: 6px;
}

#drawer-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.56);
  z-index: 35;
}

.hidden {
  display: none !important;
}

@media (max-width: 1024px) {
  #mobile-topbar { display: flex; }
  #btn-mute { display: none; }

  #game-frame {
    grid-template-columns: 1fr;
    padding: 0;
    gap: 0;
  }

  #center-stage {
    border-radius: 0;
    border-width: 0;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: min(304px, 86vw);
    z-index: 40;
    border-radius: 0;
    transition: transform 0.22s var(--ease);
  }
  #sidebar-left { left: 0; transform: translateX(-105%); }
  #sidebar-left.open { transform: translateX(0); }
  #sidebar-right { right: 0; transform: translateX(105%); }
  #sidebar-right.open { transform: translateX(0); }

  .drawer-close-btn { display: inline-flex; }
  .sidebar .panel-section:first-of-type .plaque-title { margin-right: 36px; }
  .armory-items { grid-template-columns: 1fr; }
  .gems-columns { grid-template-columns: 1fr; }
  .staff-sockets-bar { flex-direction: column; padding: 8px 10px; gap: 8px; }

  /* Mobile / Tablet Tutorial Card: compact semi-transparent banner above tray, never covering top battle scene */
  .tutorial-card {
    top: auto;
    bottom: max(var(--tut-bottom, 112px), calc(env(safe-area-inset-bottom) + 96px));
    left: 12px;
    right: 12px;
    width: auto;
    max-width: 440px;
    margin: 0 auto;
    min-height: 0;
    padding: 8px 12px 8px 48px;
    background-image: none;
    background-color: rgba(24, 16, 11, 0.82);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(217, 160, 67, 0.42);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    transition: opacity 0.14s var(--ease);
  }
  body.is-dragging-tile .tutorial-card {
    opacity: 0.22;
  }
  .tutorial-card .tut-skip-btn,
  .tutorial-card #btn-tut-next {
    pointer-events: auto;
  }
  .tut-wizard-medal {
    left: 6px;
    width: 36px;
    height: 36px;
  }
  .tut-wizard-medal img { width: 36px; height: 36px; }
  .tut-scroll-inner { gap: 2px; }
  .tut-gem { width: 14px; height: 14px; }
  .tut-title {
    font-size: 14px;
    color: var(--text-primary);
  }
  .tut-body {
    font-size: 12px;
    line-height: 1.3;
    color: var(--text-secondary);
  }
  .tut-skip-btn {
    color: var(--text-muted);
    font-size: 11px;
    padding: 4px 6px;
  }
  .tut-skip-btn:hover { color: var(--text-primary); }
}

@media (max-width: 960px) {
  .campaign-screen {
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: 10px;
    overflow-y: auto;
  }
  .campaign-topbar {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    padding: 8px 10px;
    gap: 8px;
  }
  .camp-bar-divider { display: none; }
  .camp-head-left {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    align-items: center;
    gap: 8px;
    width: 100%;
  }
  .camp-head-left .chrome-btn.icon-only {
    width: 36px;
    height: 36px;
    padding: 0;
  }
  .camp-title-plaque {
    min-width: 0;
    width: 100%;
    height: 36px;
    font-size: 14px;
  }
  .camp-stars-pill {
    height: 36px;
    padding: 0 9px;
    font-size: 13px;
  }
  .camp-head-right {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: center;
    gap: 8px;
    width: 100%;
  }
  .camp-curr-tile {
    min-width: 74px;
    height: 36px;
    padding: 0 8px;
  }
  .camp-head-right .chrome-btn:not(.icon-only) {
    width: 100%;
    height: 36px;
    font-size: 13px;
  }
  .campaign-map-viewport {
    container-type: normal;
    flex: 0 0 auto;
    margin-top: auto;
    padding: 0;
  }
  .campaign-map-board {
    width: 100%;
    height: auto;
    aspect-ratio: 1376 / 768;
  }
  .campaign-detail-bar {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px;
    margin-bottom: auto;
  }
  .camp-detail-enemies { justify-content: space-between; flex-wrap: wrap; }
  .camp-detail-info { min-width: 0; }
  .camp-lvl-name { white-space: normal; font-size: 17px; }
  .camp-play-btn { width: 100%; }
}

@media (max-width: 600px) {
  .wood-panel { border-width: 11px; }
  .modal-backdrop { padding: 8px; }

  /* Compact Battle Stage Topbar so buttons never collide with Wave Pill or Slow-Mo badge */
  #stage-topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    gap: 6px;
  }
  .stage-meta-bar {
    min-width: 72px;
    height: 30px;
    padding: 0 12px;
    font-size: 12px;
  }
  .slowmo-badge {
    min-width: 82px;
    height: 30px;
    padding: 0 10px 0 30px;
    font-size: 11px;
  }
  .topbar-controls { gap: 6px; }
  .stage-icon-btn { width: 34px; height: 34px; }
  .stage-label-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    justify-content: center;
  }
  .stage-label-btn span:not(.ico-slot) { display: none; }
  .stage-label-btn .ico-slot { display: inline-flex; }

  /* Mobile Top Nav Bar */
  #mobile-topbar {
    min-height: 48px;
    gap: 6px;
    padding: max(4px, env(safe-area-inset-top)) 8px 4px;
  }
  .mobile-quick-stats {
    gap: 8px;
    font-size: 12.5px;
  }
  .mq-stat { gap: 4px; }
  .mq-stat .ico-slot { width: 19px; height: 19px; }
  #mobile-topbar .chrome-btn {
    height: 36px;
    padding: 0 10px;
    font-size: 12px;
    gap: 5px;
  }
  #mobile-topbar .icon-only {
    width: 36px;
    padding: 0;
  }

  /* Bottom 3-Tile Tray + Shake Button */
  #tile-tray {
    width: 256px;
    height: 90px;
    padding: 13px 40px 30px 39px;
    gap: 15px;
  }
  .tray-slot { width: 48px; height: 48px; }
  .tray-tile-svg-wrap { width: 42px; height: 42px; }
  .tray-tile-badge { bottom: -19px; font-size: 9.5px; }
  .shake-btn { width: 62px; height: 62px; }
  .shake-label { font-size: 10px; bottom: -12px; }
  #bottom-controls {
    gap: 10px;
    bottom: max(var(--tray-bottom, 14px), env(safe-area-inset-bottom));
    padding: 0 6px;
  }

  /* Wave Banner (Tutorial Card uses compact bottom layout from <=1024px) */
  .tutorial-card {
    left: 8px;
    right: 8px;
    padding: 8px 12px 8px 44px;
  }
  .tut-wizard-medal {
    left: 4px;
    width: 34px;
    height: 34px;
  }
  .tut-wizard-medal img { width: 34px; height: 34px; }
  .wave-banner { min-width: 224px; height: 78px; padding: 18px 40px 12px; }
  .wave-banner-title { font-size: 17px; }

  /* Armory Modal Mobile Ergonomics */
  .armory-window {
    max-height: 94dvh;
    padding: 12px 10px;
    gap: 8px;
  }
  .armory-header {
    position: relative;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .shopkeeper-wrap { min-width: 0; gap: 8px; padding-right: 38px; }
  .shopkeeper-portrait { width: 48px; height: 48px; }
  .shopkeeper-img { width: 48px; height: 48px; }
  .armory-title { font-size: 18px; }
  .shopkeeper-quote { font-size: 11px; }
  .armory-header-right { width: 100%; justify-content: flex-start; gap: 6px; }
  #btn-armory-x { position: absolute; top: 0; right: 0; }
  .armory-currencies { width: 100%; justify-content: flex-start; gap: 6px; }
  .currency-tile { min-width: 82px; height: 34px; }
  .currency-val { font-size: 14px; }
  .armory-tabs-bar { flex-direction: column; align-items: stretch; gap: 6px; }
  .armory-tabs { gap: 4px; }
  .armory-tab {
    font-size: 12px;
    height: 36px;
    padding: 8px 4px 2px;
    gap: 4px;
  }
  .armory-tab .ico-slot { width: 14px; height: 14px; }
  .reward-pill { align-self: flex-end; margin-bottom: 4px; height: 28px; font-size: 12px; }
  .sockets-bar-title { font-size: 13px; padding: 3px 8px; }
  .sockets-hint { font-size: 11px; }
  .socket-slot-btn { min-width: 36px; min-height: 36px; }
  .socket-pos-badge { font-size: 9.5px; padding: 1px 4px; top: calc(100% + 6px); }
  .socket-swap-btn { width: 22px; height: 22px; }
  .gem-mini-card {
    grid-template-columns: 38px 1fr auto;
    gap: 6px;
    padding: 7px 8px;
  }
  .gem-mini-art { width: 38px; height: 38px; }
  .gem-mini-art img { width: 30px; height: 30px; }
  .gem-mini-name { font-size: 13px; }
  .gem-mini-tag { font-size: 10.5px; }
  .gem-mini-actions { min-width: 60px; }
  .armory-footer { flex-direction: column; align-items: stretch; padding-top: 2px; }

  /* Campaign Screen Mobile Polish */
  .campaign-screen { padding: max(6px, env(safe-area-inset-top)) 6px max(8px, env(safe-area-inset-bottom)); gap: 8px; }
  .campaign-topbar { padding: 6px 8px; gap: 6px; }
  .camp-head-left { gap: 6px; }
  .camp-head-right { gap: 6px; }
  .camp-head-right .chrome-btn:not(.icon-only) { height: 34px; font-size: 12.5px; }
  .camp-head-right .chrome-btn.icon-only { width: 34px; height: 34px; }
  .camp-curr-tile { min-width: 68px; height: 34px; padding: 0 6px; }
  .camp-stars-pill { height: 34px; padding: 0 8px; font-size: 12.5px; }
  .camp-title-plaque { height: 34px; font-size: 13.5px; }
  .camp-head-left .chrome-btn.icon-only { width: 34px; height: 34px; }
  .camp-node { width: 28px; height: 28px; }
  .camp-node.is-boss { width: 34px; height: 34px; }
  .camp-node-num { font-size: 12px; }
  .camp-node-pointer { top: -10px; border-left-width: 5px; border-right-width: 5px; border-top-width: 7px; }
  .camp-node-stars { bottom: -9px; padding: 1px 3px; }
  .camp-node-stars img { width: 8px; height: 8px; }
  .camp-enemy-ico { width: 32px; height: 32px; }
  .camp-enemy-ico img { width: 26px; height: 26px; }
  .campaign-detail-bar { padding: 10px; gap: 8px; }

  /* Modals */
  .modal-card,
  .victory-window,
  .defeat-window { max-width: calc(100vw - 16px); }
  .defeat-scroll { padding: 20px 16px; }
  .defeat-cell { font-size: 15px; gap: 6px; }
  .menu-btn { height: 44px; font-size: 14px; }
}

@media (max-width: 395px) {
  #mobile-topbar { padding: 0 4px; gap: 3px; }
  .mobile-quick-stats { gap: 4px; font-size: 11px; }
  #mobile-topbar .chrome-btn { padding: 0 5px; font-size: 11px; }
  #tile-tray {
    width: 232px;
    height: 82px;
    padding: 11px 36px 27px 35px;
    gap: 13px;
  }
  .tray-slot { width: 44px; height: 44px; }
  .tray-tile-svg-wrap { width: 38px; height: 38px; }
  .shake-btn { width: 56px; height: 56px; }
  #bottom-controls { gap: 8px; }
  .camp-node { width: 24px; height: 24px; }
  .camp-node.is-boss { width: 30px; height: 30px; }
  .camp-node-num { font-size: 11px; }
}

/* ==================== TEST GEM SELECTOR & HOVER GEM TOOLTIP ==================== */
.test-gem-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
}
.test-select {
  flex: 1;
  height: 28px;
  padding: 0 8px;
  border-radius: 6px;
  border: 1px solid #8a6435;
  background-color: #241710;
  color: #f6e7c8;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
}
.test-select-sm {
  flex: 0 0 64px;
}

.gem-hover-tip {
  position: fixed;
  z-index: 95;
  pointer-events: none;
  max-width: 248px;
  padding: 8px 10px;
  border-radius: 8px;
  background-color: rgba(24, 15, 10, 0.96);
  border: 1.5px solid #a87f44;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
  color: #f6e9ce;
  font-size: 12px;
  line-height: 1.35;
}
.gem-hover-tip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}
.gem-hover-tip-name {
  font-family: 'Philosopher', Georgia, serif;
  font-size: 14px;
  font-weight: 700;
  color: #ffd978;
}
.gem-hover-tip-lvl {
  font-size: 11px;
  font-weight: 700;
  color: #b8a386;
  font-variant-numeric: tabular-nums;
}
.gem-hover-tip-desc {
  color: #f2e4c9;
  font-size: 12px;
  margin-bottom: 4px;
}
.gem-hover-tip-tiers {
  color: #c8b28f;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  border-top: 1px solid rgba(168, 127, 68, 0.32);
  padding-top: 3px;
}

/* ==================== SPEED TOGGLE, REWARDED AD BTN, TOUCH INFO & UPGRADE BADGE ==================== */
.stage-speed-btn {
  padding: 0;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease), color 0.14s var(--ease), transform 0.1s var(--ease);
}
.stage-speed-btn.active {
  background-color: #5b3b18;
  border-color: #f0c256;
  color: #ffe28a;
}

.ad-reward-btn {
  border: 2px solid #1e4220;
  border-radius: 10px;
  background-image: linear-gradient(180deg, #4fa44e 0%, #357c35 58%, #255d27 100%);
  box-shadow:
    inset 0 1.5px 0 rgba(206, 255, 204, 0.42),
    inset 0 -3px 0 #19421b,
    0 2px 0 #12100c;
  color: #f4ffef;
  text-shadow: 0 1px 0 #132c14;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: filter 0.14s var(--ease), transform 0.1s var(--ease);
}
.ad-reward-btn:hover:not(:disabled) { filter: brightness(1.07); }
.ad-reward-btn:active:not(:disabled) { transform: translateY(1px); }
.ad-reward-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.card-info-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #8a6034;
  background-color: rgba(45, 29, 17, 0.85);
  color: #f4e2bc;
  font-family: Georgia, serif;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 3;
  transition: background-color 0.14s var(--ease), border-color 0.14s var(--ease);
}
.card-info-btn:hover {
  background-color: #6b4524;
  border-color: #f0c256;
}
.gem-info-btn {
  top: 4px;
  left: 4px;
  right: auto;
  width: 18px;
  height: 18px;
  font-size: 10px;
}

.has-upgrade-dot {
  position: relative;
}
.has-upgrade-dot::after {
  content: '';
  position: absolute;
  top: -4px;
  right: -4px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background-color: #f5c342;
  border: 2px solid #24140a;
  pointer-events: none;
}

@media (max-width: 600px) {
  .stage-speed-btn {
    font-size: 11px;
  }
}

@media (max-height: 520px) {
  #mobile-topbar {
    min-height: 36px;
    padding: 2px 8px;
  }
  #mobile-topbar .chrome-btn {
    height: 30px;
    font-size: 11.5px;
    padding: 0 8px;
  }
  #mobile-topbar .icon-only {
    width: 30px;
    padding: 0;
  }
}
