/* Peggle Editor - Mobile-first ultra-light UI */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --text-primary: #f0f6fc;
  --text-secondary: #8b949e;
  --text-dim: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --orange: #ff6b35;
  --billiard-red: #e84d4d;
  --billiard-yellow: #ffd447;
  --blue: #4ecdc4;
  --green: #95d5b2;
  --purple: #c77dff;
  --multi: #ff4d9d;
  --gamble: #8cff00;
  --obstacle: #6b7280;
  --bumper: #e0e0e0;
  --portal-blue: #4ecdc4;
  --portal-orange: #ff8b3d;
  --border: #30363d;
  --shadow: rgba(0, 0, 0, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* App Layout */
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 10px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s;
}

.header-btn:active {
  background: var(--border);
}

.level-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  flex: 1;
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Canvas Container */
.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0a0a14;
  display: flex;
  align-items: center;
  justify-content: center;
}

#gameCanvas {
  display: block;
  touch-action: none;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
  border-radius: 4px;
}

.hidden {
  display: none !important;
}

.survival-panel {
  position: absolute;
  top: 8px;
  left: max(8px, calc(50% - 380px));
  width: 190px;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 22;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: none;
}

.mode-panel-stack {
  position: absolute;
  top: 8px;
  left: max(8px, calc(50% - 380px));
  width: 190px;
  z-index: 22;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.mode-panel-stack .survival-panel {
  position: static;
  top: auto;
  left: auto;
  width: 190px;
  pointer-events: auto;
}

.aim-length-panel {
  position: absolute;
  bottom: 8px;
  left: max(8px, calc(50% - 380px));
  width: 170px;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 22;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 6px 8px;
}

.survival-panel.visible {
  display: block;
}

.compact-toggle-row {
  padding: 4px 0;
}

.survival-panel-title {
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.survival-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  font-size: 11px;
  color: var(--text-secondary);
}

.survival-toggle-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.survival-controls {
  padding: 2px 8px 8px;
}

.survival-control {
  margin-top: 6px;
}

.survival-control label {
  display: block;
  margin-bottom: 4px;
  font-size: 10px;
  color: var(--text-dim);
}

.survival-control-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.survival-control-header label {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 0;
}

.survival-control-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.survival-control-row input[type="range"] {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-tertiary);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.survival-control-row input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.survival-control-row input[type="number"] {
  width: 58px;
  padding: 2px 4px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 10px;
  text-align: right;
  -moz-appearance: textfield;
}

.survival-control-row input[type="number"]::-webkit-inner-spin-button,
.survival-control-row input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.destruction-default-btn {
  flex: 0 0 auto;
  padding: 3px 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 9px;
  cursor: pointer;
}

.destruction-default-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.hit-clear-toggle {
  display: flex !important;
  align-items: center;
  gap: 5px;
  margin: 0 0 5px;
  color: var(--text-secondary) !important;
  font-size: 10px !important;
  cursor: pointer;
}

.hit-clear-toggle input {
  width: 12px;
  height: 12px;
  margin: 0;
}

.survival-hint {
  margin-top: 7px;
  font-size: 9px;
  color: var(--text-dim);
}

.survival-bg-row {
  display: flex;
  gap: 5px;
}

.survival-curve-select {
  width: 100%;
  margin-bottom: 5px;
  padding: 3px 5px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-secondary);
  font-size: 10px;
}

.survival-curve-canvas {
  display: block;
  width: 100%;
  height: 86px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.055) 1px, transparent 1px),
    rgba(8, 12, 18, 0.86);
  background-size: 25% 50%, 25% 50%, auto;
  touch-action: none;
  cursor: crosshair;
}

.survival-curve-actions {
  display: flex;
  gap: 5px;
  margin-top: 5px;
}

.survival-bg-btn {
  flex: 1;
  padding: 3px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 10px;
  cursor: pointer;
}

.survival-bg-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent);
}

.survival-bg-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.survival-bg-status {
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 9px;
  color: var(--text-dim);
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 6px;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.peg-buttons {
  display: flex;
  gap: 4px;
}

.peg-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  position: relative;
}

.peg-btn::after {
  content: '';
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: 0 0 6px currentColor;
}

.peg-btn[data-type="orange"] {
  background: rgba(255, 107, 53, 0.2);
  color: var(--orange);
}
.peg-btn[data-type="orange"]::after {
  border: 1px solid rgba(255, 147, 48, 0.95);
  background:
    radial-gradient(ellipse at 35% 24%, rgba(255, 255, 245, 0.82) 0%, rgba(255, 255, 245, 0.82) 12%, rgba(255, 255, 245, 0) 24%),
    radial-gradient(circle at 48% 44%, #ffd7a0 0%, #ff9230 22%, #ff6b35 54%, #b83712 78%, #571607 100%);
  box-shadow:
    inset 0 -2px 3px rgba(72, 14, 4, 0.58),
    inset 0 1px 2px rgba(255, 190, 92, 0.72);
}

.peg-btn[data-type="billiardRed"] {
  background: rgba(232, 77, 77, 0.2);
  color: var(--billiard-red);
}
.peg-btn[data-type="billiardRed"]::after {
  border: 1px solid rgba(255, 168, 168, 0.9);
  background:
    radial-gradient(ellipse at 35% 24%, rgba(255, 255, 255, 0.82) 0%, rgba(255, 255, 255, 0.82) 12%, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 48% 44%, #ffe1df 0%, #ff8b82 22%, #e84d4d 56%, #9a151b 80%, #42070b 100%);
  box-shadow: inset 0 -2px 3px rgba(66, 7, 11, 0.58);
}

.peg-btn[data-type="billiardYellow"] {
  background: rgba(255, 212, 71, 0.2);
  color: var(--billiard-yellow);
}
.peg-btn[data-type="billiardYellow"]::after {
  border: 1px solid rgba(255, 242, 154, 0.92);
  background:
    radial-gradient(ellipse at 35% 24%, rgba(255, 255, 255, 0.86) 0%, rgba(255, 255, 255, 0.86) 12%, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 48% 44%, #fff7bd 0%, #ffe16a 24%, #ffd447 56%, #b57b0d 80%, #4c2b04 100%);
  box-shadow: inset 0 -2px 3px rgba(76, 43, 4, 0.56);
}

.peg-btn[data-type="blue"] {
  background: rgba(78, 205, 196, 0.2);
  color: var(--blue);
}
.peg-btn[data-type="blue"]::after {
  border: 1px solid rgba(142, 255, 247, 0.88);
  background:
    radial-gradient(ellipse at 35% 24%, rgba(255, 255, 255, 0.78) 0%, rgba(255, 255, 255, 0.78) 12%, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 48% 44%, #d7fffb 0%, #7df4ed 22%, #4ecdc4 56%, #168178 80%, #07323b 100%);
  box-shadow: inset 0 -2px 3px rgba(7, 50, 59, 0.58);
}

.peg-btn[data-type="green"] {
  background: rgba(149, 213, 178, 0.2);
  color: var(--green);
}
.peg-btn[data-type="green"]::after {
  border: 1px solid rgba(209, 255, 222, 0.86);
  background:
    radial-gradient(ellipse at 35% 24%, rgba(255, 255, 255, 0.76) 0%, rgba(255, 255, 255, 0.76) 12%, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 48% 44%, #f0fff4 0%, #c3f7d7 22%, #95d5b2 56%, #4b9a6d 80%, #163927 100%);
  box-shadow: inset 0 -2px 3px rgba(22, 57, 39, 0.56);
}

.peg-btn[data-type="purple"] {
  background: rgba(199, 125, 255, 0.2);
  color: var(--purple);
}
.peg-btn[data-type="purple"]::after {
  border: 1px solid rgba(229, 186, 255, 0.9);
  background:
    radial-gradient(ellipse at 35% 24%, rgba(255, 255, 255, 0.78) 0%, rgba(255, 255, 255, 0.78) 12%, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 48% 44%, #f6e6ff 0%, #dfadff 22%, #c77dff 56%, #8037bd 80%, #32114f 100%);
  box-shadow: inset 0 -2px 3px rgba(50, 17, 79, 0.58);
}

.peg-btn[data-type="multi"] {
  background: rgba(255, 77, 157, 0.2);
  color: var(--multi);
}
.peg-btn[data-type="multi"]::after {
  border: 1px solid rgba(255, 165, 207, 0.9);
  background:
    radial-gradient(ellipse at 35% 24%, rgba(255, 255, 255, 0.78) 0%, rgba(255, 255, 255, 0.78) 12%, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 48% 44%, #ffe0f0 0%, #ff8cc5 22%, #ff4d9d 56%, #b91f6d 80%, #4e0a2c 100%);
  box-shadow: inset 0 -2px 3px rgba(78, 10, 44, 0.58);
}

.peg-btn[data-type="gamble"] {
  background: rgba(140, 255, 0, 0.18);
  color: var(--gamble);
}
.peg-btn[data-type="gamble"]::after {
  border: 1px solid rgba(219, 255, 114, 0.9);
  background:
    radial-gradient(ellipse at 35% 24%, rgba(255, 255, 255, 0.82) 0%, rgba(255, 255, 255, 0.82) 12%, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 48% 44%, #f6ffd6 0%, #cfff5c 22%, #8cff00 56%, #4d9a00 80%, #173900 100%);
  box-shadow: inset 0 -2px 3px rgba(23, 57, 0, 0.56);
}

.peg-btn[data-type="obstacle"] {
  background: rgba(107, 114, 128, 0.2);
  color: var(--obstacle);
}
.peg-btn[data-type="obstacle"]::after {
  border: 1px solid rgba(220, 226, 236, 0.72);
  background:
    radial-gradient(ellipse at 35% 24%, rgba(255, 255, 255, 0.62) 0%, rgba(255, 255, 255, 0.62) 12%, rgba(255, 255, 255, 0) 24%),
    radial-gradient(circle at 48% 44%, #e8edf5 0%, #aab3c2 22%, #6b7280 56%, #3e4654 80%, #171b23 100%);
  box-shadow: inset 0 -2px 3px rgba(23, 27, 35, 0.58);
}

.peg-btn[data-type="bumper"] {
  background: rgba(224, 224, 224, 0.2);
  color: var(--bumper);
}
.peg-btn[data-type="bumper"]::after {
  background: var(--bumper);
  box-shadow: 0 0 6px var(--bumper), inset 0 0 3px rgba(0,0,0,0.3);
}

.peg-btn[data-type="portalBlue"] {
  background: rgba(78, 205, 196, 0.16);
  color: var(--portal-blue);
}
.peg-btn[data-type="portalBlue"]::after {
  width: 22px;
  height: 4px;
  border-radius: 999px;
  background: var(--portal-blue);
  border: 0;
  box-shadow: 0 0 8px var(--portal-blue);
  transform: rotate(-20deg);
}

.peg-btn[data-type="portalOrange"] {
  background: rgba(255, 139, 61, 0.16);
  color: var(--portal-orange);
}
.peg-btn[data-type="portalOrange"]::after {
  width: 22px;
  height: 4px;
  border-radius: 999px;
  background: var(--portal-orange);
  border: 0;
  box-shadow: 0 0 8px var(--portal-orange);
  transform: rotate(20deg);
}

.peg-btn.active {
  border-color: var(--text-primary);
  transform: scale(1.05);
}

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

/* Shape buttons */
.shape-buttons {
  display: flex;
  gap: 4px;
  border-left: 1px solid var(--border);
  padding-left: 8px;
}

.peg-color-row {
  display: flex;
  align-items: center;
  gap: 4px;
  border-left: 1px solid var(--border);
  padding-left: 8px;
}

.peg-color-row input[type="color"] {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  cursor: pointer;
  padding: 1px;
}

.shape-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.15s;
}

.shape-btn.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

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

.tool-buttons {
  display: flex;
  gap: 4px;
}

.tool-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.15s;
}

.tool-btn.active {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
}

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

/* Status Bar */
.status-bar {
  display: flex;
  justify-content: space-between;
  padding: 3px 10px;
  background: var(--bg-tertiary);
  font-size: 11px;
  color: var(--text-dim);
}

.status-bar.gamble-mode {
  display: none;
}

.gamble-hud {
  /* --frame-scale is set by JS on .visual-frame (fw / 444).
     All fixed-px sizes are multiplied by --s so the gamble UI scales
     proportionally with the frame and never changes with browser zoom. */
  --s: var(--frame-scale, 1);
  --hud-squeeze: clamp(0.82, var(--frame-squeeze, 1), 1);
  --dock-collapsed-height: calc(96px * var(--s) * var(--hud-squeeze));
  --dock-open-height: calc(196px * var(--s) * var(--hud-squeeze));
  --board-width: 100%;
  --board-layer-height: calc(44px * var(--s) * var(--hud-squeeze));
  --board-offset-collapsed: calc(-70px * var(--s) * var(--hud-squeeze));
  --board-offset-expanded: calc(200px * var(--s) * var(--hud-squeeze));
  --board-surface-top: calc(12px * var(--s) * var(--hud-squeeze));
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

.gamble-hud.gamble-hud--phase-hidden {
  display: none;
}

.gamble-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background:
    linear-gradient(180deg, rgba(8, 10, 18, 0.44) 0%, rgba(8, 10, 18, 0.24) 34%, rgba(8, 10, 18, 0.08) 62%, rgba(8, 10, 18, 0) 100%),
    radial-gradient(80% 56% at 50% 100%, rgba(8, 16, 30, 0.28), rgba(8, 16, 30, 0));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.gamble-hud.expanded .gamble-backdrop {
  opacity: 1;
  pointer-events: auto;
}

.gamble-toggle-handle {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: calc(110px * var(--s));
  height: calc(64px * var(--s));
  aspect-ratio: 281 / 155;
  transform: translate(-50%, 0);
  border: 0;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  background: transparent;
  background-image: var(--gamble-arrow-asset);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  cursor: pointer;
  pointer-events: auto;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.42));
  transition: bottom 0.42s cubic-bezier(0.22, 1, 0.36, 1),
              background-image 0.15s ease,
              transform 0.26s ease,
              filter 0.2s ease;
  z-index: 4;
}

.gamble-toggle-handle:active {
  transform: translate(-50%, 0) scale(0.96);
}

.gamble-board-layer {
  position: absolute;
  left: 50%;
  bottom: calc(var(--dock-collapsed-height) + var(--board-offset-collapsed));
  width: var(--board-width);
  height: var(--board-layer-height);
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 1;
  transition: bottom 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.gamble-hud.expanded .gamble-board-layer {
  bottom: calc(var(--dock-open-height) + var(--board-offset-expanded));
}

.gamble-board-surface {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--board-surface-top);
  z-index: 1;
  opacity: 0;
  pointer-events: none;
  transform: translateY(calc(100% + 44px));
  transition: opacity 0.24s ease, transform 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.gamble-hud.expanded .gamble-toggle-handle {
  /* Expanded: arrow_down, behind the slots board, bottom edge at board top */
  background-image: var(--gamble-arrow-down-asset);
  bottom: calc(var(--dock-open-height) + var(--board-offset-expanded) + var(--board-layer-height) - 24px * var(--s) * var(--hud-squeeze));
  transform: translate(-50%, 0);
  z-index: 0;
}

.gamble-hud.expanded .gamble-toggle-handle:active {
  transform: translate(-50%, 0) scale(0.96);
}

.gamble-hud.expanded .gamble-board-surface {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.gamble-reels-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1280 / 619;
  background-image: var(--gamble-board-asset);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  filter: drop-shadow(0 14px 28px rgba(0, 0, 0, 0.42));
}

.gamble-grid {
  position: absolute;
  inset: 9.5% 4.2% 8%;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0;
  align-items: center;
  justify-items: center;
}

.gamble-cell {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cell-color, #e6edf6);
  font-size: calc(28px * var(--s));
  line-height: 1;
  text-shadow: 0 0 14px rgba(0, 0, 0, 0.68);
  transition: transform 0.22s ease, filter 0.22s ease, opacity 0.22s ease;
}

.gamble-cell.placeholder {
  font-size: calc(10px * var(--s));
  letter-spacing: 0.5px;
  opacity: 0.45;
  font-weight: 700;
  color: #8b949e;
}

.gamble-cell.winning {
  transform: scale(1.12);
  filter: drop-shadow(0 0 8px var(--cell-color, #fff))
          drop-shadow(0 0 18px rgba(255, 255, 255, 0.22));
}

.gamble-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--dock-collapsed-height);
  padding: calc(4px * var(--s) * var(--hud-squeeze)) calc(8px * var(--s)) calc(10px * var(--s) * var(--hud-squeeze));
  background: #1e1e1e;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.52);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(10px * var(--s) * var(--hud-squeeze));
  pointer-events: auto;
  z-index: 3;
  transition: height 0.42s cubic-bezier(0.22, 1, 0.36, 1), padding 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

.gamble-hud.collapsed .gamble-dock {
  gap: 0;
}

.gamble-hud.expanded .gamble-dock {
  height: var(--dock-open-height);
  padding-top: calc(16px * var(--s) * var(--hud-squeeze));
  padding-bottom: calc(14px * var(--s) * var(--hud-squeeze));
}

.gamble-perk-rail {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: calc(6px * var(--s));
  position: relative;
  z-index: 5;
}

.gamble-perk-group {
  display: flex;
  align-items: center;
  gap: calc(4px * var(--s));
  min-width: 0;
  /* Allow chips to shrink so they never overflow the frame */
  overflow: hidden;
}

.gamble-perk-group--left {
  justify-content: flex-end;
  padding-right: calc(4px * var(--s));
}

.gamble-perk-group--right {
  justify-content: flex-start;
  padding-left: calc(4px * var(--s));
}

.gamble-perk-center-gap {
  width: calc(36px * var(--s));
  height: 1px;
}

.gamble-info-row {
  width: min(92%, calc(320px * var(--s)));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(12px * var(--s));
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.22s ease, max-height 0.22s ease, transform 0.22s ease;
}

.gamble-hud.expanded .gamble-info-row {
  opacity: 1;
  max-height: calc(56px * var(--s) * var(--hud-squeeze));
  pointer-events: auto;
  transform: translateY(0);
}

.gamble-stats-case {
  min-width: 0;
}

.gamble-info-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gamble-btn {
  width: min(68%, calc(246px * var(--s)));
  max-width: calc(246px * var(--s));
  max-height: 0;
  aspect-ratio: 639 / 250;
  border: 0;
  background: transparent;
  background-image: var(--gamble-spin-asset);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  color: transparent;
  font-size: 0;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.4));
  transition: opacity 0.22s ease, max-height 0.22s ease, transform 0.18s ease, filter 0.18s ease;
}

.gamble-hud.expanded .gamble-btn {
  opacity: 1;
  max-height: calc(96px * var(--s) * var(--hud-squeeze));
  pointer-events: auto;
}

.gamble-btn:disabled {
  opacity: 0.38;
  filter: grayscale(0.45) saturate(0.7);
  cursor: not-allowed;
}

.gamble-btn:not(:disabled):active {
  background-image: var(--gamble-spin-pressed-asset);
  transform: translateY(2px) scale(0.98);
}

.gamble-perk-chip {
  position: relative;
  width: calc(66px * var(--s));
  height: calc(66px * var(--s));
  border: 0;
  outline: none;
  background: transparent;
  background-image: var(--gamble-item-asset);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  color: #f6f6f9;
  font-size: calc(28px * var(--s));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 calc(2px * var(--s));
  cursor: pointer;
  flex-shrink: 1;
  min-width: calc(44px * var(--s));
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
  transition: transform 0.18s ease, opacity 0.18s ease, filter 0.18s ease;
}

.gamble-perk-chip::after {
  content: attr(data-count);
  position: absolute;
  right: calc(-2px * var(--s));
  bottom: calc(-2px * var(--s));
  min-width: calc(22px * var(--s));
  height: calc(20px * var(--s));
  padding: 0 calc(5px * var(--s));
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(4, 5, 8, 0.88);
  color: #f4f7fb;
  font-size: calc(12px * var(--s));
  line-height: calc(18px * var(--s));
  text-align: center;
}

.gamble-perk-chip:not(:disabled):active {
  transform: translateY(1px) scale(0.95);
}

.gamble-perk-chip:disabled {
  opacity: 0.38;
  filter: grayscale(0.4) saturate(0.7);
  cursor: not-allowed;
}

.gamble-luck {
  color: #b9c2d3;
  font-size: calc(9px * var(--s));
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: left;
  line-height: 1.2;
}

.gamble-result {
  color: #dbe1ed;
  font-size: calc(11px * var(--s));
  min-height: calc(14px * var(--s));
  text-align: left;
  line-height: 1.2;
}

.gamble-result[data-type="win"] {
  color: #9be9a8;
}

.gamble-result[data-type="warn"] {
  color: #ffcc66;
}

.gamble-result[data-type="error"] {
  color: #ff8b8b;
}

.gamble-settings-btn {
  width: calc(30px * var(--s));
  height: calc(30px * var(--s));
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(9, 12, 18, 0.8);
  color: #d7dee8;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.gamble-settings-panel {
  position: absolute;
  left: calc(12px * var(--s));
  right: calc(12px * var(--s));
  bottom: calc(var(--dock-open-height) + 14px * var(--s));
  max-height: min(42%, calc(320px * var(--s)));
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: calc(16px * var(--s));
  background: linear-gradient(180deg, rgba(18, 24, 34, 0.96), rgba(8, 11, 17, 0.96));
  padding: calc(10px * var(--s));
  display: flex;
  flex-direction: column;
  gap: calc(8px * var(--s));
  pointer-events: auto;
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.34);
}

.gamble-settings-panel.hidden {
  display: none;
}

.gamble-control {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.gamble-control label {
  font-size: calc(10px * var(--s));
  color: #9ea9bb;
}

.gamble-control-row {
  display: flex;
  align-items: center;
  gap: calc(6px * var(--s));
}

.gamble-control-row input[type="range"] {
  flex: 1;
  min-width: 0;
}

.gamble-control-row input[type="number"] {
  width: calc(56px * var(--s));
  padding: calc(2px * var(--s)) calc(4px * var(--s));
  border-radius: calc(4px * var(--s));
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(4, 7, 12, 0.76);
  color: #eff4fb;
  font-size: calc(10px * var(--s));
}

.gamble-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(6px * var(--s));
  font-size: calc(10px * var(--s));
  color: #a2adbe;
}

.gamble-toggle-row input[type="checkbox"] {
  width: calc(14px * var(--s));
  height: calc(14px * var(--s));
}

/* Small-screen media query removed — --frame-scale handles proportional sizing */

/* Quick Actions Overlay */
.actions-overlay {
  position: fixed;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  z-index: 50;
}

.actions-overlay.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.actions-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 180px;
  box-shadow: 0 8px 32px var(--shadow);
}

.action-btn {
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.action-btn:active {
  background: var(--border);
}

.action-btn.danger {
  color: #f85149;
}

/* Menu Overlay */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 50px 15px 15px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  z-index: 100;
}

.menu-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.menu-panel {
  background: var(--bg-secondary);
  border-radius: 14px;
  width: 100%;
  max-width: 340px;
  max-height: calc(100% - 30px);
  overflow-y: auto;
  border: 1px solid var(--border);
}

.menu-section {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.menu-section:last-child {
  border-bottom: none;
}

.menu-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
  letter-spacing: 0.5px;
}

.menu-input {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  margin-bottom: 10px;
}

.menu-input:focus {
  outline: none;
  border-color: var(--accent);
}

.menu-input-inline {
  margin-bottom: 8px;
}

.menu-select {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  margin-bottom: 10px;
  cursor: pointer;
}

.menu-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-tertiary);
  font-size: 12px;
  color: var(--text-secondary);
}

.menu-toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}


.menu-subsection {
  margin-bottom: 10px;
  padding: 9px 10px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(13, 17, 23, 0.55);
}

.menu-subsection.hidden {
  display: none;
}

.menu-field-label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

@media (max-width: 760px) {
  .survival-panel {
    left: 6px;
    width: 166px;
  }
}

.menu-btn {
  width: 100%;
  padding: 11px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 6px;
  text-align: left;
}

.menu-btn:last-child {
  margin-bottom: 0;
}

.menu-btn:active {
  background: var(--border);
}

.menu-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-primary);
  text-align: center;
  font-weight: 600;
}

