:root {
  --bg: #07070b;
  --ink: #f4ecdf;
  --ink-dim: #b9b1a4;
  --ink-mute: #8a8378;
  --line: rgba(255, 240, 210, 0.10);
  --line-strong: rgba(255, 240, 210, 0.22);
  --glass: rgba(20, 18, 26, 0.62);
  --glass-strong: rgba(28, 24, 36, 0.78);
  --accent: #f7c873;
  --accent-2: #d24a6b;
  --accent-3: #6ad0e8;
  --shadow-lg: 0 18px 48px -12px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 240, 210, 0.04) inset;
  --shadow-sm: 0 4px 14px -4px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 240, 210, 0.04) inset;
  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 7px;
  --pad: 14px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; color: inherit; }
input { font-family: inherit; color: inherit; }
::selection { background: var(--accent); color: #1a1308; }

#sim {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  cursor: crosshair;
  touch-action: none;
}

.hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}
.hud > * { pointer-events: auto; }

/* ------- Brand ------- */
.brand {
  position: absolute;
  top: 18px; left: 20px;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px 10px 12px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.brand .logo {
  width: 26px; height: 26px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, #f7c873 0%, #d24a6b 45%, #2a1a30 100%);
  box-shadow:
    0 0 0 1px rgba(255, 240, 210, 0.10),
    0 0 18px rgba(247, 200, 115, 0.35),
    inset 0 0 6px rgba(0, 0, 0, 0.4);
  animation: pulse 6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { filter: hue-rotate(0deg); }
  50%      { filter: hue-rotate(20deg); }
}
.brand .title {
  font-weight: 700; font-size: 15px; letter-spacing: -0.02em;
}
.brand .sub {
  color: var(--ink-mute);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 1px;
}

/* ------- Readout ------- */
.readout {
  position: absolute;
  top: 18px; right: 20px;
  width: 198px;
  padding: 12px 14px 12px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  font-family: var(--mono);
  font-size: 12px;
}
.readout-region {
  display: inline-block;
  padding: 3px 8px;
  background: linear-gradient(135deg, rgba(247,200,115,0.18), rgba(210,74,107,0.18));
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 8px;
}
.readout-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-top: 1px solid var(--line);
}
.readout-row:first-of-type { border-top: 0; }
.readout-row .lab { color: var(--ink-mute); font-style: italic; }
.readout-row .val { color: var(--ink); }
.readout-row.dim { opacity: 0.65; }

/* ------- Atlas ------- */
.atlas {
  position: absolute;
  bottom: 90px; right: 20px;
  width: 318px;
  padding: 12px 12px 10px;
  background: var(--glass-strong);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
}
.atlas-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  margin-bottom: 8px;
  padding: 0 2px;
}
.atlas-head .hint {
  color: var(--ink-mute);
  text-transform: none;
  letter-spacing: 0;
  font-size: 10.5px;
}
.atlas-frame {
  position: relative;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--line);
  background: #08080d;
  aspect-ratio: 4 / 3;
}
.atlas-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}
.atlas-axes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-mute);
}
.atlas-axes .ax-x {
  position: absolute; bottom: 6px; right: 10px;
}
.atlas-axes .ax-y {
  position: absolute; top: 10px; left: 6px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
.presets {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 10px;
}
.presets button {
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,240,210, 0.04);
  color: var(--ink-dim);
  cursor: pointer;
  transition: all 0.15s ease;
}
.presets button:hover {
  background: rgba(255,240,210, 0.10);
  color: var(--ink);
  border-color: var(--line-strong);
}
.presets button.active {
  background: linear-gradient(135deg, rgba(247,200,115,0.30), rgba(210,74,107,0.30));
  color: var(--ink);
  border-color: var(--accent);
}

/* ------- Palette strip ------- */
.palette-strip {
  position: absolute;
  bottom: 90px; left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  background: var(--glass);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
}
.palette-strip button {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  background-position: center;
  background-size: cover;
}
.palette-strip button:hover {
  transform: scale(1.10);
  border-color: var(--line-strong);
}
.palette-strip button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(247, 200, 115, 0.25);
  transform: scale(1.10);
}

/* ------- Controls (bottom) ------- */
.controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--glass-strong);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 40px);
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: rgba(255,240,210, 0.04);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover {
  background: rgba(255,240,210, 0.10);
  border-color: var(--line-strong);
}
.btn:active { transform: translateY(1px); }
.btn.icon { padding: 7px; }
.btn svg {
  width: 14px; height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.divider {
  width: 1px;
  align-self: stretch;
  background: var(--line);
  margin: 2px 4px;
}
.slider {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}
.slider .lab {
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10px;
}
.slider .num {
  font-family: var(--mono);
  color: var(--ink-dim);
  min-width: 20px;
  text-align: right;
}
.slider input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  width: 90px;
  height: 18px;
  cursor: pointer;
}
.slider input[type=range]::-webkit-slider-runnable-track {
  height: 3px;
  background: var(--line);
  border-radius: 99px;
}
.slider input[type=range]::-moz-range-track {
  height: 3px;
  background: var(--line);
  border-radius: 99px;
}
.slider input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  margin-top: -4.5px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 0 8px rgba(247,200,115,0.4);
  cursor: grab;
}
.slider input[type=range]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  border: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 0 8px rgba(247,200,115,0.4);
}

/* ------- Hint overlay ------- */
.hint-overlay {
  position: absolute;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--ink-mute);
  font-family: var(--mono);
  background: var(--glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
  opacity: 0.85;
  transition: opacity 0.6s ease;
}
.hint-overlay.fade { opacity: 0; pointer-events: none; }
kbd {
  font-family: var(--mono);
  background: rgba(255,240,210, 0.06);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  margin: 0 2px;
  font-size: 10.5px;
  color: var(--ink);
}

/* ------- Toast ------- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translate(-50%, 30px);
  background: var(--glass-strong);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line-strong);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 100;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.noscript {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: var(--bg); color: var(--ink);
  font-size: 16px;
}

/* ------- Responsive ------- */
@media (max-width: 720px) {
  .brand .sub { display: none; }
  .readout {
    width: auto;
    padding: 8px 10px;
    font-size: 11px;
  }
  .readout-row.dim { display: none; }
  .atlas {
    width: calc(100vw - 40px);
    max-width: 360px;
    bottom: auto;
    top: 90px;
    right: 20px;
  }
  .palette-strip {
    flex-direction: row;
    bottom: auto;
    top: 90px;
    left: 20px;
  }
  .palette-strip button { width: 22px; height: 22px; }
  .controls {
    padding: 6px 8px;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
  }
  .controls .btn { padding: 6px 9px; font-size: 11px; }
  .slider input[type=range] { width: 60px; }
  .slider .num { display: none; }
  .hint-overlay { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .brand .logo { animation: none; }
  * { transition: none !important; }
}
