:root {
  --bg: #0f1720;
  --bg-soft: #16212c;
  --card: #1a2634;
  --card-2: #21303f;
  --line: #2c3d4e;
  --text: #e9eff6;
  --muted: #9fb0c0;
  --accent: #2f7cf6;
  --accent-2: #1f63d1;
  --ok: #35c07f;
  --warn: #f0b429;
  --danger: #f0616d;
  --radius: 16px;
  --pad-btn: clamp(58px, 17vw, 88px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior: none;
}

h1, h2, h3 { margin: 0 0 12px; line-height: 1.3; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.12rem; }
p { line-height: 1.65; }
b { color: #fff; }

.app { min-height: 100vh; min-height: 100dvh; }

/* ---------- screens ---------- */
.screen { display: none; }
.screen.is-active { display: block; }

#screen-test.is-active {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 16px calc(28px + env(safe-area-inset-bottom));
}

.wrap.center {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  align-items: center;
}

/* ---------- brand ---------- */
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.brand h1 { margin-bottom: 2px; }
.brand .sub { margin: 0; color: var(--muted); font-size: 0.82rem; }
.logo {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 14px;
  background: #fff;
  color: #000;
  font-weight: 800;
  font-size: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Courier New", monospace;
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { margin-bottom: 10px; }

.tips { margin: 0; padding-left: 20px; color: var(--muted); font-size: 0.9rem; }
.tips li { margin-bottom: 8px; line-height: 1.6; }
.tips li:last-child { margin-bottom: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.hidden { display: none !important; }

/* ---------- calibration ---------- */
.calib-status { margin: 0 0 12px; font-size: 0.9rem; }
.calib-status.ok { color: var(--ok); }
.calib-status.warn { color: var(--warn); }

.calib-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px 6px;
  margin-bottom: 14px;
  overflow-x: auto;
}
.calib-bar {
  position: relative;
  flex: 0 0 auto;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-left: 4px solid var(--accent);
  border-right: 4px solid var(--accent);
  background: rgba(47, 124, 246, 0.12);
  border-radius: 4px;
  padding: 0 6px;
  box-sizing: border-box;
}
.calib-bar-text { font-size: 0.72rem; color: #cfe0f7; white-space: nowrap; }
.calib-cap { width: 0; }

.calib-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.calib-controls .btn { flex: 0 0 auto; padding: 10px 14px; }
.calib-readout { text-align: center; font-size: 0.88rem; color: var(--muted); }

.calib-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
}
.calib-tab {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.88rem;
  padding: 9px 8px;
  border-radius: 9px;
  cursor: pointer;
}
.calib-tab.is-on { background: var(--accent); color: #fff; font-weight: 600; }

.calib-panel { margin-bottom: 4px; }

.ruler-line {
  position: relative;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ruler-line::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: var(--accent);
  transform: translateY(-50%);
}
.ruler-line .tick {
  position: relative;
  width: 2px;
  height: 30px;
  background: var(--accent);
}

.verify-block { margin: 4px 0 14px; }
.verify-label { font-size: 0.82rem; color: var(--muted); margin-bottom: 8px; }
.verify-bar {
  height: 40px;
  box-sizing: border-box;
  border-left: 3px solid var(--ok);
  border-right: 3px solid var(--ok);
  background: rgba(53, 192, 127, 0.12);
  border-radius: 4px;
}
.slider { width: 100%; margin: 6px 0; accent-color: var(--accent); }
.calib-readout { text-align: center; margin-bottom: 8px; font-size: 0.92rem; }

/* ---------- form ---------- */
.distance-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.distance-row input {
  flex: 1;
  min-width: 0;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 1.2rem;
  padding: 12px 14px;
}
.distance-row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.distance-row .unit { color: var(--muted); font-size: 1rem; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
  cursor: pointer;
}
.chip:active { transform: scale(0.97); }
.chip.is-on { background: var(--accent); border-color: var(--accent); }

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 0.88rem;
  color: var(--muted);
}
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }

.select-row { margin-bottom: 10px; }
.select-row select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  font-size: 1rem;
  padding: 12px 14px;
  font-family: inherit;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.select-row select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 13px 18px;
  font-size: 1rem;
  font-family: inherit;
  color: #fff;
  background: var(--card-2);
  cursor: pointer;
  transition: transform 0.06s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); width: 100%; font-weight: 600; }
