/* ---------- tokens ---------- */
:root {
  --bg: #14130f;
  --bg-raise: #1d1b16;
  --bg-sink: #0e0d0a;
  --ink: #f0ede4;
  --ink-dim: #a39e8f;
  --line: #322f27;
  --accent: #c8f04a;
  --accent-ink: #191d05;
  --danger: #ff8f7d;
  --radius: 14px;
  --radius-sm: 9px;
  --sp: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 12px 32px -12px rgba(0,0,0,.5);
  --checker-a: #232119;
  --checker-b: #1a1813;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f3ec;
    --bg-raise: #fdfcf8;
    --bg-sink: #ebe8de;
    --ink: #211f18;
    --ink-dim: #6f6a5c;
    --line: #dcd8ca;
    --accent: #4a6d00;
    --accent-ink: #f4ffd6;
    --danger: #b3311c;
    --shadow: 0 1px 2px rgba(60,55,35,.08), 0 12px 32px -16px rgba(60,55,35,.25);
    --checker-a: #e7e4d9;
    --checker-b: #f5f3ec;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 calc(var(--sp) * 3); }
a { color: inherit; }
h1, h2 { margin: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.btn svg, .hero-feats svg, .drop-ico {
  stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- topbar ---------- */
.topbar { border-bottom: 1px solid var(--line); }
.topbar-in {
  display: flex; align-items: baseline; gap: calc(var(--sp) * 2);
  padding-top: calc(var(--sp) * 2); padding-bottom: calc(var(--sp) * 2);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 22px; height: 22px; }
.brand-name { font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { color: var(--ink-dim); font-size: 0.85rem; }

/* ---------- hero ---------- */
.hero {
  display: grid; grid-template-columns: 1.1fr 1fr; gap: calc(var(--sp) * 6);
  align-items: center;
  padding: clamp(40px, 8vh, 96px) 0 clamp(32px, 6vh, 72px);
}
.hero h1 {
  font-size: clamp(2.1rem, 4.5vw, 3.4rem);
  line-height: 1.04; letter-spacing: -0.025em; font-weight: 800;
}
.hero h1 em { font-style: normal; color: var(--accent); }
.hero-copy p { color: var(--ink-dim); max-width: 46ch; margin: calc(var(--sp) * 2.5) 0; }
.hero-feats { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp); font-size: 0.92rem; }
.hero-feats li { display: flex; align-items: center; gap: 10px; }
.hero-feats svg { width: 18px; height: 18px; flex: none; color: var(--accent); fill: none; }
.hero-feats svg circle, .hero-feats svg rect { fill: none; }

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp); text-align: center;
  min-height: 300px; padding: calc(var(--sp) * 4);
  background: var(--bg-raise);
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  cursor: pointer; transition: border-color .15s, background .15s, transform .15s;
}
.drop:hover, .drop.is-over { border-color: var(--accent); }
.drop.is-over { background: var(--bg-sink); transform: scale(1.01); }
.drop-ico { width: 56px; height: 56px; color: var(--accent); fill: none; margin-bottom: var(--sp); }
.drop strong { font-size: 1.1rem; letter-spacing: -0.01em; }
.drop span { color: var(--ink-dim); font-size: 0.88rem; }
.drop-hint { font-family: var(--mono); font-size: 0.75rem !important; margin-top: var(--sp); }

/* ---------- progress / error ---------- */
.progress {
  display: flex; align-items: center; gap: calc(var(--sp) * 2);
  padding: calc(var(--sp) * 3); margin-bottom: calc(var(--sp) * 3);
  background: var(--bg-raise); border: 1px solid var(--line); border-radius: var(--radius);
}
.spinner {
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error {
  padding: calc(var(--sp) * 2) calc(var(--sp) * 3); margin-bottom: calc(var(--sp) * 3);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger); border-radius: var(--radius-sm); background: var(--bg-raise);
}

/* ---------- bento ---------- */
.results {
  display: grid; gap: calc(var(--sp) * 2);
  grid-template-columns: repeat(12, 1fr);
  padding-bottom: calc(var(--sp) * 8);
}
.tile {
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); padding: calc(var(--sp) * 2.5);
  box-shadow: var(--shadow);
}
.tile h2 {
  font-size: 0.8rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--ink-dim); margin-bottom: calc(var(--sp) * 2);
}
.tile-note { color: var(--ink-dim); font-size: 0.8rem; margin: calc(var(--sp) * 1.5) 0 0; }

