:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #111827;
  --muted: #667085;
  --line: #dce3ec;
  --line-strong: #cbd5e1;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e8f5f2;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --shadow: 0 22px 55px rgba(15, 23, 42, 0.10);
  --radius: 18px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); color: var(--ink); }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 50% -10%, #e8f5f2 0, transparent 35rem), var(--bg); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(15, 118, 110, .24); outline-offset: 2px; }

.site-header {
  width: min(1180px, calc(100% - 32px));
  min-height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 760; letter-spacing: -.02em; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; color: var(--accent); }
.brand-mark svg { width: 100%; height: 100%; }
.github-button { display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px solid var(--line-strong); border-radius: 10px; color: var(--ink); text-decoration: none; background: rgba(255,255,255,.78); font-weight: 650; }
.github-button:hover { background: var(--surface); border-color: #aeb9c8; }
.github-button svg { width: 18px; height: 18px; }

main { width: 100%; }
.hero { width: min(1180px, calc(100% - 32px)); margin: 34px auto 0; }
.hero-copy { text-align: center; max-width: 760px; margin: 0 auto 24px; }
h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.8rem); line-height: 1.02; letter-spacing: -.055em; }
.hero-copy p { margin: 14px auto 0; color: var(--muted); font-size: clamp(1rem, 2vw, 1.16rem); line-height: 1.6; }

.tool-shell { background: rgba(255,255,255,.96); border: 1px solid rgba(203,213,225,.9); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.mode-tabs { display: flex; align-items: center; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); background: #fbfcfe; }
.mode-tab { min-width: 104px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); padding: 10px 18px; font-weight: 720; }
.mode-tab.is-active { color: var(--accent-strong); background: var(--accent-soft); box-shadow: inset 0 0 0 1px rgba(15,118,110,.12); }

.tool-grid { display: grid; grid-template-columns: minmax(320px, .86fr) minmax(440px, 1.14fr); min-height: 510px; }
.control-panel { padding: 24px; border-right: 1px solid var(--line); background: var(--surface); }
.control-view { display: grid; gap: 20px; }
.field-grid { display: grid; gap: 12px; }
.field-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.compact-fields { padding-top: 2px; }
.field { min-width: 0; display: grid; gap: 7px; color: #344054; font-size: .86rem; font-weight: 650; }
.field input, .field select { width: 100%; min-width: 0; height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: white; color: var(--ink); box-shadow: 0 1px 2px rgba(15,23,42,.03); }
.field input:hover, .field select:hover { border-color: #aab6c5; }
.input-with-unit { position: relative; display: block; }
.input-with-unit input { padding-right: 48px; }
.input-with-unit > span { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); color: #98a2b3; font-size: .78rem; font-weight: 700; pointer-events: none; }
.toggle-row { display: flex; flex-wrap: wrap; gap: 10px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; color: #344054; background: var(--surface-soft); font-size: .86rem; font-weight: 640; }
.toggle input { accent-color: var(--accent); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-soft); }
.segment { border: 0; border-radius: 8px; padding: 9px 12px; background: transparent; color: var(--muted); font-size: .86rem; font-weight: 700; }
.segment.is-active { background: white; color: var(--ink); box-shadow: 0 1px 4px rgba(15,23,42,.08); }
.status-message { min-height: 42px; margin-top: 18px; display: flex; align-items: center; padding: 10px 12px; border-radius: 10px; color: var(--muted); background: var(--surface-soft); font-size: .85rem; line-height: 1.4; }
.status-message.is-error { color: var(--danger); background: var(--danger-bg); }

.preview-panel { display: grid; grid-template-rows: 1fr auto; min-width: 0; background: linear-gradient(180deg, #f6faf9 0%, #fbfcfd 100%); }
.preview-stage { min-height: 405px; display: grid; place-items: center; padding: 18px; overflow: hidden; }
#model-preview { width: 100%; height: 100%; min-height: 360px; overflow: visible; }
.preview-floor { fill: #dbe6e4; opacity: .5; }
.preview-top { fill: #55a99e; }
.preview-front { fill: #2e8178; }
.preview-side { fill: #1f6d65; }
.preview-line { fill: none; stroke: rgba(17,24,39,.26); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.preview-socket { fill: #eef4f3; stroke: rgba(31,109,101,.55); stroke-width: 1; vector-effect: non-scaling-stroke; }
.preview-split { fill: none; stroke: #0f766e; stroke-width: 2.4; stroke-dasharray: 8 6; vector-effect: non-scaling-stroke; }
.result-strip { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; border-top: 1px solid var(--line); background: rgba(255,255,255,.92); }
.result-summary { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: .86rem; line-height: 1.5; }
.result-summary strong { color: var(--ink); font-weight: 760; }
.primary-button { min-height: 46px; flex: 0 0 auto; border: 0; border-radius: 11px; padding: 0 18px; background: var(--accent); color: white; font-weight: 760; box-shadow: 0 7px 16px rgba(15,118,110,.20); }
.primary-button:hover { background: var(--accent-strong); }
.primary-button:disabled { cursor: not-allowed; opacity: .5; box-shadow: none; }

.content-section { width: min(1040px, calc(100% - 32px)); margin: 72px auto 0; }
.content-section h2 { margin: 0 0 24px; font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -.035em; }
.content-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.content-grid article { padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.72); }
.content-grid h3 { margin: 0 0 8px; font-size: 1rem; }
.content-grid p, .reference-section p { margin: 0; color: var(--muted); line-height: 1.7; }
.reference-section { margin-bottom: 72px; }
footer { width: 100%; padding: 24px 16px 30px; border-top: 1px solid var(--line); text-align: center; color: #8490a1; font-size: .84rem; }

[hidden] { display: none !important; }

@media (max-width: 800px) {
  .site-header, .hero, .content-section { width: min(100% - 22px, 680px); }
  .site-header { min-height: 64px; }
  .brand span:last-child { display: none; }
  .hero { margin-top: 24px; }
  .hero-copy { margin-bottom: 18px; }
  .tool-grid { grid-template-columns: 1fr; min-height: auto; }
  .control-panel { border-right: 0; border-bottom: 1px solid var(--line); padding: 18px; }
  .preview-stage { min-height: 320px; padding: 8px; }
  #model-preview { min-height: 300px; }
  .result-strip { align-items: stretch; flex-direction: column; gap: 12px; }
  .primary-button { width: 100%; }
  .content-grid { grid-template-columns: 1fr; }
  .content-section { margin-top: 48px; }
}

@media (max-width: 520px) {
  .field-grid-3 { grid-template-columns: 1fr 1fr; }
  .field-grid-3 .field:last-child { grid-column: 1 / -1; }
  .field-grid-2 { grid-template-columns: 1fr; }
  .mode-tab { flex: 1; min-width: 0; }
}
