/* Precision Sprite Studio — dark, restrained production UI
   Spatial system: 4px grid (--sp-*), one horizontal gutter (--gutter).
   Leading: --lh-control for single-line UI text, --lh-prose for multi-line. */

:root {
  --bg0: #17171a;
  --bg1: #1e1e22;
  --bg2: #26262b;
  --bg3: #2e2e34;
  --line: #3a3a41;
  --text: #d8d8dc;
  --text-dim: #8f8f97;
  --accent: #e8a33d;
  --accent-dim: #a9782f;
  --danger: #e05555;
  --ok: #6fbf73;
  --radius: 6px;
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --gutter: 12px;      /* every horizontal panel edge */
  --lh-control: 16px;  /* 10-13px single-line UI text */
  --lh-prose: 1.45;    /* anything that can wrap */
  font-size: 13px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg0); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: var(--lh-prose);
  overflow: hidden;
}

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

button {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 10px; font-size: 12px; line-height: var(--lh-control);
  cursor: pointer;
  transition: background .1s, transform 120ms ease-out;
}
button:hover { background: #383840; }
button:active { background: #222; transform: scale(0.97); }
button.accent { background: var(--accent); border-color: var(--accent); color: #1c1607; font-weight: 600; }
button.accent:hover { background: #f0b155; }
button.wide { width: 100%; }
button.toggled { outline: 2px solid var(--accent); }
button:disabled { opacity: .45; cursor: default; }

input, select {
  background: var(--bg0); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px;
  padding: 4px 8px; font-size: 12px; line-height: var(--lh-control); min-width: 0;
}
input[type=number] { width: 64px; }
input[type=color] { padding: 1px; width: 40px; height: 26px; }
input[type=range] { accent-color: var(--accent); padding: 0; flex: 1; }
input[type=checkbox] { accent-color: var(--accent); }
input:focus, select:focus { outline: 1px solid var(--accent-dim); }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: var(--sp-3);
  background: var(--bg1); border-bottom: 1px solid var(--line);
  padding: var(--sp-2) var(--gutter); flex: 0 0 auto;
}
.brand { font-size: 14px; letter-spacing: .02em; color: var(--text-dim); line-height: var(--lh-control); }
.brand b { color: var(--text); font-weight: 700; }
.topbar-actions { display: flex; gap: var(--sp-1); align-items: center; }
#btn-guide {
  background: var(--bg3); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px 10px; font-size: 12px;
  text-decoration: none; line-height: var(--lh-control);
}
#btn-guide:hover { background: #383840; border-color: var(--accent); }
.status {
  margin-left: auto; color: var(--text-dim); font-size: 12px; line-height: var(--lh-control);
  max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.status.error { color: var(--danger); }

/* ---------- workspace ---------- */
#workspace { display: flex; flex: 1 1 auto; min-height: 0; }

#right-panel {
  background: var(--bg1); overflow-y: auto; flex: 0 0 auto;
  width: 264px; border-left: 1px solid var(--line);
}

.splitter { flex: 0 0 5px; cursor: col-resize; background: transparent; }
.splitter:hover { background: var(--accent-dim); }

.section { border-bottom: 1px solid var(--line); }
.section > summary {
  cursor: pointer; padding: 10px var(--gutter); font-weight: 600; font-size: 12px;
  line-height: var(--lh-control);
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim);
  user-select: none; list-style: none;
}
.section > summary::before { content: "▸ "; color: var(--accent); }
.section[open] > summary::before { content: "▾ "; }
.section-body {
  padding: var(--sp-1) var(--gutter) var(--gutter);
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.sub { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--sp-2); }
.sub > summary { cursor: pointer; font-size: 12px; line-height: var(--lh-control); color: var(--text-dim); user-select: none; }
.sub label.row { margin-top: var(--sp-2); }

label.row, .row {
  display: flex; align-items: center; gap: var(--sp-2); justify-content: space-between;
  font-size: 12px; line-height: var(--lh-control); color: var(--text);
}
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.row.two label { display: flex; align-items: center; gap: var(--sp-1); justify-content: space-between; min-width: 0; }
.row.two select, .row.two input:not([type=checkbox]):not([type=color]) { flex: 1; min-width: 0; width: 100%; }
.row.check, label.check { justify-content: flex-start; }
.val { color: var(--accent); font-variant-numeric: tabular-nums; font-size: 12px; }
.hint { color: var(--text-dim); font-size: 11px; line-height: var(--lh-prose); }

.palette-list { display: flex; flex-wrap: wrap; gap: var(--sp-1); }
.palette-chip {
  width: 26px; height: 26px; border-radius: 4px; border: 1px solid var(--line);
  cursor: pointer; position: relative; padding: 0;
}
.palette-chip .cnt {
  position: absolute; bottom: -1px; right: 1px; font-size: 9px;
  color: #fff; text-shadow: 0 0 2px #000;
}

.statgrid {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-1) var(--sp-2);
  font-size: 11px; line-height: var(--lh-control); color: var(--text-dim);
}
.statgrid b { color: var(--text); font-weight: 600; }

