/* Circuit Weaver — 16-Bit Cyberpunk PCB Aesthetic */
:root {
  --bg-deep: #040d10;
  --bg-panel: #0a1f24;
  --bg-panel-2: #0f2c33;
  --border-pcb: #1d4e56;
  --border-glow: #22d3ee;
  --text-main: #e6f9ff;
  --text-dim: #8bb5be;
  --cyan: #22d3ee;
  --gold: #fbbf24;
  --magenta: #f472b6;
  --danger: #ef4444;
  --success: #34d399;
  --font-pixel: 'Silkscreen', 'JetBrains Mono', monospace;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

body[data-theme="synthwave"] {
  --bg-deep: #090516;
  --bg-panel: #160c30;
  --bg-panel-2: #221247;
  --border-pcb: #5b21b6;
  --border-glow: #e879f9;
  --text-main: #f5f0ff;
  --text-dim: #b49be0;
}

body[data-theme="quantum"] {
  --bg-deep: #0c0b0e;
  --bg-panel: #19161d;
  --bg-panel-2: #25202b;
  --border-pcb: #85641b;
  --border-glow: #fbbf24;
  --text-main: #fffbeb;
  --text-dim: #c9b587;
}

body[data-theme="amber"] {
  --bg-deep: #060b05;
  --bg-panel: #0e190c;
  --bg-panel-2: #162613;
  --border-pcb: #4d7c0f;
  --border-glow: #f59e0b;
  --text-main: #fef3c7;
  --text-dim: #a3b88c;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100dvh;
  background: radial-gradient(circle at 50% 0%, var(--bg-panel) 0%, var(--bg-deep) 75%);
  color: var(--text-main);
  font-family: var(--font-mono);
  overflow-x: hidden;
  user-select: none;
}

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 10px 12px 58px; /* Bottom clearance for studio-bar.js */
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border-pcb);
  border-radius: 10px;
  padding: 8px 12px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

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

.brand-bolt {
  font-size: 20px;
  filter: drop-shadow(0 0 8px var(--cyan));
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 16px;
  letter-spacing: 0.5px;
  color: var(--text-main);
  text-shadow: 0 0 10px rgba(34, 211, 238, 0.45);
  white-space: nowrap;
}

.brand-sub {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.btn-chip {
  appearance: none;
  border: 1px solid var(--border-pcb);
  background: var(--bg-panel-2);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 6px 9px;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}

.btn-chip:hover {
  border-color: var(--border-glow);
  background: rgba(34, 211, 238, 0.14);
}

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

.btn-chip.btn-daily {
  border-color: rgba(251, 191, 36, 0.6);
  color: #fde68a;
  background: rgba(251, 191, 36, 0.12);
}

.btn-chip.btn-daily:hover {
  border-color: var(--gold);
  background: rgba(251, 191, 36, 0.24);
}

.btn-chip.btn-icon {
  padding: 6px 8px;
  font-size: 13px;
}

/* Challenge Banner */
.challenge-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(90deg, rgba(244, 114, 182, 0.2), rgba(34, 211, 238, 0.18));
  border: 1px solid var(--magenta);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #fdf4ff;
}

.mini-x {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}

/* HUD Strip */
.hud-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border-pcb);
  border-radius: 10px;
  padding: 7px 12px;
}

.hud-level-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.badge-tier {
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 3px 6px;
  border-radius: 5px;
  background: rgba(34, 211, 238, 0.2);
  border: 1px solid var(--cyan);
  color: #a5f3fc;
  flex-shrink: 0;
}

.hud-lvl-name {
  font-weight: 800;
  font-size: 13px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hud-metrics {
  display: flex;
  align-items: center;
  gap: 12px;
}

.metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}

.metric-label {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.6px;
}

.metric-val {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-main);
}

.metric-stars .metric-val {
  color: var(--gold);
  letter-spacing: 1px;
}

/* Stage & PCB Canvas */
.stage-wrap {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.pcb-frame {
  width: 100%;
  max-width: 560px;
  background: var(--bg-panel);
  border: 2px solid var(--border-pcb);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.6), 0 0 22px rgba(34, 211, 238, 0.08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
}

.pcb-frame.short-alert {
  border-color: var(--danger);
  box-shadow: 0 0 26px rgba(239, 68, 68, 0.45);
}

#pcb-canvas {
  display: block;
  width: 100%;
  max-width: 540px;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  cursor: pointer;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: manipulation;
}

.signal-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-size: 10px;
  color: var(--text-dim);
  padding: 1px 4px;
}

