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

:root {
  --bg:      #0b0400;
  --bg2:     #160800;
  --bg3:     #200c00;
  --panel:   #1a0900;
  --border:  #3a1c00;
  --accent:  #ff6a00;
  --accent2: #cc5500;
  --text:    #f0dbb8;
  --text2:   #8a6840;
  --c-servo:   #a78bfa;
  --c-led:     #fbbf24;
  --c-motor:   #34d399;
  --c-audio:   #60a5fa;
  --c-trigger: #f87171;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', monospace;
  font-size: 13px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  background: var(--bg2);
  border-bottom: 2px solid var(--accent);
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}
header h1 { font-size: 17px; color: var(--accent); letter-spacing: 1px; white-space: nowrap; }

.board-btns { display: flex; gap: 6px; }
.board-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
  cursor: pointer;
  border-radius: 3px;
  font-family: inherit;
  font-size: 11px;
  transition: all 0.15s;
}
.board-btn.active { border-color: var(--accent); color: var(--accent); background: #3a1200; }

.btn {
  padding: 5px 13px;
  border: 1px solid var(--accent);
  background: var(--accent2);
  color: var(--text);
  cursor: pointer;
  border-radius: 3px;
  font-family: inherit;
  font-size: 12px;
  white-space: nowrap;
}
.btn:hover { background: var(--accent); }
.btn.ghost {
  border-color: var(--border);
  background: var(--bg3);
  color: var(--text2);
}
.btn.ghost:hover { border-color: var(--text2); color: var(--text); background: var(--bg3); }
.btn.danger {
  border-color: #7a2020;
  background: #3a0000;
  color: #f87171;
}
.btn.danger:hover { background: #5a0000; }

/* ── Main layout ── */
main { display: flex; flex: 1; overflow: hidden; }

/* ── Left panel ── */
.left-panel {
  width: 210px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.lp-section {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.lp-section:last-child { border-bottom: none; flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.lp-title {
  font-size: 10px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.add-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.add-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
  border-radius: 3px;
  font-family: inherit;
  font-size: 11px;
  transition: all 0.15s;
}
.add-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.add-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.props-scroll { flex: 1; overflow-y: auto; padding: 4px 0; }
.prop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 3px;
  margin: 2px 0;
  cursor: default;
  transition: background 0.1s;
}
.prop-row:hover { background: var(--bg3); border-color: var(--border); }
.prop-row-info { flex: 1; min-width: 0; }
.prop-row-name { font-size: 11px; font-weight: bold; }
.prop-row-pin { font-size: 10px; color: var(--text2); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rm-btn { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; flex-shrink: 0; }
.rm-btn:hover { color: #f87171; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── Timeline area ── */
.timeline-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.tl-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tl-toolbar label { font-size: 11px; color: var(--text2); white-space: nowrap; }
.tl-toolbar input[type=range] { width: 90px; accent-color: var(--accent); }
.tl-dur { font-size: 11px; color: var(--accent); min-width: 55px; }
.tl-hint { font-size: 10px; color: var(--text2); margin-left: auto; white-space: nowrap; }

.tl-scroller { flex: 1; overflow: auto; }

.tl-grid { display: flex; flex-direction: column; }

/* Sticky corner + ruler */
.tl-ruler-row { display: flex; position: sticky; top: 0; z-index: 20; }
.tl-corner {
  width: 110px;
  flex-shrink: 0;
  height: 26px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: sticky;
  left: 0;
  z-index: 30;
}
.tl-ruler {
  flex: 1;
  height: 26px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.ruler-tick {
  position: absolute;
  bottom: 3px;
  font-size: 10px;
  color: var(--text2);
  transform: translateX(-50%);
  user-select: none;
  white-space: nowrap;
}
.ruler-vline {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--border);
  pointer-events: none;
}

/* Track rows */
.tl-track-row { display: flex; }
.tl-label {
  width: 110px;
  flex-shrink: 0;
  height: 46px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  gap: 6px;
  font-size: 11px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: sticky;
  left: 0;
  z-index: 10;
  white-space: nowrap;
}
.tl-track {
  flex: 1;
  height: 46px;
  border-bottom: 1px solid var(--border);
  position: relative;
  cursor: crosshair;
}
.tl-track:hover { background: rgba(255,106,0,0.03); }

.track-empty-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 10px;
  color: #3a1c00;
  pointer-events: none;
}

.ev-block {
  position: absolute;
  top: 5px;
  height: 36px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
  min-width: 28px;
  transition: filter 0.1s, border-color 0.1s;
}
.ev-block:hover { filter: brightness(1.25); border-color: rgba(255,255,255,0.6); }
.ev-block.sel { border-color: #fff; box-shadow: 0 0 0 1px #fff; }

.no-tracks-msg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text2);
  text-align: center;
  padding: 30px;
  line-height: 1.8;
  font-size: 12px;
}

/* ── Modal ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 20px;
  width: 90vw;
  max-width: 440px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal.wide { max-width: 680px; }
.modal h2 { font-size: 14px; color: var(--accent); margin-bottom: 14px; }
.form-row { margin-bottom: 9px; }
.form-row label { display: block; font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 3px; }
.form-row input, .form-row select {
  width: 100%;
  padding: 5px 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 3px;
  font-family: inherit;
  font-size: 12px;
}
.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--accent); }
.form-row input[type=number] { -moz-appearance: textfield; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; align-items: center; }
.form-actions .left { margin-right: auto; }

/* ── Code output ── */
.code-block {
  background: #000;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 12px;
  overflow: auto;
  white-space: pre;
  font-size: 11px;
  line-height: 1.6;
  color: #90ee90;
  max-height: 260px;
}
.code-label { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 14px; margin-bottom: 5px; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent2); }

/* ── Hardware & Wiring panel ── */
.hw-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--border);
}
.hw-row:last-of-type { border-bottom: none; }
.hw-row-info { flex: 1; min-width: 0; }
.hw-row-name { font-size: 12px; }
.hw-buy { font-size: 10px; padding: 4px 10px; flex-shrink: 0; text-decoration: none; }
.hw-power { font-size: 11px; line-height: 1.7; color: var(--text); }
.hw-power-rec { margin-top: 6px; padding: 8px 10px; background: var(--bg3); border: 1px solid var(--accent2); border-radius: 3px; color: var(--accent); }
.hw-wire-block { margin-bottom: 12px; }
.hw-wire-title { font-size: 12px; font-weight: bold; color: var(--accent); margin-bottom: 4px; }
.hw-wire-part { font-weight: normal; color: var(--text2); font-size: 11px; }
.hw-wire-steps { list-style: disc; padding-left: 18px; font-size: 11px; line-height: 1.7; color: var(--text); }

/* ── Views (auth / dashboard / editor) ── */
.view { flex: 1; min-height: 0; overflow: hidden; flex-direction: column; }
.view-center { align-items: center; justify-content: center; }

.auth-card {
  text-align: center;
  padding: 40px 50px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.auth-card h1 { font-size: 20px; color: var(--accent); margin-bottom: 10px; }
.auth-tagline { color: var(--text2); font-size: 12px; margin-bottom: 18px; }

/* ── Dashboard ── */
.dash-main { display: block; flex: 1; overflow-y: auto; padding: 20px; max-width: 700px; margin: 0 auto; width: 100%; }
.dash-new { display: flex; gap: 8px; margin-bottom: 20px; }
.dash-new input[type="text"] {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 12px;
}
.dash-new select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 12px;
}
.dash-empty { color: var(--text2); font-size: 12px; padding: 20px 4px; }
.proj-list { display: flex; flex-direction: column; gap: 8px; }
.proj-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.proj-card-info { flex: 1; min-width: 0; }
.proj-card-name { font-size: 13px; }
.proj-card-meta { font-size: 10px; color: var(--text2); margin-top: 3px; }
.proj-card-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Editor header extras ── */
.editor-proj-name { font-size: 13px; color: var(--text2); white-space: nowrap; }
.save-status { font-size: 10px; color: var(--text2); white-space: nowrap; min-width: 90px; text-align: right; }

/* ── AI Assist ── */
.ai-textarea {
  width: 100%;
  resize: vertical;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 3px;
  font-family: inherit;
  font-size: 11px;
}
.ai-row { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 6px; }
.ai-status { font-size: 10px; color: var(--text2); width: 100%; word-break: break-word; }
.ai-instruction-echo { font-size: 11px; color: var(--text2); font-style: italic; margin-bottom: 8px; }
.ai-explanation { font-size: 12px; line-height: 1.6; margin-bottom: 12px; white-space: pre-wrap; }
.ai-preview-section { margin-bottom: 12px; }
.ai-list { list-style: none; font-size: 11px; line-height: 1.8; }
.ai-empty { font-size: 11px; color: var(--text2); }
