:root {
  --bg: #f4f3f0;
  --panel: #ffffff;
  --ink: #000000;
  --ink-soft: #000000;
  --line: #e0ddd5;
  --accent: #000000;
  --accent-contrast: #ffffff;
  --mono: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

body {
  display: flex;
  flex-direction: column;
}

.back-link {
  display: inline-block;
  margin-bottom: 10px;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

.sidebar-title {
  margin-bottom: 16px;
}

.sidebar-title h1 {
  margin: 0;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: -0.01em;
  font-weight: 600;
}

.sidebar-title h1 span {
  color: var(--ink-soft);
  font-weight: 400;
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 24px 32px;
  align-items: stretch;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--panel);
  border: none;
  border-radius: 16px;
  padding: 20px;
}

.controls {
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.controls::-webkit-scrollbar {
  width: 8px;
}

.controls::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}

.panel h2 {
  font-family: var(--mono);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 12px;
  color: var(--ink-soft);
}

.block {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.block:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* Collapsible sections */

details.block > summary.block-header {
  margin-bottom: 12px;
}

.block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.block-header::-webkit-details-marker {
  display: none;
}

.block-header h2 {
  margin: 0;
}

.block-header::after {
  content: "";
  width: 8px;
  height: 8px;
  margin-left: 8px;
  border-right: 1.5px solid var(--ink-soft);
  border-bottom: 1.5px solid var(--ink-soft);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  flex: 0 0 auto;
}

details.block:not([open]) .block-header::after {
  transform: rotate(-45deg);
}

details.block:not([open]) > summary.block-header {
  margin-bottom: 0;
}

.hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 4px 0 10px;
  line-height: 1.4;
}

/* Fields */

.field {
  margin-bottom: 14px;
  flex: 1;
}

.field label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--ink);
}

.field input[type="number"] {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
}

.field select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
}

.field-spaced {
  margin-top: 14px;
}

.btn-compact {
  flex: 0 0 auto;
  width: auto;
  padding-left: 12px;
  padding-right: 12px;
}

.field-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.field-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  align-self: center;
}

.field-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  min-width: 32px;
  text-align: right;
  align-self: center;
}

/* Fillbar sliders — value displayed inside a two-tone filled track */

.fillbar {
  position: relative;
  --pct: 0%;
}

.fillbar-input {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 26px;
  margin: 0;
  border: none;
  border-radius: 13px;
  outline: none;
  cursor: pointer;
  background: linear-gradient(to right, var(--ink) var(--pct), #e6e6e6 var(--pct));
}

.fillbar-input::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  height: 26px;
  background: transparent;
}

.fillbar-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 2px;
  height: 26px;
  background: transparent;
  border: none;
}

.fillbar-input::-moz-range-track {
  height: 26px;
  border-radius: 13px;
  background: transparent;
}

.fillbar-input::-moz-range-thumb {
  width: 2px;
  height: 26px;
  border: none;
  background: transparent;
}

.fillbar-value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
}

.fillbar-value-dark {
  color: var(--ink);
}

.fillbar-value-light-wrap {
  color: #fff;
  clip-path: inset(0 calc(100% - var(--pct)) 0 0);
}

/* Pill toggle switches (invisible native checkbox + sibling span for the
   visuals — styling background/pseudo-elements directly on a native
   appearance:none checkbox proved unreliable, this sidesteps it entirely) */

.pill-toggle {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex: 0 0 auto;
  cursor: pointer;
}

.pill-toggle input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.pill-toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #ececE4;
  transition: background 0.15s ease;
  pointer-events: none;
}

.pill-toggle-track::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(20, 19, 15, 0.25);
  transition: transform 0.15s ease;
}

.pill-toggle input:checked ~ .pill-toggle-track,
.pill-toggle-track.is-on {
  background: var(--ink);
}

.pill-toggle input:checked ~ .pill-toggle-track::before,
.pill-toggle-track.is-on::before {
  transform: translateX(18px);
}

/* LFO module */

.lfo-module {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafaf8;
}

.lfo-knob {
  position: relative;
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--line);
  cursor: ns-resize;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
}

.lfo-knob:active {
  border-color: var(--ink);
}

