/* Theme tokens are written to :root by studio.js; these are first-paint fallbacks. */
:root {
  color-scheme: dark;
  --color-bg: #050807;
  --color-title: #eafff0;
  --color-body: rgba(234, 255, 240, 0.6);
  --color-highlight: #3dff7a;
  --font-heading: "Geist", system-ui, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, monospace;
  --font-ui: system-ui, -apple-system, "Helvetica Neue", sans-serif;

  --ui-line: color-mix(in srgb, var(--color-title) 10%, transparent);
  --ui-fill: color-mix(in srgb, var(--color-title) 5%, transparent);
  --ui-fill-strong: color-mix(in srgb, var(--color-title) 9%, transparent);
  --ui-muted: color-mix(in srgb, var(--color-title) 55%, transparent);
  --panel-width: 320px;
  --ease: cubic-bezier(0.65, 0, 0.35, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-width);
  background: var(--color-bg);
  color: var(--color-title);
  font: 13px/1.4 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition:
    background-color 0.5s var(--ease),
    color 0.5s var(--ease),
    grid-template-columns 0.5s var(--ease);
}

body.is-panel-hidden {
  grid-template-columns: minmax(0, 1fr) 0;
}

button,
input {
  font: inherit;
  color: inherit;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 10;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--color-title);
  color: var(--color-bg);
  transform: translateY(-200%);
}

.skip-link:focus-visible {
  transform: none;
}

/* Stage */

.stage {
  position: relative;
  min-width: 0;
  height: 100dvh;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom))
    max(24px, env(safe-area-inset-left));
}

.stage-clock {
  width: 100%;
  height: 100%;
}

.stage-toggle {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ui-muted);
  cursor: pointer;
}

.stage-toggle:hover {
  background: var(--ui-fill);
  color: var(--color-title);
}

.stage-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.stage-home {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  padding: 0 12px 0 6px;
  border-radius: 6px;
  color: var(--ui-muted);
  text-decoration: none;
}

.stage-home:hover {
  background: var(--ui-fill);
  color: var(--color-title);
}

.stage-home svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Panel */

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  overflow: hidden;
  border-left: 1px solid var(--ui-line);
}

.is-panel-hidden .panel {
  visibility: hidden;
}

.panel-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 20px 20px 12px;
}

.panel-head h1 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel-head h1 a {
  color: inherit;
  text-decoration: none;
}

.panel-tag {
  font: 400 11px/1 var(--font-mono);
  text-transform: uppercase;
  color: var(--ui-muted);
}

.panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 20px 20px;
  scrollbar-width: thin;
}

.section {
  margin: 0;
  padding: 16px 0;
  border: 0;
  border-top: 1px solid var(--ui-line);
}

.section:first-child {
  border-top: 0;
  padding-top: 4px;
}

.section-title {
  margin: 0 0 12px;
  padding: 0;
  font: 400 11px/1 var(--font-mono);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ui-muted);
  scroll-margin-top: 12px;
}

.field + .field {
  margin-top: 12px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  color: var(--color-title);
}

.field-value {
  font: 400 11px/1 var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ui-muted);
}

/* Form picker */

.forms {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

.form-option {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 10px 4px 8px;
  border-radius: 6px;
  background: var(--ui-fill);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.form-option:hover {
  background: var(--ui-fill-strong);
}

.form-option:has(input:checked) {
  background: var(--color-title);
  color: var(--color-bg);
}

.form-option:has(input:focus-visible) {
  outline: 1.5px solid var(--color-highlight);
  outline-offset: 2px;
}

.form-option input,
.segmented input,
.swatch input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.form-option svg {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1;
  stroke-linecap: round;
}

.form-option svg .dot {
  fill: currentColor;
  stroke: none;
}

.form-option span {
  font-size: 12px;
}

/* Segmented control */

.segmented {
  display: flex;
  margin: 0;
  padding: 2px;
  border: 0;
  border-radius: 6px;
  background: var(--ui-fill);
}

.segmented label {
  position: relative;
  flex: 1 1 0;
  min-height: 28px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--ui-muted);
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
}

.segmented label:hover {
  color: var(--color-title);
}

.segmented label:has(input:checked) {
  background: var(--color-bg);
  color: var(--color-title);
  box-shadow: 0 0 0 1px var(--ui-line);
}

.segmented label:has(input:focus-visible) {
  outline: 1.5px solid var(--color-highlight);
  outline-offset: 1px;
}

/* Swatches */

.swatches {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

.swatch {
  position: relative;
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px var(--ui-line);
  cursor: pointer;
}

.swatch::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sw-bg) 50%, var(--sw-accent) 50%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sw-ink) 15%, transparent);
}

.swatch:has(input:checked) {
  box-shadow: 0 0 0 2px var(--color-bg), 0 0 0 3px var(--color-title);
}

.swatch:has(input:focus-visible) {
  outline: 1.5px solid var(--color-highlight);
  outline-offset: 4px;
}






/* Toggle (switch) */

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 32px;
  cursor: pointer;
}

.toggle + .toggle {
  margin-top: 2px;
}

.toggle input {
  appearance: none;
  position: relative;
  flex: none;
  width: 30px;
  height: 18px;
  margin: 0;
  border-radius: 999px;
  background: var(--ui-fill-strong);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.toggle input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-bg);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toggle input:checked {
  background: var(--color-title);
}

.toggle input:checked::after {
  transform: translateX(12px);
}

/* Range */

.range {
  appearance: none;
  display: block;
  width: 100%;
  height: 20px;
  margin: 0;
  background: none;
  cursor: pointer;
  --fill: 50%;
}

.range::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--color-title) var(--fill), var(--ui-fill-strong) var(--fill));
}

.range::-moz-range-track {
  height: 2px;
  border-radius: 2px;
  background: var(--ui-fill-strong);
}

.range::-moz-range-progress {
  height: 2px;
  border-radius: 2px;
  background: var(--color-title);
}

.range::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -6px;
  border: 0;
  border-radius: 50%;
  background: var(--color-title);
  transition: transform 0.15s ease;
}

.range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--color-title);
}

.range:active::-webkit-slider-thumb {
  transform: scale(1.2);
}

/* Actions */

.panel-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 12px 20px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--ui-line);
}

.btn {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: var(--ui-fill);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.btn:hover {
  background: var(--ui-fill-strong);
}

.btn-primary {
  grid-column: 1 / -1;
  background: var(--color-title);
  color: var(--color-bg);
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--color-title) 85%, var(--color-bg));
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  border-radius: 8px;
  background: var(--color-title);
  color: var(--color-bg);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition:
    opacity 0.2s ease,
    transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast:empty {
  padding: 0;
}

.toast.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}

.toast button {
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: color-mix(in srgb, var(--color-bg) 16%, transparent);
  color: inherit;
  cursor: pointer;
}

/* Small screens: preview on top, controls below */

@media (max-width: 760px) {
  body {
    display: block;
    height: auto;
  }

  .stage {
    position: sticky;
    top: 0;
    z-index: 1;
    height: 46svh;
    background: var(--color-bg);
    border-bottom: 1px solid var(--ui-line);
  }

  .stage-toggle {
    display: none;
  }

  .stage-home {
    height: 44px;
  }

  .panel {
    height: auto;
    overflow: visible;
    border-left: 0;
  }

  .panel-body {
    overflow: visible;
  }


  .segmented label,
  .btn,
  .toggle {
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body,
  .toast,
  .toggle input::after,
  .form-option,
  .segmented label {
    transition: none;
  }
}

/* Controls a retro style does not use */
[data-field][hidden] {
  display: none;
}
