:root {
  --bg: #0a0d12;
  --panel: #11161e;
  --panel-2: #171d27;
  --line: #232b37;
  --line-2: #2e3846;
  --text: #e8edf3;
  --muted: #8a95a6;
  --accent: #38bdf8;
  --accent-ink: #04121c;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --danger: #f05252;
  --radius: 14px;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Barlow Condensed", "Inter", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 600px at 75% -10%, rgba(56, 189, 248, 0.08), transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font-ui);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg .fill { fill: currentColor; fill-opacity: 0.25; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 13, 18, 0.85);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 34px; height: 34px; color: var(--accent); stroke-width: 2; }
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-name { font: 800 24px/1 var(--font-display); letter-spacing: 0.16em; }
.brand-sub { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.top-actions { display: flex; gap: 8px; align-items: center; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line-2);
  background: var(--panel-2);
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { border-color: #3b4757; background: #1c2430; }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.primary {
  background: var(--accent); color: var(--accent-ink); border-color: transparent;
  font-family: var(--font-display); font-size: 16px; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 700;
}
.btn.primary:hover { background: #63ccfa; }

/* ---------- layout ---------- */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  padding: 20px 24px 28px;
  max-width: 1680px;
  margin: 0 auto;
  align-items: start;
}
.panel {
  background: linear-gradient(180deg, var(--panel), #0e131a);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  min-width: 0;
}
.preview-panel { position: sticky; top: 88px; }
.panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h2 { margin: 2px 0 0; font: 700 26px/1.05 var(--font-display); letter-spacing: 0.02em; text-transform: uppercase; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); }

/* ---------- switch ---------- */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--muted); font-size: 13px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 34px; height: 20px; border-radius: 99px; background: var(--line-2); position: relative; transition: background 0.15s; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #cfd6df; transition: transform 0.15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(14px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tool-group { display: flex; gap: 4px; padding: 4px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.tool {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 11px; border-radius: 8px;
  background: transparent; border: 0; color: var(--text); font-weight: 500; font-size: 13px;
  position: relative;
}
.tool:hover:not(:disabled) { background: #222b37; }
.tool:disabled { color: #4d5868; }
.tool.icon-only { width: 34px; padding: 0; justify-content: center; }
.tool.danger:hover:not(:disabled) { color: var(--danger); background: rgba(240, 82, 82, 0.1); }
.color-tool { cursor: pointer; }
.color-tool input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.swatch { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(255, 255, 255, 0.35); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }

/* ---------- selection properties ---------- */
.props {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 8px 12px; margin-bottom: 10px;
  border: 1px solid rgba(56, 189, 248, 0.35); background: var(--accent-soft); border-radius: 12px;
  font-size: 13px;
}
.props { min-height: 48px; }
.props.empty { border-color: var(--line); background: var(--panel-2); }
.props.empty > :not(.props-hint) { display: none !important; }
.props:not(.empty) .props-hint { display: none; }
.props-hint { color: var(--muted); font-size: 12.5px; }
.props-title { font-weight: 600; color: var(--accent); margin-right: 4px; }
.prop { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); }
.prop input[type="color"] { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line-2); border-radius: 6px; background: none; cursor: pointer; }
.prop input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.prop input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 4px; }
.prop select { height: 30px; background: var(--panel); border: 1px solid var(--line-2); border-radius: 7px; padding: 0 8px; color: var(--text); }
.prop input[type="range"] { width: 90px; accent-color: var(--accent); }
.props.is-shape .text-only { display: none; }
.prop-val { min-width: 34px; font-variant-numeric: tabular-nums; color: var(--text); font-size: 12px; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 4px 2px; }
.link-btn:hover { text-decoration: underline; }

