/* ── Reset & base ─────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1e1e1e;
  --bg2: #252526;
  --bg3: #2d2d30;
  --border: #3c3c3c;
  --text: #cccccc;
  --text-dim: #888888;
  --accent: #0e639c;
  --accent-h: #1177bb;
  --panel-w: 220px;
  --toolbar-h: 36px;
  --prefs-h: 36px;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font:
    13px/1.4 system-ui,
    sans-serif;
}

/* ── Toolbar ──────────────────────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  height: var(--toolbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-title {
  font-weight: 600;
  margin-right: 8px;
  color: #fff;
}
.sep {
  flex: 0 0 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}

button {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 10px;
  cursor: pointer;
  font-size: 12px;
}
button:hover {
  background: var(--accent-h);
  border-color: var(--accent-h);
  color: #fff;
}
button:active {
  background: var(--accent);
}

/* ── Main layout ──────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Layer panel ──────────────────────────────────────────────── */
#layerPanel {
  width: var(--panel-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

#layerPanelHeader,
#paramPanelHeader {
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#layerList {
  list-style: none;
  flex: 1;
  overflow-y: auto;
}

#layerList li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  user-select: none;
}
#layerList li:hover {
  background: var(--bg3);
}
#layerList li.active {
  background: var(--accent);
  color: #fff;
}

#layerList .layer-vis,
#layerList .layer-solo {
  width: 18px;
  height: 18px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
  cursor: pointer;
  padding: 0;
}
#layerList .layer-vis.on {
  background: #2a6;
  border-color: #2a6;
}
#layerList .layer-solo.on {
  background: #a62;
  border-color: #a62;
}

#layerList .layer-name {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 12px;
}

.layer-previews {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.layer-preview-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.layer-preview {
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background:
    linear-gradient(
      45deg,
      #2b2b2b 25%,
      transparent 25%,
      transparent 75%,
      #2b2b2b 75%
    ),
    linear-gradient(
      45deg,
      #2b2b2b 25%,
      transparent 25%,
      transparent 75%,
      #2b2b2b 75%
    );
  background-position:
    0 0,
    4px 4px;
  background-size: 8px 8px;
  image-rendering: pixelated;
  opacity: 0.4;
}

.layer-preview.ready {
  opacity: 1;
}

.layer-preview-label {
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1;
}

#layerControls {
  display: flex;
  gap: 4px;
  padding: 6px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
#layerControls button {
  flex: 1;
  padding: 4px 0;
  font-size: 14px;
}

/* ── Preview section ──────────────────────────────────────────── */
#previewSection {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  gap: 10px;
  padding: 16px;
  overflow: auto;
}

#canvasWrap {
  position: relative;
  box-shadow: 0 4px 24px #0006;
  line-height: 0;
}

#knobCanvas {
  display: block;
  image-rendering: pixelated;
}

#shapeOverlay {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}

#frameScrubber {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
#frameScrubber input[type="range"] {
  width: 200px;
}

#curveEditorPanel {
  width: min(560px, 100%);
}

#curveEditorDetails {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg2);
}

#curveEditorDetails > summary {
  cursor: pointer;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.curve-editor-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--border);
}

.curve-editor-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.curve-editor-tools label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-dim);
  font-size: 11px;
}

#curveStepReso {
  width: 56px;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 12px;
}

#curveTabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

#curveTabs button {
  padding: 4px 6px;
  font-size: 11px;
}

#curveTabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#curveCanvas {
  width: 100%;
  max-width: 544px;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #121212;
  cursor: crosshair;
  touch-action: none;
}

#curveHelp {
  font-size: 11px;
  color: var(--text-dim);
}

#shapeEditorPanel {
  width: min(560px, 100%);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#shapeEditorHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

#shapeEditorHeader strong {
  font-size: 12px;
  letter-spacing: 0.02em;
}

#shapeToolbar {
  display: flex;
  gap: 4px;
}

#shapeToolbar button {
  min-width: 28px;
  padding: 3px 8px;
  font-size: 11px;
}

#shapeToolbar button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#shapeHelp {
  font-size: 11px;
  color: var(--text-dim);
}

#shapeEditorPanel.disabled {
  opacity: 0.75;
}

#statusBar {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

#statusMetrics {
  flex-shrink: 0;
  opacity: 0.7;
}

/* ── Parameter panel ──────────────────────────────────────────── */
#paramPanel {
  width: var(--panel-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg2);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

#paramContent {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.placeholder {
  color: var(--text-dim);
  font-size: 12px;
  padding: 8px 0;
}

.param-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.param-row span {
  color: var(--text-dim);
  font-size: 11px;
}

.param-row.disabled > span {
  opacity: 0.65;
}

.param-row input[type="text"],
.param-row input[type="number"],
.param-row input[type="range"],
.param-row input[type="color"],
.param-row input[type="file"],
.param-row select,
.param-row textarea {
  width: 100%;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 6px;
  font-size: 12px;
}

.param-row textarea {
  min-height: 72px;
  resize: vertical;
}

