:root {
  color-scheme: dark;
  --bg: #080b10;
  --panel: rgba(12, 16, 23, 0.74);
  --panel-solid: rgba(12, 16, 23, 0.96);
  --panel-border: rgba(255, 255, 255, 0.11);
  --fg: #f4f7fb;
  --fg-dim: rgba(232, 239, 248, 0.62);
  --accent: #8edcff;
  --accent-strong: #45c7ff;
  --focus: #ffd166;
  --radius: 14px;
  --safe-top: max(14px, env(safe-area-inset-top));
  --safe-right: max(14px, env(safe-area-inset-right));
  --safe-bottom: max(14px, env(safe-area-inset-bottom));
  --safe-left: max(14px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 42%, transparent 38%, rgba(2, 5, 10, 0.18) 70%, rgba(2, 5, 10, 0.6) 118%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.18), transparent 28%, transparent 68%, rgba(0, 0, 0, 0.3));
}

#main {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100vw;
  height: 100dvh;
  cursor: grab;
  touch-action: none;
}

#main.is-scrubbing { cursor: ew-resize; }

.ambient-grain {
  position: fixed;
  inset: 0;
  z-index: 2;
  opacity: 0.11;
  pointer-events: none;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}

.hud {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(24, 31, 43, 0.79), var(--panel));
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.38), inset 0 1px rgba(255, 255, 255, 0.055);
  backdrop-filter: blur(18px) saturate(1.28);
  -webkit-backdrop-filter: blur(18px) saturate(1.28);
}

