@import url('tokens.css');

:root {
  /* Local names → shared primitives (app.css reuses some semantic names, so alias primitives) (css/tokens.css, generated from tokens/sb3d.tokens.json) */
  --canvas: var(--primitive-color-ink-950); --bg: var(--primitive-color-ink-900); --surface: var(--primitive-color-ink-850); --surface-2: var(--primitive-color-ink-800);
  --border: var(--primitive-color-ink-700); --ink: var(--primitive-color-ink-50); --ink-dim: var(--primitive-color-ink-400);
  --red: var(--primitive-color-red-500); --red-dim: var(--primitive-color-red-300); --red-bright: var(--primitive-color-red-400);
  --red-tint: rgba(239, 23, 70, .18); --green: var(--primitive-color-green-400);
  --gradient-brand: linear-gradient(120deg, var(--primitive-color-red-900) 0%, var(--primitive-color-red-500) 50%, var(--primitive-color-red-400) 100%);
  --gradient-brand-hover: linear-gradient(120deg, var(--primitive-color-red-500) 0%, var(--primitive-color-red-400) 50%, var(--primitive-color-red-300) 100%);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, .55), 0 2px 8px rgba(0, 0, 0, .35);
  --shadow-red: 0 10px 26px rgba(239, 23, 70, .32), 0 3px 10px rgba(255, 122, 48, .2);
  

  --color-primary: var(--surface-2);
  --color-accent: var(--red);
  --color-on-accent: #fff;
  --color-background: var(--bg);
  --color-foreground: var(--ink);
  --color-card: var(--surface);
  --color-muted: var(--border);
  --color-muted-foreground: var(--ink-dim);
  --color-border: #3a3445;
  --color-destructive: var(--red-bright);
  --color-ring: var(--red);
  --radius: 20px;
  --radius-sm: 13px;
  --panel-w: 380px;
  --font: 'Prompt', system-ui, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
::selection { background: var(--red-tint); color: var(--red-dim); }
body {
  background: var(--canvas);
  color: var(--color-foreground);
  font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--color-ring); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px; border-bottom: 1px solid var(--color-muted);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { width: 44px; height: 44px; object-fit: contain; }
.brand strong { display: block; font: 700 17px/1.2 var(--font); letter-spacing: -.01em; }
.brand span { font-size: 13px; color: var(--color-muted-foreground); }
.font-status { font-size: 13px; color: var(--color-muted-foreground); text-align: right; }
.font-status b { color: var(--red-dim); font-weight: 600; }

/* ---------- Layout ---------- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--panel-w) 1fr; }
.panel { min-width: 0; display: flex; flex-direction: column; min-height: 0; background: var(--color-card); border-right: 1px solid var(--color-muted); }
.panel-scroll { flex: 1; overflow-y: auto; padding: 8px 20px 20px; overscroll-behavior: contain; }
.viewport { position: relative; min-height: 0; overflow: hidden; background: radial-gradient(ellipse at 50% 30%, #1e1a25 0%, var(--canvas) 75%); }
.viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- Groups & fields ---------- */
.group { padding: 16px 0; border-bottom: 1px solid var(--color-muted); }
.group:last-child { border-bottom: 0; }
.group h2 { margin: 0 0 12px; font-size: 13px; font-weight: 600; letter-spacing: .04em; color: var(--color-muted-foreground); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 14px; font-weight: 500; }
.field small { color: var(--color-muted-foreground); font-weight: 400; }
.row { display: flex; gap: 8px; align-items: center; }
.row > select { flex: 1; min-width: 0; }

textarea, select, input[type=number] {
  width: 100%; background: var(--color-background); color: var(--color-foreground);
  border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  font: inherit; transition: border-color .15s var(--ease);
}
textarea { padding: 10px 12px; font-size: 20px; line-height: 1.6; resize: vertical; min-height: 88px; }
select { height: 44px; padding: 0 12px; cursor: pointer; }
textarea:hover, select:hover, input[type=number]:hover { border-color: var(--color-muted-foreground); }
textarea:focus, select:focus, input[type=number]:focus { border-color: var(--color-accent); outline: none; }

/* Slider rows */
.slider { display: grid; grid-template-columns: 1fr 92px; gap: 6px 12px; align-items: center; margin-bottom: 14px; }
.slider label { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 14px; font-weight: 500; }
.slider label small { color: var(--color-muted-foreground); font-weight: 400; }
.num { position: relative; }
.num input { height: 36px; padding: 0 30px 0 10px; text-align: right;  font-variant-numeric: tabular-nums; }
.num::after { content: attr(data-unit); position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 12px; color: var(--color-muted-foreground); pointer-events: none; }
input[type=range] { width: 100%; height: 28px; margin: 0; background: transparent; cursor: pointer; accent-color: var(--color-accent); }

