:root {
  color-scheme: dark;
  --bg: #101112;
  --panel: #191b1d;
  --panel-2: #222528;
  --line: #363b40;
  --text: #f5f2ec;
  --muted: #aaa398;
  --accent: #37c0aa;
  --accent-2: #f06d4f;
  --accent-3: #e7bd4f;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(55, 192, 170, 0.05), transparent 34%),
    linear-gradient(180deg, rgba(240, 109, 79, 0.04), transparent 40%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
}

button,
.upload-drop {
  border: 1px solid var(--line);
  background: #202326;
  color: var(--text);
  min-height: 40px;
  border-radius: 6px;
  cursor: pointer;
}

button {
  padding: 0 14px;
}

button:hover,
.upload-drop:hover {
  border-color: rgba(55, 192, 170, 0.75);
  background: #252a2d;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.is-hidden {
  display: none !important;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 0;
  width: 100%;
  overflow-x: hidden;
}

.stage {
  min-height: 0;
  min-width: 0;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 18px;
  overflow-x: hidden;
}

.stage-top {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  min-width: 0;
  width: 100%;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.05;
  font-weight: 760;
  letter-spacing: 0;
}

h2 {
  font-size: 13px;
  letter-spacing: 0;
  color: var(--muted);
  text-transform: uppercase;
}

#statusText {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.transport,
.sample-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.project-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.tool-row button {
  min-width: 0;
  padding: 0 10px;
  font-size: 12px;
}

#portalPickButton.is-active {
  border-color: rgba(55, 192, 170, 0.85);
  background: #21312f;
}

.transport button:first-child {
  border-color: rgba(55, 192, 170, 0.7);
  background: #21312f;
}

#saveExportButton {
  border-color: var(--accent);
  background: #21312f;
  font-weight: 700;
}

.canvas-wrap {
  container-type: size;
  min-height: 0;
  min-width: 0;
  width: 100%;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.canvas-wrap.is-picking {
  cursor: crosshair;
}

/* Dragging the placement box must not scroll the page on touch screens. */
.canvas-wrap.is-picking #previewCanvas {
  touch-action: none;
}

.canvas-wrap.is-picking #previewCanvas {
  border-color: rgba(55, 192, 170, 0.85);
}

.canvas-wrap.is-picking .stage-play-button {
  opacity: 0.12;
  pointer-events: none;
}

#previewCanvas {
  display: block;
  width: min(100cqw, 100cqh);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: #0b0c0d;
}

.stage-play-button {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 78px;
  height: 78px;
  min-height: 78px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border-color: rgba(245, 242, 236, 0.46);
  background: rgba(16, 17, 18, 0.68);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.42);
  transform: translate(-50%, -50%);
  transition:
    background 160ms ease,
    opacity 160ms ease,
    transform 160ms ease;
}

.stage-play-button:hover {
  background: rgba(33, 49, 47, 0.88);
  transform: translate(-50%, -50%) scale(1.04);
}

.stage-play-button:disabled {
  opacity: 0.35;
}

.stage-play-button[hidden] {
  display: none;
}

.stage-play-icon {
  display: block;
  width: 0;
  height: 0;
  margin-left: 6px;
  border-top: 15px solid transparent;
  border-bottom: 15px solid transparent;
  border-left: 23px solid var(--text);
}

.timeline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

#timeReadout {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.control-panel {
  min-height: 0;
  min-width: 0;
  width: 100%;
  border-left: 1px solid var(--line);
  background: rgba(25, 27, 29, 0.96);
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.upload-drop {
  min-height: 78px;
  display: grid;
  place-items: center;
  text-align: center;
  border-style: dashed;
  position: relative;
  overflow: hidden;
}

.upload-drop input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.upload-copy {
  display: grid;
  gap: 5px;
  pointer-events: none;
}

.upload-copy strong {
  font-weight: 700;
}

.upload-copy small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.upload-help {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.upload-help.is-error {
  color: #f6a66f;
}

.upload-help.is-ok {
  color: #8fd1c3;
}

.panel-section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: grid;
  gap: 12px;
}

.image-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.image-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.image-item img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.image-meta {
  min-width: 0;
}

.image-meta strong,
.image-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-meta strong {
  font-size: 13px;
}

