/* Pachinko Studio — Tactile Arcade-Precision & Mobile-First Stylesheet */
:root {
  --bg-app: #0a0e17;
  --bg-panel: #111826;
  --bg-surface: #172133;
  --bg-hover: #1e2c44;
  --border: #25344d;
  --border-strong: #34496b;
  --text-main: #f1f5f9;
  --text-dim: #94a3b8;
  --text-muted: #64748b;
  --gold: #e5b855;
  --gold-dim: rgba(229, 184, 85, 0.16);
  --sky: #38bdf8;
  --sky-dim: rgba(56, 189, 248, 0.16);
  --emerald: #10b981;
  --crimson: #ef4444;
  --amber: #f59e0b;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

/* Top Header Bar */
.topbar {
  min-height: 52px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  gap: 10px;
  flex-shrink: 0;
}

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

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

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: linear-gradient(145deg, #e5b855 0%, #a16207 100%);
  color: #0b1120;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  box-shadow: inset 0 1px 1px rgba(255,255,255,0.45);
}

.brand h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main);
  white-space: nowrap;
}

.brand .subtitle {
  font-size: 11px;
  color: var(--text-dim);
}

.mode-tabs {
  display: inline-flex;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  gap: 3px;
  flex-shrink: 0;
}

.mode-tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.14s, color 0.14s;
  white-space: nowrap;
}

.mode-tab:hover {
  color: var(--text-main);
  background: var(--bg-surface);
}

.mode-tab.active {
  background: var(--gold);
  color: #0a0e17;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

/* In 3D Play Mode, keep extra topbar chrome out of the way */
.app-shell.mode-play .edit-only-action {
  display: none;
}

select, input[type="text"], input[type="number"] {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}

select:focus, input:focus {
  border-color: var(--sky);
}

.btn {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.12s, border-color 0.12s, transform 0.08s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: #d97706;
  border-color: #f59e0b;
  color: #fff;
}

.btn-primary:hover {
  background: #b45309;
}

.btn-accent {
  background: #0284c7;
  border-color: #38bdf8;
  color: #fff;
}

.btn-accent:hover {
  background: #0369a1;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.28);
}

.btn-toggle.active {
  background: var(--sky-dim);
  border-color: var(--sky);
  color: #7dd3fc;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 11px;
}

/* Main Workspace Layout */
.workspace {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Left Sidebar: Component Palette (visible in Blueprint mode) */
.sidebar-left {
  width: 248px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex-shrink: 0;
}

/* Right Sidebar: Inspector, Benchmark & Physics (visible in Blueprint mode) */
.sidebar-right {
  width: 296px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex-shrink: 0;
}

/* Hide sidebars completely in 3D Play Mode so the 3D board fills the screen */
.app-shell.mode-play .sidebar-left,
.app-shell.mode-play .sidebar-right {
  display: none;
}

.panel-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.panel-hint-desktop {
  font-size: 10px;
  color: var(--text-muted);
}

.panel-hint-mobile {
  display: none;
  font-size: 10px;
  color: var(--sky);
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.palette-category {
  margin-bottom: 12px;
}

.palette-cat-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 2px 6px;
}

.palette-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 5px;
}

.palette-item {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 9px;
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: grab;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
  user-select: none;
}

.palette-item:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  transform: translateX(2px);
}

.palette-item:active {
  cursor: grabbing;
}

.palette-swatch {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.palette-meta {
  min-width: 0;
  flex: 1;
}

.palette-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px;
}

.palette-jp {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
}

.palette-hint {
  font-size: 10.5px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Center Stage */
.stage-area {
  flex: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
  background: #070b14;
  position: relative;
}

.pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.pane.hidden {
  display: none;
}

.pane-toolbar {
  min-height: 40px;
  background: rgba(17, 24, 38, 0.94);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  gap: 6px;
  flex-shrink: 0;
  overflow-x: auto;
}

.pane-toolbar-3d {
  justify-content: space-between;
  gap: 10px;
}

.view3d-segmented {
  display: inline-flex;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}

.view3d-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 5px 11px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 700;
}

.view3d-btn:hover {
  background: var(--bg-surface);
  color: var(--text-main);
}

.view3d-btn.active {
  background: var(--sky-dim);
  color: #7dd3fc;
  box-shadow: inset 0 0 0 1px var(--sky);
}

