/* ============================================================
   retinoscopy.css — Professional Streak Retinoscopy Simulator
   ─────────────────────────────────────────────────────────────
   PURPOSE : Layout, instrument hardware controls, trial frame,
             optical power cross, ray diagram, and clinical exam HUD.
   STANDARDS: Modern CSS Grid/Flexbox, clinical dark/light theme,
             ultra-sharp rendering, glassmorphism for lenses.
   ============================================================ */

/* ── Theme & Custom Properties ── */
:root {
  --ret-bg: var(--bg);
  --ret-surface: var(--surface);
  --ret-surface-card: var(--surface-sunken);
  --ret-surface-elevated: #E7E9E1;
  --ret-border: var(--border);
  --ret-border-glow: rgba(31, 75, 76, 0.2);
  
  --ret-streak: #ffe082;
  --ret-streak-glow: rgba(255, 224, 130, 0.6);
  --ret-reflex-red: #ff4500;
  --ret-reflex-glow: rgba(255, 69, 0, 0.7);
  
  --lens-plus-rim: #1a1a1a;
  --lens-minus-rim: #c62828;
  --lens-cyl-rim: #78909c;
  --lens-glass: rgba(230, 245, 255, 0.22);
}

/* ── Main App Shell for Retinoscopy ── */
.ret-app {
  display: flex;
  flex-direction: column;
  flex: 1; /* Fill the remaining space from .app shell */
  min-height: 0; /* Prevent unwanted flex overflow */
  background: var(--ret-bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  padding: 12px 20px 14px;
  gap: 10px;
  box-sizing: border-box;
}

/* ── Mode Navigation Bar ── */
.ret-mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--ret-surface);
  border: 1px solid var(--ret-border);
  border-radius: 16px;
  padding: 10px 18px;
}

.ret-mode-field {
  position: relative;
}

.ret-mode-hamburger {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ret-surface-card);
  color: var(--text);
  border: 1px solid var(--ret-border);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ret-mode-hamburger:hover {
  background: var(--ret-surface-elevated);
  border-color: var(--accent);
}

.ret-mode-hamburger svg {
  flex-shrink: 0;
  color: var(--accent);
}

.ret-mode-buttons {
  display: none; /* Hidden by default, shown as dropdown only via .is-open */
  flex-direction: column;
  gap: 6px;
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-start: 0; /* anchors to the toggle's leading edge in both LTR and RTL */
  background: var(--ret-surface-elevated);
  border: 1px solid var(--ret-border);
  border-radius: 10px;
  padding: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  z-index: 120; /* must clear the sticky .ret-panel-tabs bar (z-index: 60) below 1024px */
  width: max-content;
  max-width: 300px;
}

.ret-mode-buttons.is-open {
  display: flex;
  animation: fadeInDown 0.15s ease-out;
}

.ret-mode-btn {
  background: var(--ret-surface-card);
  color: var(--text-soft);
  border: 1px solid var(--ret-border);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
}

.ret-mode-btn:hover {
  background: var(--ret-surface-elevated);
  color: var(--text);
  border-color: var(--accent);
}

.ret-mode-btn.active {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent-strong);
  box-shadow: 0 2px 10px rgba(14, 124, 134, 0.35);
}

.ret-top-indicators {
  display: flex;
  align-items: center;
  gap: 16px;
}

.ret-badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--ret-surface-card);
  border: 1px solid var(--ret-border);
  color: var(--accent);
}

.ret-badge.warning {
  background: rgba(180, 85, 43, 0.2);
  color: var(--warn-strong);
  border-color: #b4552b;
}

/* ── Main Simulator Workspace Grid ── */
.ret-workspace {
  display: grid;
  grid-template-rows: minmax(0, 1fr); /* Crucial: forces row to fit container height */
  grid-template-columns: 320px 1fr 340px;
  gap: 16px;
  align-items: stretch; /* Crucial: stretch columns to fill full height */
  flex: 1; /* Fill remaining height in .ret-app */
  min-height: 0; /* Enable internal scrolling for flex children */
}

