:root {
  --blue: #3a7bd5;
  --blue-2: #5ba3e6;
  --wash: #f0f7ff;
  --ink: #2c3e50;
  --muted: #5f6f81;
  --line: #d6e2f0;
  --card: #ffffff;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: #2f855a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(44, 62, 80, 0.08), 0 4px 14px rgba(44, 62, 80, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--wash);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-size: 14px; line-height: 1.45; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 13px; margin: 16px 0 8px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
p { margin: 8px 0; }
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 12.5px; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* buttons */
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  box-shadow: 0 1px 1px rgba(44, 62, 80, 0.05);
}
.btn:hover:not(:disabled) { border-color: var(--blue-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #2f6bc0; }
.btn.ghost { background: transparent; border-color: transparent; color: #fff; }
.btn.ghost:hover { border-color: rgba(255, 255, 255, 0.4); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.icon-btn {
  border: 1px solid transparent; background: transparent; border-radius: 6px; min-width: 30px; height: 30px; cursor: pointer; font-size: 16px;
}
.icon-btn:hover:not(:disabled) { background: rgba(58, 123, 213, 0.12); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn.small { min-width: 26px; height: 26px; font-size: 13px; }
.icon-btn.danger { color: var(--danger); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.row.tight { gap: 2px; margin: 0; }
.row.end { justify-content: flex-end; }
.stack { display: grid; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate-card { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 32px; max-width: 460px; width: 100%; }
.gate-card .btn { margin-top: 8px; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; white-space: nowrap; }
.brand.large { font-size: 22px; color: var(--ink); margin-bottom: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: url(assets/icon.svg) center / cover no-repeat; flex: none; }

/* shell */
.shell { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--ink); color: #fff;
}
.title-group { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.design-name {
  flex: 0 1 360px; min-width: 120px; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff; border-radius: 7px; padding: 6px 10px;
}
.design-name:focus { background: rgba(255, 255, 255, 0.16); }
.save-state { font-size: 12.5px; color: #c9daf0; white-space: nowrap; }
.save-state[data-state="error"], .save-state[data-state="conflict"] { color: #ffb4a8; }
.save-state[data-state="saving"], .save-state[data-state="dirty"] { color: #ffe29a; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.top-actions .icon-btn { color: #fff; }
.top-actions .icon-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.14); }
.user { color: #c9daf0; font-size: 12.5px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-left: 8px; }
.conflict {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 16px; background: #fff4e5; border-bottom: 1px solid #f3d19c;
}
.layout { flex: 1; display: grid; grid-template-columns: 230px minmax(0, 1fr) 370px; min-height: 0; }

/* sidebar */
.sidebar { border-right: 1px solid var(--line); background: #f7fbff; overflow: auto; padding: 12px; }
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.design-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.design-list li { display: flex; align-items: center; border-radius: 8px; }
.design-list li.active { background: var(--card); box-shadow: var(--shadow); }
.design-list li.empty { color: var(--muted); padding: 8px; }
.design-link { flex: 1; min-width: 0; display: grid; padding: 7px 9px; text-decoration: none; color: inherit; }
.design-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.design-time { font-size: 12px; color: var(--muted); }
.row-actions { display: flex; padding-right: 4px; }

/* stage */
.stage { display: flex; flex-direction: column; min-width: 0; overflow: auto; padding: 14px 18px; gap: 12px; }
.view-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.segmented { display: inline-flex; background: #e3edf8; border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 3px rgba(44, 62, 80, 0.18); font-weight: 600; }
.segmented.small button { padding: 4px 10px; font-size: 13px; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.canvas {
  background: #1c2230; border-radius: 12px; box-shadow: var(--shadow); padding: 18px; min-height: 260px;
  display: grid; place-items: center; touch-action: none; user-select: none;
}
.canvas svg { width: 100%; height: auto; max-height: 62vh; display: block; }
.canvas.free { cursor: crosshair; }
.canvas .loading { color: #c9daf0; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 12px; display: grid; min-width: 130px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-weight: 650; font-size: 15px; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.checks li { background: var(--card); border-radius: 8px; padding: 8px 10px; border-left: 4px solid var(--blue-2); }
.checks .check-error { border-left-color: var(--danger); }
.checks .check-warning { border-left-color: var(--warn); }
.checks .check-ok { border-left-color: var(--ok); }
.check-level { font-size: 11px; text-transform: uppercase; font-weight: 700; margin-right: 8px; color: var(--muted); }

/* preview svg */
.preview .trim { stroke: #9aa8b8; stroke-width: 0.25; }
.preview .guide-window { stroke: #2ec5d3; stroke-width: 0.3; }
.preview .guide-safe { stroke: #e05bd0; stroke-width: 0.25; stroke-dasharray: 1.2 0.8; }
.preview .guide-leds rect { fill: #ffd166; }
.preview .guide-label { font-size: 2.2px; fill: #ffd166; font-family: inherit; }
.preview .sel-box { stroke: var(--blue-2); stroke-width: 0.35; stroke-dasharray: 1 0.7; }
.preview .sel-handle { fill: #fff; stroke: var(--blue); stroke-width: 0.35; cursor: nwse-resize; }
.preview .cap-crown { fill: #22324d; }
.preview .cap-night .cap-crown { fill: #0b1220; }
.preview .cap-brim { fill: #1a2740; }
.preview .cap-night .cap-brim { fill: #080d18; }
.preview .cap-seam { stroke: rgba(255, 255, 255, 0.12); stroke-width: 0.5; }
.preview .cap-button { fill: #1a2740; }
.preview .light.fx-breathe { animation: fx-breathe 4s ease-in-out infinite; }
.preview .light.fx-pulse { animation: fx-pulse 1.2s ease-in-out infinite; }
@keyframes fx-breathe { 0%, 100% { opacity: 0.15; } 50% { opacity: 1; } }
@keyframes fx-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .preview .light { animation: none !important; } }

/* inspector */
.inspector { border-left: 1px solid var(--line); background: #f7fbff; display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: 0; background: transparent; padding: 8px 11px; white-space: nowrap; border-radius: 8px 8px 0 0; cursor: pointer; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 -1px 0 var(--line) inset; }
.panel { overflow: auto; padding: 4px 14px 24px; }
.field { display: grid; gap: 4px; margin: 10px 0; }
.field-label { font-size: 12.5px; font-weight: 600; display: flex; justify-content: space-between; }
.field input[type="text"], .field input[type="number"], .field select {
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: var(--card); width: 100%;
}
.field input[type="text"] { letter-spacing: 0.04em; }
.slider input { width: 100%; accent-color: var(--blue); }
.slider output { font-weight: 500; color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin: 12px 0; }
.card h3 { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.template-btn {
  display: grid; text-align: left; gap: 2px; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 10px; cursor: pointer;
}
.template-btn span { font-size: 12px; color: var(--muted); }
.template-btn[aria-checked="true"] { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(58, 123, 213, 0.25); }
.element-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.element-row { width: 100%; text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 7px; padding: 6px 9px; cursor: pointer; }
.element-row.selected { border-color: var(--blue); background: #eaf3ff; }
.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.logo-tile-wrap { position: relative; display: grid; gap: 3px; justify-items: center; }
.logo-tile {
  width: 100%; aspect-ratio: 1; border: 1px solid var(--line); background: #0f1522; color: #f0f7ff; border-radius: 9px; padding: 6px; cursor: pointer;
}
.logo-tile svg { width: 100%; height: 100%; display: block; }
.logo-tile[aria-pressed="true"] { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(58, 123, 213, 0.45); }
.tile-label { font-size: 11.5px; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-delete { position: absolute; top: -6px; right: -6px; background: var(--card); box-shadow: var(--shadow); }
.pattern-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.pattern-add { display: grid; gap: 4px; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px; cursor: pointer; font-size: 12.5px; }
.pattern-add:disabled { opacity: 0.45; cursor: not-allowed; }
.pattern-thumb svg { width: 100%; height: auto; display: block; border-radius: 4px; }
.facts { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; text-align: right; }
.steps { padding-left: 18px; margin: 0; }
.steps li { margin: 4px 0; }

/* dialogs */
.dialog { border: 0; border-radius: 14px; box-shadow: 0 20px 60px rgba(20, 30, 50, 0.35); padding: 20px 22px; width: min(640px, 94vw); color: var(--ink); }
.dialog::backdrop { background: rgba(20, 30, 50, 0.45); }
.confirm-dialog { width: min(420px, 94vw); }
.starter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 14px 0; }
.starter { display: grid; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px; cursor: pointer; font-weight: 550; }
.starter[aria-checked="true"] { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(58, 123, 213, 0.3); }
.starter-thumb { background: #1c2230; border-radius: 7px; padding: 4px; }
.starter-thumb svg { width: 100%; height: auto; display: block; }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 16px; margin: 12px 0; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--blue); background: var(--wash); }
.upload-previews { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.upload-original, .upload-traced { display: grid; gap: 6px; align-content: start; }
.upload-original img { max-width: 100%; max-height: 220px; object-fit: contain; background: repeating-conic-gradient(#eef3f9 0% 25%, #fff 0% 50%) 50% / 16px 16px; border-radius: 8px; }
.upload-traced .shape { background: #0f1522; color: #f0f7ff; border-radius: 8px; padding: 10px; }
.upload-traced .shape svg { width: 100%; max-height: 200px; display: block; }
.trace-controls { margin-top: 8px; }

/* toasts */
.toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 20; }
.toast { display: flex; gap: 10px; align-items: center; background: var(--ink); color: #fff; padding: 9px 12px; border-radius: 9px; box-shadow: var(--shadow); max-width: 420px; }
.toast-error { background: var(--danger); }
.toast .icon-btn { color: #fff; }

/* narrow screens */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 210px minmax(0, 1fr); }
  .inspector { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .shell { height: auto; min-height: 100vh; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 30vh; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .title-group { order: 3; flex-basis: 100%; }
  .design-name { flex: 1; }
  .user { display: none; }
  .stage { padding: 10px; }
  .canvas { padding: 8px; min-height: 180px; }
  .upload-previews { grid-template-columns: 1fr; }
}
