/* ── Fonts ──────────────────────────────────────── */
@font-face {
  font-family: 'National Park';
  src: url('fonts/NationalPark-VariableVF.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
}

:root {
  /* ── Default (Aged Parchment) ───────────────────────── */
  --bg:        #222222;
  --surface:   #2a2a2a;
  --border:    #333333;
  --text:      #f5f3e3;
  --text-dim:  #888888;
  --bright:    #faf3e1;
  --paper:     #faf3e1;
  --ink:       #222222;
  --accent:    #ff6d1f;
  --accent-hi: #ff8c42;
  --highlight:     #f5e7c6;
  --mono:      'Courier New', Courier, monospace;
  --sans:      system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  --bar-h:     42px;
  --tray-w:    320px;
}

/* ── Retro (80s Terminal) ─────────────────────────────── */
[data-theme="retro"] {
  --bg:        #10385c;
  --surface:   #163d60;
  --border:    #1d4568;
  --text:      #7ee787;
  --text-dim:  #3fb950;
  --bright:    #f4f6ff;
  --paper:     #f4f6ff;
  --ink:       #10385c;
  --accent:    #eb8317;
  --accent-hi: #f5a623;
  --highlight:     #f3c623;
}

/* ── Vintage (Spring Pastels) ───────────────────────── */
[data-theme="vintage"] {
  --bg:        #89986d;
  --surface:   #8f9e73;
  --border:    #95a479;
  --text:      #2a331e;
  --text-dim:  #5a6b42;
  --bright:    #f6f0d7;
  --paper:     #f6f0d7;
  --ink:       #2a331e;
  --accent:    #9cab84;
  --accent-hi: #a5b48b;
  --highlight:     #c5d89d;
}

/* ── Neon (Cyberpunk) ────────────────────────────────── */
[data-theme="neon"] {
  --bg:        #362f4f;
  --surface:   #3d3656;
  --border:    #443d5d;
  --text:      #e4ff30;
  --text-dim:  #cdd6f4;
  --bright:    #ffffff;
  --paper:     #362f4f;
  --ink:       #e4ff30;
  --accent:    #008bff;
  --accent-hi: #4da8ff;
  --highlight:     #5b23ff;
}

/* ── Zen (Minimal Light) ──────────────────────────────── */
[data-theme="zen"] {
  --bg:        #cfcfcf;
  --surface:   #d9d9d9;
  --border:    #e0e0e0;
  --text:      #333333;
  --text-dim:  #666666;
  --bright:    #000000;
  --paper:     #cfcfcf;
  --ink:       #7f7f7f;
  --accent:    #7f967f;
  --accent-hi: #8fa88f;
  --highlight:     #967f7f;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  color: var(--text);
}

/* ── Canvas ─────────────────────────────────────── */
#canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: crosshair;
  touch-action: none;
  z-index: 0;
}

.canvas-overlay {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.9rem;
  transition: opacity 0.4s;
  z-index: 5;
}
.canvas-overlay.hidden { opacity: 0; pointer-events: none; }

/* ── Drawing toolbar (left strip) ───────────────── */
.mini-toolbar {
  position: fixed;
  left: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.4rem;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 2px 2px 14px rgba(0,0,0,0.45);
  z-index: 10;
}

.toolbar-sep {
  width: 1.6rem;
  height: 1px;
  background: var(--border);
  margin: 0.1rem 0;
  flex-shrink: 0;
}

/* ── Palette swatches ───────────────────────────── */
.swatch {
  width: 2rem;
  height: 2rem;
  border: 2px solid var(--border);
  cursor: pointer;
  position: relative;
  transition: border-color 0.1s, transform 0.1s, background-color 0.2s;
  flex-shrink: 0;
}
.swatch.active  { border-color: var(--bright); transform: scale(1.12); }

/* Swatch colors are set via inline styles in JS to override theme CSS */
/* Order: Ink (0), Accent (2), Highlight (3), Paper (1) */
.swatch[data-idx="0"] { background: var(--ink); }
.swatch[data-idx="2"] { background: var(--accent); }
.swatch[data-idx="3"] { background: var(--highlight); }
.swatch[data-idx="1"] { background: var(--paper); }

