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

:root {
  color-scheme: dark;
  --accent: #B791FD;
  --bg: #000;
  --panel-bg: #0a0a0a;
  --border: #1a1a1a;
  --text-dim: #444;
  --text-mid: #666;
  --text: #ccc;
}

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

/* ── Header ──────────────────────────────────── */

.site-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 32px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.header-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.dl-logo {
  width: 32px;
  height: 32px;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.header-logo:hover .dl-logo { opacity: 1; }

.header-title {
  font-family: 'Big Shoulders Display', sans-serif;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #fafafa;
  text-transform: uppercase;
  flex: 1;
}

/* ── Theme Switcher ──────────────────────────── */

.theme-switcher {
  display: flex;
  gap: 2px;
  background: #0a0a0a;
  border: 1px solid var(--border);
  padding: 3px;
}

.theme-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 0.15em;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.1s;
  text-transform: uppercase;
}

.theme-btn:hover { color: var(--text); }

.theme-btn.active {
  background: var(--accent);
  color: #fff;
}

/* theme-specific active colors */
body.theme-typewriter .theme-btn[data-theme="typewriter"].active { background: #a88020; }
body.theme-crt        .theme-btn[data-theme="crt"].active        { background: #00aa44; }
body.theme-darkroom   .theme-btn[data-theme="darkroom"].active   { background: #880000; }

/* ── App Layout ──────────────────────────────── */

#app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Left Panel ──────────────────────────────── */

#panel {
  width: 280px;
  min-width: 280px;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  overflow-y: auto;
}

.section-label {
  font-size: 11px;
  color: #aaa;
  letter-spacing: 0.2em;
  margin-bottom: 14px;
  text-transform: uppercase;
  font-weight: 700;
}

.panel-label {
  font-size: 10px;
  color: #555;
  letter-spacing: 0.2em;
  margin-bottom: 10px;
  text-transform: uppercase;
}

#panel section {
  display: flex;
  flex-direction: column;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

#panel input[type="text"] {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: #fff;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  letter-spacing: 0.05em;
  padding: 8px 0;
  outline: none;
  transition: border-color 0.1s;
}

#panel input[type="text"]:focus {
  border-bottom-color: var(--accent);
}

#panel input[type="range"] {
  accent-color: #666;
  margin-top: 8px;
  width: 100%;
}

/* Line inputs */
.line-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.line-row input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: #fff;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  letter-spacing: 0.05em;
  padding: 8px 0;
  outline: none;
  transition: border-color 0.1s;
}

.line-row input:focus { border-bottom-color: var(--accent); }

.remove-line {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 4px;
  transition: color 0.1s;
  font-family: monospace;
}

.remove-line:hover { color: var(--accent); }

.btn-add {
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 0.2em;
  cursor: pointer;
  padding: 8px 0;
  text-align: left;
  transition: color 0.1s;
  margin-top: 6px;
}

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

/* Subtitle controls */
.sub-controls {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.sub-control-label {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  width: 24px;
  flex-shrink: 0;
}

.sub-control-row input[type="range"] {
  flex: 1;
  accent-color: #666;
  height: 2px;
}

.sub-control-row input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  padding: 1px;
}

.sub-control-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.sub-control-row input[type="color"]::-webkit-color-swatch { border: none; border-radius: 1px; }

/* Cursor shape buttons */
.cursor-shape-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.shape-btn {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-family: 'Courier New', monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
  padding: 6px 10px;
  cursor: pointer;
  transition: all 0.1s;
}

