/* WonderLab — Flat Minimal UI (Zero Gradients) */
:root {
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --surface-alt: #F1F3F6;
  --border: #E2E5EB;
  --border-strong: #CBD0DA;
  --text: #111827;
  --text-muted: #5B6475;
  --accent: #573AFC;
  --accent-hover: #462BD9;
  --accent-soft: #EFEBFD;
  --danger: #DC2626;
  --danger-soft: #FEE2E2;
  --success: #15803D;
  --success-soft: #DCFCE7;
  --warn: #B45309;
  --warn-soft: #FEF3C7;
  --radius: 14px;
  --radius-sm: 12px;
}

[data-theme="dark"] {
  --bg: #111318;
  --surface: #1A1D24;
  --surface-alt: #232732;
  --border: #2E3340;
  --border-strong: #404759;
  --text: #F3F4F6;
  --text-muted: #9CA3AF;
  --accent: #573AFC;
  --accent-hover: #6D54FF;
  --accent-soft: #261E54;
  --danger: #EF4444;
  --danger-soft: #3B1818;
  --success: #22C55E;
  --success-soft: #143320;
  --warn: #F59E0B;
  --warn-soft: #3B2B10;
}

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

html, body, #app {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#lab-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* Crosshair & Target Prompt */
#crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  pointer-events: none;
  z-index: 20;
}

.pill-prompt {
  position: fixed;
  left: 50%;
  top: calc(50% + 20px);
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  z-index: 25;
  white-space: nowrap;
}

/* Top HUD Clusters */
.hud-cluster {
  position: fixed;
  top: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 40;
}

#hud-top-left {
  left: 14px;
}

#hud-top-right {
  right: 14px;
}

.brand-pill, .status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

.mode-badge {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
}

.status-pill {
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
}

.status-pill.anti-g {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
}

/* Icon Buttons */
.icon-btn, .icon-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.icon-btn {
  width: 38px;
  height: 38px;
}

.icon-btn-sm {
  width: 30px;
  height: 30px;
  border-radius: 10px;
}

.icon-btn:hover, .icon-btn-sm:hover {
  border-color: var(--accent);
  color: var(--accent);
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.toast-pill {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--accent);
  border-radius: 12px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  z-index: 95;
  pointer-events: none;
  white-space: nowrap;
}

.tour-card {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: min(350px, calc(100vw - 28px));
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 75;
}

.minimap-box {
  position: fixed;
  left: 64px;
  bottom: 42px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  z-index: 42;
}

#minimap-canvas {
  display: block;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.icon-btn.active {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
}

/* Left Edge Icon Rail */
#hud-left-rail {
  position: fixed;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 40;
}

/* Right Side Context Panel */
.context-panel {
  position: fixed;
  top: 64px;
  right: 14px;
  bottom: 52px;
  width: min(410px, calc(100vw - 28px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 60;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 8px;
}

.panel-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.panel-badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 6px;
  flex-shrink: 0;
}

.panel-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-body, .modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  user-select: text;
}

/* Wide Modal Sheet */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 19, 24, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px 52px;
  z-index: 80;
}

.modal-card {
  width: min(1060px, 100%);
  max-height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Shared Panel Controls */
.card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.between {
  justify-content: space-between;
}

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

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #FFFFFF;
}

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

.btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.input, .select, .textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.textarea {
  min-height: 76px;
  resize: vertical;
}

.label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.tag-accent {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.tag-success {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}

.tag-warn {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
}

.tag-danger {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.muted {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

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

.tab-btn {
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

/* Periodic Table Grid */
.pt-grid {
  display: grid;
  grid-template-columns: repeat(18, minmax(36px, 1fr));
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.pt-cell {
  border-radius: 6px;
  padding: 4px 2px;
  text-align: center;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.pt-cell:hover, .pt-cell.selected {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
}

.pt-num {
  font-size: 9px;
  opacity: 0.85;
}

.pt-sym {
  font-size: 13px;
  font-weight: 700;
}

/* Mini 3D Viewports (Molecule / Bohr Atom / Almari) */
.mini-canvas-box {
  width: 100%;
  height: 200px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

.mini-canvas-box canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

/* Science Book Spread */
.book-spread {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 14px;
  min-height: 420px;
}

.book-toc {
  border-right: 1px solid var(--border);
  padding-right: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 62vh;
  overflow-y: auto;
}

.book-toc-item {
  text-align: left;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.book-toc-item:hover {
  background: var(--surface-alt);
}

.book-toc-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.book-page {
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform-origin: left center;
}

/* Terminal for AI Research Computer */
.terminal-log {
  background: #111318;
  color: #E5E7EB;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Bottom Hint Bar */
.hint-bar {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 500;
  z-index: 35;
  white-space: nowrap;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 0.4s ease;
}

.hint-bar.faded {
  opacity: 0;
  pointer-events: none;
}

/* Mobile Controls */
.mobile-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 42px;
  padding: 0 18px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  pointer-events: none;
  z-index: 45;
}

.joystick-zone {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  position: relative;
  pointer-events: auto;
  touch-action: none;
}

.joystick-knob {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  left: 27px;
  top: 27px;
}

.mobile-actions {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.mobile-btn {
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--accent);
  font-size: 13px;
  font-weight: 600;
}

/* Photo Mode */
.photo-exit-btn {
  position: fixed;
  top: 14px;
  right: 14px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  z-index: 90;
}

/* Containment Blackout Overlay (solid flat color, zero gradients) */
.blackout-overlay {
  position: fixed;
  inset: 0;
  background: #0B0D12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 9500;
}

.blackout-box {
  background: #1A1D24;
  color: #F3F4F6;
  border: 2px solid #EF4444;
  border-radius: 16px;
  padding: 24px 28px;
  max-width: 400px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Handheld Lab Tablet */
.lab-tablet {
  position: fixed;
  left: 64px;
  top: 64px;
  width: min(320px, calc(100vw - 80px));
  max-height: calc(100vh - 125px);
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 55;
}

/* Tablet Split-Screen & Touch Ergonomics (768px - 1180px) */
@media (min-width: 768px) and (max-width: 1180px) {
  .context-panel {
    width: 375px;
    bottom: 48px;
  }
  .btn, .tab-btn, .input, .select {
    min-height: 38px;
    font-size: 13px;
  }
  .icon-btn {
    width: 42px;
    height: 42px;
  }
}

/* Fixed Footer Credit — always visible bottom center, above canvas, never blocked */
.footer-credit {
  position: fixed;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 9999;
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 10px;
}

.footer-credit a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.footer-credit a:hover {
  color: var(--accent);
}

/* Loading Screen (flat solid color) */
.loading-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}

.loading-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 32px;
  text-align: center;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.loading-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
}

.loading-box h1 {
  font-size: 17px;
  font-weight: 700;
}

.loading-box p {
  font-size: 13px;
  color: var(--text-muted);
}

@media (max-width: 768px) {
  .brand-title {
    display: none;
  }
  .status-pill {
    font-size: 11px;
    padding: 6px 9px;
  }
  .icon-btn {
    width: 34px;
    height: 34px;
  }
  #hud-left-rail {
    top: auto;
    bottom: 150px;
    transform: none;
  }
  .context-panel {
    top: 58px;
    bottom: 44px;
    left: 10px;
    right: 10px;
    width: auto;
  }
  .book-spread {
    grid-template-columns: 1fr;
  }
  .book-toc {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 8px;
    max-height: 150px;
  }
  .hint-bar {
    display: none;
  }
}