/* Segmented control & chips */
.seg { display: flex; padding: 3px; gap: 3px; background: var(--color-background); border: 1px solid var(--color-muted); border-radius: 999px; margin-bottom: 14px; }
.seg button { flex: 1; min-height: 38px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chips button { min-height: 38px; padding: 0 14px; border: 1px solid var(--color-border); }
.seg button, .chips button {
  border: 0; border-radius: 999px; background: transparent; color: var(--color-muted-foreground);
  font: 500 14px var(--font); cursor: pointer; transition: background .15s var(--ease), color .15s var(--ease);
}
.chips button { border: 1px solid var(--color-border); }
.seg button:hover, .chips button:hover { color: var(--color-foreground); }
.seg button[aria-checked=true], .chips button[aria-checked=true] { background: var(--gradient-brand); box-shadow: var(--shadow-red); color: var(--color-on-accent); border-color: var(--color-accent); font-weight: 600; }

/* Switch */
.switch { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 14px; font-weight: 500; }
.switch input { appearance: none; width: 40px; height: 24px; border-radius: 999px; background: var(--color-muted); position: relative; cursor: pointer; transition: background .2s var(--ease); flex: none; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--color-foreground); transition: transform .2s var(--ease); }
.switch input:checked { background: var(--gradient-brand); }
.switch input:checked::after { transform: translateX(16px); }
.is-disabled { opacity: .4; pointer-events: none; }