.lfo-knob-indicator {
  position: absolute;
  top: 3px;
  left: 50%;
  width: 2px;
  height: 11px;
  background: var(--ink);
  border-radius: 1px;
  transform: translateX(-50%) rotate(-135deg);
  transform-origin: 50% 14px;
}

.lfo-module-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  gap: 2px;
}

.lfo-label {
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.lfo-module-info .field-value {
  text-align: left;
}

.lfo-toggle-btn {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.lfo-toggle-btn.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-inline label {
  margin-bottom: 0;
}

.field-inline input[type="color"] {
  width: 36px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: none;
  cursor: pointer;
}

/* Dropzone */

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1.5px dashed var(--line);
  border-radius: 8px;
  padding: 22px 12px;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
  transition: border-color 0.15s ease, background 0.15s ease;
  min-height: 80px;
  margin-bottom: 10px;
  position: relative;
  overflow: hidden;
}

.dropzone-thumb {
  max-width: 100%;
  max-height: 140px;
  border-radius: 4px;
  object-fit: contain;
}

.dropzone:hover {
  border-color: var(--ink);
  background: #fafaf8;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: #eeeee9;
}

/* Buttons */

.btn-primary {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn-primary:not(:disabled):hover {
  opacity: 0.85;
}

.btn-secondary {
  display: block;
  width: 100%;
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  box-sizing: border-box;
}

.file-btn {
  margin-bottom: 8px;
}

#dir-status {
  margin-top: -4px;
}

.btn-secondary:hover {
  border-color: var(--ink);
  background: #fafaf8;
}

/* Preview */

.preview {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.poster-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* Poster grid */

#poster {
  display: grid;
  position: relative;
  max-width: 100%;
  max-height: 76vh;
  aspect-ratio: var(--poster-ratio, 5 / 7);
  width: min(100%, calc(76vh * var(--poster-ratio, 0.714)));
  user-select: none;
}

.bg-image-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  z-index: 0;
}

.grid-item {
  position: relative;
  overflow: hidden;
  cursor: grab;
  outline: 1px solid rgba(0, 0, 0, 0.08);
}

.grid-item:active {
  cursor: grabbing;
}

.grid-item.dragging {
  z-index: 10;
  outline: 2px solid var(--accent);
}

.grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  display: block;
}

.grid-item .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(20, 19, 15, 0.75);
  color: #fff;
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease;
  z-index: 5;
}

.grid-item:hover .remove-btn {
  opacity: 1;
}

.stack-btn {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(20, 19, 15, 0.75);
  color: #fff;
  font-size: 11px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease;
  z-index: 5;
}

.stack-btn.stack-back {
  left: 28px;
}

.grid-item:hover .stack-btn {
  opacity: 1;
}

.stretch-btn {
  position: absolute;
  bottom: 4px;
  left: 4px;
  padding: 3px 8px;
  border: none;
  border-radius: 10px;
  background: rgba(20, 19, 15, 0.75);
  color: #fff;
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.15s ease;
  z-index: 5;
}

.stretch-btn.active {
  background: rgba(20, 19, 15, 0.9);
  box-shadow: 0 0 0 1.5px #fff inset;
}

.grid-item:hover .stretch-btn {
  opacity: 1;
}

.handle {
  position: absolute;
  background: transparent;
  z-index: 4;
}

.handle-right {
  top: 0;
  right: 0;
  width: 10px;
  height: 100%;
  cursor: ew-resize;
}

.handle-bottom {
  bottom: 0;
  left: 0;
  width: 100%;
  height: 10px;
  cursor: ns-resize;
}

.handle-corner {
  bottom: 0;
  right: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
}

.handle-corner::after {
  content: "";
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-right: 2px solid rgba(255, 255, 255, 0.85);
  border-bottom: 2px solid rgba(255, 255, 255, 0.85);
}

.grid-item:hover .handle-right,
.grid-item:hover .handle-bottom {
  background: rgba(20, 19, 15, 0.06);
}

/* Grid guides overlay (screen only, excluded from export) */

#grid-guides {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

#grid-guides .guide-cell {
  box-sizing: border-box;
}
