/* ==========================================================================
   IOL Vision Simulator — stylesheet
   Re-skinned to match the learnabouteyes.com design system (design tokens
   copied verbatim from the live site's :root). Self-contained, no external
   resources besides the Google Fonts "Inter" family loaded from index.html.
   ========================================================================== */

:root {
  --primary: #5F9EAD;
  --primary-dark: #4A8A99;
  --primary-light: #EDF5F7;

  --accent: #F7A828;
  --accent-dark: #D4891A;

  --neutral-900: #1A1F2B;
  --neutral-700: #374151;
  --neutral-400: #9CA3AF;
  --neutral-200: #E5E7EB;
  --neutral-100: #F8FAFB;
  --white: #FFFFFF;
  --success: #10B981;

  --radius: 12px;
  --radius-sm: 8px;

  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);

  /* Semantic aliases used throughout this file */
  --bg: var(--neutral-100);
  --surface: var(--white);
  --surface-alt: var(--primary-light);
  --border: var(--neutral-200);
  --text: var(--neutral-900);
  --text-muted: var(--neutral-700);
  --text-faint: var(--neutral-400);

  --warning-bg: #FDF1DE;
  --warning-border: var(--accent);
  --warning-text: #7A4E0C;

  --focus-ring: var(--primary);

  color-scheme: light;
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-width: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  line-height: 1.25;
  font-weight: 700;
  color: var(--neutral-900);
}

p {
  margin: 0 0 0.6em;
}

a {
  color: var(--primary);
}

a:hover {
  color: var(--primary-dark);
}

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

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}

/* --------------------------------------------------------------------------
   Nav (branded header, shared visual language with learnabouteyes.com)
   -------------------------------------------------------------------------- */

.nav {
  background: var(--neutral-900);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-md);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
  flex-wrap: wrap;
}

.nav-logo {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  color: var(--white);
}

.nav-logo:hover {
  color: var(--white);
  opacity: 0.9;
}

.logo-img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: block;
}

.logo-text {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--white);
  letter-spacing: -0.01em;
}

.nav-tool-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-light);
  background: rgba(95, 158, 173, 0.25);
  border: 1px solid rgba(95, 158, 173, 0.5);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   Page intro
   -------------------------------------------------------------------------- */

.page-intro {
  background: var(--primary-light);
  border-bottom: 1px solid var(--border);
  padding: 2.25rem 0 1.75rem;
}

.page-intro h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.5rem, 1.1rem + 1.6vw, 2.1rem);
  color: var(--neutral-900);
  letter-spacing: -0.01em;
}

.page-intro .subtitle {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  max-width: 60ch;
  color: var(--text-muted);
}

.page-intro .disclaimer {
  margin: 0;
  font-size: 0.8rem;
  max-width: 70ch;
  color: var(--text-faint);
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */

.layout {
  padding-top: 1.75rem;
  padding-bottom: 1.75rem;
  display: flex;
  align-items: flex-start;
  gap: 1.75rem;
  flex-wrap: wrap;
}

@media (min-width: 900px) {
  .layout {
    /* Desktop: canvases sit above, wide controls sit below (not a narrow
       sidebar) -- a narrow left column was uncomfortable to use. */
    flex-direction: column;
    flex-wrap: nowrap;
  }
}

/* --------------------------------------------------------------------------
   Controls panel
   -------------------------------------------------------------------------- */

.controls-panel {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  box-shadow: var(--shadow);
}

@media (min-width: 900px) {
  .controls-panel {
    /* Full-width panel below the canvases, laid out as a wide grid instead
       of one long narrow column of fields. */
    width: 100%;
    order: 2;
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    column-gap: 2.5rem;
    row-gap: 1.5rem;
    align-items: start;
  }

  .simulation-area {
    order: 1;
  }

  /* "Your refraction" spans the full width (both eyes side by side inside
     it). Left column: correction toggle+target, then lens type, stacked.
     Right column: toric, then lighting, stacked. */
  .controls-panel > .control-section:nth-of-type(1) {
    grid-column: 1 / -1;
  }
  .controls-panel > .control-section:nth-of-type(2) {
    grid-column: 1;
    grid-row: 2;
  }
  .controls-panel > .control-section:nth-of-type(3) {
    grid-column: 1;
    grid-row: 3;
  }
  .controls-panel > .control-section:nth-of-type(4) {
    grid-column: 2;
    grid-row: 2;
  }
  .controls-panel > .control-section:nth-of-type(5) {
    grid-column: 2;
    grid-row: 3;
  }
  .controls-panel > .form-actions {
    grid-column: 1 / -1;
  }

  .controls-panel .control-section {
    border-bottom: none;
    padding-bottom: 0;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
    padding: 1.1rem 1.25rem;
  }
}

.control-section {
  padding-bottom: 1.15rem;
  border-bottom: 1px solid var(--border);
}

.control-section:last-of-type {
  border-bottom: none;
  padding-bottom: 0;
}

.control-section h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

/* Eye fieldsets -------------------------------------------------------- */

.eye-fieldsets {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

@media (min-width: 480px) {
  .eye-fieldsets {
    flex-direction: row;
  }
  .eye-fieldset {
    flex: 1 1 0;
  }
}

.eye-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 0.9rem 0.95rem;
  margin: 0;
  background: var(--surface-alt);
}

.eye-fieldset legend {
  padding: 0 0.4rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary-dark);
}

