/* ===========================================================
   Qyrys Studio — design tokens
   Art direction: dark editing environment (photo tools live in
   low-light rooms), neutral graphite surfaces so image colours
   stay truthful, single teal accent for active state only.
   =========================================================== */
:root {
  --text-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.84rem + 0.15vw, 0.9375rem);
  --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1.05rem + 0.4vw, 1.25rem);
  --text-xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem; --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem; --space-10: 2.5rem;

  --radius-sm: 6px; --radius: 9px; --radius-lg: 14px;
  --font-body: 'Satoshi', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --rail-w: 56px;
  --side-w: 306px;
  --dur: 140ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

[data-theme='dark'] {
  --bg: oklch(0.19 0.006 250);
  --surface: oklch(0.235 0.007 250);
  --surface-2: oklch(0.275 0.008 250);
  --surface-3: oklch(0.32 0.009 250);
  --line: oklch(0.36 0.01 250);
  --line-soft: oklch(0.3 0.008 250);
  --text: oklch(0.94 0.004 250);
  --text-dim: oklch(0.73 0.008 250);
  --text-mute: oklch(0.6 0.01 250);
  --accent: oklch(0.72 0.13 185);
  --accent-ink: oklch(0.2 0.03 200);
  --danger: oklch(0.66 0.17 22);
  --stage: oklch(0.145 0.005 250);
  --shadow: 0 18px 44px oklch(0.1 0.01 250 / 0.55);
}

:root, [data-theme='light'] {
  --bg: oklch(0.965 0.003 250);
  --surface: oklch(0.995 0.001 250);
  --surface-2: oklch(0.945 0.004 250);
  --surface-3: oklch(0.9 0.006 250);
  --line: oklch(0.86 0.006 250);
  --line-soft: oklch(0.91 0.005 250);
  --text: oklch(0.24 0.01 250);
  --text-dim: oklch(0.44 0.012 250);
  --text-mute: oklch(0.57 0.012 250);
  --accent: oklch(0.6 0.12 185);
  --accent-ink: oklch(0.99 0.005 200);
  --danger: oklch(0.55 0.19 25);
  --stage: oklch(0.885 0.005 250);
  --shadow: 0 14px 34px oklch(0.5 0.02 250 / 0.16);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-sm);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
h2, h3 { margin: 0; font-weight: 700; }
button, input, select { font: inherit; color: inherit; }

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}
.spacer { flex: 1; }

/* ---------------- top bar ---------------- */
.topbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--space-2); padding-right: var(--space-2); }
.logo { width: 24px; height: 24px; color: var(--accent); }
.brand-name { font-weight: 700; letter-spacing: -0.01em; }
.brand-dim { color: var(--text-mute); font-weight: 500; }
.topbar-group { display: flex; align-items: center; gap: var(--space-1); }
.zoomgroup { background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 30px; padding: 0 var(--space-3);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); font-size: var(--text-xs); font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-quiet:hover { background: var(--surface-3); color: var(--text); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
.btn-primary:hover { filter: brightness(1.07); }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.icon-btn {
  display: grid; place-items: center;
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid transparent; cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn.sm { width: 26px; height: 26px; }
.icon-btn:hover { background: var(--surface-3); }
.icon-btn.danger:hover { background: color-mix(in oklch, var(--danger) 22%, transparent); color: var(--danger); }
.icon-btn svg, .rail-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn[disabled] { opacity: 0.35; pointer-events: none; }
.readout { font-family: var(--font-mono); font-size: var(--text-xs); min-width: 48px; text-align: center; color: var(--text-dim); }

/* ---------------- options bar ---------------- */
.optionsbar {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  min-height: 44px;
}
.tool-label { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-mute); }
.opt-fields { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.opt {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-xs); color: var(--text-dim);
}
.opt input[type='range'] { width: 96px; }
.opt input[type='number'], .opt input[type='text'], .opt select {
  height: 26px; background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 0 var(--space-2); font-size: var(--text-xs);
}
.opt input[type='text'] { width: 170px; }
.opt input[type='number'] { width: 62px; }
.opt b { font-family: var(--font-mono); color: var(--text); font-weight: 500; min-width: 30px; display: inline-block; }
.opt-check { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.swatches { display: flex; align-items: center; gap: var(--space-3); }
.color-field { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-dim); cursor: pointer; }
input[type='color'] {
  width: 30px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: none; cursor: pointer;
}

input[type='range'] {
  -webkit-appearance: none; appearance: none; height: 4px; border-radius: 999px;
  background: var(--surface-3); cursor: pointer;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line);
}
input[type='range']::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--text);
  border: 3px solid var(--surface); box-shadow: 0 0 0 1px var(--line);
}

/* ---------------- main ---------------- */
.main { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--side-w); min-height: 0; }

.rail {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--space-2) 0;
  background: var(--surface); border-right: 1px solid var(--line);
  overflow-y: auto;
}
.rail-btn {
  position: relative; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid transparent; color: var(--text-dim); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.rail-btn:hover { background: var(--surface-2); color: var(--text); }
.rail-btn[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }
.rail-btn .kbd {
  position: absolute; right: 3px; bottom: 1px; font-family: var(--font-mono);
  font-size: 9px; opacity: 0.55;
}
.rail-sep { width: 24px; height: 1px; background: var(--line); margin: var(--space-2) 0; }

/* ---------------- stage ---------------- */
.stage {
  position: relative; overflow: hidden; background: var(--stage);
  display: grid; place-items: center;
  background-image: radial-gradient(oklch(0.5 0.01 250 / 0.16) 1px, transparent 1px);
  background-size: 22px 22px;
}
.canvas-wrap {
  position: relative; box-shadow: var(--shadow); transform-origin: 0 0;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #d4d4d4 25%, transparent 25%, transparent 75%, #d4d4d4 75%),
    linear-gradient(45deg, #d4d4d4 25%, transparent 25%, transparent 75%, #d4d4d4 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
}
.canvas-wrap canvas { display: block; position: absolute; inset: 0; image-rendering: auto; }
.canvas-wrap #view { position: relative; }
#overlay { pointer-events: none; }
.stage.pixelated .canvas-wrap canvas { image-rendering: pixelated; }
.stage-hint {
  position: absolute; bottom: var(--space-4); left: 50%; transform: translateX(-50%);
  font-size: var(--text-xs); color: var(--text-mute);
  background: color-mix(in oklch, var(--surface) 80%, transparent);
  border: 1px solid var(--line-soft); border-radius: 999px; padding: 6px var(--space-4);
  backdrop-filter: blur(6px); pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
.stage.dragover { outline: 2px dashed var(--accent); outline-offset: -8px; }

/* ---------------- side panels ---------------- */
.side {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto;
}
.panel { border-bottom: 1px solid var(--line); display: flex; flex-direction: column; flex: 0 0 auto; }
.panel-grow { flex: 1 1 auto; min-height: 210px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-2);
}
.panel-head h2 { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-mute); user-select: none; }
.panel-head h2:hover { color: var(--text); }
.caret { display: inline-block; font-size: 9px; transition: transform var(--dur) var(--ease); }
.panel.collapsed .caret { transform: rotate(-90deg); }
.panel.collapsed .panel-body,
.panel.collapsed .panel-foot,
.panel.collapsed .layer-props,
.panel.collapsed .layer-list,
.panel.collapsed .history-list { display: none; }
.panel.collapsed { min-height: 0; }
.panel-actions { display: flex; gap: 2px; }
.panel-body { padding: 0 var(--space-3) var(--space-3); display: grid; gap: var(--space-3); }
.panel-foot { padding: 0 var(--space-3) var(--space-3); }
.panel-foot .btn { width: 100%; justify-content: center; }

.mini { display: grid; gap: 5px; font-size: var(--text-xs); color: var(--text-dim); }
.mini > span { display: flex; justify-content: space-between; align-items: center; }
.mini b { font-family: var(--font-mono); font-weight: 500; color: var(--text); }
.mini input[type='number'], .mini input[type='text'], .mini select {
  height: 30px; background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 0 var(--space-2); width: 100%;
}
.adj-row { display: grid; gap: 4px; }
.adj-row .adj-head { display: flex; justify-content: space-between; font-size: var(--text-xs); color: var(--text-dim); }
.adj-row.changed .adj-head { color: var(--accent); }

.filters { grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.chip {
  height: 30px; border-radius: var(--radius-sm); background: var(--surface-2);
  border: 1px solid var(--line-soft); font-size: var(--text-xs); cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.chip:hover { background: var(--surface-3); }

.layer-props { padding: 0 var(--space-3) var(--space-3); display: grid; gap: var(--space-3); }
.layer-list { list-style: none; margin: 0; padding: 0 var(--space-2) var(--space-3); display: grid; gap: 4px; overflow-y: auto; }
.layer {
  display: grid; grid-template-columns: 22px 44px 1fr auto; align-items: center; gap: var(--space-2);
  padding: 5px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--surface-2); cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.layer:hover { background: var(--surface-3); }
.layer.active { border-color: var(--accent); background: color-mix(in oklch, var(--accent) 12%, var(--surface-2)); }
.layer .eye { display: grid; place-items: center; width: 22px; height: 22px; border: none; background: none; cursor: pointer; color: var(--text-dim); }
.layer .eye svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.layer.hidden-l { opacity: 0.45; }
.layer .thumb {
  width: 44px; height: 33px; border-radius: 4px; border: 1px solid var(--line);
  background-color: #fff;
  background-image: linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%), linear-gradient(45deg, #ddd 25%, transparent 25%, transparent 75%, #ddd 75%);
  background-size: 8px 8px; background-position: 0 0, 4px 4px;
  object-fit: contain;
}
.layer .lname { font-size: var(--text-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .lmeta { font-family: var(--font-mono); font-size: 10px; color: var(--text-mute); }
.layer .lname input { width: 100%; background: var(--surface); border: 1px solid var(--accent); border-radius: 4px; height: 22px; font-size: var(--text-xs); padding: 0 4px; }

.history-list { list-style: none; margin: 0; padding: 0 var(--space-3) var(--space-3); display: grid; gap: 2px; max-height: 148px; overflow-y: auto; }
.history-list li {
  font-size: var(--text-xs); color: var(--text-mute); padding: 4px var(--space-2);
  border-radius: 4px; cursor: pointer; display: flex; justify-content: space-between; gap: var(--space-2);
}
.history-list li:hover { background: var(--surface-2); color: var(--text); }
.history-list li.now { background: var(--surface-3); color: var(--text); }
.history-list li.future { opacity: 0.4; }
.history-list .hidx { font-family: var(--font-mono); font-size: 10px; }

/* ---------------- status bar ---------------- */
.statusbar {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--surface); border-top: 1px solid var(--line);
  font-size: var(--text-xs); color: var(--text-dim);
}
.statusbar .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--line); }
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-mute); }

/* ---------------- modals ---------------- */
.modal-back[hidden] { display: none; }
.modal-back {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: oklch(0.1 0.01 250 / 0.55); backdrop-filter: blur(3px); z-index: 40;
}
.modal {
  width: min(360px, 92vw); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: var(--space-5); box-shadow: var(--shadow);
  display: grid; gap: var(--space-4);
}
.modal h3 { font-size: var(--text-lg); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); }

.toast {
  position: fixed; bottom: var(--space-8); left: 50%; transform: translate(-50%, 8px);
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 8px var(--space-5); font-size: var(--text-xs);
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; z-index: 50;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1080px) {
  :root { --side-w: 260px; }
}
@media (max-width: 820px) {
  .main { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .side { position: absolute; right: 0; top: 0; bottom: 0; width: 280px; z-index: 20; box-shadow: var(--shadow); }
  .brand-name { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
