:root {
  --bg: #f7f7f7;
  --paper: rgba(255, 255, 255, 0.9);
  --ink: #0e0f0c;
  --muted: #5f625d;
  --line: rgba(14, 15, 12, 0.12);
  --accent: #d9482f;
  --accent-soft: rgba(217, 72, 47, 0.14);
  --teal: #126b61;
  --shadow: 0 18px 48px rgba(14, 15, 12, 0.1);
  color-scheme: light;
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
}

.page {
  width: min(1320px, calc(100vw - 20px));
  margin: 0 auto;
  padding: 12px 0 24px;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 2px 20px;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  font-weight: 720;
}

.brand-link img {
  width: 34px;
  height: 34px;
}

.crumbs {
  color: var(--muted);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.controls {
  padding: 18px;
  position: sticky;
  top: 14px;
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 8px 0 10px;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 0.98;
}

.intro {
  margin: 0;
  color: #3d413d;
  line-height: 1.6;
}

.group {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.group-title {
  margin: 0 0 12px;
  font-size: 15px;
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.field:first-child {
  margin-top: 0;
}

.field label,
.field legend {
  padding: 0;
  font-size: 13px;
  font-weight: 650;
  color: #2e302b;
}

.field input[type="search"],
.field input[type="number"],
.field select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(14, 15, 12, 0.18);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.segmented button,
.toggle-row button,
.preset-row button,
.actions button {
  min-height: 40px;
  border: 1px solid rgba(14, 15, 12, 0.18);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.segmented button.active,
.toggle-row button.active,
.preset-row button.active,
.actions button.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.preset-row,
.toggle-row,
.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.toggle-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.hint,
.source-list,
.stat-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.stat {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.72);
}

.stat strong {
  display: block;
  font-size: 20px;
}

.source-list {
  margin: 10px 0 0;
  padding-left: 18px;
}

.source-list li + li {
  margin-top: 6px;
}

.viewer {
  min-height: calc(100svh - 36px);
  padding: 14px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.hero-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chipline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid var(--line);
  font-size: 13px;
}

.calibration-banner {
  padding: 10px 12px;
  border: 1px solid rgba(217, 72, 47, 0.22);
  border-radius: 6px;
  background: var(--accent-soft);
  font-size: 14px;
}

.ruler-surface {
  position: relative;
  width: 100%;
  min-height: 340px;
  border: 1px solid rgba(14, 15, 12, 0.12);
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(249, 248, 244, 0.92)),
    linear-gradient(90deg, rgba(18, 107, 97, 0.05), transparent 28%),
    #fff;
}

.ruler-scroll {
  overflow: auto hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.ruler-strip {
  position: relative;
  height: 220px;
  min-width: 100%;
}

.ruler-strip.vertical {
  width: 220px;
  min-width: 220px;
  height: min(72svh, 920px);
}

.ruler-baseline {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 3px;
  background: var(--accent);
  transform: translateY(-50%);
}

.ruler-strip.vertical .ruler-baseline {
  left: 50%;
  right: auto;
  top: 0;
  bottom: 0;
  width: 3px;
  height: auto;
  transform: translateX(-50%);
}

.tick {
  position: absolute;
  bottom: 50%;
  width: 1px;
  background: #111;
  transform: translateX(-0.5px);
}

.tick.minor { height: 18px; }
.tick.mid { height: 32px; }
.tick.major { height: 54px; width: 2px; }

.tick.vertical {
  bottom: auto;
  left: 50%;
  transform: translateY(0);
  width: auto;
  height: 1px;
}

.tick.vertical.minor { width: 18px; height: 1px; }
.tick.vertical.mid { width: 32px; height: 1px; }
.tick.vertical.major { width: 54px; height: 2px; }

.tick-label {
  position: absolute;
  bottom: calc(50% + 60px);
  transform: translateX(-50%);
  font-size: 12px;
  color: #292a27;
  white-space: nowrap;
}

.tick-label.vertical {
  bottom: auto;
  left: calc(50% + 62px);
  transform: translateY(-50%);
}

.measure-zone {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 14px;
}

.guide-card,
.calibration-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.calibration-preview {
  position: relative;
  height: 66px;
  margin-top: 12px;
  border-radius: 6px;
  background: rgba(14, 15, 12, 0.04);
  overflow: hidden;
}

.calibration-bar {
  position: absolute;
  top: 50%;
  left: 12px;
  height: 18px;
  border-radius: 999px;
  background: var(--accent);
  transform: translateY(-50%);
}

.range-wrap {
  display: grid;
  gap: 8px;
}

.range-wrap input[type="range"] {
  width: 100%;
}

.footnote {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .controls {
    position: static;
  }

  .viewer {
    order: -1;
    min-height: auto;
  }

  .measure-zone {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .page {
    width: min(100vw - 10px, 100%);
  }

  .masthead {
    padding-bottom: 14px;
  }

  .viewer {
    padding: 10px;
  }

  .preset-row,
  .actions {
    grid-template-columns: 1fr;
  }

  .ruler-surface {
    min-height: 280px;
  }
}
