:root {
  --bg: #17181b;
  --panel: #1f2024;
  --panel-2: #26272c;
  --line: #34363c;
  --text: #e9e7e3;
  --muted: #9a9894;
  --accent: #6bc4b8;
  --accent-ink: #0b1d1a;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- viewport ---------- */
#viewport { position: relative; flex: 1; min-width: 0; }
#stage { position: absolute; inset: 60px 16px 62px; overflow: auto; }
#dropHint {
  position: absolute; inset: 10px; display: none; place-items: center; z-index: 4;
  border: 2px dashed var(--accent); border-radius: 14px; background: rgba(107,196,184,.08);
  color: var(--accent); font-size: 15px; font-weight: 600; pointer-events: none;
}
#viewport.dropping #dropHint { display: grid; }

.toolbar {
  position: absolute; left: 12px; right: 12px; z-index: 2;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  pointer-events: none;
}
.toolbar > * { pointer-events: auto; }
.toolbar.top { top: 12px; }
.toolbar.bottom { bottom: 12px; }
.toolbar.bottom #saveSheet { margin-left: auto; }
.toolbar.bottom #openImage[hidden] { display: none; }

.dropzone {
  flex: 1; min-height: 240px; height: 100%; display: grid; place-items: center; text-align: center;
  border: 2px dashed var(--line); border-radius: 14px; color: var(--muted); padding: 24px;
}
.dropzone p { margin: 0 0 12px; font-size: 14px; max-width: 360px; }

