/* PX·STUDIO — dark studio theme */
:root {
  --bg: #16181d;
  --bg2: #1c1f26;
  --bg3: #232733;
  --line: #2a2e37;
  --text: #c9ceda;
  --dim: #7c8494;
  --accent: #f0a35e;
  --accent-dim: rgba(240, 163, 94, 0.16);
  --danger: #e5636a;
  --radius: 6px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
}

body { display: flex; flex-direction: column; height: 100vh; }

.hidden { display: none !important; }
.spacer { flex: 1; }
.dim { color: var(--dim); }

canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

.checker {
  background-image: conic-gradient(#33363f 25%, #262931 0 50%, #33363f 0 75%, #262931 0);
  background-size: 16px 16px;
}

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand {
  font-family: var(--mono);
  font-weight: 700; font-size: 13px; letter-spacing: 1px;
  color: var(--accent);
  user-select: none;
}
#project-name {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 8px; width: 150px; font-family: var(--mono); font-size: 12px;
}
#project-name:focus { outline: 1px solid var(--accent); }
#dirty-dot { color: var(--accent); font-size: 10px; visibility: hidden; }
#dirty-dot.on { visibility: visible; }

.hgroup { display: flex; gap: 4px; }
.hbtn {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 5px 10px; font-size: 12px; cursor: pointer;
  transition: background 0.1s, transform 0.05s;
}
.hbtn:hover:not(:disabled) { background: #2b303c; border-color: #3a3f4c; }
.hbtn:active:not(:disabled) { transform: translateY(1px); }
.hbtn:disabled { opacity: 0.35; cursor: default; }
.hbtn.accent { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.hbtn.accent:hover { background: rgba(240, 163, 94, 0.28); }
#palette-toggle { display: none; }

/* ---------- main layout ---------- */
#main { display: flex; flex: 1; min-height: 0; }

/* toolbar */
#toolbar {
  flex: 0 0 auto;
  width: 108px;
  background: var(--bg2);
  border-right: 1px solid var(--line);
  padding: 8px 6px;
  display: flex; flex-direction: column; gap: 12px;
  overflow-y: auto;
}
.tgroup { display: flex; flex-direction: column; gap: 4px; }
.tlabel {
  font-family: var(--mono); font-size: 9px; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--dim); padding-left: 2px;
}
#tools { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 2px 4px; font-size: 13px; cursor: pointer;
  transition: background 0.1s, transform 0.05s;
}
.tool-btn span { font-size: 8px; font-family: var(--mono); color: var(--dim); letter-spacing: 0.5px; }
.tool-btn:hover { background: #2b303c; }
.tool-btn:active { transform: translateY(1px); }
.tool-btn.active { border-color: var(--accent); background: var(--accent-dim); }
.tool-btn.active span { color: var(--accent); }

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg-btn {
  flex: 1; background: var(--bg3); color: var(--dim);
  border: none; padding: 4px 2px; font-size: 11px; cursor: pointer;
  border-right: 1px solid var(--line);
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: #2b303c; color: var(--text); }
.seg-btn.active { background: var(--accent-dim); color: var(--accent); }

.tbtn {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 6px; font-size: 11px; cursor: pointer;
}
.tbtn:hover { background: #2b303c; }
.tbtn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.zrow { display: flex; gap: 4px; }
.zrow .tbtn { flex: 1; }

/* center / canvas */
#center { flex: 1; min-width: 0; display: flex; position: relative; }
#canvas-wrap {
  flex: 1; overflow: auto; display: grid; place-items: center;
  padding: 24px; position: relative;
}
#canvas { cursor: crosshair; box-shadow: 0 0 0 1px var(--line), 0 8px 32px rgba(0,0,0,0.45); }

#preview-panel {
  position: absolute; top: 12px; right: 12px;
  background: rgba(28, 31, 38, 0.92);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; display: flex; flex-direction: column; gap: 6px;
  pointer-events: none; z-index: 5;
}
.plabel { font-family: var(--mono); font-size: 9px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--dim); }
.prow { display: flex; align-items: center; gap: 8px; }
.prow span { font-family: var(--mono); font-size: 9px; color: var(--dim); width: 14px; }
.prow canvas { box-shadow: 0 0 0 1px var(--line); }

/* palette panel */
#palette-panel {
  flex: 0 0 auto; width: 216px;
  background: var(--bg2);
  border-left: 1px solid var(--line);
  padding: 10px; display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto;
}
.pp-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--mono); font-size: 11px; letter-spacing: 1.5px;
  text-transform: uppercase; color: var(--text);
}
.pp-head .dim { font-size: 10px; }
.pp-row select, .pp-edit input[type="text"], #ex-cols, #ex-scale {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 6px; font-size: 12px; font-family: var(--mono);
}
.pp-row select { width: 100%; }

#palette-warning {
  display: flex; align-items: center; gap: 6px;
  background: rgba(229, 99, 106, 0.12); border: 1px solid var(--danger);
  border-radius: var(--radius); padding: 5px 7px; font-size: 11px; color: var(--danger);
}

#swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.swatch {
  aspect-ratio: 1; border-radius: 4px; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.09);
  position: relative;
  transition: transform 0.06s;
}
.swatch:hover { transform: scale(1.12); z-index: 2; }
.swatch.active { outline: 2px solid var(--accent); outline-offset: 1px; z-index: 1; }
.swatch .rm {
  position: absolute; top: -5px; right: -5px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 9px; line-height: 14px;
  text-align: center; display: none; border: none; cursor: pointer; padding: 0;
}
.swatch:hover .rm { display: block; }
.swatch.dragging { opacity: 0.35; }

.pp-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#color-well {
  width: 34px; height: 28px; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg3); cursor: pointer;
}
#hex-input { width: 74px; }
.pp-edit-btns { display: flex; gap: 4px; }
.pp-row.btns { display: flex; gap: 6px; }

.mini-btn {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 9px; font-size: 11px; cursor: pointer;
  transition: background 0.1s, transform 0.05s;
}
.mini-btn:hover:not(:disabled) { background: #2b303c; }
.mini-btn:active:not(:disabled) { transform: translateY(1px); }
.mini-btn:disabled { opacity: 0.35; cursor: default; }
.mini-btn.accent { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* ---------- filmstrip ---------- */
#filmstrip-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border-top: 1px solid var(--line);
  padding: 6px 10px; min-height: 76px;
}
#filmstrip { display: flex; gap: 8px; overflow-x: auto; flex: 1; padding: 4px 2px; }
.frame-thumb {
  flex: 0 0 auto; cursor: pointer; text-align: center;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 3px; background: var(--bg3); position: relative;
  transition: border-color 0.1s, transform 0.06s;
}
.frame-thumb:hover { border-color: #3a3f4c; transform: translateY(-1px); }
.frame-thumb.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.frame-thumb canvas { display: block; width: 52px; height: 52px; }
.frame-thumb .fnum {
  font-family: var(--mono); font-size: 9px; color: var(--dim); display: block; padding-top: 2px;
}
.frame-thumb.active .fnum { color: var(--accent); }
.frame-thumb.dragging { opacity: 0.35; }
.fbtns { display: flex; flex-direction: column; gap: 4px; }

/* ---------- status bar ---------- */
#status-bar {
  flex: 0 0 auto;
  display: flex; gap: 16px; align-items: center;
  padding: 4px 12px;
  background: var(--bg2); border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px; color: var(--dim);
}
#st-color { display: flex; align-items: center; gap: 5px; }
#st-color-chip {
  width: 11px; height: 11px; border-radius: 3px; display: inline-block;
  border: 1px solid rgba(255,255,255,0.2);
}

/* ---------- dialogs ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 11, 14, 0.65);
  display: flex; align-items: center; justify-content: center;
}
.dialog {
  background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px;
  min-width: 340px; max-width: 92vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.55);
  display: flex; flex-direction: column; gap: 12px;
  max-height: 90vh; overflow-y: auto;
}
.dtitle { font-family: var(--mono); font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--accent); }
.drow { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.drow.end { justify-content: flex-end; }
.dlabel { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); }
.drow label { display: flex; align-items: center; gap: 4px; font-size: 12px; cursor: pointer; }
#ex-cols { width: 52px; }
#ex-preview { max-width: 420px; max-height: 260px; box-shadow: 0 0 0 1px var(--line); }
#pal-export-preview {
  width: 100%; background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-family: var(--mono); font-size: 11px; padding: 6px;
}
#help-grid {
  display: grid; grid-template-columns: auto 1fr; gap: 5px 16px; font-size: 12px;
}
#help-grid span:nth-child(odd) {
  font-family: var(--mono); color: var(--accent); font-size: 11px;
}

/* ---------- toasts ---------- */
#toasts {
  position: fixed; bottom: 40px; right: 14px; z-index: 200;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
}
.toast {
  background: var(--bg3); border: 1px solid var(--accent);
  color: var(--text); border-radius: var(--radius);
  padding: 7px 12px; font-size: 12px;
  animation: toast-in 0.15s ease-out;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}
.toast.fade { opacity: 0; transition: opacity 0.3s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #palette-toggle { display: block; }
  #palette-panel {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 90;
    width: 240px; transform: translateX(100%);
    transition: transform 0.18s ease;
    box-shadow: -12px 0 32px rgba(0,0,0,0.5);
  }
  #palette-panel.open { transform: translateX(0); }
  #drawer-scrim { position: fixed; inset: 0; z-index: 80; background: rgba(10,11,14,0.5); }
  #toolbar { width: 88px; }
  .hbtn { padding: 5px 7px; }
  #project-name { width: 90px; }
  .brand { display: none; }
}
@media (max-width: 480px) {
  #toolbar { width: 64px; padding: 6px 4px; }
  #tools { grid-template-columns: 1fr; }
  .tool-btn span { display: none; }
  #btn-import-png, #btn-new { display: none; }
  #topbar { flex-wrap: wrap; row-gap: 4px; }
  #project-name { width: 76px; }
  .seg { flex-direction: column; }
  .seg-btn { border-right: none; border-bottom: 1px solid var(--line); }
  .seg-btn:last-child { border-bottom: none; }
  .zrow { flex-direction: column; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