/* Colors */
.colors { gap: 16px; }
.color { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.color input { width: 36px; height: 36px; padding: 0; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: none; cursor: pointer; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid transparent;
  font: 600 14px var(--font); cursor: pointer; white-space: nowrap;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--gradient-brand); color: #fff; box-shadow: var(--shadow-red); }
.btn-primary:hover { background: var(--gradient-brand-hover); box-shadow: var(--shadow-red-lg); }
.btn-ghost { background: transparent; color: var(--color-foreground); border-color: var(--color-border); }
.btn-ghost:hover { background: var(--color-muted); }
.btn-glass { background: rgba(12, 10, 16, .72); color: var(--color-foreground); border-color: rgba(148, 141, 163, .22); backdrop-filter: blur(8px); }
.btn-glass:hover { background: rgba(30, 26, 37, .92); }
.btn-icon { width: 44px; min-height: 44px; padding: 0; flex: none; }

/* ---------- Export dock ---------- */
.export-dock { position: relative; }
.export {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 40; width: 320px; display: grid; gap: 12px;
  padding: 14px; border: 1px solid var(--color-muted); border-radius: var(--radius); background: var(--color-card);
  box-shadow: var(--shadow-md, 0 20px 50px rgba(0, 0, 0, .55));
}
.export[hidden] { display: none; }
.export-group { display: grid; gap: 6px; }
.export h3 { margin: 0; font-size: 11px; font-weight: 600; letter-spacing: .04em; color: var(--color-muted-foreground); }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.export .btn { min-height: 40px; padding: 0 12px; font-size: 13px; justify-content: flex-start; gap: 8px; }
.export .btn.wide { grid-column: 1 / -1; }
.export .btn em { margin-left: auto; font-style: normal; font-size: 11px; opacity: .55; font-variant-numeric: tabular-nums; }

/* ---------- HUD ---------- */
.hud { position: absolute; z-index: 2; display: flex; gap: 6px; }
.hud-tl { top: 16px; left: 16px; }
.hud-tr { top: 16px; right: 16px; flex-wrap: wrap; justify-content: flex-end; }
.hud-bl { bottom: 16px; left: 16px; max-width: calc(100% - 32px); }
.hud-br { bottom: 16px; right: 16px; }
.dims { padding: 8px 14px; border-radius: 999px; background: rgba(12, 10, 16, .78); border: 1px solid rgba(148, 141, 163, .22); backdrop-filter: blur(8px); font: 600 14px var(--font); font-variant-numeric: tabular-nums; }
.dims span { color: var(--color-muted-foreground); font-weight: 400; }
.hint { font-size: 12px; color: var(--color-muted-foreground); }
#warn { padding: 8px 14px; border-radius: var(--radius); background: var(--red-tint); border: 1px solid var(--red); color: #ffd0da; font-size: 14px; }

.drop { position: fixed; inset: 12px; z-index: 10; display: grid; place-items: center; border: 2px dashed var(--color-accent); border-radius: 20px; background: rgba(5, 5, 8, .9); font-size: 22px; font-weight: 600; pointer-events: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  body { height: auto; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: min(62vh, 520px) auto; }
  .font-status { display: none; }
  .hud-tr { top: auto; bottom: 12px; right: 12px; left: 12px; justify-content: center; }
  .hud-tl { top: 12px; left: 12px; }
  .hud-bl { bottom: 64px; }
  .viewport { grid-row: 1; }
  .panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--color-muted); }
  .panel-scroll { overflow: visible; }
  .hint { display: none; }
  .topbar { padding: 10px 16px; }
  .panel-scroll { padding-left: 16px; padding-right: 16px; }
  .export { width: min(320px, calc(100vw - 32px)); }
}
@media (max-width: 420px) {
  .brand span { display: none; }
  .export { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; border: 3px solid var(--color-card); }
::-webkit-scrollbar-thumb:hover { background: var(--red); }
::-webkit-scrollbar-corner { background: transparent; }

/* ---------- Icons ---------- */
.ic { width: 18px; height: 18px; stroke-width: 1.8; }
.group h2 { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
.group h2 .ic { width: 28px; height: 28px; padding: 5px; border-radius: 9px; background: var(--red-tint); color: var(--red-bright); }
.lbl { display: inline-flex; align-items: center; gap: 7px; }
.lbl .ic { width: 16px; height: 16px; color: var(--ink-dim); }
.export h3 { display: flex; align-items: center; gap: 5px; }
.export h3 .ic { width: 15px; height: 15px; color: var(--red-dim); flex: none; }
.export .btn .ic { width: 16px; height: 16px; }
.btn-glass .ic { width: 17px; height: 17px; }
.hint { align-items: center; }
.hint .ic { width: 14px; height: 14px; }
#warn { align-items: center; gap: 8px; }
#warn .ic { color: var(--red-bright); }
.chips button { display: inline-flex; align-items: center; gap: 8px; }
.chips button::before { content: ''; width: 14px; height: 14px; border-radius: 50%; background: var(--sw); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }

/* ---------- Style picker ---------- */
.styles { display: grid; grid-template-columns: 1fr; gap: 6px; }
.styles button {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; row-gap: 2px; align-items: center;
  min-height: 60px; padding: 8px 12px; text-align: left; cursor: pointer;
  background: var(--bg); color: var(--ink); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; transition: border-color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
.styles button:hover { border-color: var(--ink-dim); }
.styles button > span { grid-row: 1 / 3; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--surface-2); color: var(--ink-dim); }
.styles button > span .ic { width: 20px; height: 20px; }
.styles strong { font-size: 14px; font-weight: 600; line-height: 1.3; }
.styles small { font-size: 12px; color: var(--ink-dim); line-height: 1.35; }
.styles button[aria-checked=true] { border-color: var(--red); background: linear-gradient(160deg, rgba(239, 23, 70, .16), rgba(239, 23, 70, .04)); box-shadow: 0 0 0 1px var(--red) inset, var(--shadow-red); }
.styles button[aria-checked=true] > span { background: var(--gradient-brand); color: #fff; }

/* ---------- Summary ---------- */
.notes { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 6px; }
.notes li { padding: 8px 12px; border-radius: var(--radius-sm); background: var(--bg); border: 1px solid var(--border); font-size: 13px; }
.sub { margin: 12px 0 6px; font-size: 13px; font-weight: 500; color: var(--ink-dim); }
.sub small { font-weight: 400; }
.steps { list-style: none; margin: 0 0 4px; padding: 0; display: grid; gap: 4px; counter-reset: s; }
.steps button { width: 100%; display: flex; gap: 10px; align-items: flex-start; padding: 8px; border: 1px solid transparent; border-radius: var(--radius-sm); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.steps button:hover { background: var(--surface-2); border-color: var(--border); }
.steps b { flex: none; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--gradient-brand); color: #fff; font-size: 12px; }
.steps strong { display: block; font-size: 13px; font-weight: 600; }
.steps small { display: block; font-size: 12px; color: var(--ink-dim); line-height: 1.45; }
.parts { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.parts li { display: flex; font-size: 13px; }
.parts .part { flex: 1; display: flex; align-items: center; gap: 8px; min-height: 30px; padding: 0 8px; border: 1px solid transparent; border-radius: var(--radius-sm); background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.parts .part:hover { background: var(--surface-2); }
.parts .part.on { border-color: var(--red); background: rgba(239, 23, 70, .12); }
.explode { display: flex; align-items: center; gap: 6px; padding: 0 10px; border-radius: 999px; background: rgba(18, 16, 23, .55); border: 1px solid var(--border); backdrop-filter: blur(8px); }
.explode .ic { width: 16px; height: 16px; color: var(--ink-dim); }
.explode input[type=range] { width: 96px; }
.parts li span { flex: 1; }
.parts b, .parts code { font-weight: 500; color: var(--ink-dim); font-variant-numeric: tabular-nums; font-family: inherit; font-size: 12px; }
.sw { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.sw-letter { background: var(--red); }
.sw-plate { background: #f1f5f9; }
.sw-acrylic { background: #fff; box-shadow: 0 0 8px rgba(255, 255, 255, .7); }
.sw-pin { background: #b8bec6; }

/* ---------- Night / warnings ---------- */
#nightBtn[aria-pressed=true] { background: var(--gradient-brand); border-color: transparent; box-shadow: var(--shadow-red); }
.viewport.is-night { background: radial-gradient(ellipse at 50% 40%, #121018 0%, #020203 75%); }
#warn { flex-direction: column; align-items: stretch; }
#warn > div { display: flex; align-items: center; gap: 8px; }

/* ---------- Layers ---------- */
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.group-head h2 { margin: 0; }
.btn-sm { min-height: 34px; padding: 0 10px; font-size: 13px; gap: 5px; }
.btn-sm .ic { width: 15px; height: 15px; }
.layer-list { list-style: none; margin: 0; padding: 4px; display: grid; gap: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 240px; overflow-y: auto; }
.layer-list li { display: flex; align-items: center; gap: 2px; min-height: 40px; padding: 0 4px 0 8px; border-radius: 9px; cursor: pointer; }
.layer-list li:hover { background: var(--surface-2); }
.layer-list li[aria-selected=true] { background: var(--red-tint); box-shadow: inset 0 0 0 1px rgba(239, 23, 70, .55); }
.layer-list li.is-hidden .ln, .layer-list li.is-hidden .lt { opacity: .4; }
.layer-list li.empty { cursor: default; color: var(--ink-dim); font-size: 13px; padding: 10px; }
.layer-list .lt { color: var(--red-dim); display: grid; place-items: center; width: 22px; }
.layer-list .lt .ic { width: 16px; height: 16px; }
.layer-list .ln { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; padding-left: 4px; }
.layer-list button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--ink-dim); cursor: pointer; }
.layer-list button:hover { background: var(--border); color: var(--ink); }
.layer-list button .ic { width: 15px; height: 15px; }
.layer-list button[data-act=del]:hover { color: var(--red-bright); }

.help { margin-top: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); font-size: 13px; }
.help summary { display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 12px; cursor: pointer; color: var(--ink-dim); list-style: none; }
.help summary::-webkit-details-marker { display: none; }
.help summary .ic { width: 15px; height: 15px; color: var(--red-dim); }
.help[open] summary { color: var(--ink); border-bottom: 1px solid var(--border); }
.help ul { margin: 0; padding: 10px 12px 12px 28px; display: grid; gap: 6px; line-height: 1.5; }
.help small { color: var(--ink-dim); }
.help-body { padding: 12px; display: grid; gap: 2px; }
.sub { margin: 4px 0 8px; font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--ink-dim); text-transform: none; }
.topbar .btn-sm[href] { flex: none; }
.topbar .btn-sm[href]:first-of-type { margin-left: auto; }
.tip { margin: 10px 0 0; font-size: 12px; color: var(--ink-dim); line-height: 1.6; }
.link { background: none; border: 0; padding: 0; color: var(--red-dim); font: inherit; text-decoration: underline; cursor: pointer; }

/* ---------- Layer properties ---------- */
#props h2 { color: var(--ink); }
#props h2 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#props textarea { font-size: 18px; min-height: 64px; }
.slider label small:empty { display: none; }
.xy { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 12px; }
.xy label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-dim); }
.align-row { display: flex; gap: 4px; justify-content: space-between; }
.align-row .btn-icon { width: 40px; min-height: 40px; border-radius: 10px; }
.align-row .btn-icon .ic { width: 18px; height: 18px; }
.note-warn { display: flex; gap: 8px; align-items: flex-start; margin: 0 0 8px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--red-tint); color: #ffd0da; font-size: 13px; }
.note-warn .ic { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.viewport.can-drag canvas { cursor: grab; }
.viewport.is-dragging canvas { cursor: grabbing; }
