/* ── Variables ─────────────────────────────────────────────────────────────────── */
:root {
  --bg:          #0e1114;
  --bg-panel:    #161a1f;
  --bg-raised:   #1e242a;
  --bg-inset:    #0a0d10;
  --bg-display:  #001400;
  --line:        #2a3239;
  --line-soft:   #20262c;
  --color-ch1:   #e8e000;
  --color-ch2:   #d65be6;
  --color-green: #45d483;
  --color-green-soft: rgba(69,212,131,0.12);
  --color-amber: #f5b83d;
  --color-red:   #ff6b5e;
  --text-main:   #dbe1e6;
  --text-dim:    #98a2ac;
  --font-ui:     system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono:   ui-monospace, 'Cascadia Mono', 'SF Mono', Consolas, monospace;
  --radius:      8px;
  --radius-sm:   5px;
  --gap:         10px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 13px;
  overflow: hidden;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--color-green);
  outline-offset: 1px;
}

/* ── App shell ────────────────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: 48px 1fr;
  grid-template-columns: minmax(0, 1fr);
  height: 100vh;
}

/* ── Navbar ─────────────────────────────────────────────────────────────────── */
#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
  padding: 0 14px;
  z-index: 10;
}

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

.nav-mark { flex-shrink: 0; display: block; }

#navbar .nav-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.nav-tagline {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

#navbar .nav-mode {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.mode-btn:hover { color: var(--text-main); }
.mode-btn.active {
  background: var(--bg-raised);
  color: var(--color-green);
}

.nav-link {
  color: var(--text-dim);
  font-size: 12px;
  text-decoration: none;
}
.nav-link:hover { color: var(--text-main); text-decoration: underline; }

/* ── Main layout ──────────────────────────────────────────────────────────────── */
#main {
  display: grid;
  grid-template-columns: 276px 1fr;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  height: 100%;
  min-height: 0;
}

/* La teoria tiene su propio indice: la lista de experimentos sobra. */
#main.theory-mode { grid-template-columns: minmax(0, 1fr); }
#main.theory-mode #sidebar { display: none; }

/* ── Left sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  overflow: hidden;
  min-height: 0;
}

#sidebar-list {
  flex: 0 1 44%;
  min-height: 120px;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

#guide-panel {
  flex: 1 1 56%;
  min-height: 0;
  border-top: 1px solid var(--line);
  overflow-y: auto;
  padding: 12px;
}

/* ── Right workspace ────────────────────────────────────────────────────────────── */
#workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

/* ── Instrument row ─────────────────────────────────────────────────────────────── */
#instruments {
  display: grid;
  grid-template-columns: minmax(214px, 0.8fr) minmax(246px, 0.9fr) minmax(460px, 2.4fr);
  gap: var(--gap);
  padding: var(--gap);
  border-bottom: 1px solid var(--line);
  height: 344px;
  min-width: 0;
}

/* ── Breadboard area ────────────────────────────────────────────────────────────── */
#breadboard-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: var(--gap);
  gap: var(--gap);
  position: relative;
  min-height: 0;
}

/* ── Shared control styles ────────────────────────────────────────────────────────── */
.ctrl-label {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.stepper-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.step-btn {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text-main);
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s, border-color 0.1s;
  flex-shrink: 0;
}
.step-btn:hover  { background: #283038; border-color: #3c4650; }
.step-btn:active { background: #323b44; }

.num-input {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--color-amber);
  padding: 3px 4px;
  height: 24px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  width: 74px;
  text-align: center;
  -moz-appearance: textfield;
  appearance: textfield;
}
.num-input::-webkit-inner-spin-button { display: none; }
.num-input:focus { outline: none; border-color: var(--color-green); }

.toggle-btn {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text-dim);
  padding: 3px 14px;
  height: 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.toggle-btn.active {
  background: var(--color-green-soft);
  border-color: var(--color-green);
  color: var(--color-green);
}

.wave-btns { display: flex; gap: 2px; flex: 1; justify-content: flex-end; }
.wave-btn {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text-dim);
  padding: 3px 7px;
  height: 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  white-space: nowrap;
}
.wave-btn:hover { color: var(--text-main); }
.wave-btn.active {
  color: var(--color-amber);
  border-color: var(--color-amber);
}

/* ── Numeric readouts ──────────────────────────────────────────────────────────────── */
.seg7 {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--color-amber);
  text-shadow: 0 0 8px rgba(245,184,61,0.35);
}

/* ── Scope controls row ──────────────────────────────────────────────────────────── */
#scope-controls {
  display: flex;
  align-items: center;
  gap: 6px 10px;
  padding: 6px 10px;
  background: var(--bg-panel);
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.scope-ctrl-group {
  display: flex;
  align-items: center;
  gap: 4px;
  border-right: 1px solid var(--line);
  padding-right: 10px;
}
.scope-ctrl-group:last-child { border-right: none; padding-right: 0; }

.scope-ctrl-label {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.ch1-label { color: var(--color-ch1); }
.ch2-label { color: var(--color-ch2); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

/* ── Pantallas estrechas: se apila y la pagina pasa a tener scroll ─────────────────── */
@media (max-width: 1180px) {
  html, body { overflow: auto; height: auto; }
  #app { height: auto; min-height: 100vh; grid-template-rows: auto 1fr; }
  #navbar { flex-wrap: wrap; padding: 8px 16px; }
  .nav-tagline { display: none; }
  #main { display: block; height: auto; overflow: visible; }
  #sidebar { border-right: none; border-bottom: 1px solid var(--line); overflow: visible; }
  #sidebar-list { max-height: 240px; flex: none; }
  #guide-panel { overflow: visible; flex: none; }
  #workspace { display: block; overflow: visible; }
  #instruments { height: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #scope-panel { grid-column: 1 / -1; grid-row: 1; }
  #scope-panel .scope-canvas-wrap { height: 300px; flex: none; }
  #breadboard-area { overflow: visible; }

  /* Protoboard libre en pantallas estrechas: primero la placa, despues los instrumentos. */
  #main.freeform-mode #sidebar-list,
  #main.freeform-mode .sidebar-header { display: none; }
  #main.freeform-mode #workspace { display: flex; flex-direction: column; }
  #main.freeform-mode #breadboard-area { order: -1; }
}

@media (max-width: 640px) {
  #instruments { grid-template-columns: minmax(0, 1fr); padding: 8px 16px; }
  #breadboard-area { padding: 8px 16px; }
  .scope-ctrl-group { border-right: none; padding-right: 0; }
  .nav-actions { width: 100%; justify-content: space-between; }
}