/* ---------- palette ---------- */
.pal-wrap { display: flex; gap: 20px; height: 100%; min-height: 360px; }
.pal-image { margin: 0; flex: 1 1 auto; min-width: 0; display: flex; align-items: center; justify-content: center; }
.pal-image img { max-width: 100%; max-height: 100%; display: block; cursor: crosshair; border-radius: 6px; }
.pal-list { flex: 0 0 280px; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.pal-swatch {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: 44px; flex-basis: 0;
  border: 0; border-radius: 8px; padding: 0 12px; text-align: left; font-variant-numeric: tabular-nums;
}
.pal-swatch:hover { border: 0; filter: brightness(1.04); }
.pal-swatch.sel { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.pal-swatch .hex { font-weight: 600; letter-spacing: .02em; }
.pal-swatch .share { margin-left: auto; opacity: .8; }
.pal-swatch .lock { font-size: 11px; }
.pal-swatch .share + .lock { margin-left: 0; }
.pal-swatch .hex + .lock { margin-left: auto; }
.pal-swatch .val { width: 30px; align-self: stretch; margin: 6px -6px 6px 0; border-radius: 5px; border: 1px solid rgba(255,255,255,.18); flex: none; }

/* ---------- harmony ---------- */
.harm-wrap { display: flex; gap: 28px; align-items: flex-start; flex-wrap: wrap; }
.harm-wheel { flex: none; width: 300px; }
.harm-wheel canvas { display: block; touch-action: none; cursor: crosshair; }
.harm-wheel .hint { margin-top: 10px; }
.harm-swatches { flex: 1; min-width: 260px; display: flex; gap: 10px; }
.harm-col { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.harm-main {
  position: relative; height: 180px; border-radius: 10px; padding: 10px 12px;
  display: flex; align-items: flex-end; font-weight: 600; font-variant-numeric: tabular-nums;
}
.harm-val { height: 36px; border-radius: 6px; border: 1px solid rgba(255,255,255,.15); }
.harm-ramp { display: flex; flex-direction: column; gap: 3px; }
.ramp-cell { height: 30px; border: 0; border-radius: 5px; padding: 0; }
.ramp-cell:hover { border: 0; outline: 2px solid var(--text); outline-offset: -2px; }
.lock-btn {
  position: absolute; top: 8px; right: 8px; padding: 2px 6px; font-size: 12px; line-height: 1.2;
  background: rgba(20,20,22,.55); border-color: transparent;
}
.lock-btn.on { background: rgba(20,20,22,.85); border-color: var(--accent); }

/* ---------- values ---------- */
.val-wrap { display: flex; gap: 16px; height: 100%; min-height: 300px; }
.val-wrap figure { margin: 0; flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.val-wrap figure img, .val-wrap figure canvas { max-width: 100%; max-height: calc(100% - 28px); object-fit: contain; display: block; border-radius: 6px; }
.val-wrap figcaption { color: var(--muted); font-size: 12px; }
canvas.hist { width: 100%; height: 60px; display: block; margin: 4px 0 6px; }
.step-legend { display: flex; gap: 4px; margin: 2px 0 6px; }
.step-legend i { flex: 1; height: 14px; border-radius: 3px; border: 1px solid var(--line); }

/* ---------- script ---------- */
.script-title { font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0 0 14px; }
.frames { display: grid; gap: 16px; align-items: start; }
.frame {
  display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; min-width: 0;
}
.frame:hover { background: var(--panel); }
.frame.sel { border-color: var(--accent); background: var(--panel); }
.frame.over { border-color: var(--text); border-style: dashed; }
.frame.dragging { opacity: .4; }
.frame-box { aspect-ratio: var(--aspect, 1.78); border-radius: 6px; overflow: hidden; background: var(--panel-2); display: grid; place-items: center; }
.frame-box img { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame-bands { display: flex; width: 100%; height: 100%; }
.frame-bands i { flex-basis: 0; }
.frame-empty { color: var(--muted); font-size: 12px; }
.frame-chips { display: flex; gap: 3px; min-height: 12px; }
.frame-chips i { width: 22px; height: 12px; border-radius: 3px; }
.frame-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.frame-title b { color: var(--muted); margin-right: 4px; }
.frame-note { margin: 0; color: var(--muted); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.add-frame {
  aspect-ratio: var(--aspect, 1.78); align-items: center; justify-content: center; gap: 4px;
  border: 2px dashed var(--line); background: transparent; color: var(--muted);
}
.add-frame span { font-weight: 600; color: var(--text); }
.frame-colors { display: flex; flex-direction: column; gap: 6px; }
.frame-color { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; }
textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--panel-2); resize: vertical;
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px;
}
.note-row { align-items: start; }
.note-row .lbl { padding-top: 5px; }

/* ---------- panel ---------- */
#panel {
  width: 340px; flex: none; overflow-y: auto;
  background: var(--panel); border-left: 1px solid var(--line);
  padding: 16px 16px 24px;
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; color: var(--muted); }

section { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
h2 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
h2.sub { margin-top: 16px; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.color-info b { color: var(--text); }

/* ---------- buttons ---------- */
button {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 11px; cursor: pointer;
}
button:hover { border-color: #4a4c53; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .frame:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.small { padding: 5px 9px; font-size: 12px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.danger { color: #ff8f8f; }
button.on { background: var(--text); color: var(--bg); border-color: var(--text); }

.seg { display: inline-flex; background: rgba(20,20,22,.75); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 10px; border-radius: 7px; }
.seg button.on { background: var(--text); color: var(--bg); }
#panel .seg { background: var(--panel-2); backdrop-filter: none; flex-wrap: wrap; }
#panel .seg button { padding: 5px 8px; }
.toolbar button.ghost, .toolbar button:not(.primary):not(.seg button) { background: rgba(20,20,22,.75); backdrop-filter: blur(6px); }

/* ---------- form rows ---------- */
.row { display: grid; grid-template-columns: 70px 1fr 46px; align-items: center; gap: 8px; margin: 7px 0; }
.row .lbl { color: var(--muted); }
.row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }
.row.wide { grid-template-columns: 70px 1fr; }
input[type=range] { width: 100%; accent-color: var(--accent); margin: 0; }
input[type=color] { width: 100%; height: 28px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); cursor: pointer; }
input[type=text], select {
  width: 100%; font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px;
}
.color-field { display: grid; grid-template-columns: 1fr 90px; gap: 6px; }
.color-field input[type=text] { font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 8px; margin: 7px 0; color: var(--text); cursor: pointer; }
.check input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; flex: none; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- projects ---------- */
.save-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.project-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.project-card { position: relative; }
.project-load { width: 100%; padding: 0; overflow: hidden; display: flex; flex-direction: column; text-align: left; }
.project-load img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--bg); }
.project-load span { padding: 5px 7px; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-del {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; padding: 0; line-height: 1;
  border-radius: 50%; background: rgba(20,20,22,.8); font-size: 14px;
}

footer { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.credit { color: var(--muted); font-size: 11px; margin: 10px 0 0; }
.credit a { color: var(--muted); }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 10;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px;
  opacity: 0; transition: .2s; pointer-events: none; font-weight: 500;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  body { overflow: auto; }
  #app { flex-direction: column; height: auto; min-height: 100dvh; }
  #viewport { flex: none; height: 62dvh; }
  #stage { inset: 54px 8px 54px; }
  #panel { width: auto; flex: 1; border-left: 0; border-top: 1px solid var(--line); padding: 12px 16px 24px; overflow: visible; }
  .brand { display: none; }
  #tabPanel > section:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
  .toolbar { left: 8px; right: 8px; }
  .toolbar.top { top: 8px; }
  .toolbar.bottom { bottom: 8px; gap: 6px; }
  .toolbar.bottom button { padding: 6px 9px; }
  .seg button { padding: 6px 8px; }
  .pal-wrap { flex-direction: column; }
  .pal-image { flex: 1 1 50%; min-height: 0; }
  .pal-list { flex: 1 1 50%; }
  .harm-wheel { width: 100%; display: flex; flex-direction: column; align-items: center; }
  .val-wrap { flex-direction: column; }
  .frames { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}