.tile-preview  { grid-column: span 8; grid-row: span 2; display: flex; flex-direction: column; }
.tile-stats    { grid-column: span 4; background: var(--bg-sink); }
.tile-settings { grid-column: span 4; }
.tile-palette  { grid-column: span 7; }
.tile-gradients{ grid-column: span 5; }

/* preview */
.tile-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp); flex-wrap: wrap; margin-bottom: calc(var(--sp) * 2);
}
.canvas {
  flex: 1; min-height: 340px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.checker {
  background-image:
    linear-gradient(45deg, var(--checker-a) 25%, transparent 25%, transparent 75%, var(--checker-a) 75%),
    linear-gradient(45deg, var(--checker-a) 25%, var(--checker-b) 25%, var(--checker-b) 75%, var(--checker-a) 75%);
  background-size: 24px 24px; background-position: 0 0, 12px 12px;
}
.canvas img, .canvas .svg-out { max-width: 100%; max-height: 68vh; display: block; }
.canvas .svg-out svg { max-width: 100%; height: auto; display: block; }

/* segmented control */
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--bg-sink); border: 1px solid var(--line); border-radius: 999px;
}
.seg-btn {
  border: 0; background: transparent; color: var(--ink-dim);
  padding: 6px 14px; border-radius: 999px; font-size: 0.85rem; font-weight: 600;
}
.seg-btn.is-on { background: var(--accent); color: var(--accent-ink); }
.seg-sm .seg-btn { padding: 4px 10px; font-size: 0.78rem; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 999px; font-weight: 600; font-size: 0.88rem;
  border: 1px solid var(--line); background: transparent;
  transition: transform .12s, background .12s;
}
.btn:hover { transform: translateY(-1px); }
.btn svg { width: 16px; height: 16px; fill: none; }
.btn-solid { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-ghost:hover { background: var(--bg-sink); }
.btn-wide { width: 100%; justify-content: center; margin-top: var(--sp); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.tile-actions { display: flex; gap: var(--sp); }

/* stats */
.stats { margin: 0; display: grid; gap: calc(var(--sp) * 1.25); }
.stats > div { display: flex; justify-content: space-between; gap: var(--sp); align-items: baseline; }
.stats dt { color: var(--ink-dim); font-size: 0.85rem; }
.stats dd { margin: 0; font-family: var(--mono); font-size: 0.9rem; text-align: right; }
.stats .big dd { font-size: 1.35rem; font-weight: 700; color: var(--accent); }

/* settings */
.field { margin-bottom: calc(var(--sp) * 1.75); }
.field label {
  display: flex; justify-content: space-between; font-size: 0.85rem;
  color: var(--ink-dim); margin-bottom: 6px;
}
.field output { font-family: var(--mono); color: var(--ink); }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* palette */
.palette-bar {
  display: flex; height: 26px; border-radius: 999px; overflow: hidden;
  border: 1px solid var(--line); margin-bottom: calc(var(--sp) * 2);
}
.palette { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.palette li {
  display: grid; grid-template-columns: 26px 1fr auto; align-items: center;
  gap: 10px; padding: 5px 6px; border-radius: var(--radius-sm); cursor: pointer;
}
.palette li:hover { background: var(--bg-sink); }
.pal-swatch { width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line); }
.pal-hex { font-family: var(--mono); font-size: 0.85rem; }
.pal-name { color: var(--ink-dim); font-size: 0.78rem; display: block; }
.pal-pct { font-family: var(--mono); font-size: 0.82rem; color: var(--ink-dim); }

/* gradients */
.grad-item {
  display: grid; grid-template-columns: 84px 1fr; gap: 12px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line);
}
.grad-item:last-child { border-bottom: 0; }
.grad-chip { height: 48px; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.grad-meta { font-size: 0.82rem; color: var(--ink-dim); }
.grad-meta b { color: var(--ink); font-weight: 600; }
.grad-meta code { font-family: var(--mono); font-size: 0.78rem; }
.grad-empty { color: var(--ink-dim); font-size: 0.9rem; }

/* footer / toast */
.footer {
  border-top: 1px solid var(--line); padding: calc(var(--sp) * 3) 0;
  color: var(--ink-dim); font-size: 0.82rem;
}
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 20px;
  border-radius: 999px; font-size: 0.88rem; font-weight: 600;
  box-shadow: var(--shadow); z-index: 10;
}

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .hero { grid-template-columns: 1fr; gap: calc(var(--sp) * 4); }
  .tile-preview, .tile-stats, .tile-settings, .tile-palette, .tile-gradients { grid-column: span 12; }
  .palette { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