/* ---------- design canvas ---------- */
.canvas-stage {
  background:
    linear-gradient(45deg, #151b24 25%, transparent 25%, transparent 75%, #151b24 75%),
    linear-gradient(45deg, #151b24 25%, transparent 25%, transparent 75%, #151b24 75%), #11161e;
  background-size: 20px 20px; background-position: 0 0, 10px 10px;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px;
}
.canvas-legend { display: flex; justify-content: space-between; gap: 8px; max-width: max(300px, calc(100vh - 400px)); margin: 0 auto 8px; font: 700 12px/1 var(--font-display); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.canvas-wrap { max-width: max(300px, calc(100vh - 400px)); margin: 0 auto; position: relative; width: 100%; aspect-ratio: 1 / 1; border-radius: 6px; overflow: hidden; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
.canvas-wrap .canvas-container { position: absolute !important; inset: 0; }
.guide { position: absolute; inset: 0; pointer-events: none; transition: opacity 0.2s; }
.guide.off { opacity: 0; }
.guide img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; }
.guide-lines { opacity: 0.32; mix-blend-mode: multiply; }
.guide-tag {
  position: absolute; transform: translate(-50%, -50%);
  font: 700 12px/1 var(--font-display); letter-spacing: 0.14em; text-transform: uppercase;
  color: #fff; background: rgba(10, 14, 20, 0.72); padding: 5px 8px; border-radius: 6px; white-space: nowrap;
}
.guide-tag.sub { font-size: 10px; background: rgba(10, 14, 20, 0.55); color: #c9d3df; }
.guide-tag.muted { color: #8a95a6; }

/* ---------- starters ---------- */
.starters { margin-bottom: 12px; }
.starter-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.starter {
  display: grid; grid-template-columns: 56px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center;
  text-align: left; padding: 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2);
  transition: border-color 0.15s, transform 0.15s;
}
.starter:hover { border-color: var(--accent); transform: translateY(-1px); }
.starter-art { grid-row: span 2; width: 56px; height: 44px; border-radius: 8px; display: grid; place-items: center; overflow: hidden; }
.starter-name { font: 700 17px/1.1 var(--font-display); letter-spacing: 0.04em; text-transform: uppercase; }
.starter-meta { font-size: 12px; color: var(--muted); }
.art-flames {
  background:
    radial-gradient(14px 26px at 18px 30px, #ffd400 40%, transparent 42%),
    radial-gradient(12px 30px at 30px 26px, #ff8a00 45%, transparent 47%),
    radial-gradient(16px 34px at 40px 34px, #ff3d00 45%, transparent 47%),
    #0d0d10;
}
.art-stripes { background: linear-gradient(90deg, #0b2545 0 30%, #fff 30% 36%, #d62839 36% 64%, #fff 64% 70%, #0b2545 70%); }
.art-number { background: #c8102e; }
.art-number b { font: 400 26px/1 "Graduate", var(--font-display); color: #fff; -webkit-text-stroke: 1px #0b1d3a; }

/* ---------- 3D viewer ---------- */
.seg { display: inline-flex; align-items: center; gap: 2px; padding: 3px; border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; }
.seg-label { font-size: 12px; color: var(--muted); padding: 0 8px 0 6px; }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 7px; font-size: 13px; font-weight: 500; color: var(--muted); }
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] { background: #263142; color: var(--text); }

.viewer {
  position: relative; width: 100%; aspect-ratio: 1 / 1; max-height: calc(100vh - 290px); min-height: 340px;
  border-radius: 12px; overflow: hidden; border: 1px solid var(--line);
  background: radial-gradient(70% 60% at 50% 38%, #3a4555 0%, #1b222c 55%, #0d1117 100%);
}
#three-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#three-canvas:active { cursor: grabbing; }
.viewer-status { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); background: rgba(13, 17, 23, 0.6); transition: opacity 0.3s; }
.viewer-status.hidden { opacity: 0; pointer-events: none; }
.viewer-status.error { color: #ffb4b4; }
.viewer-status.error .spinner { display: none; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.view-buttons {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  display: flex; gap: 2px; padding: 4px; border-radius: 12px;
  background: rgba(13, 17, 23, 0.75); border: 1px solid rgba(255, 255, 255, 0.08); backdrop-filter: blur(6px);
}
.view-buttons button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 8px;
  font: 700 14px/1 var(--font-display); letter-spacing: 0.1em; text-transform: uppercase; color: #c9d3df;
}
.view-buttons button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.view-buttons button.active { background: var(--accent); color: var(--accent-ink); }
.viewer-hint { position: absolute; top: 12px; left: 14px; font-size: 12px; color: rgba(232, 237, 243, 0.55); pointer-events: none; }

.outputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.out-card {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2);
  transition: border-color 0.15s, background 0.15s;
}
.out-card svg { width: 22px; height: 22px; color: var(--accent); }
.out-card b { display: block; font-weight: 600; }
.out-card small { color: var(--muted); font-size: 12px; }
.out-card:hover:not(:disabled) { border-color: var(--accent); background: #1a2230; }
.out-card:disabled { opacity: 0.5; }
.out-card.busy { opacity: 0.7; pointer-events: none; }

/* ---------- modals & toast ---------- */
.modal { border: 1px solid var(--line-2); border-radius: 16px; background: var(--panel); color: var(--text); padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); }
.modal.wide { width: min(980px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(4, 6, 10, 0.7); backdrop-filter: blur(3px); }
.modal-body { padding: 24px; }
.modal-body.center { text-align: center; }
.modal h3 { margin: 0 0 8px; font: 700 26px/1.1 var(--font-display); text-transform: uppercase; letter-spacing: 0.03em; }
.modal p { color: #c3ccd8; margin: 0 0 12px; }
.modal .fine, .fine { font-size: 12px; color: var(--muted); }
.modal .btn { margin-top: 8px; }
.check-badge { width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 14px; }
.check-badge svg { width: 30px; height: 30px; stroke-width: 2.6; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h3 { margin: 0; }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--line-2); background: transparent; display: grid; place-items: center; }
.icon-btn:hover { background: var(--panel-2); }
.preview-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.preview-grid figure { margin: 0; }
.preview-grid button { padding: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: none; display: block; width: 100%; }
.preview-grid button:hover { border-color: var(--accent); }
.preview-grid img { display: block; width: 100%; height: auto; }
.preview-grid figcaption { font: 700 14px/1 var(--font-display); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); margin-top: 8px; text-align: center; }
.modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #1f2835; border: 1px solid var(--line-2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(240, 82, 82, 0.6); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .preview-panel { position: static; order: -1; }
  .viewer { max-height: none; aspect-ratio: 4 / 3; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .brand-sub { display: none; }
  .btn.ghost span { display: none; }
  .btn.ghost { padding: 0 11px; }
  .btn.primary { padding: 0 12px; font-size: 14px; }
  .workspace { padding: 12px 16px 20px; gap: 14px; }
  .panel { padding: 14px; }
  .panel-head h2 { font-size: 22px; }
  .viewer { aspect-ratio: 1 / 1; min-height: 0; }
  .tool .tool-label { display: none; }
  .tool { padding: 0 9px; }
  .starter { grid-template-columns: 1fr; text-align: center; justify-items: center; row-gap: 4px; }
  .starter-art { grid-row: auto; width: 100%; }
  .starter-meta { display: none; }
  .starter-name { font-size: 14px; }
  .canvas-legend { font-size: 10px; }
  .outputs { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: 1fr; }
  .guide-tag { font-size: 9px; padding: 3px 5px; }
  .guide-tag.sub { font-size: 8px; }
  .view-buttons button { padding: 7px 10px; font-size: 13px; }
}