.menu-btn.danger {
  color: #f85149;
}

/* Level List Overlay */
.level-list-overlay {
  position: fixed;
  top: 44px;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 100vw;
  background: var(--bg-primary);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease-out;
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.level-list-overlay.visible {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.level-list-header {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 10px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.level-list-title {
  flex: 1;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.level-list-content {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.level-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.level-item:active {
  background: var(--bg-tertiary);
}

.level-item.active {
  border-color: var(--accent);
}

.level-item-info {
  flex: 1;
  min-width: 0;
}

.level-item-name {
  display: block;
  font-weight: 500;
  font-size: 13px;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.level-item-meta {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.level-item-actions {
  display: flex;
  gap: 6px;
  margin-left: 10px;
}

.level-action-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.level-action-btn:active {
  background: var(--border);
}

/* Physics Settings Overlay */
.physics-overlay {
  position: fixed;
  top: 44px;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 100vw;
  background: var(--bg-primary);
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.physics-overlay.visible {
  transform: translateX(0);
}

.physics-panel {
  background: var(--bg-secondary);
  width: 100%;
  border-left: 1px solid var(--border);
}

.physics-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
}

.physics-header h2 {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  text-align: center;
}

.physics-content {
  padding: 14px;
}

.slider-group {
  margin-bottom: 16px;
}

.slider-group:last-of-type {
  margin-bottom: 12px;
}

.slider-group label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.slider-group input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--bg-tertiary);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.toggle-group {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.toggle-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Animation Side Panel */
.anim-panel {
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 148px;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 240;
  display: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.anim-panel.visible {
  display: block;
}

.anim-panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.anim-close-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.anim-close-btn:active {
  background: var(--border);
}

.anim-panel-body {
  padding: 6px 8px 8px;
}

.anim-slider {
  margin-bottom: 6px;
}

.anim-slider label {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.anim-num {
  width: 42px;
  padding: 1px 3px;
  margin: 0 1px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
  font-size: 10px;
  text-align: center;
  -moz-appearance: textfield;
}

.anim-num::-webkit-inner-spin-button,
.anim-num::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.anim-num:focus {
  outline: none;
  border-color: var(--accent);
}

.anim-slider input[type="range"] {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--bg-tertiary);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.anim-slider input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.anim-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 0;
}

.anim-toggle input[type="checkbox"] {
  width: 13px;
  height: 13px;
  cursor: pointer;
}

.anim-toggle input[type="checkbox"]:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.anim-toggle:has(input:disabled) {
  opacity: 0.4;
  cursor: not-allowed;
}

.anim-buttons {
  display: flex;
  gap: 4px;
  margin-top: 6px;
}

.anim-btn {
  flex: 1;
  padding: 5px 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 10px;
  cursor: pointer;
  text-align: center;
}

.anim-btn-toggle {
  width: 100%;
  margin-top: 2px;
  padding: 5px 0;
  font-size: 10px;
}

.anim-btn:active {
  background: var(--border);
}

.anim-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-primary);
  font-weight: 600;
}

.anim-btn-toggle.active {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: rgba(88, 166, 255, 0.2);
}

.anim-hit-mode-row {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

.anim-btn-sm {
  flex: 1;
  padding: 3px 0;
  font-size: 9px;
}

.anim-steps-label {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Bumper Properties Panel (right side) */
.bumper-panel {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 148px;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 240;
  display: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.bumper-panel.visible {
  display: block;
}


.bumper-panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
}

.bumper-panel-body {
  padding: 6px 8px 8px;
}

.anim-hint {
  margin-top: 5px;
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1.3;
}

/* Safe area support */
@supports (padding: env(safe-area-inset-bottom)) {
  .toolbar {
    padding-bottom: calc(6px + env(safe-area-inset-bottom));
  }
  
  .header {
    padding-top: env(safe-area-inset-top);
    height: calc(44px + env(safe-area-inset-top));
  }
  
  .actions-overlay {
    bottom: calc(70px + env(safe-area-inset-bottom));
  }
}

/* Scrollbar styling */
.menu-panel::-webkit-scrollbar,
.level-list-content::-webkit-scrollbar {
  width: 4px;
}

.menu-panel::-webkit-scrollbar-track,
.level-list-content::-webkit-scrollbar-track {
  background: transparent;
}

.menu-panel::-webkit-scrollbar-thumb,
.level-list-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Responsive - larger screens */
@media (min-width: 500px) {
  .toolbar {
    justify-content: center;
    gap: 16px;
  }
  
  .peg-buttons, .tool-buttons {
    gap: 6px;
  }
  
  .peg-btn, .shape-btn, .tool-btn {
    width: 40px;
    height: 40px;
  }
}

/* ─── Campaign Overlays ─────────────────────────────── */

.campaign-overlay {
  position: fixed;
  top: 44px;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 100vw;
  background: var(--bg-primary);
  z-index: 210;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease-out;
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.campaign-overlay.visible {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.campaign-header {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 10px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

.campaign-name-input {
  flex: 1;
  min-width: 0;
  height: 30px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 0 8px;
}

.campaign-content,
.campaign-edit-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.campaign-section {
  margin-bottom: 16px;
}

.campaign-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.campaign-level-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.campaign-level-item {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 8px;
}

.campaign-level-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg-primary);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.campaign-level-name {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.campaign-level-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.campaign-action-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.campaign-action-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.campaign-action-btn:active:not(:disabled) {
  background: var(--border);
}

.campaign-remove-btn {
  color: #f85149;
}

.campaign-add-btn {
  background: var(--accent);
  color: var(--bg-primary);
  border-color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}

.campaign-available-item {
  opacity: 0.8;
}

.campaign-empty-hint {
  font-size: 12px;
  color: var(--text-dim);
  padding: 12px;
  text-align: center;
}

.campaign-edit-level-btn {
  color: var(--accent) !important;
}

.dialogue-edit-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialogue-editor-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.dialogue-toolbar-spacer {
  flex: 1 1 auto;
}

.dialogue-chip-btn,
.dialogue-preview-btn {
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 11px;
  cursor: pointer;
}

.dialogue-chip-btn:active,
.dialogue-preview-btn:active {
  background: var(--bg-tertiary);
}

.dialogue-chip-btn.is-active,
.dialogue-preview-btn.is-active {
  background: rgba(88, 166, 255, 0.12);
  border-color: var(--accent);
  color: #dbeeff;
}

.dialogue-chip-btn:disabled,
.dialogue-preview-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.dialogue-editor-note {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(88, 166, 255, 0.08);
  border: 1px solid rgba(88, 166, 255, 0.18);
  color: var(--text-secondary);
  font-size: 11px;
  line-height: 1.45;
}

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

.dialogue-entry-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
}

.dialogue-entry-item.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(88, 166, 255, 0.18);
}

.dialogue-entry-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.dialogue-entry-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.dialogue-entry-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.dialogue-entry-badge {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(88, 166, 255, 0.12);
  color: #cfe6ff;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dialogue-entry-meta {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.35;
}

.dialogue-entry-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dialogue-icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dialogue-icon-btn:active {
  background: var(--border);
}

.dialogue-icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.dialogue-icon-btn--danger {
  color: #f85149;
}

.dialogue-editor-empty {
  padding: 20px 14px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}

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

.character-edit-body {
  gap: 10px;
}

.character-slot-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 0;
}

.character-slot-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.035);
}

.character-slot-thumb {
  width: 38px;
  height: 38px;
  border-radius: 5px;
  background-color: rgba(0, 0, 0, 0.26);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.character-slot-main {
  min-width: 0;
}

.character-slot-name {
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  word-break: break-word;
}

.character-slot-state {
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 10px;
}

.character-json-input {
  min-height: 128px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.35;
}

.character-custom-slot {
  align-items: end;
}

.character-panel-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.character-expression-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.character-expression-card {
  min-width: 0;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.character-expression-thumb {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background-color: rgba(0, 0, 0, 0.26);
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}

.character-expression-stage {
  position: relative;
}

.character-variant-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text-primary);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.character-variant-arrow:hover {
  background: rgba(0, 0, 0, 0.75);
}

.character-variant-arrow--prev {
  left: 4px;
}

.character-variant-arrow--next {
  right: 4px;
}

.character-variant-counter {
  position: absolute;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--text-primary);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.character-expression-title {
  margin-top: 6px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
}

.character-expression-key,
.character-expression-state {
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 10px;
  overflow-wrap: anywhere;
}

.character-expression-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.character-expression-actions .dialogue-chip-btn,
.character-expression-actions .dialogue-preview-btn {
  flex: 1;
  min-width: 0;
}

.character-mini-heading {
  margin-top: 4px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.character-tune-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.character-tune-row.is-disabled {
  opacity: 0.58;
}

.character-tune-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.character-tune-label {
  min-width: 0;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 650;
}

.character-tune-value {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

.character-range {
  width: 100%;
  accent-color: var(--accent);
}

.character-event-list,
.character-escalation-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.character-event-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.12);
}

.character-event-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 750;
}

.character-event-title small {
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 650;
}

.character-weight-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.character-weight-grid.is-disabled {
  opacity: 0.55;
}

.character-weight-row {
  display: grid;
  grid-template-columns: minmax(76px, 1fr) minmax(80px, 1.2fr) 38px;
  gap: 8px;
  align-items: center;
  color: var(--text-primary);
  font-size: 11px;
}

.character-weight-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.character-weight-row b {
  color: var(--accent);
  font-size: 10px;
  text-align: right;
}

.character-override-summary {
  padding: 7px 8px;
  border-radius: 8px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.04);
  font-size: 11px;
  font-weight: 700;
}

.character-override-help {
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.4;
}

.character-override-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.character-override-toggle {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
}

.character-override-toggle input {
  flex: 0 0 auto;
  margin-top: 2px;
  accent-color: var(--accent);
}

.character-override-toggle span {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.character-override-toggle b {
  font-size: 12px;
  font-weight: 750;
}

.character-override-toggle small {
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 500;
  line-height: 1.35;
}

.character-inherited {
  color: var(--text-dim);
  font-size: 10px;
}

.dialogue-impulse-strength.is-hidden {
  display: none;
}

.dialogue-card-block {
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.025);
}

.dialogue-block-title {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dialogue-block-note {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
}

.dialogue-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}

.dialogue-field:last-child {
  margin-bottom: 0;
}

.dialogue-field-label {
  font-size: 11px;
  color: var(--text-dim);
}

.dialogue-field-input,
.dialogue-field-select,
.dialogue-field-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 8px 9px;
  font-size: 12px;
}

.dialogue-field-textarea {
  min-height: 58px;
  resize: vertical;
  line-height: 1.35;
}

.link-import-overlay {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(0, 0, 0, 0.58);
}

.link-import-overlay.visible {
  display: flex;
}

.link-import-panel {
  width: min(640px, 100%);
  max-height: calc(100dvh - 28px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-primary);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}

.link-import-body {
  padding: 12px;
  overflow: auto;
}

.link-import-textarea {
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  resize: vertical;
  user-select: text;
  -webkit-user-select: text;
  touch-action: auto;
}

.link-import-status {
  min-height: 18px;
  margin: 2px 0 12px;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.35;
}

.link-import-status.error {
  color: #f85149;
}

.link-import-status.success {
  color: var(--green);
}

.link-import-actions {
  justify-content: flex-end;
}

.dialogue-inline-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.dialogue-toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.dialogue-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 8px 9px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 11px;
  color: var(--text-secondary);
}

.dialogue-toggle input {
  margin: 0;
}

.dialogue-trigger-extra {
  margin-top: 8px;
}

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

.dialogue-perk-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 11px;
  color: var(--text-secondary);
}

.dialogue-perk-chip input {
  margin: 0;
}

.dialogue-perk-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialogue-locale-card {
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.dialogue-locale-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.dialogue-locale-title {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.dialogue-locale-actions {
  display: flex;
  gap: 6px;
}

.dialogue-locale-hint {
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
}

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

.dialogue-segment-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px 28px;
  gap: 8px;
  align-items: start;
}

.dialogue-color-input {
  width: 42px;
  height: 58px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-primary);
  cursor: pointer;
}

.dialogue-segment-empty {
  padding: 10px;
  border-radius: 10px;
  border: 1px dashed var(--border);
  color: var(--text-dim);
  font-size: 11px;
  text-align: center;
  line-height: 1.45;
}

.editor-side-sheet-layer {
  position: absolute;
  inset: 0;
  z-index: 240;
  pointer-events: none;
}

.editor-side-sheet-layer > .level-list-overlay,
.editor-side-sheet-layer > .campaign-overlay {
  position: absolute;
  top: 12px;
  bottom: 12px;
  max-width: none;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 44px rgba(0, 0, 0, 0.42);
}

.editor-side-sheet-layer > .level-list-overlay .level-list-content,
.editor-side-sheet-layer > .campaign-overlay .campaign-content,
.editor-side-sheet-layer > .campaign-overlay .campaign-edit-body,
.editor-side-sheet-layer > .campaign-overlay .dialogue-edit-body {
  overscroll-behavior: contain;
}

@media (max-width: 520px) {
  .dialogue-inline-grid,
  .dialogue-toggle-grid,
  .dialogue-perk-grid,
  .character-expression-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
