@font-face {
  font-family: "Public Sans";
  src: url("fonts/public-sans-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Public Sans";
  src: url("fonts/public-sans-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Public Sans";
  src: url("fonts/public-sans-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #143d2f;
  --deep: #0d2a20;
  --link: #2c6a54;
  --gold: #d9a441;
  --tint: #eff4f0;
  --rule: #dce6df;
  --text: #1e2b24;
  --body: #33463b;
  --muted: #56665c;
  --paper: #fff;
  --primary: var(--ink);
  --accent: var(--link);
  --surface: var(--tint);
  --label: var(--muted);
  --hairline: var(--rule);
  --warn: #fff4cc;
  --tab: calc(44px + env(safe-area-inset-bottom));
  --sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-family: var(--sans);
}

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  text-size-adjust: 100%;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.4;
  min-height: 100dvh;
  overflow-x: hidden;
  max-width: 100%;
}

h1, h2, .brand span {
  font-weight: 700;
  color: var(--ink);
}

body[data-screen="chart"] {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: var(--tab);
}

body[data-screen="calibrate"] {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: var(--tab);
}

body[data-screen="calibrate"] #main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

:focus { outline: none; }

:focus-visible {
  outline: 3px solid var(--link);
  outline-offset: 3px;
}

.skip {
  position: absolute;
  left: 0.5rem;
  top: -4rem;
  background: #fff;
  color: var(--ink);
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--primary);
  z-index: 40;
}

.skip:focus { top: calc(0.5rem + env(safe-area-inset-top)); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

a { color: var(--link); }
a:hover { color: var(--deep); text-decoration-thickness: 2px; }

button,
input { font: inherit; color: var(--ink); background: #fff; }

button {
  min-height: 44px;
  min-width: 44px;
  padding: 0.45rem 0.9rem;
  border: 0;
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}

button.primary {
  background: var(--ink);
  color: #fff;
  font-weight: 700;
}

button.primary:hover,
button.primary:active { background: var(--deep); }

button:disabled {
  color: #3a3a3a;
  background: #ececef;
  cursor: not-allowed;
}

code {
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.prose {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.25rem 1.25rem calc(2rem + env(safe-area-inset-bottom));
}

.gate {
  min-height: 100dvh;
  max-width: 26rem;
  margin: 0 auto;
  padding: calc(1.5rem + env(safe-area-inset-top)) 1.5rem calc(1.75rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
}

.gate-logo {
  width: 88px;
  height: 88px;
  border-radius: 20px;
}

.gate h1,
.brand {
  font-weight: 700;
  letter-spacing: -0.02em;
}

.gate h1 {
  margin: 0.35rem 0 0.15rem;
  font-size: 2rem;
  line-height: 1.05;
}

.lede { margin: 0.35rem 0 0; font-size: 1.05rem; }
.setup { margin: 0.35rem 0 0.6rem; max-width: 22rem; color: var(--muted); }

h1 { font-size: 1.7rem; line-height: 1.1; margin: 0 0 0.6rem; }
h2 { font-size: 1.15rem; margin: 0.2rem 0 0.55rem; }

ul { padding-left: 1.15rem; margin: 0.4rem 0; }
li + li { margin-top: 0.45rem; }

.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.4rem 0 0; }
.actions .primary { min-width: 11rem; min-height: 48px; font-size: 1.1rem; }

.fine { color: var(--muted); font-size: 0.95rem; }
.fine a,
button.link { font-weight: 600; }

button.link {
  min-height: 44px;
  min-width: 44px;
  padding: 0.35rem 0.6rem;
  background: transparent;
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

button.link:hover { color: var(--deep); background: transparent; }

.banner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  background: var(--warn);
  color: var(--ink);
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  font-weight: 700;
}

.banner p { margin: 0; }

.warn {
  background: var(--warn);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  font-weight: 650;
}

#screen-calibrate {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.cal-page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.45rem 0.85rem 0;
}

.cal-top {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

#cal-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
}

.cal-info {
  flex: none;
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  border-radius: 22px;
  background: var(--tint);
  color: var(--primary);
}

.cal-info svg { width: 28px; height: 28px; display: block; margin: 0 auto; }

.stage-wrap {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: #fff;
}

.stage {
  min-height: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 8px;
  background: #fff;
}

.ref-rect {
  flex: none;
  margin: 0;
  border: 2px solid #000;
  background: #fff;
  box-sizing: border-box;
}

.cal-footer {
  flex: none;
  position: relative;
  z-index: 2;
  background: #fff;
  padding: 0.45rem 0 0.5rem;
  box-shadow: 0 -1px 0 var(--hairline);
}

.cal-controls {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.cal-controls button {
  width: 52px;
  height: 52px;
  min-width: 52px;
  padding: 0;
  font-size: 1.7rem;
  line-height: 1;
}

.cal-controls input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 44px;
  margin: 0;
  accent-color: var(--ink);
}

#save-cal { width: 100%; }

body[data-screen="chart"] #main {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#screen-chart,
.chart-app {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  padding: calc(0.3rem + env(safe-area-inset-top)) 1rem 0.15rem;
}

.brand {
  display: flex;
  align-items: center;
  margin: 0;
  min-width: 0;
  font-size: 1.15rem;
  line-height: 1;
}

.brand a {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0 4px;
  margin-left: -4px;
  color: var(--ink);
  text-decoration: none;
  border-radius: 10px;
}

.brand a:hover { color: var(--ink); text-decoration: none; }

.brand img {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex: none;
}

.head-set {
  margin: 0 0 0 auto;
  min-height: 44px;
  min-width: 44px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  border-radius: 10px;
}

.chart-scroll {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: auto;
  background: #fff;
}

.chart-surface {
  background: #fff;
  color: var(--ink);
  forced-color-adjust: none;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.25rem 12px 0.35rem;
}

#lines { flex: 0 0 auto; }

.omission {
  margin: 0.35rem 0.75rem 0.5rem;
  padding: 0 0.75rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.omission:empty { display: none; }

.line {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin: 0 auto;
}

.approx { font-weight: 650; line-height: 1; margin-left: 0.15rem; }
.symbols { display: flex; align-items: flex-start; line-height: 0; }
.optotype { display: block; overflow: visible; background: #fff; }
.optotype path { fill: #000; }
.optotype.crisp { shape-rendering: crispEdges; overflow: hidden; }
.optotype.smooth { shape-rendering: geometricPrecision; }
.optotype.smooth path[fill="none"],
.optotype.smooth circle,
.optotype.smooth ellipse { fill: none; stroke: #000; }

.acuity {
  position: absolute;
  left: var(--label-left, 0px);
  top: 50%;
  transform: translateY(-50%);
  margin: 0;
  color: var(--label);
  font-size: var(--label-size, 12px);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  line-height: 1;
  text-align: left;
  white-space: nowrap;
  pointer-events: none;
}

.tabbar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: var(--tab);
  padding: 0 0.2rem env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--rule);
  backdrop-filter: blur(16px);
}

body[data-screen="chart"] .tabbar,
body[data-screen="calibrate"] .tabbar { display: flex; }

.tabbar button {
  flex: 1;
  min-width: 44px;
  min-height: 44px;
  height: 44px;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0 2px;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.05;
}

.tabbar button svg { width: 20px; height: 20px; display: block; }
.tabbar button .icon-check { display: none; }

.tabbar button[aria-pressed="true"],
.tabbar button[aria-current="page"] {
  color: var(--link);
  background: var(--tint);
}

#tab-cal:not(.is-calibrated) {
  color: var(--ink);
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.tabbar button.is-calibrated,
.tabbar button.is-calibrated[aria-current="page"],
.tabbar button.is-calibrated[aria-pressed="true"] {
  flex: 0 0 auto;
  width: auto;
  max-width: calc(100% - 96px);
  flex-direction: row;
  gap: 2px;
  color: #fff;
  background: var(--ink);
  box-shadow: none;
  padding: 0 6px;
  text-align: left;
}

.tabbar button.is-calibrated .icon-cal { display: none; }
.tabbar button.is-calibrated .icon-check { display: block; width: 12px; height: 12px; color: var(--gold); flex: none; }
.tabbar button.is-calibrated span {
  white-space: nowrap;
  font-size: 12px;
  line-height: 1;
  letter-spacing: -0.03em;
}

@media (max-width: 340px) {
  .tabbar button.is-calibrated { padding: 0 5px; gap: 2px; }
  .tabbar button.is-calibrated .icon-check { width: 11px; height: 11px; }
  .tabbar button.is-calibrated span { font-size: 11px; letter-spacing: -0.04em; }
}

dialog.sheet {
  --sheet-y: 0px;
  border: 0;
  padding: 0.15rem 1.15rem calc(0.9rem + env(safe-area-inset-bottom));
  margin: auto auto 0;
  width: 100%;
  max-width: 32rem;
  max-height: min(86dvh, 680px);
  overflow: auto;
  border-radius: 16px 16px 0 0;
  color: var(--ink);
  background: #fff;
  transform: translateY(var(--sheet-y));
  transition: transform 0.26s cubic-bezier(0.2, 0.9, 0.2, 1);
  touch-action: pan-y;
}

dialog.sheet.dragging { transition: none; }

dialog.sheet::backdrop { background: rgba(33, 33, 33, 0.4); }

.grab {
  width: 100%;
  height: 28px;
  margin: 0 0 0.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  touch-action: none;
  cursor: grab;
}

.grab::before {
  content: "";
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: #c8c8cc;
}

dialog.sheet h2 { touch-action: none; }

dialog.sheet p {
  margin: 0.2rem 0 0.75rem;
  line-height: 1.35;
}

.sheet .fine { margin: 0.7rem 0; }

#privacy-sheet a { overflow-wrap: anywhere; }

.about {
  margin: 0.2rem 0 0;
  border-top: 1px solid var(--hairline);
}

.about summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 650;
  cursor: pointer;
}

.about p {
  margin: 0 0 0.55rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.sheet form { margin: 0.7rem 0 0.2rem; }
.sheet form button,
.sheet > button { width: 100%; }

.set-segment {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(44px, 1fr));
  min-height: 44px;
  padding: 3px;
  margin: 0.2rem 0 0.8rem;
  border-radius: 12px;
  background: var(--tint);
}

.set-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / 3);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(13, 42, 32, 0.16);
  transform: translateX(calc(var(--i, 0) * 100%));
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.2, 1);
}

.set-segment button {
  position: relative;
  z-index: 1;
  min-height: 44px;
  min-width: 44px;
  margin: 0;
  padding: 0 4px;
  background: transparent;
  color: var(--body);
  font-weight: 600;
  border-radius: 9px;
}

.set-segment button[aria-checked="true"] {
  color: var(--ink);
  font-weight: 700;
}

.set-segment button:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .set-thumb { transition: none; }
}

