/* Line-art → SVG POC — compact, neutral UI. No external fonts or libraries. */
:root {
  --bg: #f2f2ef;
  --panel: #ffffff;
  --sunken: #f7f7f4;
  --line: #e3e3dd;
  --line-strong: #cbcbc3;
  --text: #1b1c1f;
  --muted: #6b6f77;
  --accent: #1f4fd6;
  --accent-soft: #e9eefc;
  --ink: #16171a;
  --ink-text: #ffffff;
  --warn: #a15c07;
  --warn-soft: #fdf4e4;
  --err: #b42318;
  --err-soft: #fdeceb;
  --ok: #1b7f3b;
  --radius: 8px;
  --panel-w: 340px;
  --frame-h: clamp(220px, 44vh, 640px);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --panel: #1c1d20;
    --sunken: #232428;
    --line: #2d2f33;
    --line-strong: #3d4046;
    --text: #e8e8e6;
    --muted: #9a9ea6;
    --accent: #7d9cff;
    --accent-soft: #232b45;
    --ink: #e8e8e6;
    --ink-text: #141517;
    --warn: #f0b252;
    --warn-soft: #3a2d17;
    --err: #ff8a80;
    --err-soft: #3b1d1b;
    --ok: #6fd18f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h2, h3 { margin: 0; font-size: 11px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  height: 48px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 2.4; stroke-linejoin: round; }
.brand strong { font-size: 15px; letter-spacing: -.01em; white-space: nowrap; }
.tagline { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.health { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.health .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.health.ok .dot { background: var(--ok); }
.health.warn .dot { background: var(--warn); }
.health.down .dot { background: var(--err); }

/* ---------------------------------------------------------------- layout */
.layout { display: grid; grid-template-columns: var(--panel-w) minmax(0, 1fr); height: calc(100vh - 48px); }
.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.main { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.block { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.block-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hint { margin: 0; font-size: 12px; color: var(--muted); }
.hint.warn { color: var(--warn); }

details.block > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
details.block > summary::-webkit-details-marker { display: none; }
details.block > summary::after { content: "▾"; color: var(--muted); font-size: 12px; transition: transform .15s; }
details.block:not([open]) > summary::after { transform: rotate(-90deg); }

/* ---------------------------------------------------------------- dropzone */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 104px; padding: 14px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius); background: var(--sunken);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-title { font-weight: 750; letter-spacing: .1em; font-size: 14px; }
.dz-sub { font-size: 12px; color: var(--muted); }
.dz-file { margin-top: 6px; font-size: 12px; font-family: var(--mono); color: var(--text); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- inputs */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 12px; color: var(--muted); }
select, input[type="number"] {
  width: 100%; height: 32px; padding: 0 8px; font: inherit; color: var(--text);
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 6px;
}
select:focus, input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.unit { position: relative; display: block; }
.unit input { padding-right: 34px; font-variant-numeric: tabular-nums; }
.unit em { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 12px; color: var(--muted); pointer-events: none; }
.readout { height: 32px; display: flex; align-items: center; padding: 0 8px; border-radius: 6px; background: var(--sunken); font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; user-select: none; }
.check input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); }

.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 7px; overflow: hidden; background: var(--panel); }
.seg button {
  flex: 1; height: 32px; border: 0; border-right: 1px solid var(--line); background: transparent;
  font: inherit; font-size: 13px; color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--sunken); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--ink-text); font-weight: 600; }
.swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px rgba(255,255,255,.6); }

.badge { font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); }

