:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  background: #f6f8f4;
  color: #202722;
  --ink: #202722;
  --muted: #647069;
  --line: #d7ded7;
  --panel: #ffffff;
  --panel-strong: #f9fbf8;
  --green: #267a59;
  --green-soft: #e7f3ec;
  --blue: #315f8d;
  --blue-soft: #e9f0f7;
  --amber: #9b6a20;
  --amber-soft: #fff4df;
  --red: #b54040;
  --shadow: 0 22px 60px rgba(43, 64, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(231, 243, 236, 0.7), transparent 48%),
    linear-gradient(180deg, #fbfcfa 0%, #eef3ef 100%);
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(380px, 560px) minmax(0, 1fr);
  gap: clamp(18px, 3vw, 36px);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 34px);
}

.control-panel,
.test-panel {
  min-width: 0;
}

.control-panel {
  display: grid;
  align-content: start;
  gap: 18px;
}

.brand-row,
.test-topbar,
.progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.home-link {
  color: var(--green);
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

.home-link:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(49, 95, 141, 0.28);
  outline-offset: 3px;
}

.mode-pill,
.acuity-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  padding: 7px 11px;
  white-space: nowrap;
}

.title-block {
  display: grid;
  gap: 10px;
}

.eyebrow {
  margin: 0;
  color: var(--green);
  font-size: 13px;
  font-weight: 900;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  color: var(--ink);
  font-size: clamp(42px, 8vw, 78px);
  line-height: 0.96;
  letter-spacing: 0;
}

h2 {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.25;
}

h3 {
  color: var(--ink);
  font-size: 18px;
}

.summary {
  max-width: 520px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.75;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.setup-section,
.test-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.setup-section {
  min-width: 0;
  display: grid;
  gap: 14px;
  padding: 16px;
}

.setup-section.compact {
  box-shadow: 0 16px 40px rgba(43, 64, 51, 0.08);
}

.section-heading {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.section-heading p,
.tips-list,
.metric-line {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.step-number {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 14px;
  font-weight: 900;
}

.calibration-stage {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
}

.card-calibrator {
  width: min(var(--card-width, 300px), 100%);
  max-width: 100%;
  aspect-ratio: 85.6 / 53.98;
  position: relative;
  overflow: hidden;
  border: 1px solid #9bb2a9;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent),
    #dfe8e2;
}

.mag-strip {
  position: absolute;
  top: 18%;
  left: 0;
  right: 0;
  height: 20%;
  background: #29332d;
}

.chip-shape {
  position: absolute;
  left: 9%;
  bottom: 20%;
  width: 16%;
  height: 23%;
  border-radius: 5px;
  background: #caa867;
  box-shadow: inset 0 0 0 1px rgba(57, 40, 16, 0.22);
}

.card-lines {
  position: absolute;
  right: 8%;
  bottom: 23%;
  width: 40%;
  display: grid;
  gap: 8px;
}

.card-lines span {
  height: 8px;
  border-radius: 999px;
  background: rgba(49, 62, 54, 0.35);
}

.field-label {
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.range-row,
.distance-row {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.distance-row {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.icon-button,
.preset-button,
.primary-button,
.direction-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
}

.icon-button {
  width: 38px;
  height: 38px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

input[type="number"] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 800;
}

.preset-button {
  height: 42px;
  padding: 0 13px;
}

.primary-button {
  height: 48px;
  border-color: #1f6d4e;
  background: #267a59;
  color: #fff;
  font-size: 16px;
}

.primary-button:disabled {
  border-color: #cfd9d1;
  background: #dfe7e1;
  color: #748078;
  cursor: not-allowed;
}

.distance-status {
  min-height: 42px;
  display: grid;
  align-items: center;
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.45;
}

.distance-status.warning {
  background: var(--amber-soft);
  color: var(--amber);
}

.distance-status.blocked {
  background: #fbe9e9;
  color: var(--red);
}

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

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

.protocol-row label {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

.test-panel {
  min-height: calc(100vh - clamp(16px, 3vw, 34px) * 2);
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto auto auto;
  gap: 18px;
  padding: clamp(16px, 3vw, 28px);
}

.test-topbar h2 {
  margin-top: 5px;
  font-size: clamp(24px, 4vw, 38px);
}

.acuity-badge {
  min-width: 82px;
  text-align: center;
  color: var(--blue);
  background: var(--blue-soft);
}

.chart-stage {
  min-height: 360px;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  border: 1px solid #dfe5df;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(0, 0, 0, 0.04) 1px, transparent 1px),
    #ffffff;
  background-size: 44px 44px;
}

.empty-state {
  display: grid;
  gap: 8px;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.empty-state p {
  color: var(--ink);
  font-size: 22px;
  font-weight: 900;
}

.empty-state span {
  font-size: 15px;
}

.optotype {
  --size: 96px;
  --stroke: calc(var(--size) / 5);
  width: var(--size);
  height: var(--size);
  display: none;
  position: relative;
  transform: rotate(var(--rotation, 0deg));
}

.optotype.is-visible {
  display: block;
}

.optotype::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--stroke);
  background: #050806;
}

.optotype span {
  position: absolute;
  left: 0;
  width: 100%;
  height: var(--stroke);
  background: #050806;
}

.optotype span:nth-child(1) {
  top: 0;
}

.optotype span:nth-child(2) {
  top: calc(50% - var(--stroke) / 2);
}

.optotype span:nth-child(3) {
  bottom: 0;
}

.answer-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(62px, 1fr));
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 10px;
  width: min(430px, 100%);
  justify-self: center;
}

.direction-button {
  min-height: 48px;
  background: #f7faf7;
  font-size: 16px;
}

.direction-button:hover,
.preset-button:hover,
.icon-button:hover {
  border-color: #9fb9ac;
  background: #eef6f1;
}

.direction-button.up {
  grid-area: up;
}

.direction-button.left {
  grid-area: left;
}

.direction-button.right {
  grid-area: right;
}

.direction-button.down {
  grid-area: down;
}

.progress-block {
  display: grid;
  gap: 8px;
}

.progress-label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e9e4;
}

.progress-track span {
  width: 0;
  height: 100%;
  display: block;
  background: linear-gradient(90deg, var(--green), var(--blue));
  transition: width 180ms ease;
}

.result-panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 14px;
}

.result-panel p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(21, 31, 25, 0.48);
}

.modal-backdrop[hidden] {
  display: none;
}

.result-dialog {
  width: min(480px, 100%);
  position: relative;
  display: grid;
  gap: 12px;
  border: 1px solid #cbd8cf;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 28px 90px rgba(12, 24, 17, 0.3);
  padding: 26px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf7;
  color: var(--ink);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.modal-acuity {
  width: 100%;
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  font-size: clamp(52px, 16vw, 88px);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  padding: 20px 12px;
}

.modal-meta {
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
  line-height: 1.5;
}

.modal-body {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.modal-action {
  margin-top: 4px;
}

@media (max-width: 1060px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .test-panel {
    min-height: auto;
  }
}

@media (max-width: 680px) {
  .app-shell {
    padding: 12px;
  }

  .setup-grid,
  .protocol-row {
    grid-template-columns: 1fr;
  }

  .range-row {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
  }

  .distance-row {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .distance-row input {
    grid-column: 1 / -1;
  }

  .chart-stage {
    min-height: 300px;
  }

  .result-dialog {
    padding: 22px;
  }
}