.param-numeric {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 8px;
  align-items: center;
}

.param-numeric input[type="range"] {
  padding: 0;
  border: 0;
  background: transparent;
}

.param-row.checkbox {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.param-file {
  display: flex;
  gap: 6px;
}

.param-file button {
  flex: 0 0 auto;
  padding: 3px 8px;
}

.param-row small {
  color: var(--text-dim);
  font-size: 10px;
}

.param-group-title {
  margin: 12px 0 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.effect-section {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg3);
  margin-bottom: 8px;
}

.effect-section > summary {
  cursor: pointer;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  user-select: none;
}

.effect-section-body {
  padding: 8px;
  border-top: 1px solid var(--border);
}

.texture-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.texture-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  text-align: left;
}

.texture-card.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.texture-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  color: var(--text-dim);
  font-size: 10px;
}

.texture-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

.texture-meta {
  font-size: 10px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.param-color {
  display: grid;
  grid-template-columns: 42px 1fr 46px;
  align-items: center;
  gap: 6px;
}

.param-color input[type="color"] {
  width: 42px;
  height: 28px;
  padding: 0;
}

.param-color output {
  font-size: 11px;
  color: var(--text-dim);
  text-align: right;
}

/* ── Prefs bar ────────────────────────────────────────────────── */
#prefsBar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 12px;
  height: var(--prefs-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 12px;
  flex-wrap: wrap;
}

#prefsBar label {
  display: flex;
  align-items: center;
  gap: 4px;
}

#prefsBar input[type="number"] {
  width: 52px;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 12px;
}

#prefPreviewFrames {
  width: 68px;
}

#prefsBar input[type="color"] {
  width: 32px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}

#prefBgAlpha {
  width: 70px;
}

#prefsBar select {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 4px;
  font-size: 12px;
}

@media (max-width: 920px) {
  #curveTabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ── Loading overlay ──────────────────────────────────────────── */
#loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  font-size: 18px;
  color: var(--text-dim);
}

.samples-overlay[hidden] {
  display: none;
}

.samples-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: 20px;
}

.samples-dialog {
  width: min(700px, 100%);
  max-height: min(640px, 90vh);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.samples-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.samples-header h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.samples-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.samples-search input {
  flex: 1;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 5px 8px;
  font-size: 12px;
}

.samples-list {
  overflow-y: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
}

.sample-item {
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg3);
  text-align: left;
  padding: 8px;
}

.sample-preview-item {
  min-height: 96px;
  padding: 10px;
}

.sample-preview-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(92px, 1fr);
  gap: 10px;
  align-items: stretch;
  min-height: 74px;
}

.sample-preview-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.sample-item:hover {
  border-color: var(--accent);
}

.sample-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 12px;
}

.sample-item small {
  color: var(--text-dim);
  font-size: 10px;
}

.sample-preview {
  min-height: 74px;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-sizing: border-box;
  background:
    linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.04) 25%,
      transparent 25%,
      transparent 75%,
      rgba(255, 255, 255, 0.04) 75%
    ),
    linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.04) 25%,
      transparent 25%,
      transparent 75%,
      rgba(255, 255, 255, 0.04) 75%
    ),
    #1a1a1c;
  background-position:
    0 0,
    6px 6px;
  background-size: 12px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.sample-preview.loading {
  border-style: dashed;
}

.sample-preview.failed {
  background: #1a1a1c;
}

.sample-preview-status {
  color: var(--text-dim);
  font-size: 10px;
  text-align: center;
  padding: 0 6px;
}

.sample-preview-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  image-rendering: pixelated;
  display: block;
  flex: 0 0 auto;
}

.sample-item[disabled] {
  cursor: default;
  opacity: 0.65;
}

.sample-item .sample-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.sample-item .sample-tag {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 10px;
  color: var(--text-dim);
}

.sample-preview-frame {
  display: none;
}

.export-dialog {
  width: min(520px, 100%);
}

.export-body {
  padding: 14px 16px 10px;
}

.export-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}

.export-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.export-form select,
.export-form input[type="number"] {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 6px 8px;
  font-size: 12px;
}

.export-checkbox {
  grid-column: 1 / -1;
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  color: var(--text);
}

.export-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 16px 14px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

@media (max-width: 720px) {
  .export-form {
    grid-template-columns: 1fr;
  }
}

/* ── Welcome dialog ───────────────────────────────────────────── */

.welcome-dialog {
  width: min(700px, 100%);
}

.welcome-intro {
  padding: 10px 12px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.4;
}

.welcome-intro p {
  margin: 0;
}

.welcome-intro p + p {
  margin-top: 6px;
}

.welcome-dialog .samples-search {
  padding-top: 8px;
  padding-bottom: 8px;
}

.welcome-dialog .samples-list {
  padding-top: 6px;
}

.welcome-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

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

.welcome-suppress {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.welcome-suppress input[type="checkbox"] {
  cursor: pointer;
}

/* ── Scrollbars ───────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg2);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #555;
}