.exgrid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }

/* ---------- center ---------- */
#center-panel { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; background: var(--bg0); }

#view-tabs {
  display: flex; align-items: center; gap: 2px;
  background: var(--bg1); border-bottom: 1px solid var(--line); padding: 0 var(--sp-2);
}
.tab {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  border-radius: 0; padding: var(--sp-2) 14px; color: var(--text-dim);
  font-size: 13px; line-height: var(--lh-control);
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-spacer { flex: 1; }
.kbd-hint { color: var(--text-dim); font-size: 11px; line-height: var(--lh-control); padding-right: var(--sp-1); }

.view { display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; position: relative; }
.view.active { display: flex; }

.toolbar {
  display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap;
  background: var(--bg1); border-bottom: 1px solid var(--line);
  padding: var(--sp-1) var(--gutter);
}
.toolbar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 var(--sp-1); }
.toolbar .tb { display: flex; align-items: center; gap: var(--sp-1); font-size: 11px; line-height: var(--lh-control); color: var(--text-dim); }

.canvas-scroll { flex: 1; overflow: auto; position: relative; background: var(--bg0); }
.canvas-wrap { flex: 1; overflow: hidden; position: relative; background: var(--bg0); }
#sheet-canvas { display: block; image-rendering: pixelated; }
#editor-canvas, #preview-canvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }

.diffbar {
  position: absolute; left: var(--sp-2); bottom: var(--sp-2); background: rgba(20,20,24,.85);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--sp-1) var(--sp-3); font-size: 11px; line-height: var(--lh-control); color: var(--text-dim);
}
.diffbar b { color: var(--text); }

/* drop zone / empty state */
#dropzone {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg0); z-index: 5;
}
#dropzone.hidden { display: none; }
#dropzone.drag { outline: 3px dashed var(--accent); outline-offset: -14px; }
.drop-inner { text-align: center; color: var(--text-dim); }
.drop-inner h2 { color: var(--text); margin: var(--sp-2) 0 var(--sp-1); font-size: 16px; line-height: 1.3; font-weight: 600; }
.drop-icon { font-size: 42px; line-height: 1; color: var(--accent); }

/* ---------- timeline ---------- */
#timeline-panel {
  flex: 0 0 auto; background: var(--bg1); border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.tl-header {
  display: flex; gap: var(--gutter); align-items: center; padding: var(--sp-1) var(--gutter);
  font-size: 11px; line-height: var(--lh-control); color: var(--text-dim); border-bottom: 1px solid var(--line);
}
.tl-actions { margin-left: auto; display: flex; gap: var(--sp-1); align-items: center; }
#timeline {
  display: flex; gap: var(--sp-2); overflow-x: auto; padding: var(--sp-2) var(--gutter); min-height: 118px;
}
.thumb {
  flex: 0 0 auto; width: 132px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg2); cursor: pointer; position: relative; user-select: none;
}
.thumb.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.thumb.current::after {
  content: ""; position: absolute; top: -1px; left: -1px; right: -1px; height: 3px;
  background: var(--accent); border-radius: 2px;
}
.thumb.disabled { opacity: .4; }
.thumb canvas { display: block; width: 130px; height: 72px; border-radius: 5px 5px 0 0; }
.thumb .meta {
  display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-1) 6px;
  font-size: 10px; line-height: 14px; color: var(--text-dim);
}
.thumb .meta .n { font-weight: 700; color: var(--text); }
.thumb .meta input.dur { width: 44px; font-size: 10px; line-height: 12px; padding: 1px 3px; }
.thumb .flags { margin-left: auto; display: flex; gap: 3px; align-items: center; }
.thumb .warn { color: var(--danger); cursor: help; }
.thumb .score { font-size: 9px; color: var(--text-dim); }
.thumb .score.bad { color: var(--danger); }

/* ---------- busy / toast ---------- */
.busy {
  position: fixed; inset: 0; background: rgba(10,10,12,.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.busy[hidden], .toast[hidden] { display: none; }
.busy-box {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px;
  padding: var(--sp-4) 24px; display: flex; align-items: center; gap: var(--sp-3); font-size: 13px;
}
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 140px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--line); border-radius: var(--radius);
  padding: var(--sp-2) var(--sp-4); font-size: 12px; z-index: 60; max-width: 60%;
}
.toast.error { border-color: var(--danger); color: #f2b3b3; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }
