:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #111111;
  --ink-soft: #555555;
  --ink-mute: #999999;
  --line: #e7e7e3;
  --line-soft: #f0f0ec;
  --accent: #111111;
  --active: #111111;
  --active-ink: #ffffff;
  --slider-fill: #7c5cf2;
  --radius: 10px;
  --radius-sm: 6px;
  --lib-w: 260px;
  --ctl-w: 300px;
  --gap: 28px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 500 14px/1.4 "NHG-Medium", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: grid;
  grid-template-columns: var(--lib-w) 1fr var(--ctl-w);
  grid-template-rows: 100vh;
}

/* ───── Library (left sidebar) ───── */
.library {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  overflow: hidden;
}
.library-header { margin-bottom: 28px; }
.brand { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--ink-mute); margin-top: 2px; }
.tool-list { list-style: none; flex: 1; overflow-y: auto; margin: 0 -8px; padding: 0 8px; }
.tool-list li {
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s ease;
  margin-bottom: 2px;
}
.tool-list li:hover { background: var(--line-soft); }
.tool-list li.active { background: var(--active); color: var(--active-ink); }
.tool-list li .tool-name { font-size: 13px; font-weight: 500; }
.tool-list li .tool-desc { font-size: 11px; color: var(--ink-mute); margin-top: 3px; line-height: 1.4; }
.tool-list li.active .tool-desc { color: rgba(255,255,255,0.6); }
.library-footer {
  margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--ink-mute);
}
.library-footer a { color: inherit; text-decoration: none; }
.library-footer a:hover { color: var(--ink); }

/* ───── Stage (center canvas area) ───── */
.stage {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
}
.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px var(--gap);
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  min-height: 64px;
}

.ratio-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.ratio-pill {
  min-height: 30px; padding: 6px 12px;
  font: 500 11px/1 "NHG-Medium", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--line-soft); color: var(--ink-soft);
  border: none; border-radius: 100px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, color .15s;
}
.ratio-pill:hover { background: var(--line); color: var(--ink); }
.ratio-pill.active { background: var(--active); color: var(--active-ink); }
.ratio-pill svg { width: 11px; height: 11px; stroke: currentColor; stroke-width: 1.6; fill: none; }

.export-group { display: flex; align-items: center; gap: 8px; }
.select-min {
  font: 500 12px/1 "NHG-Medium", "Helvetica Neue", Helvetica, Arial, sans-serif;
  padding: 7px 24px 7px 10px;
  background: var(--line-soft) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path d='M2 4l3 3 3-3' stroke='%23555' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>") right 8px center no-repeat;
  border: none; border-radius: var(--radius-sm); color: var(--ink);
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
.select-min:hover { background-color: var(--line); }
.btn-primary {
  font: 500 12px/1 "NHG-Medium", "Helvetica Neue", Helvetica, Arial, sans-serif;
  padding: 9px 16px; background: var(--active); color: var(--active-ink);
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  transition: transform .1s ease, opacity .15s ease;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gap);
  overflow: hidden;
  position: relative;
}
.frame {
  position: relative;
  background: #1a1a1a;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 24px rgba(0,0,0,0.06);
  max-width: 100%;
  max-height: 100%;
}
.frame iframe {
  display: block;
  border: none;
  width: 100%;
  height: 100%;
  background: #1a1a1a;
}

/* ───── Controls (right sidebar) ───── */
.controls {
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.controls-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--line);
}
.controls-header h2 { font-size: 16px; font-weight: 500; letter-spacing: -0.005em; }
.controls-header p { font-size: 12px; color: var(--ink-mute); margin-top: 4px; line-height: 1.4; }
.controls-body { flex: 1; overflow-y: auto; padding: 20px 20px 24px; }

.ctrl-group { padding: 18px 0; border-bottom: 1px solid var(--line-soft); }
.ctrl-group:last-child { border-bottom: none; }
.ctrl-group h3 {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 500; color: var(--ink);
  margin-bottom: 16px;
}
.ctrl-group-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; color: var(--ink);
}
.ctrl-group-icon svg { width: 100%; height: 100%; }

