:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: #111722;
  --panel-2: #161e2a;
  --line: #273241;
  --muted: #98a6b7;
  --text: #eff4fa;
  --blue: #53b2ff;
  --green: #35c7a0;
  --amber: #f5b85d;
  font-family: "Segoe UI Variable", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; }
.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}
button:disabled { opacity: .5; cursor: not-allowed; }
[hidden] { display: none !important; }
svg { display: block; }
.topbar {
  flex: 0 0 58px; min-height: 0; display: flex; justify-content: space-between;
  align-items: center; gap: 12px; padding: 0 16px;
  background: #0a1019; border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 11px; align-items: center; min-width: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.brand-text strong { font-size: 12px; font-weight: 750; letter-spacing: .12em; white-space: nowrap; }
.brand-text span { font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back, .ghost {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-height: 38px; min-width: 38px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; text-decoration: none;
}
.back:hover, .ghost:hover { border-color: #52657b; }
.back svg, .ghost svg, .primary svg {
  width: 18px; height: 18px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.ghost { gap: 7px; padding: 0 11px; color: #c7d3e1; font-size: 12px; }
.workspace {
  flex: 1 1 auto; min-height: 0; max-width: 1700px; width: 100%; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 440px); overflow: hidden;
}
.visual-column {
  display: flex; flex-direction: column; gap: 9px;
  padding: 15px; min-width: 0; min-height: 0; overflow: hidden;
}
.preview-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex: 0 0 auto; }
h1 { font-size: 16px; font-weight: 700; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 14px; margin: 0; font-weight: 680; }
.view-switch { display: flex; align-items: center; gap: 3px; padding: 3px; background: #192231; border: 1px solid #2a394c; border-radius: 9px; }
.view-switch button {
  border: 0; border-radius: 7px; color: #9aa9ba; background: transparent;
  font-size: 11px; padding: 6px 12px; min-height: 30px;
}
.view-switch button.active { background: #324661; color: #f3f7fb; }
.drawing {
  flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; position: relative;
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  background: radial-gradient(ellipse at 50% 26%, #1b2a3b 0%, #121a25 55%, #0f1721 100%);
}
#profileSvg { display: block; flex: 1 1 auto; min-height: 0; height: 100%; width: 100%; }
#profileSvg .gridline { stroke: #91a4bd; stroke-opacity: .105; stroke-width: 1; }
#profileSvg .axis { stroke: #bec8d4; stroke-opacity: .3; stroke-width: 1; stroke-dasharray: 6 6; }
#profileSvg .original { fill: none; stroke: #8d9cb0; stroke-dasharray: 6 8; stroke-width: 2; opacity: .7; }
#profileSvg .shape { fill: none; stroke: var(--blue); stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; }
#profileSvg .solid-preview { fill: #51adff; fill-opacity: .07; stroke: none; }
#profileSvg .join-line { stroke: var(--amber); stroke-dasharray: 5 7; stroke-width: 1.5; }
#profileSvg .join-dot { fill: var(--amber); }
#profileSvg .section-guide { stroke: #ff876d; stroke-width: 2; stroke-dasharray: 7 6; }
#profileSvg .section-diameter { stroke: #ff876d; stroke-width: 3; stroke-linecap: round; }
#profileSvg .section-end { fill: #ffb29f; }
#profileSvg .top-rim { stroke: #55cba7; stroke-width: 3; stroke-linecap: round; }
#profileSvg .bottom-rim { stroke: #82a8c6; stroke-width: 1.8; stroke-dasharray: 3 3; }
#profileSvg text { fill: #aab8c8; font: 12px "Segoe UI",sans-serif; }
#profileSvg .highlight-text { fill: #f2c783; }
.section-slider {
  position: absolute; z-index: 3; right: 5px; top: 9px; bottom: 37px;
  width: 38px; display: flex; align-items: center; justify-content: center;
}
#sectionRange {
  position: absolute; top: 50%; left: 50%; display: block; min-height: 0;
  width: var(--slider-length, 220px); height: 32px; margin: 0;
  appearance: none; -webkit-appearance: none;
  transform: translate(-50%, -50%) rotate(-90deg);
  transform-origin: center center;
  background: transparent; accent-color: #ff876d; touch-action: none;
  cursor: ns-resize;
}
#sectionRange::-webkit-slider-runnable-track {
  height: 6px; border-radius: 8px; background: #36506b;
}
#sectionRange::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 22px; height: 22px; margin-top: -8px;
  border-radius: 50%; border: 2px solid #ffe1d5;
  background: #ff9a7d; box-shadow: 0 0 0 3px rgba(12,18,28,.75);
}
.section-readout {
  flex: 0 0 27px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px; padding: 3px 10px 6px; align-items: center;
  font-size: 11px; color: var(--muted);
}
.section-readout span { white-space: nowrap; text-align: center; }
.section-readout b { color: var(--text); font-variant-numeric: tabular-nums; }
.below-target { color: #ff9778 !important; }
.side-overlaps {
  margin-top: 8px; display: grid; grid-template-columns: repeat(2,1fr);
  gap: 8px; color: var(--muted); font-size: 11px;
}
.side-overlaps b { color: var(--text); }
.layer-diagram { display: block; width: 100%; height: 112px; margin: 4px 0 2px; }
.selected-overlap { display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin: 5px 0 9px; color: var(--muted); font-size: 12px; }
.selected-overlap strong { font-size: 32px; font-weight: 720;
  font-variant-numeric: tabular-nums; color: var(--text); }
.layer-card .overlap-meter { margin: 5px 0 12px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); flex: 0 0 auto; gap: 7px; }
.stat {
  display: flex; min-width: 0; flex-direction: column; justify-content: center; gap: 3px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px;
}
.stat small { color: var(--muted); font-size: 11px; white-space: nowrap; }
.stat div { display: flex; align-items: baseline; gap: 4px; white-space: nowrap; }
.stat strong { font-size: clamp(17px, 2vw, 24px); font-weight: 720; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.stat span { font-size: 10px; color: var(--muted); }

.controls {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  background: #0e131b; border-left: 1px solid var(--line);
}
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; flex: 0 0 auto; padding: 9px; border-bottom: 1px solid var(--line); }
.tabs button {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  font-weight: 620; min-height: 40px; border-radius: 9px; font-size: 12px;
}
.tabs button.active { background: #263a51; color: #eaf5ff; border-color: #365a7e; }
.tabs button:not(.active):hover { background: #192534; color: var(--text); }
.tab-panels { min-height: 0; flex: 1 1 auto; }
.tab-panel {
  height: 100%; min-height: 0; padding: 12px; overflow-y: auto; overscroll-behavior-y: contain;
  scrollbar-width: thin; scrollbar-color: #364252 transparent;
}
.control-group, .layer-card, .export-group {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px;
}
.field { min-width: 0; margin: 0 0 12px; }
.field:last-child, .bottom-settings .field { margin-bottom: 0; }
.field-top {
  display: flex; justify-content: space-between; align-items: center;
  gap: 7px; min-height: 32px; margin-bottom: 2px;
}
.field-top label { font-size: 12px; font-weight: 600; line-height: 1.15; min-width: 0; }
.numeric { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); font-size: 11px; flex: none; }
.numeric input {
  width: 57px; min-height: 32px; text-align: right; padding: 4px 6px; font-size: 12px;
  font-variant-numeric: tabular-nums; background: #0b131e; color: var(--text);
  border: 1px solid #344154; border-radius: 7px;
}
.numeric input::-webkit-inner-spin-button { opacity: .35; }
.one-wall-preset {
  min-width: 33px; height: 32px; padding: 0 6px; border-radius: 7px;
  border: 1px solid #39506a; color: #b5c7dc; background: #162434;
  font-weight: 700; font-size: 12px; flex: none;
}
.one-wall-preset.active { background: #24527b; border-color: #53b2ff; color: #f2f8ff; }
.numeric input:disabled, input[type="range"]:disabled { opacity: .55; cursor: not-allowed; }
input[type="range"] {
  display: block; width: 100%; height: 29px; margin: 0; cursor: pointer;
  background: transparent; accent-color: var(--blue); touch-action: pan-y;
}
input[type="range"]::-webkit-slider-runnable-track { background: #354252; height: 5px; border-radius: 12px; }
input[type="range"]::-webkit-slider-thumb { margin-top: -7px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.field-grid .field { margin-bottom: 10px; }
.field.highlight {
  padding: 9px 12px 4px; margin: 0 0 12px;
  background: #142438; border: 1px solid #294d71; border-radius: 10px;
}
select {
  width: 100%; min-height: 37px; padding: 6px 8px; border-radius: 8px;
  background: #101c2a; color: var(--text); border: 1px solid #354255;
  font-size: 12px;
}
.hint, .note { margin: 8px 0 0; font-size: 11px; line-height: 1.4; color: var(--muted); }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.status {
  flex: none; color: var(--green); background: #10261f; border: 1px solid #267862;
  font-size: 10px; border-radius: 6px; padding: 5px 7px;
}
.status.warning { color: var(--amber); background: #302719; border-color: #766035; }
.overlap-meter { background: #283341; border-radius: 20px; height: 9px; position: relative; }
.overlap-meter > div { height: 100%; background: var(--green); border-radius: inherit; }
.overlap-meter > i { position: absolute; display: block; top: -5px; bottom: -5px; width: 2px; background: white; opacity: .85; }
.layer-info { display: flex; gap: 10px; justify-content: space-between; flex-wrap: wrap; margin: 11px 0 4px; color: var(--muted); font-size: 11px; }
.layer-info b { color: var(--text); font-variant-numeric: tabular-nums; }
.primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 44px; border-radius: 9px; font-weight: 650; font-size: 13px;
}
.primary { color: #091522; background: #2d94ed; border: 1px solid #51b2ff; }
.primary:hover { background: #52b3ff; }
.primary.full { width: 100%; }
#exportMessage { margin: 10px 0 0; min-height: 16px; font-size: 11px; color: var(--green); overflow-wrap: anywhere; }

@media (max-width: 930px) {
  .workspace { grid-template-columns: minmax(0,1fr) minmax(310px,40%); }
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stat { padding: 7px 10px; }
}
@media (max-width: 760px) {
  .topbar { flex: 0 0 52px; padding: 0 10px; }
  .ghost { width: 38px; padding: 0; }
  .ghost span { display: none; }
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(160px,1fr) 360px; }
  .visual-column { padding: 9px 10px 6px; gap: 6px; }
  h1 { font-size: 14px; }
  .view-switch button { min-height: 28px; padding: 5px 10px; }
  .drawing { border-radius: 11px; }
  .section-readout { flex-basis: 25px; gap: 2px; font-size: 10px; padding-inline: 4px; }
  .section-slider { right: 3px; top: 8px; bottom: 33px; width: 28px; }
  .stats { grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; }
  .stat { padding: 5px 8px; min-height: 49px; gap: 1px; }
  .stat small { font-size: 10px; }
  .stat strong { font-size: clamp(16px,4.7vw,20px); }
  .stat-extra { display: none; }
  .controls { border-left: 0; border-top: 1px solid var(--line); }
  .tabs { padding: 6px 8px; gap: 4px; }
  .tabs button { min-height: 39px; font-size: 12px; }
  .tab-panel { padding: 8px 10px max(8px, env(safe-area-inset-bottom)); }
  .control-group, .export-group, .layer-card { padding: 12px; border-radius: 11px; }
  .field { margin-bottom: 8px; }
  .field.highlight { margin-bottom: 7px; padding: 5px 10px 0; }
  .field-grid { gap: 9px; }
  .field-grid .field { margin-bottom: 7px; }
  .field-top { min-height: 30px; }
  input[type="range"] { height: 28px; }
  .hint { margin-top: 4px; }
}
@media (max-width: 340px) {
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .field { margin-bottom: 5px; }
  .stat span { font-size: 9px; }
}
@media (max-height: 670px) and (max-width: 760px) {
  .workspace { grid-template-rows: minmax(160px,1fr) 360px; }
  .visual-column { padding-top: 5px; }
  .stat { min-height: 44px; }
  .section-readout { flex-basis: 24px; }
}
@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color 120ms, border-color 120ms; }
}