.sliders { display: flex; flex-direction: column; gap: 12px; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.slider-head label { font-size: 13px; }
.slider-head label small { color: var(--muted); font-size: 11.5px; margin-left: 4px; }
.slider-head output { font-family: var(--mono); font-size: 12px; min-width: 34px; text-align: right; padding: 1px 6px; border-radius: 4px; background: var(--sunken); }
.slider-head output.changed { background: var(--warn-soft); color: var(--warn); }
input[type="range"] { width: 100%; margin: 4px 0 0; accent-color: var(--accent); }

/* ---------------------------------------------------------------- generate */
.actions-block { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); border-bottom: 0; margin-top: -1px; }
.btn-primary {
  height: 48px; border: 0; border-radius: var(--radius); cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-size: 15px; font-weight: 750; letter-spacing: .12em;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: filter .15s, opacity .15s;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary .spinner { display: none; border-color: rgba(255,255,255,.35); border-top-color: #fff; }
.btn-primary.busy .spinner { display: inline-block; }
.kbd { font-size: 11px; color: var(--muted); font-family: var(--mono); }

.spinner {
  width: 18px; height: 18px; border-radius: 50%; display: inline-block;
  border: 2.5px solid rgba(0,0,0,.15); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- alerts */
.alert {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius); background: var(--err-soft); color: var(--err);
  border: 1px solid color-mix(in srgb, var(--err) 30%, transparent); font-size: 13px;
}
.alert button { border: 0; background: none; color: inherit; font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }

/* ---------------------------------------------------------------- previews */
.previews { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.card { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card figcaption {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 12px;
  font-size: 11px; font-weight: 700; letter-spacing: .1em; border-bottom: 1px solid var(--line);
}
.card .meta { font-weight: 450; letter-spacing: 0; color: var(--muted); font-family: var(--mono); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.frame {
  position: relative; display: flex; align-items: center; justify-content: center; height: var(--frame-h);
  background: #fff; padding: 10px; cursor: zoom-in; overflow: hidden;
}
.frame:not([href]) { cursor: default; }
.frame img { max-width: 100%; max-height: 100%; object-fit: contain; transition: opacity .2s; }
#cardVector .frame img { width: 100%; height: 100%; }
.frame .empty { color: #8a8d93; font-size: 13px; }
.busy-overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(255,255,255,.35); }
.card.busy .busy-overlay { display: flex; }
.card.busy img { opacity: .45; }

/* ---------------------------------------------------------------- toolbar */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn {
  height: 34px; padding: 0 14px; display: inline-flex; align-items: center; border-radius: 7px;
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--text);
  text-decoration: none; font-weight: 600; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--text); }
.btn-dark { background: var(--ink); color: var(--ink-text); border-color: var(--ink); }
.btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.summary { margin-left: auto; font-size: 12px; color: var(--muted); font-family: var(--mono); }

/* ---------------------------------------------------------------- stats / history */
.bottom { display: grid; grid-template-columns: minmax(250px, 1fr) minmax(230px, .9fr) minmax(360px, 1.6fr); gap: 12px; align-items: start; }
.panel-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
.kv td { padding: 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.kv tr:last-child td { border-bottom: 0; }
.kv td:last-child { text-align: right; font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.kv tr.group td { padding-top: 10px; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border-bottom: 0; font-family: inherit; text-align: left; }
.kv tr.warn td:last-child { color: var(--warn); font-weight: 650; }
.kv tr.good td:last-child { color: var(--ok); }

.timings { display: flex; flex-direction: column; gap: 7px; }
.t-row { display: grid; grid-template-columns: 108px 1fr 62px; align-items: center; gap: 8px; font-size: 12.5px; }
.t-bar { height: 8px; background: var(--sunken); border-radius: 4px; overflow: hidden; }
.t-bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; min-width: 2px; }
.t-row b { font-family: var(--mono); font-weight: 500; text-align: right; font-size: 12px; }
.t-row.total { border-top: 1px solid var(--line); padding-top: 7px; font-weight: 650; }
.t-row.total b { font-weight: 700; }

.table-scroll { overflow-x: auto; }
.history th { text-align: left; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 0 6px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.history td { padding: 5px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.history .num { text-align: right; font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.history tbody tr:not(.placeholder) { cursor: pointer; }
.history tbody tr:not(.placeholder):hover { background: var(--sunken); }
.history tbody tr.active { background: var(--accent-soft); }
.history tbody tr.active td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.history .thumb { width: 34px; height: 26px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 3px; display: block; }
.history .placeholder td { white-space: normal; padding: 8px 6px; }
.op-tag { display: inline-flex; align-items: center; gap: 5px; }
.link-btn { border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; padding: 0; }
.link-btn:hover { color: var(--text); text-decoration: underline; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1280px) {
  .bottom { grid-template-columns: 1fr 1fr; }
  .history-card { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .main { overflow: visible; }
  .tagline { display: none; }
  .bottom { grid-template-columns: 1fr; }
  :root { --frame-h: clamp(220px, 60vw, 420px); }
}

/* v2: AI stylize step */
.prompt-box { margin: 0 0 8px; font-size: 12px; }
.prompt-box summary { cursor: pointer; color: var(--muted); margin-bottom: 6px; }
.prompt-box textarea {
  width: 100%; box-sizing: border-box; resize: vertical; font: 12px/1.4 var(--mono);
  padding: 8px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--panel); color: inherit;
}
#stylize { width: 100%; margin-bottom: 10px; display: inline-flex; justify-content: center; gap: 8px; }
#stylize .spinner { display: none; }
#stylize.busy .spinner { display: inline-block; }
.seg button:disabled { opacity: .45; cursor: not-allowed; }