.segment {
  display: flex;
  background: var(--surface);
  border-radius: 12px;
  padding: 3px;
  margin: 0 0 0.7rem;
}

.segment button {
  flex: 1;
  background: transparent;
  border-radius: 9px;
  color: var(--ink);
}

.segment button[aria-pressed="true"] {
  background: var(--tint);
  color: var(--link);
  box-shadow: inset 0 0 0 1.5px var(--link);
}

.option-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
  text-align: left;
}

.option-row::after {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 11px;
  border: 2px solid #8e8e93;
  box-sizing: border-box;
  flex: none;
}

.option-row[aria-pressed="true"]::after {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 4px #fff;
}

#new-sequence { width: 100%; margin-bottom: 0.5rem; }

.print-warning { display: none; }

@media (min-width: 700px) {
  dialog.sheet {
    margin: auto;
    width: min(28rem, calc(100% - 2rem));
    border-radius: 16px;
    padding-bottom: 1rem;
  }
}

@media (min-width: 900px) {
  .cal-page { max-width: 32rem; margin: 0 auto; width: 100%; }
}

@media (prefers-color-scheme: dark) {
  .chart-surface,
  .optotype { background: #fff; color: #000; }
  .optotype.crisp path { fill: #000; }
  .optotype.smooth path[fill="none"],
  .optotype.smooth circle,
  .optotype.smooth ellipse { fill: none; stroke: #000; }
}

@media (forced-colors: active) {
  :focus-visible { outline: 3px solid Highlight; }
  .chart-surface,
  .ref-rect { forced-color-adjust: none; background: #fff; color: #000; }
}

@media print {
  .print-warning { display: block; padding: 1rem; font-weight: 650; }
  .chart-scroll, .tabbar, .stage, .banner, dialog { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  dialog.sheet { transition: none; }
}