@media (max-width: 1280px) {
  .ret-workspace {
    grid-template-columns: 280px 1fr 300px;
  }
}

@media (max-width: 1024px) {
  .ret-workspace {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
}

/* ── Common Card Styling ── */
.ret-card {
  background: var(--ret-surface);
  border: none;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.03), 0 2px 8px rgba(0,0,0,0.02);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  overflow-y: auto; /* Allow independent scrolling if content is too tall */
  scrollbar-width: thin;
  scrollbar-color: var(--ret-border) transparent;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05), 0 1px 3px rgba(0,0,0,0.03);
}

.ret-card-title {
  font-size: 13.5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--ret-border);
  padding-bottom: 12px; margin-bottom: 4px; border-bottom: 1px solid rgba(0,0,0,0.04);
}

/* ── Center Viewport: The Virtual Eye & Retinoscopic Beam ── */
.ret-viewport-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #ffffff;
  box-shadow: 0 12px 32px rgba(0,0,0,0.04);
  border: none;
  border-radius: 16px;
  padding: 16px;
  min-height: 520px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--ret-border) transparent;
}

.ret-viewport-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  z-index: 5;
}

.ret-eye-toggle {
  display: inline-flex;
  background: var(--surface-sunken);
  border: none;
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}

.ret-eye-btn {
  background: transparent;
  border: none;
  color: var(--text-soft);
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 999px;
  transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.ret-eye-btn.active {
  background: #ffffff;
  color: var(--accent-strong);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.ret-hand-eye-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-tint);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  box-shadow: 0 2px 8px rgba(31, 75, 76, 0.15);
}

/* ── Canvas Container ── */
.ret-canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 600px;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  user-select: none;
  touch-action: none;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,0.1);
  background: #0f172a;
  border: 4px solid #ffffff;
  box-shadow: 0 16px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);
}

.ret-canvas-wrap:active {
  cursor: grabbing;
}

#retinoscopyCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Trial Frame On-Screen Overlay ── */
.ret-trial-frame-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 340px;
  height: 340px;
  pointer-events: none;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.trial-ring-axis {
  position: absolute;
  width: 320px;
  height: 320px;
  border: 2px dashed rgba(0, 0, 0, 0.25);
  border-radius: 50%;
  pointer-events: none;
}

/* ── Sweep Hint & Motion Overlay ── */
.ret-sweep-guide {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  border-color: var(--accent);
  backdrop-filter: blur(8px);
  border: 1px solid var(--ret-border);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

/* ── Right Panel: Retinoscope Hardware Device Controls ── */
.ret-hardware-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}



/* ── Collar Rotation Knob / Dial ── */
.ret-dial-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--ret-surface-card);
  border-radius: 10px;
  border: 1px solid var(--ret-border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.ret-dial-wrap {
  position: relative;
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: pointer;
}

.ret-dial-svg {
  width: 100%;
  height: 100%;
}

.ret-dial-center-val {
  position: absolute;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 16px;
  font-weight: 800;
  color: var(--accent-strong);
  background: #ffffff;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.ret-snap-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
}

.ret-snap-btn {
  background: var(--surface-sunken);
  border: none;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}

.ret-snap-btn:hover {
  background: var(--accent);
  color: #FFFFFF;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(14, 124, 134, 0.4);
}

/* ── Sleeve Mode Switch ── */
.ret-sleeve-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-sunken);
  border-radius: 12px;
  border: none;
  padding: 12px;
}

.ret-sleeve-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ret-sleeve-btn {
  padding: 10px 8px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.2s;
}

.ret-sleeve-btn small {
  font-size: 10px;
  color: var(--text-faint);
}

.ret-sleeve-btn.active {
  background: #ffffff;
  color: var(--accent-strong);
  box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.ret-sleeve-btn.active small {
  color: var(--accent);
}

/* ── Sliders ── */
.ret-slider-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ret-slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-soft);
}

.ret-slider-label span:last-child {
  font-family: 'IBM Plex Mono', monospace;
  color: var(--accent);
}

.ret-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--ret-border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

.ret-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(14, 124, 134, 0.8);
}

