/* ==================================================================
 * Lens Thickness page only. Shared styles live in base.css.
 * ================================================================== */

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

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 470px) minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "mode     viewer"
    "controls viewer";
  gap: 18px 40px;
}
.layout[data-mode="frame"] {
  grid-template-areas:
    "mode     options"
    "controls viewer";
}

[data-group="mode"] { grid-area: mode; }
.frame-options { grid-area: options; display: none; gap: 20px; }
.layout[data-mode="frame"] .frame-options { display: flex; }
.controls { grid-area: controls; display: flex; flex-direction: column; gap: 18px; }
.viewer { grid-area: viewer; }

.frame-options .seg[data-group="material"] { flex: 0 0 auto; min-width: 290px; }
.frame-options .seg[data-group="shape"] { flex: 1; }

/* ---------------- Prescription cards ---------------- */

.rx { padding: 20px 24px 20px; }
.rx h2 {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 21px;
  margin: 0 0 8px;
}

/* label on the left, control on the right (keeps the cards short) */
.rx-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  align-items: end; /* label lines up with the slider track */
  margin-bottom: 12px;
}
.rx-row:last-child { margin-bottom: 0; }
.rx-row-index { align-items: center; margin-top: 4px; }
.field-label { display: block; font-size: 16px; line-height: 18px; }

.slider-row {
  display: flex;
  align-items: flex-end; /* end labels line up with the track, below the bubble */
  gap: 10px;
}
.slider-end { font-size: 17px; line-height: 18px; flex: 0 0 auto; }
.slider-end:last-child { min-width: 3.3em; } /* keeps sphere and cylinder tracks the same length */

.slider-wrap {
  position: relative;
  flex: 1;
  padding-top: 27px; /* room for the value bubble above the track */
}

.slider-bubble {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  padding: 3px 9px;
  border-radius: 7px;
  white-space: nowrap;
  pointer-events: none;
}

input[type="range"].power {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  margin: 0;
  cursor: pointer;
}
input[type="range"].power::-webkit-slider-runnable-track {
  height: 3px; background: var(--line); border-radius: 3px;
}
input[type="range"].power::-moz-range-track {
  height: 3px; background: var(--line); border-radius: 3px;
}
input[type="range"].power::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--navy);
  margin-top: -6.5px;
  border: 0;
  transition: transform 0.1s;
}
input[type="range"].power::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--navy); border: 0;
}
input[type="range"].power:active::-webkit-slider-thumb { transform: scale(1.2); }
input[type="range"].power:focus-visible { outline: 3px solid var(--teal); outline-offset: 4px; border-radius: 6px; }