.btn-primary:hover { background: var(--accent-2); }
.btn-secondary { background: var(--card-2); border: 1px solid var(--line); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn-lg { padding: 16px 18px; font-size: 1.06rem; }
.btn-sm { padding: 9px 14px; font-size: 0.85rem; }

.row-btns {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}
.row-btns .btn { flex: 1 1 auto; }

.disclaimer {
  margin: 16px 0 0;
  font-size: 0.78rem;
  color: #7f8f9e;
  line-height: 1.6;
}

/* ---------- eye ready ---------- */
.eye-badge {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 6px 20px;
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 16px;
}
.wrap.center h2 { font-size: 1.4rem; }
.wrap.center .btn { margin-top: 20px; width: min(320px, 90%); }

/* ---------- test ---------- */
.test-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 8px;
  gap: 10px;
}
.test-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge {
  background: var(--accent);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}
.badge-plain { background: var(--card-2); color: var(--muted); font-weight: 500; }
.progress-text { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }

.optotype-stage {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 12px;
  background: #ffffff;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.optotype { display: flex; align-items: center; justify-content: center; }
.optotype svg { display: block; }

.size-warn {
  margin: 8px 16px 0;
  background: rgba(240, 180, 41, 0.12);
  border: 1px solid rgba(240, 180, 41, 0.4);
  color: var(--warn);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.78rem;
}
.voice-live {
  margin: 8px 16px 0;
  color: var(--accent);
  font-size: 0.82rem;
  text-align: center;
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
  max-width: 420px;
  margin: 0 auto;
  width: 100%;
}
.pad-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  height: var(--pad-btn);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.06s ease, background 0.12s ease;
}
.pad-btn:active { transform: scale(0.95); background: var(--card-2); }
.pad-btn .arrow { font-size: 1.3rem; line-height: 1; }
.pad-btn .cap { font-size: 0.72rem; color: var(--muted); }
.pad-btn[data-dir="up"] { grid-area: 1 / 2; }
.pad-btn[data-dir="left"] { grid-area: 2 / 1; }
.pad-cant { grid-area: 2 / 2; }
.pad-btn[data-dir="right"] { grid-area: 2 / 3; }
.pad-btn[data-dir="down"] { grid-area: 3 / 2; }
.pad-cant {
  background: var(--card-2);
  font-size: 0.92rem;
  font-weight: 600;
  color: #ffd97a;
  border-color: rgba(240, 180, 41, 0.45);
}
.pad-cant:active { background: #2a3b4d; }

.quit {
  display: block;
  margin: 0 auto calc(16px + env(safe-area-inset-bottom));
}

/* ---------- report ---------- */
table.report {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  font-size: 0.9rem;
  margin-bottom: 14px;
}
table.report th, table.report td {
  padding: 11px 10px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}
table.report th {
  background: var(--card-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
}
table.report tr:last-child td { border-bottom: none; }
.big-value { font-size: 1.25rem; font-weight: 700; color: #fff; }
.tag {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.76rem;
  font-weight: 600;
}
.tag.ok { background: rgba(53, 192, 127, 0.18); color: var(--ok); }
.tag.mild { background: rgba(240, 180, 41, 0.18); color: var(--warn); }
.tag.bad { background: rgba(240, 97, 109, 0.18); color: var(--danger); }
.tag.na { background: var(--card-2); color: var(--muted); }

.summary {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 0.92rem;
  line-height: 1.7;
}
.summary.alert { border-left-color: var(--warn); }

details.detail {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}
details.detail summary { cursor: pointer; color: var(--muted); }
.detail-list { margin: 10px 0 0; padding-left: 18px; color: var(--muted); line-height: 1.8; }

.conditions {
  font-size: 0.8rem;
  color: #7f8f9e;
  line-height: 1.7;
  margin-bottom: 14px;
}

@media (max-width: 360px) {
  .pad { gap: 6px; padding: 8px; }
  .distance-row input { font-size: 1rem; }
}
