:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-soft: #eef2f1;
  --ink: #151918;
  --muted: #697471;
  --line: #d8dfdd;
  --line-strong: #aebbb7;
  --teal: #008f7a;
  --teal-dark: #006b5c;
  --lime: #bbf246;
  --amber: #db7b16;
  --danger: #c94738;
  --radius: 8px;
  --shadow: 0 18px 46px rgba(19, 34, 30, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; }
button, select { cursor: pointer; }
svg { width: 18px; height: 18px; stroke-width: 1.8; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(20px, 4vw, 64px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: var(--ink);
  color: var(--lime);
  border-radius: 6px;
}

.brand strong { display: block; font-size: 15px; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; font-weight: 700; }

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 0 4px rgba(0, 143, 122, 0.12);
}

main { padding: 18px clamp(16px, 4vw, 64px) 28px; }

.standard-strip {
  max-width: 1440px;
  min-height: 112px;
  margin: 0 auto 18px;
  padding: 22px 26px;
  display: grid;
  grid-template-columns: minmax(260px, 1.2fr) minmax(450px, 2fr) auto;
  gap: 28px;
  align-items: center;
  color: #f6fbf9;
  background: #182321;
  border-radius: var(--radius);
}

.eyebrow { color: #8fa39e; font-size: 10px; font-weight: 800; }
.standard-strip h1 { margin: 7px 0 0; font-size: 20px; line-height: 1.35; }

.standard-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 1px;
  background: #34413e;
  border: 1px solid #34413e;
}