.field {
  margin-bottom: 0.65rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.field input[type="number"] {
  width: 100%;
  padding: 0.45rem 0.55rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.field input[type="number"]:focus-visible {
  border-color: var(--focus-ring);
}

.help-text {
  margin: 0.3rem 0 0;
  font-size: 0.76rem;
  color: var(--text-faint);
  line-height: 1.4;
}

/* Buttons ----------------------------------------------------------------
   Adapted from the real site's .btn / .btn-accent / .btn-outline classes. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  font-family: inherit;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  text-decoration: none;
}

.btn-accent {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
}

.btn-accent:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline:hover {
  background: var(--primary);
  color: var(--white);
}

.btn-block {
  width: 100%;
}

.button-row {
  margin-top: 0.9rem;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.button-row .btn {
  flex: 1 1 auto;
  padding: 10px 18px;
  font-size: 0.88rem;
}

/* Form actions (Go / Simulate) -------------------------------------------- */

.form-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.stale-hint {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--warning-text);
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.75rem;
  text-align: center;
}

.stale-hint[hidden] {
  display: none;
}

/* Option lists (radio groups) -------------------------------------------- */

.option-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.option-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  font-size: 0.9rem;
}

.option-row:hover {
  border-color: var(--primary);
}

.option-row:has(input:checked) {
  border-color: var(--primary);
  background: var(--surface-alt);
}

.option-row input[type="radio"],
.option-row input[type="checkbox"] {
  margin-top: 0.15rem;
  accent-color: var(--primary);
  width: 1.05em;
  height: 1.05em;
  flex-shrink: 0;
}

.option-row span {
  color: var(--text);
}

/* Lens description box --------------------------------------------------- */

.info-box {
  margin-top: 0.75rem;
  padding: 0.7rem 0.85rem;
  font-size: 0.83rem;
  color: var(--text-muted);
  background: var(--surface-alt);
  border: 1px dashed var(--primary);
  border-radius: var(--radius-sm);
  min-height: 1.5em;
}

.info-box:empty {
  display: none;
}

/* Toric block ------------------------------------------------------------ */

.toric-block .option-row--toric {
  border: 2px solid var(--accent);
  background: var(--surface-alt);
  font-weight: 600;
}

.toric-block .option-row--toric:has(input:checked) {
  background: var(--accent);
  color: var(--white);
}

.toric-block .option-row--toric:has(input:checked) span {
  color: var(--white);
}

/* Correction toggle + target refraction ----------------------------------- */

.switch-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

.switch-side {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-faint);
}

#corrected-toggle:checked ~ .switch-side,
.switch-row:has(#corrected-toggle:checked) #switch-label-corrected {
  color: var(--text);
}

.switch-row:has(#corrected-toggle:not(:checked)) #switch-label-uncorrected {
  color: var(--text);
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--neutral-200);
  border-radius: 999px;
  transition: var(--transition);
}

.switch input:checked + .switch-track {
  background: var(--primary);
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: var(--white);
  border-radius: 50%;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.switch input:checked ~ .switch-track .switch-thumb {
  transform: translateX(20px);
}

.target-fields {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  transition: opacity 0.15s ease;
}

#lens-type-section {
  transition: opacity 0.15s ease;
}

.is-uncorrected #target-refraction-fields,
.is-uncorrected #lens-type-section {
  opacity: 0.45;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Simulation area
   -------------------------------------------------------------------------- */

.simulation-area {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#webgl-warning {
  display: none;
  padding: 0.9rem 1.1rem;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.canvas-row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  transition: opacity 0.2s ease;
}

.simulation-area.is-stale .canvas-row {
  opacity: 0.55;
}

@media (min-width: 900px) {
  .canvas-row {
    flex-direction: row;
  }
}

.canvas-figure {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.canvas-figure canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1280 / 800;
  max-width: 100%;
  background: #000;
  border-radius: var(--radius-sm);
}

.canvas-figure figcaption {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   How it works
   -------------------------------------------------------------------------- */

.how-it-works {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.how-it-works-inner {
  max-width: 900px;
  padding: 2rem 24px;
}

.how-it-works h2 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
}

.how-it-works p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 68ch;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.footer {
  background: var(--neutral-900);
  color: var(--neutral-400);
  padding: 2.5rem 0 1.5rem;
  margin-top: 1rem;
}

.footer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  padding-bottom: 1.5rem;
}

@media (min-width: 640px) {
  .footer-grid {
    grid-template-columns: 1.2fr 1fr;
  }
}

.footer-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.footer-brand .logo-text {
  color: var(--white);
}

.footer-logo-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.footer-brand p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--neutral-400);
  max-width: 40ch;
}

.footer-about h3 {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--white);
}

.footer-about .disclaimer {
  font-size: 0.8rem;
  color: var(--neutral-400);
  max-width: 50ch;
}

.footer-about a {
  color: var(--primary-light);
  font-size: 0.85rem;
}

.footer-about a:hover {
  color: var(--white);
}

.footer-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 1.25rem;
}

.footer-bottom p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--neutral-400);
}
