/* ============================================================
   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: #0d1317;
  --ret-surface: #141c22;
  --ret-surface-card: #1c2730;
  --ret-surface-elevated: #24333f;
  --ret-border: #2c3e4c;
  --ret-border-glow: rgba(14, 124, 134, 0.4);
  
  --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;
  min-height: calc(100vh - 120px);
  background: var(--ret-bg);
  color: #e0e8ed;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  padding: 16px 24px 32px;
  gap: 16px;
}

/* ── 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: 12px;
  padding: 10px 18px;
}

.ret-mode-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ret-mode-btn {
  background: var(--ret-surface-card);
  color: #a4b8c4;
  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: inline-flex;
  align-items: center;
  gap: 6px;
}

.ret-mode-btn:hover {
  background: var(--ret-surface-elevated);
  color: #ffffff;
  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: #7dd3fc;
}

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

/* ── Main Simulator Workspace Grid ── */
.ret-workspace {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  gap: 16px;
  align-items: start;
}

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

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

/* ── Common Card Styling ── */
.ret-card {
  background: var(--ret-surface);
  border: 1px solid var(--ret-border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ret-card-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--ret-border);
  padding-bottom: 8px;
}

/* ── Center Viewport: The Virtual Eye & Retinoscopic Beam ── */
.ret-viewport-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #080c0f;
  border: 1px solid var(--ret-border);
  border-radius: 12px;
  padding: 16px;
  min-height: 520px;
  overflow: hidden;
}

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

.ret-eye-toggle {
  display: flex;
  background: var(--ret-surface-card);
  border: 1px solid var(--ret-border);
  border-radius: 8px;
  overflow: hidden;
}

.ret-eye-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.ret-eye-btn.active {
  background: var(--accent);
  color: #fff;
}

.ret-hand-eye-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

/* ── 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: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
  background: #000;
}

.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(255, 255, 255, 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: rgba(13, 19, 23, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--ret-border);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  color: #94a3b8;
  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: 16px;
}

.ret-device-preview {
  position: relative;
  width: 100%;
  height: 150px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--ret-border);
  background: #000;
}

.ret-device-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.85;
}

.ret-device-preview-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.75);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: #fbbf24;
}

/* ── 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);
}

.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: 18px;
  font-weight: 700;
  color: var(--ret-streak);
  text-shadow: 0 0 8px rgba(255, 224, 130, 0.5);
  pointer-events: none;
}

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

.ret-snap-btn {
  background: var(--ret-surface-elevated);
  border: 1px solid var(--ret-border);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 2px;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}

.ret-snap-btn:hover {
  background: var(--accent);
  color: #fff;
}

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

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

.ret-sleeve-btn {
  padding: 10px 8px;
  border-radius: 8px;
  border: 1px solid var(--ret-border);
  background: var(--ret-surface-elevated);
  color: #94a3b8;
  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: #64748b;
}

.ret-sleeve-btn.active {
  background: rgba(14, 124, 134, 0.25);
  border-color: var(--accent);
  color: #38bdf8;
}

.ret-sleeve-btn.active small {
  color: #7dd3fc;
}

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

.ret-slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #94a3b8;
}

.ret-slider-label span:last-child {
  font-family: 'IBM Plex Mono', monospace;
  color: #38bdf8;
}

.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: 16px;
  height: 16px;
  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: var(--ret-surface-card);
  border: 1px solid var(--ret-border);
  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: 11px;
  font-family: 'IBM Plex Mono', monospace;
  color: #94a3b8;
}

/* ── Ray Diagram Side Panel (Beginner Mode) ── */
.ret-ray-diagram-card {
  background: #090e12;
  border: 1px solid var(--ret-border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#rayDiagramCanvas {
  width: 100%;
  height: 100px;
  background: #05080a;
  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: 12px;
  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: var(--ret-surface-card);
  border: 1px solid var(--ret-border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  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 #38bdf8;
}

.ret-lens-badge {
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
  color: #94a3b8;
}

.ret-lens-glass-preview {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 4px solid #334155;
  background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0.02) 80%);
  box-shadow: inset 0 0 12px rgba(255,255,255,0.2), 0 4px 10px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  transition: all 0.2s;
}

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

.ret-step-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--ret-surface-elevated);
  border: 1px solid var(--ret-border);
  color: #fff;
  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);
}

.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(56, 189, 248, 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: #94a3b8;
  font-weight: 600;
}

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

.ret-submit-btn {
  background: #10b981;
  color: #fff;
  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: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--ret-border);
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
  line-height: 1.5;
  color: #cbd5e1;
  min-height: 50px;
}
