:root {
  --bg: #0b0d12;
  --bg-panel: #12151d;
  --bg-raised: #181c26;
  --line: #262b38;
  --text: #e7e9f0;
  --text-dim: #9aa0b4;
  --text-faint: #626a80;
  --accent: #ffb454;
  --accent-dim: #7a5a2a;
  --accent-glow: rgba(255, 180, 84, 0.35);
  --good: #6fd39a;
  --radius: 10px;
  --mono: "SF Mono", "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

::selection { background: var(--accent-glow); color: var(--text); }

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1.5rem 1.75rem 1rem;
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  font-weight: 700;
}

.brand h1::before {
  content: "◆";
  color: var(--accent);
  margin-right: 0.5rem;
  font-size: 1.1rem;
}

.brand .tag {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.92rem;
  max-width: 46ch;
}

.hud {
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  white-space: nowrap;
}

.hud-sep { color: var(--text-faint); margin: 0 0.4em; }
#hudSamples { color: var(--text); }
#hudState { color: var(--accent); }

/* ---------- layout ---------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1.5rem;
  padding: 1.5rem 1.75rem;
  align-items: start;
}

.canvas-column {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: 0 20px 60px -30px rgba(0, 0, 0, 0.8);
  cursor: grab;
  touch-action: none;
}

.canvas-wrap:active { cursor: grabbing; }

#viewCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 0.85rem;
  transform: translateX(-50%);
  font-size: 0.78rem;
  color: rgba(231, 233, 240, 0.75);
  background: rgba(10, 11, 15, 0.6);
  backdrop-filter: blur(4px);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  pointer-events: none;
  transition: opacity 0.5s ease 1.5s;
}

.canvas-hint.is-hidden { opacity: 0; transition-delay: 0s; }

.marker {
  position: absolute;
  width: 26px;
  height: 26px;
  margin-left: -13px;
  margin-top: -13px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  animation: pick-pulse 0.55s ease-out forwards;
}

@keyframes pick-pulse {
  from { transform: scale(0.4); opacity: 1; }
  to { transform: scale(1.3); opacity: 0; }
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

/* ---------- buttons & inputs ---------- */

.btn {
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.btn:hover { border-color: var(--accent-dim); background: #1e2330; }
.btn:active { transform: translateY(1px); }
.btn.is-active { border-color: var(--accent); color: var(--accent); background: #241c10; }

.btn:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-small { font-size: 0.76rem; padding: 0.28rem 0.55rem; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: #201823; border-color: #4a2a34; color: #ff9f9f; }

.btn kbd {
  font-family: var(--mono);
  font-size: 0.72em;
  background: #000;
  border: 1px solid #333;
  border-radius: 4px;
  padding: 0.05em 0.4em;
  color: var(--text-faint);
}

select {
  font: inherit;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0.4rem 0.5rem;
}

.quality-picker {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* range sliders */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #1a1207;
  margin-top: -5px;
  box-shadow: 0 0 0 3px rgba(255, 180, 84, 0.15);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #1a1207;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 50%;
  padding: 0;
  background: none;
  cursor: pointer;
  flex: none;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 50%; }

/* ---------- side panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  min-width: 0;
}

.panel-block {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.15rem;
}

.panel-block h2 {
  margin: 0 0 0.7rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 600;
}

.panel-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-block-head h2 { margin: 0; }

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 0.8rem;
}
.field:last-child { margin-bottom: 0; }

.field select { width: 100%; }

.field-val {
  float: right;
  font-family: var(--mono);
  color: var(--text);
  font-size: 0.78rem;
}

.hint {
  margin: 0.6rem 0 0;
  font-size: 0.76rem;
  color: var(--text-faint);
  line-height: 1.4;
}

/* sphere rows */

.sphere-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sphere-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.sphere-row:hover { border-color: #3a4256; }
.sphere-row.is-selected { border-color: var(--accent); background: rgba(255, 180, 84, 0.06); }

.sphere-row.flash { animation: flash-row 0.5s ease; }
@keyframes flash-row {
  0%, 100% { background: rgba(255, 180, 84, 0.06); }
  40% { background: rgba(255, 180, 84, 0.28); }
}

.sphere-row-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sphere-label {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sphere-row select {
  font-size: 0.76rem;
  padding: 0.2rem 0.35rem;
}

.sphere-extra {
  display: flex;
  gap: 0.9rem;
  margin-top: 0.5rem;
}

.mini-slider {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
}

/* ---------- footer ---------- */

.footer {
  padding: 1.25rem 1.75rem 2rem;
  font-size: 0.85rem;
  color: var(--text-faint);
}

.footer a { color: var(--text-dim); text-decoration: none; }
.footer a:hover { color: var(--accent); text-decoration: underline; }

/* ---------- responsive ---------- */

@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 1rem;
  }
  .topbar { padding: 1.25rem 1rem 1rem; }
  .quality-picker { margin-left: 0; }
}