.standard-facts > div { padding: 13px 16px; background: #202c29; }
.standard-facts span { display: block; color: #93a49f; font-size: 11px; }
.standard-facts strong { display: block; margin-top: 5px; color: #fff; font-size: 13px; font-variant-numeric: tabular-nums; }

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--lime);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.source-link:hover { text-decoration: underline; }

.workspace-grid {
  max-width: 1440px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(280px, 0.66fr) minmax(560px, 1.7fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.result-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.control-panel { padding: 20px; }
.result-panel { overflow: hidden; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.section-heading > div:first-child { display: flex; align-items: baseline; gap: 11px; }
.section-heading h2 { margin: 0; font-size: 18px; }
.step { color: var(--teal); font-family: Consolas, monospace; font-size: 11px; font-weight: 800; }

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.icon-button:hover { color: var(--ink); border-color: var(--line-strong); background: var(--surface-soft); }
.result-actions { display: flex; gap: 8px; }

.field { display: block; margin-bottom: 14px; }
.field > span:first-child { display: block; margin-bottom: 8px; color: #4f5b58; font-size: 12px; font-weight: 700; }

.select-wrap, .input-with-unit { position: relative; display: block; }
select, input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  color: var(--ink);
  background: #fbfcfc;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
  font-variant-numeric: tabular-nums;
}
select { appearance: none; padding-right: 42px; }
select:focus, input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0, 143, 122, 0.1); }
.select-wrap > svg { position: absolute; top: 13px; right: 14px; pointer-events: none; color: var(--muted); }
.input-with-unit input { padding-right: 58px; font-size: 17px; font-weight: 750; }
.input-with-unit b { position: absolute; top: 14px; right: 14px; color: var(--muted); font-size: 11px; }

.range-box { margin: 2px 0 8px; padding: 12px; background: var(--surface-soft); border-left: 3px solid var(--teal); }
.range-box > div:first-child { display: flex; justify-content: space-between; gap: 12px; }
.range-box span { color: var(--muted); font-size: 11px; }
.range-box strong { font-size: 12px; font-variant-numeric: tabular-nums; }
.range-box small { display: block; margin-top: 9px; color: var(--muted); font-size: 10px; }

.range-track { position: relative; height: 5px; margin-top: 14px; background: #ccd6d3; }
.range-track span { position: absolute; inset: 0; background: var(--teal); }
.range-track b { position: absolute; top: 50%; left: 30%; width: 11px; height: 11px; border: 2px solid #fff; border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 1px var(--ink); transform: translate(-50%, -50%); }

.field-error { min-height: 18px; margin: 8px 0; color: var(--danger); font-size: 11px; }

.primary-button {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: #fff;
  background: var(--teal-dark);
  border: 0;
  border-radius: 6px;
  font-weight: 750;
}
.primary-button:hover { background: #00594d; }
.primary-button:disabled { cursor: not-allowed; opacity: 0.45; }

.calibration { margin-top: 20px; border-top: 1px solid var(--line); }
.calibration summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #4f5b58;
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  font-weight: 700;
}
.calibration summary::-webkit-details-marker { display: none; }
.calibration summary span { display: inline-flex; align-items: center; gap: 8px; }
.calibration[open] summary > svg { transform: rotate(180deg); }
.calibration-body { padding: 6px 0 2px; }
.ratio-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 11px; }
.ratio-row span { color: var(--muted); }
.ratio-row strong { font-family: Consolas, monospace; }
.calibration table { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: 10px; text-align: right; }
.calibration th, .calibration td { padding: 7px 4px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.calibration th:first-child, .calibration td:first-child { text-align: left; }
.calibration th { color: var(--muted); font-weight: 600; }

.result-heading { margin: 0; padding: 18px 22px 14px; }
.result-meta {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #f9fbfa;
}
.result-meta > span { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.result-meta b { color: var(--ink); }
.valid-badge { color: var(--teal-dark) !important; font-weight: 750; }

.table-wrap { overflow: hidden; padding: 18px; }
.result-table { width: 100%; min-width: 0; table-layout: fixed; border-collapse: collapse; border: 2px solid #202725; }
.result-table .col-vertical { width: 6%; }
.result-table .col-direction { width: 8%; }
.result-table .col-label { width: 29%; }
.result-table .col-value { width: 19%; }
.result-table th, .result-table td { height: 54px; padding: 7px; border: 1px solid #202725; text-align: center; }
.result-table thead th { height: 40px; background: #eef2f1; font-size: 11px; }
.result-table td { font-family: Consolas, "Segoe UI", monospace; font-size: 13px; font-weight: 750; font-variant-numeric: tabular-nums; }
.result-table td.flash { animation: value-flash 360ms ease-out; }
@keyframes value-flash {
  0% { background: rgba(187, 242, 70, 0.55); }
  100% { background: transparent; }
}
.vertical-title { background: #f4f7f6; font-size: 11px; }
.vertical-title span { display: inline-block; width: 1em; line-height: 1.35; }
.direction { color: var(--teal-dark); background: #f6faf8; font-size: 12px; }
.direction.down { color: #9d5a12; background: #fff9f1; }
.measure-label { font-size: 11px; line-height: 1.35; text-align: left !important; }
.measure-label small { color: var(--muted); font-size: 10px; }
.muted-value { color: #9aa5a2; font-weight: 400 !important; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  margin: 0 18px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.summary-grid > div { min-width: 0; padding: 12px 10px; border-right: 1px solid var(--line); }
.summary-grid > div:last-child { border-right: 0; }
.summary-grid span { display: block; overflow-wrap: anywhere; color: var(--muted); font-size: 10px; }
.summary-grid strong { display: inline-block; margin-top: 5px; font-family: Consolas, monospace; font-size: 16px; font-variant-numeric: tabular-nums; }
.summary-grid small { color: var(--muted); font-size: 9px; }

.constraint-line { display: flex; flex-wrap: wrap; gap: 8px 20px; padding: 14px 18px; }
.constraint-line span { display: inline-flex; align-items: center; gap: 6px; color: var(--teal-dark); font-size: 11px; }
.constraint-line svg { width: 14px; height: 14px; }

.simulation-note { display: flex; gap: 9px; margin: 0 18px 18px; padding: 11px 13px; color: #754510; background: #fff5e7; border: 1px solid #f0d2ac; }
.simulation-note svg { flex: 0 0 auto; color: var(--amber); }
.simulation-note p { margin: 0; font-size: 11px; line-height: 1.55; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  padding: 11px 16px;
  color: #fff;
  background: var(--ink);
  border-radius: 6px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 180ms ease;
  font-size: 12px;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1080px) {
  .standard-strip { grid-template-columns: 1fr; gap: 18px; }
  .source-link { justify-self: start; }
  .workspace-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  .topbar { height: 50px; padding: 0 12px; }
  .brand-mark { width: 32px; height: 32px; }
  .brand strong { font-size: 13px; }
  .topbar-status span:last-child { display: none; }
  main { padding: 8px 6px 14px; }
  .workspace-grid { gap: 8px; }
  .control-panel { padding: 12px; }
  .section-heading { margin-bottom: 10px; }
  .section-heading h2 { font-size: 15px; }
  .icon-button { width: 32px; height: 32px; }
  #generatorForm { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  #generatorForm .field { min-width: 0; margin: 0; }
  .field > span:first-child { min-height: 28px; margin-bottom: 4px; font-size: 10px; line-height: 1.4; }
  select, input { height: 40px; padding: 0 9px; }
  .select-wrap > svg { top: 11px; right: 8px; }
  .input-with-unit input { padding-right: 38px; font-size: 14px; }
  .input-with-unit b { top: 13px; right: 8px; font-size: 9px; }
  .range-box, .field-error, .primary-button { grid-column: 1 / -1; }
  .range-box { margin: 0; padding: 8px 9px; }
  .range-box > div:first-child { align-items: center; }
  .range-track, .range-box small { display: none; }
  .field-error { min-height: 12px; margin: 0; font-size: 10px; }
  .primary-button { height: 40px; }
  .result-heading { padding: 11px 12px 9px; }
  .result-meta { min-height: 34px; padding: 0 12px; }
  .table-wrap { padding: 8px 5px; }
  .result-table .col-vertical { width: 6%; }
  .result-table .col-direction { width: 9%; }
  .result-table .col-label { width: 31%; }
  .result-table .col-value { width: 18%; }
  .result-table th, .result-table td { height: 44px; padding: 3px 2px; }
  .result-table thead th { height: 30px; font-size: 10px; }
  .result-table td { font-size: 11px; }
  .vertical-title { font-size: 9px; }
  .direction { font-size: 10px; }
  .measure-label { font-size: 9px; line-height: 1.25; }
  .measure-label small { font-size: 8px; }
  .summary-grid { grid-template-columns: repeat(4, 1fr); margin: 0 8px; }
  .summary-grid > div { padding: 8px 3px; text-align: center; border-bottom: 0; }
  .summary-grid > div:nth-child(2) { border-right: 1px solid var(--line); }
  .summary-grid > div:nth-child(-n+2) { border-bottom: 0; }
  .summary-grid span { min-height: 26px; font-size: 8px; line-height: 1.35; }
  .summary-grid strong { margin-top: 3px; font-size: 13px; }
  .summary-grid small { display: none; }
  .constraint-line { display: none; }
  .simulation-note { margin: 9px 8px 10px; padding: 8px 9px; }
  .simulation-note p { font-size: 9px; }
}

@media print {
  body { background: #fff; }
  .topbar, .standard-strip, .control-panel, .result-actions, .simulation-note, .toast { display: none !important; }
  main { padding: 0; }
  .workspace-grid { display: block; }
  .result-panel { border: 0; box-shadow: none; }
  .table-wrap { overflow: visible; }
  .result-table { min-width: 0; }
}

.android-app #printBtn { display: none; }