.index-group {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.index-btn {
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 0;
  font-size: 17px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.index-btn:hover:not(.is-active) { border-color: #c9d0d8; background: #f7fafb; }
.index-btn.is-active { background: var(--navy); border-color: var(--navy); color: #fff; }
.index-btn:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

/* ---------------- Viewer ---------------- */

.viewer {
  position: relative;
  padding: 18px 24px 24px;
  display: flex;
  flex-direction: column;
  min-height: 520px;
}

/* Expanded: viewer fills the window below the navbar (navbar stays on top) */
.viewer.is-expanded {
  position: fixed;
  z-index: 40; /* under the navbar (50) */
  top: var(--expand-top, 120px);
  left: 24px; right: 24px; bottom: 24px;
  min-height: 0;
  box-shadow: 0 0 0 100vmax rgba(221, 240, 241, 0.94), var(--shadow); /* dims the page behind */
}
body.viewer-expanded { overflow: hidden; }

/* Round icon buttons in the stage's bottom-right corner: [i] [expand] */
.expand-btn,
.info-btn {
  position: absolute;
  bottom: 36px;
  z-index: 3;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.expand-btn { right: 36px; }
.info-btn { right: 84px; }
.expand-btn:hover, .info-btn:hover { background: #fff; }
.info-btn.is-active { background: var(--navy); border-color: var(--navy); }
.info-btn.is-active svg { stroke: #fff; }
.expand-btn:focus-visible, .info-btn:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.expand-btn svg, .info-btn svg {
  width: 20px; height: 20px;
  fill: none; stroke: var(--navy); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
}

/* Formula panel, opens above the [i] button */
.info-panel {
  position: absolute;
  right: 36px; bottom: 86px;
  z-index: 4;
  width: min(460px, calc(100% - 72px));
  max-height: calc(100% - 130px);
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 14px 36px rgba(20, 27, 71, 0.18);
  padding: 16px 18px 14px;
  font-size: 13.5px;
  line-height: 1.45;
}
.info-panel[hidden] { display: none; }
.info-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.info-head h4 { margin: 0 0 8px; font-family: var(--font-head); font-weight: 600; font-size: 16px; }
.info-close {
  border: 0; background: transparent; cursor: pointer;
  font-size: 22px; line-height: 1; padding: 0 4px; color: var(--muted);
}
.info-close:hover { color: var(--navy); }
.info-steps { margin: 0; padding-left: 20px; }
.info-steps li { margin-bottom: 7px; }
.info-steps b { font-weight: 700; }
.info-steps code {
  display: block;
  margin: 3px 0 1px;
  padding: 4px 8px;
  background: #f2f7f8;
  border-radius: 6px;
  font-family: Consolas, 'Courier New', monospace;
  font-size: 13px;
  color: var(--navy);
}
.info-steps span { display: block; color: var(--muted); font-size: 12.5px; }
.info-example { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.info-example h5 { margin: 0 0 6px; font-family: var(--font-head); font-weight: 600; font-size: 13.5px; }
.info-example p { margin: 0 0 6px; font-size: 12.5px; }
.info-example .info-note { color: var(--muted); margin: 0; }
.expand-btn .icon-exit,
.viewer.is-expanded .expand-btn .icon-enter { display: none; }
.viewer.is-expanded .expand-btn .icon-exit { display: block; }
.viewer-lens, .viewer-frame { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.layout[data-mode="lens"] .viewer-frame,
.layout[data-mode="frame"] .viewer-lens { display: none; }
.layout[data-mode="frame"] .viewer { padding-top: 24px; }

.viewer-titles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  text-align: center;
  padding: 2px 0 14px;
}
.viewer-titles h3 {
  margin: 0;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 20px;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 420px;
  border-radius: 6px;
  overflow: hidden;
  /* faint vertical lines like the design */
  background:
    repeating-linear-gradient(90deg, transparent 0 51px, rgba(20, 27, 71, 0.05) 51px 52px),
    #f8fafc;
}

.canvas-host { position: absolute; inset: 0; }
.canvas-host canvas { display: block; width: 100% !important; height: 100% !important; cursor: grab; touch-action: none; }
.canvas-host canvas:active { cursor: grabbing; }

.stage-divider {
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 2px;
  background: rgba(20, 27, 71, 0.12);
  pointer-events: none;
}

.lens-info {
  position: absolute;
  top: 18px;
  width: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  text-align: center;
}
.lens-info[data-eye="left"] { left: 0; }
.lens-info[data-eye="right"] { left: 50%; }
.lens-index { font-size: 13px; color: var(--muted); letter-spacing: 0.04em; }
.lens-sphere { font-family: var(--font-head); font-weight: 600; font-size: 20px; }
.lens-thick {
  margin-top: 6px;
  white-space: nowrap;
  font-size: 13px;
  color: var(--navy);
  background: rgba(98, 191, 193, 0.18);
  padding: 3px 10px;
  border-radius: 999px;
}

.drag-hint {
  position: absolute;
  bottom: 10px; left: 0; right: 0;
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}
.drag-hint .dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #e5383b; vertical-align: middle; margin-right: 2px;
}

.float-label {
  position: absolute;
  top: 0; left: 0;
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  background: var(--navy);
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  pointer-events: none;
  will-change: transform;
}

.frame-readout {
  position: absolute;
  top: 14px; left: 14px; right: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}
.frame-readout > div {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex; flex-direction: column;
  font-size: 13px;
}
.frame-readout span { color: var(--muted); }
.frame-readout strong { font-family: var(--font-head); font-weight: 600; font-size: 15px; }

/* ---------------- Responsive ---------------- */

@media (max-width: 1100px) {
  .layout[data-mode="frame"] .frame-options { flex-direction: column; gap: 12px; }
  .frame-options .seg[data-group="material"] { min-width: 0; }
}

@media (max-width: 900px) {
  .layout,
  .layout[data-mode="frame"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    grid-template-areas: "mode" "options" "viewer" "controls";
  }
  .viewer { min-height: 0; padding: 14px; }
  .stage { min-height: 340px; }
  .lens-sphere { font-size: 16px; }
  .lens-thick { font-size: 10.5px; white-space: nowrap; padding: 3px 8px; }
  .lens-index { font-size: 11px; }
  .frame-readout { flex-direction: column; align-items: flex-start; gap: 6px; }
  .frame-readout strong { font-size: 13px; }
}

/* ---------------- Fit to screen (desktop) ----------------
 * With body.fit-screen (see base.css) the layout fills the remaining height
 * and the 3D viewer stretches, so there is no page scroll at 1920×1080 or 1366×768.
 */
@media (min-width: 1200px) and (min-height: 560px) {
  .fit-screen .intro h1 { font-size: 34px; margin: 0 0 2px; }
  .fit-screen .intro p { margin: 0 0 16px; }
  .fit-screen .layout {
    flex: 1;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 16px 32px;
  }
  .fit-screen .controls { gap: 16px; min-height: 0; }
  .fit-screen .viewer { min-height: 0; }
  .fit-screen .stage { min-height: 0; }
}

/* Shorter desktop screens (e.g. 1366×768) */
@media (min-width: 1200px) and (max-height: 820px) {
  .fit-screen .intro h1 { font-size: 26px; margin-bottom: 10px; }
  .fit-screen .intro p { display: none; } /* the navbar tab already names the tool */
  .fit-screen .layout { gap: 12px 28px; }
  .fit-screen .controls { gap: 12px; }
  .seg { padding: 6px; }
  .seg-btn { padding: 10px 14px; font-size: 16px; }
  .rx { padding: 14px 20px 14px; }
  .rx h2 { font-size: 18px; margin-bottom: 4px; }
  .rx-row { margin-bottom: 8px; }
  .slider-wrap { padding-top: 25px; }
  .index-btn { padding: 7px 0; font-size: 16px; }
  .viewer { padding: 14px 18px 18px; }
  .viewer-titles { padding-bottom: 10px; }
  .viewer-titles h3 { font-size: 18px; }
  .expand-btn, .info-btn { bottom: 28px; }
  .expand-btn { right: 28px; }
  .info-btn { right: 76px; }
  .info-panel { right: 28px; bottom: 76px; max-height: calc(100% - 110px); }
}

/* Very short windows: drop the page title too */
@media (min-width: 1200px) and (max-height: 660px) {
  .fit-screen .intro { display: none; }
}