/* ── Brush / text-tool buttons ──────────────────── */
.brush-btn {
  width: 2.1rem;
  height: 2.1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.1s, color 0.1s;
  flex-shrink: 0;
}
.brush-btn.active { border-color: var(--bright); color: var(--bright); }

/* Color editor tool button - SVG icon */
#tool-colors svg {
  display: block;
}
#tool-colors.active {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Action bar (bottom strip) ──────────────────── */
.action-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bar-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 0.5rem 0 4rem; /* left gap clears the mini-toolbar */
  gap: 0.3rem;
  z-index: 10;
  overflow-x: auto;
  overflow-y: hidden;
}

.bar-group { display: flex; align-items: center; gap: 0.25rem; flex-shrink: 0; }
.bar-sep   { width: 1px; height: 22px; background: var(--border); flex-shrink: 0; margin: 0 0.15rem; }
.bar-spacer { flex: 1 1 auto; min-width: 0.25rem; }

.bar-btn {
  padding: 0.3rem 0.6rem;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  font-family: var(--sans);
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.1s, color 0.1s;
}
.bar-btn:hover { border-color: var(--text-dim); color: var(--bright); }

.bar-btn.bar-accent {
  background: var(--accent);
  color: var(--bright);
  border-color: transparent;
}
.bar-btn.bar-accent:hover { background: var(--accent-hi); }

.bar-btn.active {
  border-color: var(--accent-hi);
  color: var(--bright);
  background: var(--accent);
}

.bar-icon-btn {
  width: 1.7rem;
  height: 1.7rem;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.1s, border-color 0.1s;
}
.bar-icon-btn:hover { color: var(--bright); border-color: var(--text-dim); }

.bar-mono {
  font-size: 0.72rem;
  font-family: var(--mono);
  color: var(--text-dim);
  min-width: 3.2em;
  text-align: center;
  flex-shrink: 0;
}

.bar-metric {
  font-size: 0.72rem;
  font-family: var(--mono);
  color: var(--text-dim);
  flex-shrink: 0;
  white-space: nowrap;
}

/* Bar label styling */
.bar-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Theme selector */
#theme-select {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.3rem 0.5rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  cursor: pointer;
  min-width: 80px;
}
#theme-select:hover {
  border-color: var(--text-dim);
}
#theme-select:focus {
  outline: none;
  border-color: var(--accent);
}
/* Dropdown options styling - combined for both selects */
#theme-select option,
#age-stack-select option {
  background: var(--surface);
  color: var(--text);
}

/* Aging stack selector - matches theme selector */
#age-stack-select {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.3rem 0.5rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  cursor: pointer;
  min-width: 120px;
}
#age-stack-select:hover {
  border-color: var(--text-dim);
}
#age-stack-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Aging technique selector */
#age-type-select {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.3rem 0.5rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  cursor: pointer;
  min-width: 100px;
}
#age-type-select:hover {
  border-color: var(--text-dim);
}
#age-type-select:focus {
  outline: none;
  border-color: var(--accent);
}
#age-type-select option {
  background: var(--surface);
  color: var(--text);
}

/* Color picker panel - floating above action bar */
.color-picker-panel {
  position: fixed;
  bottom: calc(var(--bar-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  z-index: 100;
  display: none;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
}

.color-picker-panel.visible {
  display: block;
}

.color-picker-row {
  display: flex;
  gap: 1.5rem;
}

.color-picker-row label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  color: var(--text-dim);
  cursor: pointer;
}

.color-picker {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 2px solid var(--border);
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  overflow: hidden;
}

.color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 0;
}

.color-picker::-moz-color-swatch {
  border: none;
  border-radius: 0;
}

.color-picker:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Load button — hidden file input overlays it */
.btn-load {
  display: inline-block;
  position: relative;
  cursor: pointer;
}
.btn-load input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
}

