:root {
  --ground: #f2f3f0; --panel: #ffffff; --panel-2: #fbfbf9; --ink: #1c2330; --ink-2: #3b4558; --muted: #566074;
  --line: #d9dcd4; --line-2: #b9bea3; --seg-bg: #e6e8e1;
  --accent: #34469a; --accent-ink: #ffffff; --focus: #34469a;
  --ok-bg: #ddf1e8; --ok-ink: #14543f; --ok-bd: #8cc5ae; --ok-card: #e3f3ec; --ok-card-ink: #0f3f2f;
  --warn-bg: #fff1dc; --warn-ink: #7a4700; --warn-bd: #e1b565; --warn-card-ink: #4d2d00;
  --danger-bg: #fbe3df; --danger-ink: #8e2b15; --danger-bd: #e5a69b;
  --role-base: #27366b; --role-anchored: #1f8179; --role-lifting: #b87400; --role-free: #b0316f;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0f131a; --panel: #171c26; --panel-2: #131822; --ink: #e6e9ef; --ink-2: #c3cad6; --muted: #9aa4b5;
    --line: #2a3242; --line-2: #3a4458; --seg-bg: #222a38;
    --accent: #8fa6f5; --accent-ink: #0f131a; --focus: #8fa6f5;
    --ok-bg: #173a2d; --ok-ink: #8fdcb9; --ok-bd: #2f6b55; --ok-card: #14302a; --ok-card-ink: #b7ead2;
    --warn-bg: #3a2c12; --warn-ink: #ffcf85; --warn-bd: #7a5a1f; --warn-card-ink: #ffe2b3;
    --danger-bg: #3d1c18; --danger-ink: #ffb4a6; --danger-bd: #7a3a30;
    --role-base: #8fa6f5; --role-anchored: #4fc3b8; --role-lifting: #e8b04a; --role-free: #f07ab0;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font: 14.5px/1.45 'Instrument Sans', system-ui, 'Segoe UI', sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, .file-link:focus-within {
  outline: 3px solid var(--focus); outline-offset: 2px;
}
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 13px; } .strong { font-weight: 600; }
.eyebrow { margin: 0 0 10px; font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h1, h2 { margin: 0; }
.title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap; min-height: 60px; padding: 8px 24px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); }
.sep { width: 1px; height: 24px; background: var(--line); }
.docname input {
  min-height: 44px; padding: 0 12px; border: 1px solid transparent; border-radius: 8px; background: transparent;
  color: var(--ink); font: inherit; font-weight: 500; width: 220px; max-width: 100%;
}
.docname input:hover { border-color: var(--line); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.icon-btn {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
}
.icon-btn:disabled { color: var(--muted); opacity: 0.55; }
.btn {
  min-height: 44px; padding: 0 16px; display: inline-flex; align-items: center; gap: 8px; font-weight: 600;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:disabled { opacity: 0.5; }
.export-size { font-weight: 500; opacity: 0.85; }

/* layout */
.app { display: flex; flex-wrap: wrap; align-items: stretch; min-height: calc(100% - 61px); }
.designs { flex: 0 0 300px; padding: 20px; display: flex; flex-direction: column; gap: 24px; border-right: 1px solid var(--line); }
.stage { flex: 999 1 520px; min-width: 0; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.settings {
  flex: 1 1 380px; max-width: 420px; padding: 20px; display: flex; flex-direction: column; gap: 22px;
  border-left: 1px solid var(--line); background: var(--panel-2);
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

/* designs */
.tile {
  width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; padding: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.tile.selected { border: 2px solid var(--accent); padding: 11px; }
.tile-thumb { flex: none; background: var(--ground); border-radius: 8px; }
.tile-text { display: flex; flex-direction: column; gap: 2px; }
.tile-title { font-weight: 700; font-size: 16px; }
.tile-sub { font-size: 13.5px; color: var(--muted); }
.placeholder-tile { margin-top: 10px; padding: 14px; border: 1.5px dashed var(--line-2); border-radius: var(--radius); font-size: 13.5px; color: var(--muted); }
.printer-card { display: flex; flex-direction: column; gap: 12px; }
.printer-name { font-weight: 700; font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.chip.ok { background: var(--ok-bg); color: var(--ok-ink); }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.link {
  align-self: flex-start; min-height: 44px; padding: 0 4px; background: transparent; border: 0;
  color: var(--accent); font-weight: 600; text-decoration: underline; display: inline-flex; align-items: center;
}

/* stage */
.stage-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.seg { display: inline-flex; background: var(--seg-bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  min-height: 38px; padding: 0 16px; border: 0; border-radius: 8px; background: transparent; font-weight: 600; color: var(--ink-2);
}
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18); }
.seg.two { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
.seg.two button { min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.25; padding: 6px 10px; }
.seg.two.compact button { min-height: 44px; }
.seg-main { font-weight: 700; } .seg-sub { font-size: 13px; opacity: 0.85; font-weight: 500; }
.seg button.planned, .seg button:disabled { border: 1px dashed var(--line-2); color: var(--muted); background: transparent; box-shadow: none; }
.layers { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill {
  min-height: 38px; padding: 0 14px; border-radius: 999px; font-weight: 600; background: var(--panel); border: 1.5px solid var(--line-2);
}
.pill[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.canvas-wrap {
  position: relative; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2); overflow: hidden;
  min-height: 360px; flex: 1 1 420px; display: flex;
}
.preview { flex: 1; min-height: 360px; }
.canvas-wrap.dimmed .preview { opacity: 0.45; }
.canvas-note, .busy-chip {
  position: absolute; top: 12px; left: 14px; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-bd);
}
.busy-chip { left: auto; right: 14px; background: var(--panel); color: var(--muted); border-color: var(--line); }
.roles { position: absolute; left: 12px; bottom: 12px; display: flex; flex-wrap: wrap; gap: 8px; max-width: calc(100% - 24px); }
.role-chip {
  min-height: 36px; padding: 0 12px; display: inline-flex; align-items: center; gap: 8px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; background: var(--panel); border: 1.5px solid var(--line);
}
.role-chip[aria-pressed="false"] { color: var(--muted); }
.role-chip[aria-pressed="false"] .swatch { opacity: 0.25; }
.swatch { display: inline-block; width: 22px; border-radius: 3px; }
.thickness-note { position: absolute; left: 14px; bottom: 60px; max-width: calc(100% - 28px); font-size: 12.5px; color: var(--muted); background: color-mix(in srgb, var(--panel-2) 88%, transparent); padding: 2px 6px; border-radius: 6px; }
.playback { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding: 8px 14px; }
.play { width: 44px; height: 44px; flex: none; border-radius: 999px; border: 0; background: var(--accent); color: var(--accent-ink); display: inline-flex; align-items: center; justify-content: center; }
.scrub { flex: 1 1 200px; display: flex; flex-direction: column; }
input[type="range"] { width: 100%; height: 28px; margin: 0; accent-color: var(--accent); }
.time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 130px; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-weight: 500; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 20px; padding: 2px 4px; }
.status .fit { color: var(--ok-ink); font-weight: 600; }
.status .link { margin-left: auto; }
.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.details[hidden] { display: none; }
.details .k { font-size: 13px; color: var(--muted); }
.details .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.details .note { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }

/* settings */
.errors { padding: 12px 14px; border-radius: var(--radius); background: var(--danger-bg); color: var(--danger-ink); border: 1px solid var(--danger-bd); display: flex; flex-direction: column; gap: 4px; }
.errors[hidden], .canvas-note[hidden], .busy-chip[hidden], .thickness-note[hidden], .toast[hidden] { display: none; }
.verdict { border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; border: 1px solid var(--line); background: var(--panel); }
.verdict.heads-up { background: var(--warn-bg); border-color: var(--warn-bd); color: var(--warn-card-ink); }
.verdict.ok { background: var(--ok-card); border-color: var(--ok-bd); color: var(--ok-card-ink); }
.verdict .v-title { font-weight: 700; font-size: 16px; }
.verdict p { margin: 0; }
.verdict .v-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.verdict .v-btn { min-height: 44px; padding: 0 16px; border-radius: 8px; font-weight: 600; background: var(--accent); color: var(--accent-ink); border: 1.5px solid var(--accent); }
.verdict .v-btn.ghost { background: transparent; color: inherit; border-color: currentColor; }
.verdict .v-why { min-height: 44px; padding: 0 6px; background: transparent; border: 0; text-decoration: underline; font-weight: 600; color: inherit; }
.verdict .v-explain { font-size: 14px; }
.custom-size summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--accent); }
.custom-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 8px; }
.field-row { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
.field-row.stacked { margin: 12px 0; }
.field-row input, .field-row select {
  min-height: 44px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); color: var(--ink); font: inherit; width: 100%;
}
.field-row input[aria-invalid="true"] { border-color: var(--danger-ink); box-shadow: 0 0 0 1px var(--danger-ink); }
.field-row input[type="checkbox"] { min-height: 0; width: 22px; height: 22px; accent-color: var(--accent); }
.field-row.inline { grid-template-columns: 1fr auto; align-items: center; }
.field-error { margin: 0; color: var(--danger-ink); font-size: 13.5px; font-weight: 600; }
.field-error[hidden] { display: none; }
.sliders { display: flex; flex-direction: column; gap: 16px; }
.slider .row-top, .room-row .row-top { display: flex; justify-content: space-between; align-items: center; }
.slider .label, .room-row .label { font-weight: 600; }
.slider .value, .room-row .value { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.slider .ends { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.room-row { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }

/* Swatch direct inputs & presets */
.swatch-direct-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.swatch-dim-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.swatch-dim-box span {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.swatch-dim-box input {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  width: 100%;
}
.swatch-times {
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  margin-top: 16px;
}
.swatch-presets {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}
.swatch-presets button {
  flex: 1;
  min-height: 32px;
  padding: 0 8px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink-2);
  transition: all 0.15s;
}
.swatch-presets button:hover {
  border-color: var(--accent);
}
.swatch-presets button.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* Tooltips, number inputs, and link constraints */
.label-with-tip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.info-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--seg-bg);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  user-select: none;
}
.info-tip:hover {
  background: var(--accent);
  color: var(--accent-ink);
}
.input-val-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.num-input {
  width: 68px;
  min-height: 32px;
  padding: 2px 6px;
  font-size: 13.5px;
  font-weight: 700;
  text-align: right;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
}
.num-input:focus {
  border-color: var(--accent);
  outline: none;
}
.unit-tag {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
.link-constraint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--accent) 7%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: 8px;
  margin: -4px 0 4px;
}
.link-constraint-row .check {
  min-height: auto;
  font-size: 13px;
}
.readout-text {
  font-weight: 600;
  color: var(--ink-2);
}
.disclosure {
  width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: space-between; background: transparent; border: 0;
  border-top: 1px solid var(--line); padding: 0; font-weight: 700; font-size: 15px;
}
.disclosure svg { transition: transform 0.15s; }
.disclosure[aria-expanded="true"] svg { transform: rotate(180deg); }
.adv-group { border-top: 1px solid var(--seg-bg); padding: 12px 0; }
.adv-group h3 { margin: 0; font-size: 15px; }
.adv-group .hint { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.adv-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.adv-fields .field-row.wide { grid-column: 1 / -1; }
.adv-actions { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.file-link { cursor: pointer; }
.file-link input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; padding: 10px 16px;
  border-radius: 10px; background: var(--ink); color: var(--ground); font-weight: 600; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); max-width: 440px; width: calc(100% - 32px); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { font-size: 20px; margin-bottom: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 12px; }

/* dropzone & image uploads */
.dropzone {
  border: 1.5px dashed var(--line-2);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  background: var(--panel);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, background-color 0.15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, var(--panel));
}
.dropzone svg { color: var(--accent); }

@media (max-width: 900px) {
  .app { flex-direction: column; flex-wrap: nowrap; padding-bottom: 84px; }
  .stage { order: 1; padding: 12px 16px; }
  .settings { order: 2; max-width: none; border-left: 0; border-top: 1px solid var(--line); }
  .designs { order: 3; flex: none; border-right: 0; border-top: 1px solid var(--line); }
  .canvas-wrap, .preview { min-height: 300px; }
  .layers { margin-left: 0; }
  .docname input { width: 150px; }
  #btn-export {
    position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 30; justify-content: center; min-height: 52px; font-size: 16px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  }
  .adv-fields { grid-template-columns: 1fr; }
  .canvas-wrap { flex-direction: column; }
  .roles { position: static; padding: 8px 10px 10px; max-width: none; }
  .role-chip { min-height: 40px; }
  .thickness-note { position: static; padding: 0 12px 8px; background: transparent; }
  .canvas-note, .busy-chip { top: 8px; }
}

/* desktop: a fixed-height studio, each column scrolls on its own */
@media (min-width: 901px) {
  body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
  .app { flex: 1 1 auto; min-height: 0; flex-wrap: nowrap; }
  .designs, .stage, .settings { overflow-y: auto; min-height: 0; }
  .canvas-wrap { min-height: 320px; }
  .preview { min-height: 320px; }
}