/* ── Left Panel: Optical Cross & Clinical Cases ── */
.ret-optical-cross-card {
  background: #ffffff;
  border: 2px solid var(--accent-tint);
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.02);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.ret-optical-cross-svg {
  width: 160px;
  height: 160px;
}

.ret-cross-info {
  display: flex;
  justify-content: space-between;
  width: 100%;
  font-size: 12.5px;
  font-weight: 600;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--accent-strong);
}

/* ── Ray Diagram Side Panel (Beginner Mode) ── */
.ret-ray-diagram-card {
  background: var(--bg);
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.04);
  border: 1px solid var(--ret-border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#rayDiagramCanvas {
  width: 100%;
  height: 100px;
  background: var(--surface);
  border-radius: 6px;
}

/* ── Bottom Section: Trial Lens Rack & Clinical Rx Submission ── */
.ret-bottom-bar {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 16px;
  background: var(--ret-surface);
  border: 1px solid var(--ret-border);
  border-radius: 16px;
  padding: 16px;
}

@media (max-width: 1024px) {
  .ret-bottom-bar {
    grid-template-columns: 1fr;
  }
}

/* ── Lens Wheel / Rack UI ── */
.ret-lens-slot-box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.ret-lens-slot {
  background: #ffffff;
  border: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.04);
  border-radius: 14px;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  position: relative;
}

.ret-lens-slot.plus {
  border-top: 3px solid #10b981;
}

.ret-lens-slot.minus {
  border-top: 3px solid #ef4444;
}

.ret-lens-slot.cyl {
  border-top: 3px solid var(--accent);
}

.ret-lens-badge {
  font-size: 11.5px;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-soft);
  letter-spacing: 0.02em;
}

.ret-lens-glass-preview {
  width: 68px;
  height: 68px;
  font-size: 14px;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: radial-gradient(circle, rgba(255,255,255,0.5) 0%, rgba(0,0,0,0.02) 100%);
  box-shadow: inset 0 0 10px rgba(0,0,0,0.03), 0 2px 6px rgba(0,0,0,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  transition: all 0.2s;
}

.ret-lens-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  justify-content: center;
}

.ret-step-btn {
  width: 44px;
  height: 44px;
  font-size: 20px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid var(--ret-border);
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  color: var(--text-soft);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s, transform 0.06s;
  /* The steppers ramp on press-and-hold, so a touch-hold must not be taken
     as the start of a page scroll, and a fast repeat must not select text. */
  touch-action: none;
  user-select: none;
}

.ret-step-btn:hover {
  background: var(--accent-tint);
  color: var(--accent-strong);
  border-color: var(--accent);
  box-shadow: 0 4px 8px rgba(31, 75, 76, 0.1);
}

.ret-step-btn:active {
  transform: scale(0.92);
}

/* Auto-repeat is running: the dial is visibly "spinning" under the finger. */
.ret-step-btn.is-ramping {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 75, 76, 0.35);
}

/* End of the physical trial-lens range. Marked with aria-disabled rather than
   the disabled property so the button keeps its place in the tab order. */
.ret-step-btn[aria-disabled='true'] {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.ret-step-btn[aria-disabled='true']:hover {
  background: var(--ret-surface-elevated);
}

/* ── Clinical Rx Submission Form (Exam Mode) ── */
.ret-rx-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--ret-surface-card);
  border: 1px solid var(--ret-border);
  border-radius: 10px;
  padding: 12px;
}

.ret-rx-inputs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.ret-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ret-input-wrap label {
  font-size: 11px;
  color: var(--text-soft);
  font-weight: 600;
}

.ret-input-wrap input {
  background: var(--ret-surface-elevated);
  border: 1px solid var(--ret-border);
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  width: 100%;
}

.ret-submit-btn {
  background: #10b981;
  color: #FFFFFF;
  border: none;
  padding: 10px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.ret-submit-btn:hover {
  background: #059669;
}

.ret-feedback-box {
  background: var(--bg);
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.04);
  border: 1px solid var(--ret-border);
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-soft);
  min-height: 50px;
}