/* ── Tray backdrop ──────────────────────────────── */
.tray-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.tray-backdrop.visible { opacity: 1; pointer-events: auto; }

/* ── Tray panel (about only) ────────────────────── */
.tray {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--tray-w);
  max-width: 90vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 30;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow: hidden;
}
.tray.open { transform: translateX(0); }

.tray-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tray-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--bright);
  text-transform: uppercase;
}
.tray-close-btn {
  width: 2rem;
  height: 2rem;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.1s, border-color 0.1s;
}
.tray-close-btn:hover { color: var(--bright); border-color: var(--text-dim); }

.tray-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
}

/* ── About section (in tray) ────────────────────── */
.about { display: flex; flex-direction: column; gap: 0.85rem; }

h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--bright);
  letter-spacing: 0.03em;
  margin-bottom: 0.4rem;
}
p { font-size: 0.88rem; line-height: 1.6; color: var(--text); margin-bottom: 0.75rem; }
p:last-child { margin-bottom: 0; }
ul { list-style: none; padding: 0; }
ul li {
  padding: 0.2rem 0 0.2rem 1.1rem;
  position: relative;
  font-size: 0.88rem;
  line-height: 1.5;
}
ul li::before { content: '·'; position: absolute; left: 0; color: var(--accent-hi); }
code {
  font-family: var(--mono);
  font-size: 0.82em;
  color: var(--accent-hi);
  background: var(--bg);
  padding: 0.1em 0.35em;
  border: 1px solid var(--border);
}
.links { margin-top: 0.5rem; }
.btn-link {
  display: inline-block;
  padding: 0.48rem 1rem;
  border: 1px solid var(--accent);
  color: var(--accent-hi);
  text-decoration: none;
  font-size: 0.88rem;
  letter-spacing: 0.04em;
  transition: background 0.15s, color 0.15s;
}
.btn-link:hover { background: var(--accent); color: var(--bright); }

/* ── Custom Stack Modal ───────────────────────────── */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--paper);
  padding: 1.5rem;
  border-radius: 8px;
  min-width: 400px;
  max-width: 90vw;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
  margin: 0 0 0.5rem 0;
  color: var(--ink);
}

.modal-content p {
  margin: 0 0 1rem 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.stack-inputs {
  display: flex;
  gap: 8px;
  margin: 1rem 0;
  justify-content: center;
}

.stack-inputs input {
  width: 40px;
  height: 40px;
  text-align: center;
  font-size: 1.2rem;
  border: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
}

.stack-inputs input:focus {
  outline: none;
  border-color: var(--accent);
}

.stack-preview {
  font-family: monospace;
  margin: 0.5rem 0;
  color: var(--ink);
  min-height: 1.5rem;
  text-align: center;
}

.modal-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 1rem;
}

.modal-buttons button {
  padding: 0.5rem 1rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  border-radius: 4px;
}

.modal-buttons button:first-child {
  background: var(--accent);
  color: var(--bright);
  border-color: var(--accent);
}

.modal-buttons button:hover {
  opacity: 0.9;
}

/* ── Mobile (≤540 px) ───────────────────────────── */
@media (max-width: 540px) {
  .mini-toolbar {
    left: 50%;
    top: auto;
    bottom: calc(var(--bar-h) + 0.5rem);
    transform: translateX(-50%);
    flex-direction: row;
  }
  .toolbar-sep {
    width: 1px;
    height: 1.7rem;
    margin: 0 0.1rem;
  }
  .action-bar { padding-left: 0.5rem; }
  /* Mobile color picker panel */
  .color-picker-panel {
    bottom: calc(var(--bar-h) + 8px);
    padding: 0.5rem;
  }
  .color-picker-row {
    gap: 0.75rem;
  }
  .color-picker-row label {
    font-size: 0.65rem;
  }
  .color-picker {
    width: 2rem;
    height: 2rem;
  }
  .tray {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 85dvh;
    max-height: 85vh;
    border-left: none;
    border-top: 1px solid var(--border);
    transform: translateY(100%);
  }
  .tray.open { transform: translateY(0); }
}
