/* ─────────────────────────────────────────────────────────────────
   Aesthetic: atmospheric studio. Deep warm-tinted black surfaces, a
   single saturated gold accent. Distinctive variable display sans
   (Bricolage Grotesque) + JetBrains Mono for tool values & numerics.
   Deliberately NOT the typical "indigo on white" creative-app look.
   ───────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400..700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --font-ui:   'Bricolage Grotesque', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --bg:        #0a0a0e;      /* near-black with warm tint */
  --surface:   #14141b;
  --surface-2: #1c1c25;
  --lift:      #232331;
  --rule:      #2a2a37;
  --rule-soft: #1f1f2a;

  --ink:       #f0f0f5;
  --ink-mute:  #9aa0ad;
  --ink-faint: #5d6371;

  --accent:    #fbbf24;       /* gold */
  --accent-2:  #f59e0b;
  --danger:    #ef4444;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  /* Subtle radial glow + film-grain feel via repeated gradient */
  background-image:
    radial-gradient(ellipse 1400px 700px at 50% -200px, rgba(251, 191, 36, 0.04), transparent 70%),
    radial-gradient(ellipse 700px 400px at 100% 100%, rgba(251, 191, 36, 0.025), transparent 70%);
  background-attachment: fixed;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-variation-settings: 'opsz' 14;
}

.app { display: flex; flex-direction: column; height: 100vh; }

/* ── Top bar ─────────────────────────────────────────────────────── */

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  box-shadow: 0 1px 0 rgba(0,0,0,0.5);
}
.logo {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-ui);
  font-variation-settings: 'opsz' 96, 'wght' 600;
  font-size: 17px;
  letter-spacing: -0.01em;
}
.logo .mark { color: var(--accent); font-size: 20px; line-height: 1; }
.spacer { flex: 1; }

.topbar-group { display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; border-right: 1px solid var(--rule); }
.topbar-group:last-of-type { border-right: none; }
.topbar button, .upload-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink);
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
  display: inline-flex; align-items: center; gap: 5px;
  transition: all 0.12s ease;
}
.topbar button:hover:not(:disabled), .upload-btn:hover {
  background: var(--lift);
  border-color: var(--rule);
}
.topbar button:disabled { opacity: 0.3; cursor: not-allowed; }
.topbar button.primary {
  background: var(--accent);
  color: #1a1408;
  font-weight: 600;
  border-color: var(--accent);
}
.topbar button.primary:hover { background: var(--accent-2); }

.upload-btn { position: relative; overflow: hidden; }
.upload-btn input[type="file"] {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer;
}

.zoom-group { display: inline-flex; gap: 0; background: var(--bg); border: 1px solid var(--rule); border-radius: 7px; padding: 2px; }
.zoom-group button {
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  border-radius: 5px;
  color: var(--ink-mute);
}
.zoom-group button:hover { background: var(--lift); }
.zoom-group button.active { background: var(--accent); color: #1a1408; border-color: var(--accent); }

/* ── Body ────────────────────────────────────────────────────────── */

.body { flex: 1; display: flex; min-height: 0; }

/* ── Tools sidebar ───────────────────────────────────────────────── */

.tools {
  width: 240px;
  padding: 18px;
  background: var(--surface);
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.tools h3 {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 18px 0 8px;
  font-weight: 500;
}
.tools h3:first-child { margin-top: 0; }

/* Tool grid */

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.tool {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px 6px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--ink-mute);
  cursor: pointer;
  font-size: 10px;
  font-family: var(--font-ui);
  transition: all 0.12s ease;
}
.tool-glyph {
  font-size: 18px; line-height: 1;
  color: var(--ink);
  margin-bottom: 2px;
}
.tool-label { font-size: 10px; letter-spacing: 0.02em; }
.tool-shortcut {
  position: absolute; top: 4px; right: 5px;
  font-family: var(--font-mono);
  font-size: 8px;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
}
.tool:hover {
  background: var(--lift);
  border-color: var(--rule);
}
.tool.active {
  background: var(--accent);
  color: #1a1408;
  border-color: var(--accent);
}
.tool.active .tool-glyph { color: #1a1408; }
.tool.active .tool-shortcut { color: #6e5311; }

/* Segmented control (fill mode) */

.seg { display: flex; gap: 0; background: var(--bg); border: 1px solid var(--rule); border-radius: 7px; padding: 2px; }
.seg button {
  flex: 1;
  padding: 6px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink-mute);
  font-family: var(--font-ui);
  font-size: 11px;
  border-radius: 5px;
}
.seg button.active { background: var(--accent); color: #1a1408; font-weight: 600; }
.seg button:hover:not(.active) { color: var(--ink); }

/* Color picker */

input[type="color"] {
  width: 100%; height: 36px;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 7px;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 4px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }

.swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.swatches.recent { grid-template-columns: repeat(8, 1fr); }
.swatches.recent .swatch { height: 18px; }
.swatch {
  width: 100%; aspect-ratio: 1; padding: 0;
  border: 1.5px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.swatch:hover { transform: scale(1.06); border-color: var(--ink-mute); }
.swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.3); }

/* Brush controls */

.control {
  display: grid;
  grid-template-columns: 56px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--ink-mute);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.control input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 0;
}
.control .val {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink);
  font-weight: 500;
}

.link-help {
  margin-top: 16px;
  background: none;
  border: 1px dashed var(--rule);
  color: var(--ink-mute);
  padding: 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.link-help:hover { color: var(--accent); border-color: var(--accent); }

/* ── Canvas stage ────────────────────────────────────────────────── */

.stage {
  flex: 1;
  padding: 24px;
  background:
    linear-gradient(135deg, var(--bg) 25%, var(--surface) 25%, var(--surface) 50%, var(--bg) 50%, var(--bg) 75%, var(--surface) 75%, var(--surface) 100%) 0 0 / 16px 16px;
  overflow: auto;
  display: flex; align-items: flex-start; justify-content: center;
}
.canvas-frame { position: relative; }
.canvas-frame canvas {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(251, 191, 36, 0.04),
    0 32px 70px -20px rgba(0, 0, 0, 0.7),
    0 12px 28px -8px rgba(0, 0, 0, 0.6);
  display: block;
}
.canvas-frame canvas.overlay {
  position: absolute;
  top: 0; left: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  pointer-events: none;
}

/* ── Status bar ──────────────────────────────────────────────────── */

.status {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 18px;
  background: var(--surface);
  border-top: 1px solid var(--rule);
  font-size: 12px;
}
.status span {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink);
}
.status em {
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.status code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--ink);
}
.status .swatch-mini {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 3px;
  border: 1px solid var(--rule);
}

/* ── Shortcuts modal ─────────────────────────────────────────────── */

.overlay-modal {
  position: fixed; inset: 0;
  background: rgba(10, 10, 14, 0.75);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fade-in 0.15s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 28px 32px;
  min-width: 320px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.modal h2 {
  font-family: var(--font-ui);
  font-variation-settings: 'opsz' 96;
  font-weight: 600;
  font-size: 18px;
  margin: 0 0 18px;
}
.modal ul {
  list-style: none; padding: 0; margin: 0 0 18px;
  display: flex; flex-direction: column; gap: 6px;
}
.modal li {
  display: flex; align-items: center; gap: 14px;
  font-size: 13px;
  color: var(--ink-mute);
}
.modal kbd {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 3px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  min-width: 28px; text-align: center;
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(0,0,0,0.4);
}
.modal button {
  background: var(--accent);
  color: #1a1408;
  border: none;
  padding: 8px 18px;
  border-radius: 7px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.modal button:hover { background: var(--accent-2); }