.hud-inline-3d {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

.hud-inline-3d strong {
  color: var(--text-main);
  font-family: var(--font-mono);
}

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

.canvas-host {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

#editor-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#three-container {
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Mobile scroll cue (hidden on desktop) */
.mobile-scroll-cue {
  display: none;
}

/* Focused 3D Play Controls Dock */
.play-dock {
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-shrink: 0;
}

.play-velocity {
  flex: 1;
  max-width: 340px;
  min-width: 150px;
}

.play-velocity .control-label {
  font-size: 12px;
  margin-bottom: 4px;
}

.play-velocity input[type="range"] {
  height: 28px;
}

.btn-fire {
  min-width: 148px;
  padding: 10px 20px;
  border-radius: 10px;
  background: linear-gradient(180deg, #fbbf24 0%, #d97706 100%);
  border: 1px solid #fde68a;
  color: #090d16;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  box-shadow: 0 4px 16px rgba(245, 158, 11, 0.28);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.btn-fire:hover {
  background: linear-gradient(180deg, #fcd34d 0%, #d97706 100%);
  border-color: #fef08a;
}

.btn-fire.firing,
.btn-fire:active {
  transform: scale(0.97);
  background: linear-gradient(180deg, #f59e0b 0%, #b45309 100%);
  box-shadow: 0 0 22px rgba(251, 191, 36, 0.55);
}

.fire-main {
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.1;
}

.fire-sub {
  font-size: 9.5px;
  font-weight: 700;
  opacity: 0.82;
  letter-spacing: 0.02em;
}

/* Floating HUD badges inside viewports */
.viewport-hud {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
}

.hud-pill {
  pointer-events: auto;
  background: rgba(10, 14, 23, 0.84);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-pill strong {
  color: var(--text-main);
  font-family: var(--font-mono);
}

.ballcam-badge {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 14, 23, 0.82);
  border: 1px solid var(--sky);
  color: #7dd3fc;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 12px;
  border-radius: 999px;
  pointer-events: none;
  display: none;
  white-space: nowrap;
}

.ballcam-badge.active {
  display: block;
}

.fever-banner {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, #b91c1c, #d97706, #b91c1c);
  color: #fef08a;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 5px 14px;
  border-radius: 7px;
  border: 1px solid #fde047;
  box-shadow: 0 6px 22px rgba(220, 38, 38, 0.45);
  pointer-events: none;
  display: none;
  white-space: nowrap;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
  animation: pulseBanner 0.55s infinite alternate;
}

.fever-banner.active { display: block; }

@keyframes pulseBanner {
  from { transform: translateX(-50%) scale(1); }
  to { transform: translateX(-50%) scale(1.04); }
}

/* Right Sidebar Sections */
.section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gold);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.control-row {
  margin-bottom: 8px;
}

.control-row:last-child {
  margin-bottom: 0;
}

.control-label {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.control-label span.val {
  color: var(--text-main);
  font-family: var(--font-mono);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
  cursor: pointer;
}

/* Telemetry KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

.kpi-box {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

.kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.kpi-val {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 1px;
}

.kpi-val.pos { color: #34d399; }
.kpi-val.neg { color: #f87171; }
.kpi-val.gold { color: #fbbf24; }

.hit-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-dim);
}

.hit-chip {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
}

/* Inspector Empty & Action Row */
.inspector-empty {
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 0;
}

.inspector-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.checkbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  padding: 3px 0;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.78);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  width: min(760px, 95vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--gold);
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.55;
}

.modal-body h3 {
  color: var(--text-main);
  font-size: 14px;
  margin: 14px 0 6px;
}

.modal-body h3:first-child { margin-top: 0; }

.modal-body ul {
  padding-left: 18px;
  margin-bottom: 8px;
}

.modal-body li { margin-bottom: 4px; }

.modal-body strong { color: var(--text-main); }

.modal-body textarea {
  width: 100%;
  min-height: 220px;
  background: var(--bg-app);
  color: #cbd5e1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  resize: vertical;
}

.toast {
  position: fixed;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 200;
  max-width: 92vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Medium screens */
@media (max-width: 1080px) {
  .brand .subtitle { display: none; }
  .sidebar-left { width: 216px; }
  .sidebar-right { width: 256px; }
}

/* Mobile & Portrait Layout (<= 820px) */
@media (max-width: 820px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 6px 10px;
    gap: 6px;
  }

  .topbar-primary {
    justify-content: space-between;
    gap: 8px;
  }

  .brand h1 {
    display: none;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .mode-tab {
    padding: 5px 10px;
    font-size: 12px;
  }

  .topbar-actions {
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 1px;
  }

  .topbar-actions select {
    flex: 1;
    min-width: 0;
    padding: 4px 6px;
    font-size: 11.5px;
  }

  /* 3D Play Mode on mobile: maximize board height, sleek bottom play dock */
  .app-shell.mode-play .topbar-actions {
    display: flex;
  }

  .pane-toolbar-3d {
    padding: 5px 8px;
  }

  .view3d-btn {
    padding: 5px 9px;
    font-size: 11.5px;
  }

  .hud-inline-3d {
    gap: 8px;
    font-size: 11px;
  }

  .play-dock {
    padding: 10px 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    gap: 12px;
  }

  .play-velocity {
    min-width: 0;
  }

  .btn-fire {
    min-width: 118px;
    padding: 11px 14px;
  }

  .fire-main {
    font-size: 14px;
  }

  /* 2D Blueprint Mode on mobile: vertical scroll with Blueprint first, then Components below, then Inspector */
  .app-shell.mode-edit .workspace {
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .app-shell.mode-edit .stage-area {
    order: 1;
    flex: 0 0 auto;
    width: 100%;
  }

  .app-shell.mode-edit #pane-2d {
    flex: 0 0 auto;
    width: 100%;
  }

  .app-shell.mode-edit .canvas-host-2d {
    flex: 0 0 auto;
    height: min(62vh, 112vw);
    min-height: 320px;
    width: 100%;
  }

  .hud-desktop-tip {
    display: none;
  }

  .app-shell.mode-edit .mobile-scroll-cue {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-surface);
    border: none;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    color: var(--sky);
    font-size: 11.5px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.02em;
  }

  .app-shell.mode-edit .sidebar-left {
    order: 2;
    width: 100%;
    flex: 0 0 auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    min-height: auto;
  }

  .app-shell.mode-edit .sidebar-right {
    order: 3;
    width: 100%;
    flex: 0 0 auto;
    border-left: none;
    min-height: auto;
  }

  .app-shell.mode-edit .sidebar-left .panel-scroll,
  .app-shell.mode-edit .sidebar-right .panel-scroll {
    overflow: visible;
    flex: 0 0 auto;
  }

  .panel-hint-desktop { display: none; }
  .panel-hint-mobile { display: inline; }

  .app-shell.mode-edit .palette-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .app-shell.mode-edit .palette-item {
    padding: 8px;
    gap: 7px;
  }

  .app-shell.mode-edit .palette-hint {
    display: none;
  }

  .app-shell.mode-edit .palette-name {
    flex-direction: column;
    gap: 1px;
  }
}