.leg-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot-a { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.dot-b { background: var(--gold); box-shadow: 0 0 6px var(--gold); }
.dot-m { background: var(--magenta); box-shadow: 0 0 6px var(--magenta); }

/* Status / Tip Bar */
.status-bar {
  background: var(--bg-panel);
  border: 1px solid var(--border-pcb);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 11.5px;
  color: var(--text-dim);
  text-align: center;
  min-height: 33px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.status-bar.is-short {
  background: rgba(239, 68, 68, 0.16);
  border-color: var(--danger);
  color: #fecaca;
  font-weight: 700;
}

.status-bar.is-solved {
  background: rgba(52, 211, 153, 0.16);
  border-color: var(--success);
  color: #a7f3d0;
  font-weight: 700;
}

/* Tactile Control Bar */
.control-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.ctrl-btn {
  appearance: none;
  border: 1px solid var(--border-pcb);
  background: var(--bg-panel);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}

.ctrl-btn:hover:not(:disabled) {
  border-color: var(--border-glow);
  background: var(--bg-panel-2);
}

.ctrl-btn:active:not(:disabled) {
  transform: scale(0.95);
}

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

.ctrl-btn kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
}

.ctrl-hint {
  border-color: rgba(251, 191, 36, 0.55);
  color: #fde68a;
}

.hint-pill {
  background: var(--gold);
  color: #111827;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 99px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 8, 12, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 14px 56px;
  z-index: 900;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--bg-panel);
  border: 2px solid var(--border-glow);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.75);
}

.modal-wide {
  max-width: 580px;
}

.modal-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-title {
  margin: 0;
  font-family: var(--font-pixel);
  font-size: 16px;
  color: var(--text-main);
  letter-spacing: 0.5px;
}

.modal-close {
  appearance: none;
  border: 1px solid var(--border-pcb);
  background: var(--bg-panel-2);
  color: var(--text-main);
  width: 30px;
  height: 30px;
  border-radius: 7px;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

/* Victory Modal */
.modal-victory {
  text-align: center;
}

.vic-burst {
  font-size: 32px;
  margin-bottom: 2px;
  filter: drop-shadow(0 0 12px var(--gold));
}

.vic-sub {
  margin: 4px 0 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.vic-stars {
  font-size: 30px;
  color: var(--gold);
  letter-spacing: 5px;
  text-shadow: 0 0 14px rgba(251, 191, 36, 0.6);
  margin: 4px 0 12px;
}

.vic-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.vstat {
  background: var(--bg-panel-2);
  border: 1px solid var(--border-pcb);
  border-radius: 8px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vstat-lbl {
  font-size: 9px;
  color: var(--text-dim);
}

.vstat-val {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-main);
}

.daily-submit-box {
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.5);
  border-radius: 9px;
  padding: 10px;
  margin-bottom: 10px;
  text-align: left;
}

.ds-lbl {
  display: block;
  font-size: 10px;
  font-weight: 800;
  color: #fde68a;
  margin-bottom: 6px;
}

.ds-row {
  display: flex;
  gap: 6px;
}

.ds-row input {
  flex: 1;
  background: var(--bg-deep);
  border: 1px solid var(--border-pcb);
  border-radius: 6px;
  padding: 7px 9px;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.ds-status {
  margin-top: 5px;
  font-size: 11px;
  color: #a7f3d0;
}

.cliffhanger-box {
  background: rgba(34, 211, 238, 0.1);
  border: 1px solid rgba(34, 211, 238, 0.45);
  border-radius: 9px;
  padding: 8px 10px;
  margin-bottom: 14px;
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cliff-tag {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--cyan);
}

.vic-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.btn-primary, .btn-secondary, .btn-accent {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-family: var(--font-pixel);
  font-size: 11px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
}

.btn-primary {
  background: linear-gradient(180deg, #22d3ee, #0891b2);
  color: #041317;
  box-shadow: 0 0 14px rgba(34, 211, 238, 0.4);
}

.btn-secondary {
  background: var(--bg-panel-2);
  color: var(--text-main);
  border: 1px solid var(--border-pcb);
}

.btn-accent {
  background: linear-gradient(180deg, #fbbf24, #d97706);
  color: #1c1002;
}

.btn-sm {
  padding: 7px 11px;
  font-size: 10px;
}

.btn-primary:hover, .btn-secondary:hover, .btn-accent:hover {
  filter: brightness(1.1);
}

.btn-primary:active, .btn-secondary:active, .btn-accent:active {
  transform: scale(0.96);
}

.share-feedback {
  margin-top: 8px;
  font-size: 11px;
  color: var(--success);
  min-height: 16px;
}

/* Levels Grid */
.daily-banner-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.16), rgba(244, 114, 182, 0.14));
  border: 1px solid rgba(251, 191, 36, 0.6);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.db-title {
  font-family: var(--font-pixel);
  font-size: 12px;
  color: #fde68a;
}

.db-sub {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.tier-section {
  margin-bottom: 12px;
}

.tier-hdr {
  font-family: var(--font-pixel);
  font-size: 11px;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
  gap: 6px;
}

.lvl-tile {
  appearance: none;
  border: 1px solid var(--border-pcb);
  background: var(--bg-panel-2);
  color: var(--text-main);
  border-radius: 8px;
  padding: 7px 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-family: var(--font-mono);
}

.lvl-tile:hover:not(:disabled) {
  border-color: var(--cyan);
}

.lvl-tile.current {
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.35);
}

.lvl-tile.boss {
  border-color: rgba(244, 114, 182, 0.7);
}

.lvl-tile:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.lvl-num {
  font-weight: 800;
  font-size: 13px;
}

.lvl-stars {
  font-size: 10px;
  color: var(--gold);
  letter-spacing: 1px;
}

/* Lab Bench */
.lab-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.ls-box {
  background: var(--bg-panel-2);
  border: 1px solid var(--border-pcb);
  border-radius: 8px;
  padding: 7px 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ls-lbl { font-size: 9px; color: var(--text-dim); }
.ls-val { font-size: 13px; font-weight: 800; color: var(--gold); }

.sec-heading {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--cyan);
  margin: 10px 0 6px;
}

.themes-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.theme-card {
  border: 1px solid var(--border-pcb);
  background: var(--bg-panel-2);
  border-radius: 8px;
  padding: 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  text-align: left;
  color: var(--text-main);
  font-family: var(--font-mono);
}

.theme-card.active {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.35);
}

.theme-card.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.theme-swatch {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
}

.theme-name { font-size: 11.5px; font-weight: 800; }
.theme-req { font-size: 10px; color: var(--text-dim); }

.badges-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-pcb);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11.5px;
}

