:root {
  --bg: #17140f;
  --panel: #221e17;
  --panel-border: #3a3226;
  --text: #f2ecdf;
  --muted: #b2a68f;
  --accent: #e3ad62;
  --focus: #8fd3ff;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

header, footer {
  padding: 1rem 1.25rem 0.5rem;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: normal;
  letter-spacing: 0.02em;
}

.subtitle, footer {
  color: var(--muted);
  margin: 0.25rem 0 0;
  max-width: 60rem;
}

footer {
  font-size: 0.9rem;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 21rem;
  gap: 1rem;
  padding: 0.5rem 1.25rem 1rem;
  align-items: start;
}

.plate-wrap {
  width: min(100%, calc(100vh - 11rem));
  min-width: 16rem;
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.5);
}

#plate {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.spectrum {
  display: block;
  width: 100%;
  height: 4.5rem;
  border-radius: 4px;
  background: #1a1611;
  cursor: pointer;
  touch-action: none;
}

.stage-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.status {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.atlas {
  margin-top: 1.25rem;
}

.atlas h2 {
  margin: 0 0 0.25rem;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: normal;
  font-size: 1.2rem;
}

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

.atlas-order {
  flex: 0 0 4.25rem;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.atlas-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.atlas-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.25rem;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.atlas-item canvas {
  display: block;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 2px;
  image-rendering: pixelated;
}

.atlas-item[aria-current="true"] {
  border-color: var(--accent);
  background: #3a2f20;
}

.controls {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

fieldset {
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  margin: 0;
  padding: 0.5rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

legend {
  color: var(--accent);
  padding: 0 0.3rem;
}

.readout {
  margin: 0;
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.control-row.inline {
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

label output {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-left: 0.25rem;
}

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

.control-row.inline input[type="range"] {
  width: auto;
  flex: 1;
}

select, button {
  font: inherit;
  color: var(--text);
  background: #2e281f;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
}

button {
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button[aria-pressed="true"] {
  background: var(--accent);
  color: #1b1610;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

kbd {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.8em;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 0 0.25rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 52rem) {
  main {
    grid-template-columns: 1fr;
  }

  .plate-wrap {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  button {
    transition: none;
  }
}
