:root {
  color-scheme: dark;
  --bg: #0a101c;
  --panel: #121a2b;
  --panel-border: #243149;
  --text: #e8eef7;
  --muted: #9aa8bd;
  --accent: #7eb6ff;
  --accent-dim: #3d6ea3;
  --field: #0e1624;
  --danger: #f0a070;
  --radius: 14px;
  --font: "Avenir Next", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--accent);
}

#app {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  height: 100%;
  min-height: 100vh;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.4rem 1.35rem 1.1rem;
  background:
    linear-gradient(165deg, #172238 0%, var(--panel) 42%, #0d1422 100%);
  border-right: 1px solid var(--panel-border);
  overflow: auto;
}

.brand .eyebrow {
  margin: 0 0 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--accent);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand .version {
  text-transform: none;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  opacity: 0.9;
}

.brand h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.lede {
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

#controls {
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.86rem;
  color: var(--muted);
}

.field span em {
  font-style: normal;
  color: var(--text);
  float: right;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.field .hint {
  float: right;
  font-style: normal;
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.85;
}

.presets {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  flex: 1;
}

.swatch {
  position: relative;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 2px solid transparent;
  padding: 0;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.swatch-name {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.swatch.active {
  border-color: var(--accent);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.2),
    0 0 0 2px rgba(126, 182, 255, 0.25);
}

.fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
}

.fieldset legend {
  padding: 0;
  margin-bottom: 0.4rem;
  font-size: 0.86rem;
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.segmented.segmented-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 0.4rem;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--field);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  text-align: center;
  line-height: 1.2;
}

.segmented input {
  accent-color: var(--accent);
}

.segmented label:has(input:checked) {
  border-color: var(--accent-dim);
  box-shadow: inset 0 0 0 1px var(--accent-dim);
}

.warn {
  margin: -0.35rem 0 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: rgba(240, 160, 112, 0.12);
  border: 1px solid rgba(240, 160, 112, 0.35);
  color: var(--danger);
  font-size: 0.8rem;
  line-height: 1.35;
}

.warn.warn-hard {
  background: rgba(240, 96, 96, 0.14);
  border-color: rgba(240, 96, 96, 0.45);
  color: #ffb0a0;
}

.field-note {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
}

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.chip {
  appearance: none;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 0.28rem 0.65rem;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.named-gallery .named-covers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-top: 0.35rem;
}

.named-cover {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.4rem;
  background: var(--field);
}

.named-cover img {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
}

.named-cover span {
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
}

.named-cover:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.scale-presets {
  margin-top: 0.45rem;
}

.post-download-cta {
  margin-top: 0.55rem !important;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #0c1422;
}

button.linkish {
  appearance: none;
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.secondary-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.secondary {
  appearance: none;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 0.65rem 0.7rem;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.secondary:hover {
  border-color: var(--accent-dim);
}

.secondary.full {
  width: 100%;
}

.field.check {
  flex-direction: row;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
}

.field.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.field input[type="text"] {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--field);
  color: var(--text);
  padding: 0.7rem 0.8rem;
  font: inherit;
  font-size: 1rem;
}

.field input[type="text"]:focus,
.field input[type="text"]:focus-visible {
  outline: 2px solid var(--accent-dim);
  border-color: var(--accent);
}

.field input[type="color"] {
  width: 52px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field select {
  width: 100%;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--field);
  color: var(--text);
  padding: 0.7rem 0.8rem;
  font: inherit;
  font-size: 0.95rem;
}

.field select:focus,
.field select:focus-visible {
  outline: 2px solid var(--accent-dim);
  border-color: var(--accent);
}

.primary:focus-visible,
.secondary:focus-visible,
.swatch:focus-visible,
.segmented label:focus-within,
.field input[type="range"]:focus-visible,
.field input[type="color"]:focus-visible,
.field input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: 2px;
}

.form.is-busy,
#controls.is-busy {
  opacity: 0.92;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.25rem;
}

.primary {
  appearance: none;
  border: 0;
  border-radius: 11px;
  padding: 0.85rem 1rem;
  background: linear-gradient(180deg, #8ec0ff 0%, var(--accent) 55%, #5a9be0 100%);
  color: #081018;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.primary:hover {
  filter: brightness(1.05);
}

.primary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.primary.alt {
  background: linear-gradient(180deg, #9ad0c0 0%, #5fb89a 55%, #3f9a7c 100%);
}

.secondary:disabled {
  opacity: 0.55;
  cursor: wait;
}

.status {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.82rem;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

.fineprint {
  margin-top: auto;
  padding-top: 0.5rem;
  border-top: 1px solid var(--panel-border);
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.fineprint p {
  margin: 0.45rem 0 0;
}

#viewport {
  position: relative;
  min-width: 0;
  min-height: 320px;
  background:
    radial-gradient(900px 500px at 70% 18%, #1a2740 0%, transparent 55%),
    var(--bg);
}

#viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#hud {
  position: absolute;
  left: 16px;
  bottom: 16px;
  padding: 8px 11px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--panel-border);
  color: var(--muted);
  font-size: 0.8rem;
  pointer-events: none;
}

@media (max-width: 860px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(42vh, 1fr) auto;
  }

  #viewport {
    order: -1;
    min-height: 42vh;
  }

  .panel {
    border-right: 0;
    border-bottom: 0;
    border-top: 1px solid var(--panel-border);
    max-height: 58vh;
    overflow-y: auto;
  }

  .primary,
  .secondary {
    min-height: 44px;
  }

  .swatch {
    width: 34px;
    height: 34px;
  }
}