.badge-row.earned {
  border-color: rgba(52, 211, 153, 0.7);
}

.badge-title { font-weight: 800; color: var(--text-main); }
.badge-desc { font-size: 10.5px; color: var(--text-dim); }
.badge-state { font-size: 10px; font-weight: 800; flex-shrink: 0; }
.badge-state.ok { color: var(--success); }
.badge-state.need { color: var(--gold); }

/* Leaderboard */
.board-sub {
  margin: 0 0 10px;
  font-size: 11.5px;
  color: var(--text-dim);
}

.board-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
  min-height: 110px;
}

.board-row {
  display: grid;
  grid-template-columns: 32px 1fr 68px 54px;
  align-items: center;
  background: var(--bg-panel-2);
  border: 1px solid var(--border-pcb);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
}

.board-rank { font-weight: 800; color: var(--gold); }
.board-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-score { font-weight: 800; text-align: right; color: var(--cyan); }
.board-stars { text-align: right; color: var(--gold); font-size: 11px; }
.board-empty { text-align: center; padding: 24px 8px; color: var(--text-dim); font-size: 12px; }
.board-footer { text-align: center; }

/* Mobile Responsive (390x844 zero horizontal overflow!) */
@media (max-width: 560px) {
  #app {
    padding: 6px 8px 54px;
    gap: 6px;
  }

  .topbar {
    padding: 6px 8px;
  }

  .brand-title {
    font-size: 13px;
  }

  .brand-sub {
    display: none;
  }

  .btn-chip {
    padding: 5px 6px;
    font-size: 10.5px;
  }

  .btn-chip .lbl {
    display: none;
  }

  #btn-lab .lbl {
    display: inline;
  }

  .hud-strip {
    padding: 6px 8px;
    gap: 5px;
  }

  .hud-lvl-name {
    font-size: 12px;
  }

  .hud-metrics {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }

  .metric-val {
    font-size: 12px;
  }

  .pcb-frame {
    padding: 5px;
  }

  .signal-legend {
    gap: 8px;
    font-size: 9.5px;
  }

  .status-bar {
    font-size: 10.5px;
    padding: 5px 8px;
    min-height: 28px;
  }

  .control-bar {
    gap: 4px;
  }

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

  .ctrl-btn kbd {
    display: none;
  }

  .lab-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .themes-grid {
    grid-template-columns: 1fr;
  }
}
