:root {
  color-scheme: light;
  --ink: #17223b;
  --muted: #64718a;
  --line: #cad2df;
  --paper: #f4f7fb;
  --surface: #ffffff;
  --blue: #2156d7;
  --blue-soft: #e9efff;
  --red: #e13b3f;
  --teal: #168a8a;
  --amber: #c77a12;
  --shadow: 0 18px 50px rgba(35, 50, 80, .1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 5%, rgba(33, 86, 215, .08), transparent 28rem),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button { font: inherit; }

.app-shell {
  width: min(1420px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 46px;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: .98;
  letter-spacing: -.055em;
}

.instructions {
  max-width: 430px;
  margin-bottom: 4px;
  color: var(--muted);
  line-height: 1.55;
}

.optic-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
  padding: 7px;
  border: 1px solid #dfe5ee;
  border-radius: 15px;
  background: rgba(255, 255, 255, .72);
}

.optic-button {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
  transition: color .18s ease, background .18s ease, transform .18s ease;
}

.optic-button:hover { color: var(--ink); background: #eef2f8; }
.optic-button:active { transform: translateY(1px); }
.optic-button:focus-visible { outline: 3px solid rgba(33, 86, 215, .3); outline-offset: 2px; }
.optic-button.is-active { color: #fff; background: var(--ink); }

.lab {
  overflow: hidden;
  border: 1px solid #dfe5ee;
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.lab-toolbar,
.diagram-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
}

.lab-toolbar { border-bottom: 1px solid #e6eaf0; }
.lab-toolbar h2 { margin-bottom: 3px; font-size: 1.08rem; }
.lab-toolbar p { margin-bottom: 0; color: var(--muted); font-size: .9rem; }

.result { text-align: right; white-space: nowrap; }
.result-label { display: block; margin-bottom: 2px; color: var(--muted); font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; }
.result strong { color: var(--blue); }

.diagram-wrap {
  position: relative;
  width: 100%;
  background-image:
    linear-gradient(rgba(31, 49, 85, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 49, 85, .035) 1px, transparent 1px);
  background-size: 28px 28px;
}

#diagram { display: block; width: 100%; height: auto; touch-action: none; user-select: none; }

.principal-axis { stroke: #738097; stroke-width: 2; }
.tick { stroke: #aab4c5; stroke-width: 2; }
.focus-tick { stroke: var(--blue); stroke-width: 4; }
.focus-label { fill: var(--blue); font-size: 18px; font-weight: 800; text-anchor: middle; }
.distance-label { fill: #8591a5; font-size: 14px; font-weight: 700; text-anchor: middle; }
.focus-handle { fill: var(--surface); stroke: var(--blue); stroke-width: 4; filter: url(#soft-shadow); }
.focus-handle-ring { fill: transparent; cursor: ew-resize; }
.focus-handle-ring:focus { outline: none; }
.focus-handle-ring:focus-visible + .focus-ring { display: block; }
.focus-ring { display: none; fill: none; stroke: rgba(33, 86, 215, .34); stroke-width: 8; }

.ray { color: var(--red); fill: none; stroke: var(--red); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.ray.actual { marker-end: url(#ray-arrow); }
.ray.virtual { stroke-dasharray: 10 10; opacity: .72; }
.ray-marker-fill { fill: var(--red); }
.object-marker-fill { fill: var(--ink); }
.image-marker-fill { fill: var(--blue); }

.optic-center { stroke: var(--ink); stroke-width: 3; }
.lens-fill { fill: rgba(76, 137, 232, .17); stroke: var(--blue); stroke-width: 4; }
.mirror-fill { fill: rgba(44, 160, 160, .12); stroke: var(--teal); stroke-width: 5; }
.mirror-back { fill: none; stroke: #8aa1aa; stroke-width: 3; stroke-dasharray: 8 7; }
.optic-label { fill: var(--muted); font-size: 14px; font-weight: 800; text-anchor: middle; letter-spacing: .08em; }

.object-arrow { color: var(--ink); stroke: currentColor; stroke-width: 9; stroke-linecap: round; marker-end: url(#object-arrow); }
.object-base { stroke: currentColor; stroke-width: 7; stroke-linecap: round; }
.image-arrow { color: var(--blue); stroke: currentColor; stroke-width: 7; stroke-linecap: round; marker-end: url(#image-arrow); }
.image-arrow.virtual-image { opacity: .66; stroke-dasharray: 9 7; }
.arrow-label { fill: currentColor; font-size: 15px; font-weight: 800; text-anchor: middle; }
.object-group { color: var(--ink); }
.image-group { color: var(--blue); }
.drag-target { fill: transparent; cursor: grab; }
.drag-target:active { cursor: grabbing; }
.object-halo { fill: rgba(33, 86, 215, .08); stroke: rgba(33, 86, 215, .35); stroke-width: 2; stroke-dasharray: 5 5; }

.infinity-note { fill: var(--blue); font-size: 18px; font-weight: 800; text-anchor: middle; }
.interaction-surface { fill: transparent; pointer-events: none; }

.diagram-footer {
  justify-content: flex-start;
  min-height: 58px;
  border-top: 1px solid #e6eaf0;
  color: var(--muted);
  font-size: .82rem;
}

.diagram-footer p { display: flex; align-items: center; gap: 8px; margin: 0; }
.diagram-footer p:last-child { margin-left: auto; color: var(--ink); font-weight: 700; }
.line-key { width: 28px; border-top: 3px solid var(--red); }
.line-key.dashed { border-top-style: dashed; opacity: .72; }

@media (max-width: 760px) {
  .app-shell { width: min(100% - 20px, 1420px); padding-top: 20px; }
  .app-header { display: block; }
  .instructions { margin-top: 14px; }
  .optic-picker { grid-template-columns: repeat(2, 1fr); }
  .lab-toolbar { align-items: flex-start; }
  .diagram-wrap { overflow-x: auto; }
  #diagram { min-width: 720px; }
  .diagram-footer { flex-wrap: wrap; }
  .diagram-footer p:last-child { width: 100%; margin-left: 0; }
}

@media (max-width: 1180px) and (min-width: 761px) {
  .app-header { display: block; }
  .instructions { margin-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
