:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --ink: #2b2622;
  --muted: #7a7068;
  --line: #e6dfd6;
  --accent: #d97b4a;
  --accent-ink: #ffffff;
  --accent-soft: #fbeadf;
  --ok: #2f8a57;
  --ok-soft: #e3f3ea;
  --warn: #b26a00;
  --warn-soft: #fff3dc;
  --bad: #c0392b;
  --bad-soft: #fde6e3;
  --viewer: #efe9e1;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #1c1a18;
    --panel: #262320;
    --ink: #eee7df;
    --muted: #a39a90;
    --line: #3a3530;
    --accent: #e8915f;
    --accent-ink: #1c1a18;
    --accent-soft: #3d2a1f;
    --ok: #5cc28a;
    --ok-soft: #1f3328;
    --warn: #f0b04a;
    --warn-soft: #3a2f1a;
    --bad: #f07a6c;
    --bad-soft: #3d2220;
    --viewer: #211f1c;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #1c1a18;
  --panel: #262320;
  --ink: #eee7df;
  --muted: #a39a90;
  --line: #3a3530;
  --accent: #e8915f;
  --accent-ink: #1c1a18;
  --accent-soft: #3d2a1f;
  --ok: #5cc28a;
  --ok-soft: #1f3328;
  --warn: #f0b04a;
  --warn-soft: #3a2f1a;
  --bad: #f07a6c;
  --bad-soft: #3d2220;
  --viewer: #211f1c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  position: relative; /* anchors the footer just below the app on desktop */
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.brand svg { width: 28px; height: 28px; }
.brand h1 { margin: 0; font-size: 18px; color: var(--ink); letter-spacing: 0.01em; }
.preset { display: flex; align-items: center; gap: 8px; color: var(--muted); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 300px;
  min-height: 0;
}
.panel {
  overflow-y: auto;
  padding: 12px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
.panel.side { border-right: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }

.viewer { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#canvas-wrap { position: relative; flex: 1; min-height: 320px; background: var(--viewer); }
#canvas-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.view-tools {
  position: absolute; left: 10px; top: 10px; display: flex; gap: 8px; flex-wrap: wrap;
}
.view-tools label, .view-tools button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; color: var(--ink); display: flex; align-items: center; gap: 6px;
}
.busy {
  position: absolute; right: 10px; top: 10px; background: var(--accent); color: var(--accent-ink);
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.summary {
  display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 10px 16px; border-top: 1px solid var(--line);
  background: var(--panel); font-size: 13px;
}
.summary b { font-variant-numeric: tabular-nums; }
.summary span { color: var(--muted); }

details.section { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; background: var(--panel); }
details.section > summary {
  cursor: pointer; list-style: none; padding: 10px 12px; font-weight: 650; display: flex; justify-content: space-between; align-items: center;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::after { content: '▾'; color: var(--muted); transition: transform 0.15s; }
details.section:not([open]) > summary::after { transform: rotate(-90deg); }
.section-body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.field > span em { font-style: normal; color: var(--muted); opacity: 0.8; }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check > span { color: var(--ink); font-size: 13px; }
.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-row input[type='range'] { flex: 1; accent-color: var(--accent); min-width: 0; }
.slider-row input[type='number'] { width: 72px; }
input[type='number'], input[type='text'], select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 7px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type='checkbox'] { accent-color: var(--accent); width: 16px; height: 16px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; border: 0; border-right: 1px solid var(--line); background: var(--bg); color: var(--ink);
  padding: 6px 4px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.shapes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.shapes button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 2px 4px; cursor: pointer;
  color: var(--ink); font: inherit; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.shapes button svg { width: 30px; height: 30px; }
.shapes button[aria-pressed='true'] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }

.hint { font-size: 12px; color: var(--muted); margin: 0; }
.hint.file-name { margin-top: 6px; overflow-wrap: anywhere; }
.note { font-size: 12px; padding: 6px 8px; border-radius: 6px; background: var(--accent-soft); }
.note.warn { background: var(--warn-soft); color: var(--warn); }
.note.ok { background: var(--ok-soft); color: var(--ok); }

.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.card h2 { margin: 0; font-size: 14px; }
.buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.buttons button {
  flex: 1 1 auto; font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); cursor: pointer; font-weight: 600;
}
.buttons.small button { font-size: 12px; padding: 6px 8px; font-weight: 500; }
.buttons button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.buttons button:disabled { opacity: 0.5; cursor: progress; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

ul.tips { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
ul.tips li.warn { color: var(--warn); }
ul.tips li.bad { color: var(--bad); }
.analysis h3 { margin: 4px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.analysis .small { margin: 0; font-size: 12px; }
.analysis .muted { color: var(--muted); }
ul.findings { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
ul.findings li { padding: 6px 8px; border-radius: 6px; border-left: 3px solid var(--line); background: var(--bg); }
ul.findings li.warn { border-left-color: var(--warn); background: var(--warn-soft); }
ul.findings li.bad { border-left-color: var(--bad); background: var(--bad-soft); }
ul.findings button.fix {
  margin-left: 6px; font: inherit; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  border: 1px solid currentColor; background: var(--panel); color: var(--ink); cursor: pointer;
}
ul.findings button.fix:hover { background: var(--accent-soft); }
table.kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.kv td { padding: 2px 0; }
table.kv td:last-child { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 10;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr); }
  .panel.side { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; }
  .panel.side .card { flex: 1 1 260px; }
}
@media (max-width: 720px) {
  body { height: auto; }
  .layout { display: flex; flex-direction: column; }
  .viewer { order: -1; }
  #canvas-wrap { height: 55vh; flex: none; }
  .panel { border-right: 0; overflow: visible; }
  .panel.side { flex-direction: column; }
  .panel.side .card { flex: none; } /* in a column, the 260px basis above would become a height */
}

/* trademark / affiliation note under the app. On desktop the app fills the
   window, so the footer sits just below it (scroll to see it) and never takes
   height from the viewer or panels; on phones it follows the page content. */
.site-footer {
  position: absolute; top: 100%; left: 0; right: 0;
  padding: 6px 16px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}
.site-footer p { margin: 0; max-width: 960px; margin-inline: auto; }
@media (max-width: 720px) {
  .site-footer { position: static; }
}

[hidden] { display: none !important; }

/* undo / redo */
.top-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.history { display: flex; gap: 6px; }
.history button {
  display: flex; align-items: center; gap: 5px; font: inherit; font-size: 13px; padding: 5px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); cursor: pointer;
}
.history button svg { width: 16px; height: 16px; }
.history button:disabled { opacity: 0.4; cursor: default; }

/* 3D / compartments tabs */
.viewer-tabs { margin: 8px auto; width: min(420px, calc(100% - 32px)); background: var(--panel); }

/* compartment (top view) editor */
.layout-view { position: absolute; inset: 0; z-index: 2; background: var(--viewer); display: flex; flex-direction: column; }
.layout-view svg { flex: 1; width: 100%; min-height: 0; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.layout-bar { display: flex; align-items: center; gap: 12px; padding: 8px 12px; flex-wrap: wrap; }
.layout-bar button {
  display: flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--ink); cursor: pointer;
}
.layout-bar button svg { width: 16px; height: 16px; }
.lv-wall { fill: var(--basket, var(--accent)); stroke: var(--muted); stroke-width: 1; }
.lv-floor { fill: var(--panel); }
.lv-cell { fill: var(--bg); stroke: var(--line); stroke-width: 1; }
.lv-cell.active { fill: var(--accent-soft); }
.lv-divider { fill: var(--basket, var(--accent)); stroke: var(--muted); stroke-width: 0.75; pointer-events: none; }
.lv-hit { fill: transparent; }
.lv-hit.x { cursor: ew-resize; }
.lv-hit.y { cursor: ns-resize; }
.lv-hit:hover + .lv-divider, .lv-divider.dragging { fill: var(--ink); }
.lv-handle { fill: var(--viewer); stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 2; }
.lv-text { fill: var(--muted); font: 600 12px/1 ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-variant-numeric: tabular-nums; }
.lv-size { cursor: text; }
.lv-size:hover { fill: var(--accent); }
.lv-caption { fill: var(--muted); font: 12px system-ui, sans-serif; }
.lv-btn { cursor: pointer; opacity: 0; pointer-events: none; transition: opacity 0.12s; }
.lv-btn.show { opacity: 1; pointer-events: auto; }
.lv-btn circle { fill: var(--ink); }
.lv-btn path { stroke: var(--bg); stroke-width: 2.4; stroke-linecap: round; fill: none; }
.lv-btn.minus circle { fill: var(--bad); }
.lv-btn circle.dot { fill: var(--bg); }
.lv-btn:hover circle:not(.dot), .lv-btn:focus-visible circle:not(.dot) { fill: var(--accent); }
.lv-btn:focus { outline: none; }
.lv-hit:focus { outline: none; }
.lv-hit:focus-visible { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
.lv-size:focus { outline: none; }
.lv-size:focus-visible { fill: var(--accent); text-decoration: underline; }
@media (hover: none) {
  .lv-btn { opacity: 0.85; pointer-events: auto; }
}
.lv-edit {
  position: absolute; width: 76px; transform: translate(-50%, -50%); z-index: 3; text-align: center;
  font: 600 13px ui-monospace, Menlo, Consolas, monospace;
}
.field-action button {
  font: inherit; font-size: 13px; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent-soft); color: var(--ink); cursor: pointer; font-weight: 600; width: 100%;
}
.field.inline input { flex: 1; min-width: 0; margin-left: 10px; }

/* colour picker */
.color-field { display: flex; flex-direction: column; gap: 10px; }
.swatches { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatches button {
  aspect-ratio: 1; min-width: 0; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; padding: 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatches button[aria-pressed='true'] { outline: 2px solid var(--accent); outline-offset: 2px; }
.color-custom { display: flex; align-items: center; gap: 10px; }
.color-custom input[type='color'] {
  width: 44px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); cursor: pointer;
}
.color-custom .hex, .rgb label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.color-custom .hex input { width: 90px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.rgb { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.rgb input { width: 100%; min-width: 0; }

/* Sub-headings inside a section (e.g. each colour) */
.subhead { font-size: 12px; font-weight: 600; color: var(--muted, inherit); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.subhead[hidden] { display: none; }

/* Colour pickers per part: each button shows its colour */
.seg.colorpick button::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: -1px;
  background: var(--sw, #ccc);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.seg button[hidden] { display: none; }
.seg { flex-wrap: wrap; }
.field input[type='text'] { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }

/* Links between the Basket Maker and the Tube Maker. */
.app-switch {
  margin-left: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 12.5px; font-weight: 600; color: var(--accent); text-decoration: none; white-space: nowrap;
}
.app-switch:hover { background: var(--accent-soft); }
button.snap { font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); cursor: pointer; }
input[type='color'] { width: 44px; height: 28px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