.shape-btn:hover { color: var(--text); border-color: var(--text-dim); }
.shape-btn.active { background: #333; color: #fff; border-color: #333; }

/* Collapsible panels */
.collapsible {
  cursor: pointer;
  user-select: none;
  transition: color 0.1s;
}

.collapsible:hover { color: var(--text); }

.toggle-arrow {
  font-size: 8px;
  display: inline-block;
  transition: transform 0.15s;
}

.collapsible.open .toggle-arrow { transform: rotate(90deg); }

.collapsible-panel {
  overflow: hidden;
  max-height: 400px;
  transition: max-height 0.2s ease, opacity 0.2s ease;
  opacity: 1;
}

.collapsible-panel.collapsed {
  max-height: 0;
  opacity: 0;
}

/* Cursor color rows */
.cursor-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.cursor-color-label {
  font-size: 10px;
  color: var(--text-dim);
  width: 12px;
  text-align: right;
}

.cursor-color-swatch {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  padding: 1px;
}

.cursor-color-swatch::-webkit-color-swatch-wrapper { padding: 0; }
.cursor-color-swatch::-webkit-color-swatch { border: none; border-radius: 1px; }

/* Color picker */
.color-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

#color-input {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: none;
  cursor: pointer;
  padding: 1px;
}

#color-input::-webkit-color-swatch-wrapper { padding: 0; }
#color-input::-webkit-color-swatch { border: none; border-radius: 1px; }

.color-hex {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
}

/* Action buttons */
.actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn-action {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-mid);
  font-family: 'Courier New', monospace;
  font-size: 11px;
  letter-spacing: 0.2em;
  padding: 10px 16px;
  cursor: pointer;
  text-align: left;
  transition: all 0.1s;
}

.btn-action:hover:not(:disabled) {
  border-color: var(--accent);
  color: #fff;
}

.btn-action:disabled { opacity: 0.3; cursor: not-allowed; }

#status {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  min-height: 16px;
}

.back-link {
  margin-top: auto;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  text-decoration: none;
  text-transform: uppercase;
  transition: color 0.1s;
}

.back-link:hover { color: #fff; }

/* ── Preview Area ────────────────────────────── */

#preview-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  padding: 24px;
  position: relative;
}

#canvas-frame {
  position: relative;
  display: inline-flex;
}

#preview {
  max-width: 100%;
  max-height: calc(100vh - 80px);
  display: block;
}

/* CRT scanline DOM overlay (subtle, in addition to canvas post-process) */
.scanline-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 3px
  );
}

/* ── Theme body classes ──────────────────────── */

body.theme-typewriter {
  --accent: #a88020;
  --panel-bg: #0d0a04;
  --border: #2a2010;
  --text-dim: #4a3c18;
  --text-mid: #7a6030;
  --text: #a88840;
}

body.theme-crt {
  --accent: #00aa44;
  --panel-bg: #000a00;
  --border: #001a00;
  --text-dim: #003300;
  --text-mid: #005500;
  --text: #00aa55;
}

body.theme-darkroom {
  --accent: #880000;
  --panel-bg: #0a0000;
  --border: #200000;
  --text-dim: #3a0000;
  --text-mid: #660000;
  --text: #aa2222;
}

body.theme-crt #preview-area { background: #000a00; }
body.theme-typewriter #preview-area { background: #0d0a04; }
body.theme-darkroom #preview-area { background: #0a0000; }

body.theme-crt .scanline-overlay { opacity: 1; }

/* ── Mobile Responsive ──────────────────────── */

@media (max-width: 767px) {
  body {
    overflow: auto;
  }

  .site-header {
    padding: 12px 16px;
    gap: 12px;
  }

  .header-title {
    font-size: 16px;
  }

  #app {
    flex-direction: column;
  }

  #preview-area {
    order: 1;
    height: 50vh;
    flex: none;
    padding: 8px;
  }

  #preview {
    max-height: calc(50vh - 16px);
  }

  #panel {
    order: 2;
    width: 100%;
    min-width: unset;
    border-right: none;
    border-top: 1px solid var(--border);
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    gap: 20px;
  }

  .remove-line {
    padding: 8px;
    font-size: 18px;
  }

  .shape-btn {
    padding: 10px 14px;
    font-size: 10px;
  }

  .btn-action {
    padding: 14px 16px;
  }

  .sub-control-row input[type="color"],
  .cursor-color-swatch {
    width: 32px;
    height: 32px;
  }

  #color-input {
    width: 36px;
    height: 36px;
  }
}