.image-meta span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
}

.image-actions {
  display: grid;
  grid-template-columns: repeat(3, 32px);
  gap: 4px;
}

.image-actions button {
  min-height: 32px;
  padding: 0;
  font-size: 12px;
}

.image-actions .frame-button {
  grid-column: 1 / -1;
}

#frameDialog {
  width: min(92vw, 540px);
  max-height: 94dvh;
  overflow-y: auto;
  padding: 20px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

#frameDialog::backdrop {
  background: rgba(0, 0, 0, 0.75);
}

#frameDialog .field {
  margin-top: 12px;
}

#frameCanvas {
  display: block;
  width: min(100%, 44dvh);
  height: auto;
  aspect-ratio: 1;
  margin: 12px auto;
  background: #101112;
}

.field {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 10px;
  background: #121415;
  color: var(--text);
}

.field input:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.toggle-field input[type="checkbox"] {
  justify-self: start;
  width: 42px;
  min-height: 24px;
  height: 24px;
  padding: 0;
  appearance: none;
  border-radius: 999px;
  background: #121415;
  position: relative;
  accent-color: var(--accent);
}

.toggle-field input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
  transition:
    background 140ms ease,
    transform 140ms ease;
}

.toggle-field input[type="checkbox"]:checked {
  background: rgba(55, 192, 170, 0.28);
  border-color: rgba(55, 192, 170, 0.82);
}

.toggle-field input[type="checkbox"]:checked::after {
  background: var(--accent);
  transform: translateX(18px);
}

.slider-field input {
  padding: 0;
}

.is-over {
  border-color: var(--accent);
  background: rgba(55, 192, 170, 0.12);
}

@media (max-width: 980px) {
  .app-shell {
    height: auto;
    min-height: 100dvh;
    grid-template-columns: 1fr;
  }

  .control-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: none;
  }

  #previewCanvas {
    width: 100%;
  }

  .canvas-wrap {
    container-type: normal;
  }
}

@media (max-width: 620px) {
  .stage {
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  }

  .stage-top {
    align-items: flex-start;
    flex-direction: column;
  }

  .transport {
    width: calc(100vw - 32px);
    max-width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .canvas-wrap,
  .timeline {
    width: calc(100vw - 32px);
    max-width: 100%;
  }

  .control-panel {
    padding-left: 16px;
    padding-right: 16px;
  }

  .transport button {
    min-width: 0;
    width: 100%;
  }

  .field {
    grid-template-columns: 1fr;
    gap: 7px;
  }
}

.hint {
  margin-top: -6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

/* Slider rows: name and current value above a full-width slider. */
.slider-field {
  grid-template-columns: 1fr;
  gap: 6px;
}

.slider-field > span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.field output {
  color: var(--text);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.timing-summary {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121415;
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

.effects-section > summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.effects-section > summary::before {
  content: "B8";
  color: var(--muted);
}

.effects-section[open] > summary::before {
  content: "BE";
}

.effects-section > summary .hint {
  margin: 0;
}

.effects-section > summary .hint.is-locked {
  color: var(--accent-3);
}

.picker-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(55, 192, 170, 0.6);
  border-radius: 10px;
  background: #15191a;
  min-width: 0;
}

.picker-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 12px;
  align-items: baseline;
}

.picker-head strong {
  font-size: 14px;
}

.picker-match {
  font-size: 12px;
  font-weight: 650;
  color: #8fd1c3;
}

.picker-match[data-tone="ok"] {
  color: var(--accent-3);
}

.picker-match[data-tone="warn"] {
  color: #f6a66f;
}

.picker-panel .hint {
  margin: 0;
}

.picker-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  transition: opacity 120ms ease;
}

.picker-strip.is-updating {
  opacity: 0.45;
}

.picker-strip figure {
  margin: 0;
  display: grid;
  gap: 4px;
}

.picker-strip canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #0b0c0d;
}

.picker-strip figcaption {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.picker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.picker-actions button {
  flex: 1 1 auto;
  min-height: 36px;
  padding: 0 10px;
  font-size: 13px;
}

#pickerDoneButton {
  border-color: var(--accent);
  background: #21312f;
  font-weight: 700;
}