.top-bar {
  position: fixed;
  top: var(--safe-top);
  right: var(--safe-right);
  left: var(--safe-left);
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.top-bar > * { pointer-events: auto; }

.top-left {
  width: min(370px, calc(100vw - 30px));
  padding: 15px 17px 14px;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
}

.eyebrow,
.mode-line,
.seed-row,
.panel-heading,
.range-ends {
  display: flex;
  align-items: center;
}

.eyebrow {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 4px;
}

.title,
.playback-state,
.section-heading,
.panel-heading {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.title { color: var(--fg-dim); }

.title-mark {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 8px 1px 0;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 0 14px var(--accent-strong);
}

.playback-state { color: var(--accent); letter-spacing: 0.08em; }
.playback-state i {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin: 0 5px 1px 0;
  border-radius: 50%;
  background: #8ef0bd;
  box-shadow: 0 0 8px #8ef0bd;
}
.playback-state.paused { color: var(--fg-dim); }
.playback-state.paused i { background: var(--fg-dim); box-shadow: none; }

.mode-line { align-items: baseline; gap: 10px; }

.mode-name {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: clamp(20px, 2.1vw, 27px);
  font-weight: 630;
  letter-spacing: -0.025em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-count {
  flex: 0 0 auto;
  color: var(--accent);
  opacity: 0.78;
  font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.08em;
}

.mode-note {
  margin: 1px 0 11px;
  overflow: hidden;
  color: var(--fg-dim);
  font-size: 12px;
  line-height: 1.45;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seed-row { gap: 8px; }
.seed-row .label {
  color: var(--fg-dim);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.seed-row code {
  color: var(--accent);
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.seed-row input {
  width: 88px;
  margin-left: auto;
  padding: 5px 7px;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  outline: 0;
  background: rgba(0, 0, 0, 0.24);
  color: var(--fg);
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  user-select: text;
}

button,
select,
input { font: inherit; }

button {
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--fg);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

button:hover {
  border-color: rgba(142, 220, 255, 0.28);
  background: rgba(142, 220, 255, 0.12);
  box-shadow: 0 0 20px rgba(69, 199, 255, 0.11);
}

button:active { transform: scale(0.96); }
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button.on {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: #031822;
  box-shadow: 0 0 22px rgba(69, 199, 255, 0.32);
}

.button-icon {
  display: inline-block;
  margin-right: 5px;
  color: var(--accent);
  font-size: 14px;
  line-height: 0;
  vertical-align: -1px;
}
button.on .button-icon { color: inherit; }
.settings-button { min-width: 38px; }

.right {
  position: fixed;
  top: 92px;
  right: var(--safe-right);
  z-index: 12;
  width: 278px;
  padding: 15px;
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms;
}

.right:not(.open) {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateX(14px);
}

.panel-heading {
  justify-content: space-between;
  margin-bottom: 13px;
}

.close-button {
  display: none;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 21px;
  line-height: 1;
}

.control-section {
  padding: 12px 0 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.075);
}

.section-heading { margin-bottom: 12px; color: var(--fg); }
.control { margin-bottom: 14px; }
.control label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  color: var(--fg-dim);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.control label span {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0;
  text-transform: none;
}

.control input[type="range"] {
  width: 100%;
  height: 5px;
  margin: 0;
  accent-color: var(--accent-strong);
  cursor: ew-resize;
}

.range-ends {
  justify-content: space-between;
  margin-top: 4px;
  color: rgba(232, 239, 248, 0.36);
  font-size: 8px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.control select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  appearance: none;
  background: rgba(0, 0, 0, 0.27);
  color: var(--fg);
  font-size: 12px;
  cursor: pointer;
}
.control select option { background: #111722; color: var(--fg); }

.gesture-hint {
  margin-top: 2px;
  padding: 9px 10px;
  border-radius: 8px;
  background: rgba(142, 220, 255, 0.065);
  color: var(--fg-dim);
  font-size: 10px;
  line-height: 1.45;
}
.gesture-hint span { margin-right: 5px; color: var(--accent); }
.hint {
  margin-top: 11px;
  color: rgba(232, 239, 248, 0.45);
  font-size: 9px;
  line-height: 1.8;
}
kbd {
  padding: 1px 4px;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--fg);
  font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.bottom-deck {
  position: fixed;
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  left: var(--safe-left);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  pointer-events: none;
}
.bottom-deck > * { pointer-events: auto; }

.transport {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  padding: 5px 6px 7px;
}
.transport-buttons { display: flex; align-items: center; gap: 3px; }
.icon-button {
  min-width: 36px;
  padding: 5px 10px;
  font-size: 22px;
  line-height: 1;
}
.play-button { min-width: 92px; }
.cycle-button { min-width: 62px; }
.cycle-meter {
  position: absolute;
  right: 6px;
  bottom: 3px;
  left: 6px;
  height: 2px;
  overflow: hidden;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.07);
}
.cycle-meter span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent-strong);
  box-shadow: 0 0 8px var(--accent-strong);
  transform: scaleX(0);
  transform-origin: left;
}

.gallery {
  display: flex;
  width: max-content;
  max-width: min(1120px, calc(100vw - var(--safe-left) - var(--safe-right)));
  gap: 5px;
  padding: 7px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
}

.thumb {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
  min-height: 0;
  padding: 4px 4px 6px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  scroll-snap-align: center;
}
.thumb:hover { transform: translateY(-2px); }
.thumb canvas {
  display: block;
  width: 88px;
  height: 54px;
  border-radius: 6px;
  transition: transform 220ms ease, filter 220ms ease;
}
.thumb:hover canvas { filter: saturate(1.14) contrast(1.05); transform: scale(1.035); }
.thumb span {
  width: 88px;
  overflow: hidden;
  color: var(--fg-dim);
  font-size: 9px;
  letter-spacing: 0.025em;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thumb.active {
  border-color: rgba(69, 199, 255, 0.82);
  background: linear-gradient(180deg, rgba(69, 199, 255, 0.15), rgba(69, 199, 255, 0.025));
  box-shadow: inset 0 0 0 1px rgba(69, 199, 255, 0.18), 0 0 22px rgba(69, 199, 255, 0.1);
}
.thumb.active span { color: var(--accent); }

.panel-scrim {
  position: fixed;
  inset: 0;
  z-index: 11;
  display: none;
  background: rgba(3, 6, 11, 0.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 30;
  max-width: calc(100vw - 32px);
  padding: 9px 13px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(7, 11, 17, 0.86);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.34);
  color: var(--fg);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  .right {
    top: auto;
    right: var(--safe-right);
    bottom: var(--safe-bottom);
    width: min(340px, calc(100vw - var(--safe-left) - var(--safe-right)));
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
    overflow-y: auto;
    visibility: hidden;
    opacity: 0;
    transform: translateY(18px) scale(0.985);
    transition: opacity 180ms ease, transform 180ms ease, visibility 180ms;
  }
  .right.open { visibility: visible; opacity: 1; pointer-events: auto; transform: none; }
  .close-button { display: inline-block; }
  .panel-scrim.open { display: block; }
}

@media (max-width: 740px) {
  .top-right button { min-width: 40px; padding-inline: 8px; }
  .top-right .button-label { display: none; }
  .top-right .button-icon { margin-right: 0; }
}

@media (max-width: 680px) {
  :root {
    --safe-top: max(9px, env(safe-area-inset-top));
    --safe-right: max(9px, env(safe-area-inset-right));
    --safe-bottom: max(9px, env(safe-area-inset-bottom));
    --safe-left: max(9px, env(safe-area-inset-left));
  }

  .top-bar { gap: 7px; }
  .top-left { width: min(270px, calc(100vw - 62px)); padding: 11px 12px 10px; }
  .eyebrow { margin-bottom: 2px; }
  .playback-state { display: none; }
  .mode-name { font-size: 19px; }
  .mode-note { margin-bottom: 7px; font-size: 10px; }
  .seed-row input { display: none; }
  .top-right { flex-direction: column; gap: 3px; padding: 4px; }
  .top-right button { min-width: 44px; min-height: 44px; padding: 7px; }
  .top-right .button-label { display: none; }
  .top-right .button-icon { margin-right: 0; }
  .bottom-deck { align-items: stretch; gap: 6px; }
  .transport { align-self: center; }
  .gallery { width: 100%; max-width: none; }
  .thumb canvas { width: 72px; height: 46px; }
  .thumb span { width: 72px; }
  .right {
    right: var(--safe-right);
    left: var(--safe-left);
    width: auto;
    border-radius: 18px;
  }
  .right .hint { display: none; }
  .gesture-hint { margin-bottom: 2px; }
}

@media (max-width: 360px) {
  .top-left { width: calc(100vw - 78px); }
}

@media (max-width: 300px) {
  .play-button { min-width: 84px; }
  .cycle-button { min-width: 56px; }
}

@media (pointer: coarse) {
  button { min-height: 44px; }
  .icon-button { min-width: 44px; }
}

@media (max-height: 640px) and (orientation: landscape) {
  .top-left { padding: 9px 12px; }
  .mode-note, .seed-row { display: none; }
  .bottom-deck { align-items: flex-end; }
  .gallery { display: none; }
  .right { max-height: calc(100dvh - 18px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
  .ambient-grain { display: none; }
}
