:root {
  --bg: #f5efe4;
  --card: #fffcf6;
  --line: #e7dcc9;
  --ink: #2d2924;
  --muted: #7d7263;
  --field: #f4ecdf;
  --field-line: #e3d6c1;
  --accent: #1f6f63;
  --accent-ink: #185a50;
  --accent-soft: #e2efe9;
  --track: #3a3530;
  --warn: #9a4a12;
  --warn-bg: #fdf0e2;
  --warn-line: #f1d2b2;
  --info-bg: #f1f5f0;
  --info-line: #d7e5dd;
  --model: #e07b39;
  --dark: #1e1c19;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select { font: inherit; color: inherit; }

.top {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 30px; height: 30px; }
h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; }
.tagline { margin: 0; color: var(--muted); flex: 1; min-width: 200px; }
.local {
  font-size: 12px;
  color: var(--accent-ink);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 400px) minmax(0, 1fr);
  grid-template-areas: "controls preview";
  gap: 20px;
  padding: 20px 24px 32px;
  align-items: start;
}
.controls { grid-area: controls; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.preview {
  grid-area: preview;
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 96px);
  min-height: 520px;
  min-width: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgb(60 40 10 / 4%), 0 6px 18px rgb(60 40 10 / 5%);
}
.card > h2 {
  margin: 0;
  padding: 12px 16px;
  font-size: 12px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.intro { margin: 0; color: var(--muted); font-size: 13px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px 12px; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.off, .toggle.off { opacity: 0.45; }
.toggle.off { cursor: default; }
.field label, .label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
}
.tag {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
}
.num { position: relative; }
.num input {
  width: 100%;
  padding: 8px 38px 8px 10px;
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 9px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.num input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.unit {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}
.hint { font-size: 12px; color: var(--muted); min-height: 0; }
.hint.good { color: var(--accent-ink); }
.hint.bad { color: var(--warn); }
.hint button {
  border: 0;
  background: none;
  color: var(--accent-ink);
  text-decoration: underline;
  padding: 0 2px;
  cursor: pointer;
  font-size: 12px;
}

input[type="range"] {
  --pct: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 16px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--pct), var(--track) var(--pct));
}
input[type="range"]::-moz-range-track { height: 5px; border-radius: 3px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 5px; border-radius: 3px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
  box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
}
input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
  box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
}
input[type="range"]:disabled { cursor: default; }

.help {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--field-line);
  background: var(--field);
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1;
  cursor: help;
}
.help:hover::after, .help:focus::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 250px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--dark);
  color: #f7f1e6;
  font-size: 12px;
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  z-index: 20;
  box-shadow: 0 6px 20px rgb(0 0 0 / 25%);
}

select {
  width: 100%;
  padding: 8px 10px;
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 9px;
  font-size: 15px;
}
.preset-note { margin: -4px 0 0; font-size: 12.5px; color: var(--muted); }

.diagram {
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 10px;
  padding: 6px;
}
.diagram svg { display: block; width: 100%; height: auto; }
.diagram .dim { stroke: var(--muted); }
.diagram .dim.on { stroke: var(--accent); stroke-width: 2; }
.diagram .dimtag rect { fill: var(--muted); }
.diagram .dimtag.on rect { fill: var(--accent); }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile, .toggle {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--field-line);
  border-radius: 10px;
  background: var(--field);
  cursor: pointer;
}
.tile input, .toggle input { position: absolute; opacity: 0; pointer-events: none; }
.tile:has(input:checked), .toggle:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.tile:has(input:focus-visible), .toggle:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.tile b, .toggle b { display: block; font-size: 13.5px; }
.tile small, .toggle small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.tick {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border-radius: 5px;
  border: 1.5px solid var(--muted);
  background: var(--card);
}
.tile .tick { border-radius: 50%; }
.tile:has(input:checked) .tick, .toggle:has(input:checked) .tick {
  border-color: var(--accent);
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 8.5l2.5 2.5L12 5.5' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat;
}

details.more { border-top: 1px dashed var(--line); padding-top: 10px; }
details.more summary { cursor: pointer; color: var(--accent-ink); font-size: 13px; }
details.more[open] summary { margin-bottom: 12px; }

.buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--field-line);
  background: var(--field);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: wait; }
input[type="file"] { width: 100%; min-width: 0; font-size: 12px; }
details.more > .field, details.more > .buttons, details.more > .intro { margin-bottom: 12px; }
.tiles:has(input[name="mounting"]) { grid-template-columns: 1fr; }
.tiles:has(input[name="cap"]) { grid-template-columns: 1fr; }
.advanced > summary { padding: 14px 16px; cursor: pointer; color: var(--accent-ink); font-weight: 600; }
.advanced > section > h2 { margin: 0; padding: 12px 16px; font-size: 13px; border-top: 1px solid var(--line); }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  flex: 1 1 100%;
  padding: 11px 14px;
}
.btn.primary:hover { background: var(--accent-ink); }
.print-tip { margin: 0; font-size: 12.5px; color: var(--muted); }

.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button {
  border: 1px solid var(--field-line);
  background: var(--field);
  padding: 6px 13px;
  border-radius: 999px;
  cursor: pointer;
  color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--muted); font-size: 13px; }
.switch input { position: absolute; opacity: 0; }
.switch .knob {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--field-line);
  position: relative;
  transition: background 0.15s;
}
.switch .knob::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 25%);
  transition: transform 0.15s;
}
.switch input:checked + .knob { background: var(--accent); }
.switch input:checked + .knob::after { transform: translateX(14px); }
.switch input:focus-visible + .knob { outline: 2px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px 0; }
.chip {
  padding: 6px 11px;
  border-radius: 10px;
  background: var(--field);
  border: 1px solid var(--field-line);
  min-width: 0;
}
.chip span { display: block; font-size: 11.5px; color: var(--muted); }
.chip b { font-size: 14.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip.bad { background: var(--warn-bg); border-color: var(--warn-line); }
.chip.bad b { color: var(--warn); }

.notes { list-style: none; margin: 0; padding: 10px 14px 0; display: flex; flex-direction: column; gap: 6px; max-height: 170px; overflow-y: auto; flex-shrink: 0; }
.notes:empty { display: none; }
.notes li {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  background: var(--info-bg);
  border: 1px solid var(--info-line);
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.notes li.warn { background: var(--warn-bg); border-color: var(--warn-line); color: #6b3510; }
.notes li button {
  flex: none;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  border-radius: 8px;
  padding: 3px 9px;
  cursor: pointer;
  font-size: 12.5px;
}

.viewport {
  position: relative;
  flex: 1;
  min-height: 220px;
  margin: 12px 14px 0;
  border-radius: 12px;
  overflow: hidden;
  background: #efe6d7;
  border: 1px solid var(--line);
}
.viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.section-view { position: absolute; inset: 0; background: #fbf7f0; }
.section-view svg { width: 100%; height: 100%; display: block; }
.overlay {
  position: absolute;
  left: 12px;
  top: 10px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  max-width: calc(100% - 24px);
}
.overlay.dark { color: #d9d0c2; }
.section-tools {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgb(255 252 246 / 92%);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}
.section-tools input { flex: 1; }
.section-tools output { width: 42px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }
.busy {
  position: absolute;
  right: 12px;
  top: 10px;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgb(255 252 246 / 90%);
  color: var(--muted);
}
.summary { margin: 0; padding: 10px 14px 12px; text-align: center; color: var(--muted); font-size: 12.5px; }
.summary b { color: var(--ink); }

@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "preview" "controls"; padding: 14px 16px 28px; }
  .preview { position: static; height: auto; min-height: 0; }
  .viewport { flex: none; height: min(78vw, 520px); min-height: 280px; }
  .top { padding: 10px 16px; gap: 6px 14px; }
  .tagline { flex-basis: 100%; order: 3; }
}
@media (max-width: 480px) {
  .tiles { grid-template-columns: 1fr; }
  .grid { grid-template-columns: 1fr 1fr; }
  .chip b { font-size: 13.5px; }
  .help:hover::after, .help:focus::after { left: auto; right: 0; transform: none; max-width: 150px; }
}