.ctrl { margin-bottom: 16px; }
.ctrl:last-child { margin-bottom: 0; }
.ctrl-label-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; font-size: 13px;
}
.ctrl-label { color: var(--ink); font-size: 13px; }
.ctrl > .ctrl-label { display: block; margin-bottom: 10px; }
.ctrl-value {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Sliders */
.ctrl-slider-row {
  display: flex; align-items: center; gap: 12px;
}
.ctrl-slider-row input[type="range"] { flex: 1; min-width: 0; }
.ctrl-slider-row .ctrl-value {
  flex: 0 0 auto;
  min-width: 44px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
  text-align: center;
  background: var(--surface);
}
.ctrl input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px;
  background-color: var(--line);
  background-repeat: no-repeat;
  border-radius: 2px;
  outline: none;
}
.ctrl input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.04);
  cursor: pointer;
  border: none;
  transition: transform .1s ease;
}
.ctrl input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.08); }
.ctrl input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.04);
  cursor: pointer; border: none;
}

/* Color pickers — row of swatches */
.color-row { display: flex; flex-wrap: wrap; gap: 10px; }
.color-swatch {
  position: relative; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); cursor: pointer;
  overflow: hidden;
  transition: transform .1s ease;
}
.color-swatch:hover { transform: scale(1.05); }
.color-swatch input[type="color"] {
  position: absolute; inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px);
  border: none; padding: 0; background: transparent; cursor: pointer;
  opacity: 0;
}
.color-swatch-fill { position: absolute; inset: 0; border-radius: 50%; }
.color-swatch-label {
  position: absolute; top: calc(100% + 4px); left: 50%;
  transform: translateX(-50%);
  font-size: 10px; color: var(--ink-mute); white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity .15s ease;
}
.color-swatch:hover .color-swatch-label { opacity: 1; }

/* Toggles */
.toggle-row { display: flex; justify-content: space-between; align-items: center; }
.toggle-switch {
  position: relative; width: 32px; height: 18px;
  background: var(--line); border-radius: 100px; cursor: pointer;
  transition: background .15s ease;
}
.toggle-switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: left .15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle-switch.on { background: var(--ink); }
.toggle-switch.on::after { left: 16px; }
.toggle-switch input { position: absolute; opacity: 0; pointer-events: none; }

/* Dropdowns (cfg) */
.ctrl select {
  width: 100%;
  font: 500 12px/1 "NHG-Medium", "Helvetica Neue", Helvetica, Arial, sans-serif;
  padding: 8px 24px 8px 10px;
  background: var(--line-soft) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'><path d='M2 4l3 3 3-3' stroke='%23555' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>") right 8px center no-repeat;
  border: none; border-radius: var(--radius-sm); color: var(--ink);
  -webkit-appearance: none; appearance: none; cursor: pointer;
}

.empty-state {
  padding: 24px 20px; font-size: 12px; color: var(--ink-mute);
  text-align: center; line-height: 1.5;
}

/* ───── Responsive ───── */
@media (max-width: 1100px) {
  body { grid-template-columns: 220px 1fr 260px; }
}
@media (max-width: 840px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
  }
  .library {
    flex-direction: row; align-items: center;
    padding: 12px 16px; border-right: none; border-bottom: 1px solid var(--line);
    overflow-x: auto;
  }
  .library-header { margin-bottom: 0; margin-right: 16px; flex-shrink: 0; }
  .brand { font-size: 15px; }
  .brand-sub { display: none; }
  .tool-list { display: flex; gap: 6px; margin: 0; padding: 0; overflow-x: auto; }
  .tool-list li { flex-shrink: 0; padding: 8px 12px; margin-bottom: 0; }
  .tool-list li .tool-desc { display: none; }
  .library-footer { display: none; }
  .controls { border-left: none; border-top: 1px solid var(--line); max-height: 40vh; }
  .controls-header { padding: 12px 16px; }
  .controls-body { padding: 4px 16px 16px; }
}
