@font-face {
  font-family: 'OpenDyslexic';
  src: url('OpenDyslexic-Regular.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #FAFAFA;
  --panel: #FFFFFF;
  --text-strong: #1A1A1A;
  --text-subtle: #5a5a5a;
  --border: #E0E0E0;

  --brand-purple: #7B2D8B;
  --brand-teal: #117A65;
  --g1: #7B2D8B;
  --g2: #117A65;

  --radius-lg: 20px;
  --shadow-1: 0 2px 6px rgba(0,0,0,0.06);
  --shadow-2: 0 10px 20px rgba(17, 24, 39, 0.06);

  --dyslexic-font: 'OpenDyslexic', 'Comic Sans MS', Arial, sans-serif;
  --standard-font: Arial, sans-serif;
}

/* ================= STANDARD FONT OVERRIDE ================= */
html.standard-font body,
html.standard-font .btn,
html.standard-font .btn-primary,
html.standard-font .btn-outline,
html.standard-font .mode-card,
html.standard-font .mode-overlay-title,
html.standard-font .mode-overlay-close,
html.standard-font #reading-text {
  font-family: var(--standard-font) !important;
}

/* ================= TOGGLE BUTTONS ================= */
.theme-toggle-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  z-index: 10000;
  transition: transform 0.2s, box-shadow 0.2s;
}

.theme-toggle-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 14px rgba(0,0,0,0.15);
}

/* ================= DARK THEME (#27) ================= */
.dark-mode {
  --bg: #1a1a2e;
  --panel: #16213e;
  --text-strong: #e0e0e0;
  --text-subtle: #a0a0b0;
  --border: #2a2a4a;
  --brand-purple: #a855f7;
  --brand-teal: #2dd4bf;
  --g1: #a855f7;
  --g2: #2dd4bf;
  --shadow-1: 0 2px 6px rgba(0,0,0,0.3);
  --shadow-2: 0 10px 20px rgba(0,0,0,0.4);
}

.dark-mode body { background: var(--bg); color: var(--text-strong); }
.dark-mode .unified-card { background: var(--panel); }
.dark-mode .right-unified-card { background: #1e1e3a; }
.dark-mode .btn { background: var(--panel); color: var(--text-strong); border-color: var(--border); }
.dark-mode .btn:hover { background: linear-gradient(120deg, #2a1a4a, #1a2a3a); }
.dark-mode .btn-outline { background: var(--panel); color: var(--text-strong); border-color: var(--border); }
.dark-mode .control-bar { background: var(--panel); }
.dark-mode .tools-panel { background: var(--panel); border-color: var(--border); }
.dark-mode .chat-message.ai { background: linear-gradient(135deg, #4a2080 0%, #2a1050 100%); color: #e8e0f8; }
.dark-mode .chat-message.user { background: rgba(200,200,220,0.15); color: var(--text-strong); }
.dark-mode .modal-content { background: var(--panel); color: var(--text-strong); }
.dark-mode .mode-overlay-content { background: rgba(22, 33, 62, 0.95); }
.dark-mode .mode-overlay-title { color: var(--text-strong); }
.dark-mode .mode-overlay-close { color: var(--text-strong); border-color: var(--border); }
.dark-mode #reading-text { color: var(--text-strong); }
.dark-mode .active-word { background: rgba(168, 85, 247, 0.3); }
.dark-mode .difficult-word { color: #c084fc; text-decoration-color: #7c3aed; }
.dark-mode .camera-feed { background: #0f0f2e; }
.dark-mode #video { background: #0f0f2e; }
.dark-mode .dictation-text { color: var(--text-strong); }
.dark-mode .write-mode-panel textarea { background: var(--panel); color: var(--text-strong); border-color: var(--border); }


/* ================= RESET & BASE ================= */
body {
  margin: 0;
  font-family: var(--dyslexic-font);
  font-size: 18px;
  background: var(--bg);
  color: var(--text-strong);
  letter-spacing: 0.05em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ================= MAIN LAYOUT ================= */
.main-layout {
  display: flex;
  gap: 24px;
  padding: 24px 40px 24px 24px;
  height: 100vh;
  box-sizing: border-box;
  overflow: hidden;
}

/* ================= LEFT PANEL (Resizable) ================= */
.left-panel {
  display: flex;
  flex-direction: column;
  width: 35%; /* Default width */
  min-width: 250px; /* Prevent shrinking too much */
  max-width: 60%; /* Prevent expanding too much */
  resize: horizontal; /* Enables native dragging on the right edge */
  overflow: auto; /* Required for resize to work */
  padding-right: 12px; /* Breathing room for the drag handle */
}

/* ================= RIGHT PANEL ================= */
.right-panel {
  display: flex;
  flex-direction: column;
  flex: 1; /* Takes up remaining space */
  min-width: 0;
  height: 100%;
}

/* ================= UNIFIED CARDS ================= */
.unified-card {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  height: 100%;
  overflow: hidden;
}

    

.right-unified-card {
  background: #FFFDF7; /* Warmer background for reading */
}

/* ================= CAMERA CARD (Now just content) ================= */
.unified-camera {
  padding: 16px 16px 4px 16px; /* Top, Right, Bottom, Left. Bottom is smaller because chat is below it */
}

.camera-feed {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 12px;
  overflow: hidden;
  background: #FAFBFF;
  aspect-ratio: 16 / 9;
}
.camera-feed { box-shadow: 0 1px 0 rgba(0,0,0,0.06); }
.camera-feed::after { display:none; }

#video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #FAFBFF;
  border-radius: 16px;
}

/* ================= OVERLAY BUTTONS ================= */
.camera-overlay { position: static; bottom: auto; left: auto; }

.btn {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  font-family: var(--dyslexic-font);
  background: #fff;
  color: var(--text-strong);
  box-shadow: var(--shadow-1);
  transition: background .2s ease, border-color .2s ease, transform .12s ease;
}
.btn:hover {
  background: linear-gradient(120deg, #F2EDFF, #ECF4FF);
  border-color: #DAD5FF;
  transform: translateY(-1px);
}

.mic-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-strong);
  position: relative;
  overflow: hidden;
  transition: transform .2s ease, background .2s ease, border-color .2s ease, color .2s ease;
}
.mic-btn::before {
  content: "";
  position: absolute;
  bottom: 6px;
  left: 50%;
  width: 22px;
  height: 2px;
  background: #10b981;
  border-radius: 4px;
  transform: translateX(-50%);
  transition: all .08s linear;
}
.mic-btn.recording {
  background: #F6FFFA;
  border-color: #BBF7D0;
  color: #065f46;
  box-shadow:
    0 0 0 3px rgba(16,185,129,0.08),
    var(--shadow-1);
}
.mic-btn.recording::before {
  height: calc(2px + (var(--energy, 0) * 16px));
  opacity: 0.9;
}

.mic-btn.silent::before {
  height: 2px !important;
  opacity: 0.5;
}
@keyframes pulse {
  0%   { transform: translateX(-50%) scale(1);   opacity: .35; }
  50%  { transform: translateX(-50%) scale(1.8); opacity: .8;  }
  100% { transform: translateX(-50%) scale(1);   opacity: .35; }
}

/* ================= VOICE VISUALISER (#3) ================= */
.mic-vis-group {
  display: flex;
  align-items: center;
  gap: 0;
  position: relative;
}

.voice-visualiser {
  display: none;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 80px;
  pointer-events: none;
  z-index: -1;
}

.voice-visualiser.active {
  display: flex;
}

.vis-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(139, 92, 246, 0.35);
  animation: pulse-ring 1.8s ease-in-out infinite;
}

.vis-ring:nth-child(1) {
  width: 44px; height: 44px;
  animation-delay: 0s;
}
.vis-ring:nth-child(2) {
  width: 60px; height: 60px;
  animation-delay: 0.3s;
}
.vis-ring:nth-child(3) {
  width: 76px; height: 76px;
  animation-delay: 0.6s;
}

@keyframes pulse-ring {
  0%   { transform: scale(0.8); opacity: 0.6; }
  50%  { transform: scale(1.2); opacity: 0.15; }
  100% { transform: scale(0.8); opacity: 0.6; }
}

.camera-frame {
  background: #fff;
  border-radius: 16px;
  padding: 12px 12px 10px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
}

/* ================= RIGHT PANEL ================= */
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding-top: 0;
}

.panel-title {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 12px;
}

/* ================= TEXT DISPLAY (Phase 2 Formats) ================= */
.text-display {
  position: relative;
  padding: 20px 22px 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden; /* Prevent horizontal scroll from overflowing tooltips */
}

#reading-text {
  font-family: var(--dyslexic-font);
  font-size: 20px;
  line-height: 1.8;
  max-width: 700px;
  margin: 0;
  padding: 10px;
  min-height: 150px;
  letter-spacing: 0.05em;
  word-spacing: 0.1em;
  transition: background 0.2s, outline 0.2s;
}

#reading-text.dragover {
  background: rgba(169, 140, 255, 0.1);
  outline: 2px dashed #A98CFF;
  border-radius: 8px;
}

.text-display::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: linear-gradient(90deg, var(--g1), var(--g2));
}

/* Word spans — more clickable area for dyslexic users */
.word {
  padding: 2px 1px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s ease;
  position: relative; /* Anchor for tooltips */
}
.word:hover {
  background: rgba(169, 140, 255, 0.1);
}

/* Bionic Reading bolding */
.word b {
  font-weight: 700;
  color: #111; /* Slightly darker than normal text for better contrast */
}

/* ================= CHAT HISTORY ================= */
.chat-history {
  padding: 15px 15px 15px 15px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border-top: 1px solid rgba(0,0,0,0.05); /* Separator inside left card */
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* ================= CHAT MESSAGES BASE ================= */
.chat-message {
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 62%;
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: 0.03em;
  word-wrap: break-word;
  animation: fadeIn 0.25s ease;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin: 0;
}

/* ================= AI BUBBLE (left) ================= */
.chat-message.ai {
  align-self: flex-start;
  margin-right: auto;
  margin-left: 0;
  background: linear-gradient(135deg, #d8b4fe 0%, #f3e8ff 100%);
  color: #1f2933;
  box-shadow:
    inset 0 1px 2px rgba(255,255,255,0.3),
    0 3px 10px rgba(0,0,0,0.1);
  backdrop-filter: blur(4px);
}

/* ================= USER BUBBLE (right) ================= */
.chat-message.user {
  align-self: flex-end;
  margin-left: auto;
  margin-right: 0;
  background: rgba(75,85,99,0.2);
  color: #1f2933;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow:
    inset 0 1px 2px rgba(255,255,255,0.2),
    0 3px 10px rgba(0,0,0,0.1);
}

/* ================= HOVER EFFECT ================= */
.chat-message:hover {
  transform: translateY(-1px) scale(1.01);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ================= FADE-IN ANIMATION ================= */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ================= SCROLLBAR ================= */
.chat-history::-webkit-scrollbar {
  width: 8px;
}
.chat-history::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}
.text-display::-webkit-scrollbar {
  width: 8px;
}
.text-display::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}


/* ================= ACTIVE WORD HIGHLIGHT ================= */
.active-word {
  background: #F9E79F;
  border-radius: 3px;
  transition: 0.15s;
}

/* ================= ACTIVE SENTENCE HIGHLIGHT ================= */
.sentence {
  display: inline;
  transition: background 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease, transform 0.3s ease;
  border-radius: 6px;
  padding: 2px 0;
}

.active-sentence {
  background: linear-gradient(135deg, rgba(169, 140, 255, 0.15), rgba(110, 168, 255, 0.15));
  box-shadow: 0 0 0 4px rgba(169, 140, 255, 0.08);
  border-radius: 6px;
  padding: 2px 4px;
}

/* ================= FOCUS MODE (Dyslexia/ADHD) ================= */
.text-display.focus-mode-active .sentence {
  opacity: 0.25; /* Dim all sentences by default */
  filter: blur(0.5px); /* Slight blur reduces cognitive distraction */
}

/* Brighten the active sentence, or whatever sentence the user hovers over */
.text-display.focus-mode-active .sentence.active-sentence,
.text-display.focus-mode-active .sentence:hover {
  opacity: 1 !important;
  filter: blur(0) !important;
  transform: scale(1.02);
  display: inline-block; /* Required for transform scale to work on text */
  margin: 0 4px; /* Compensate for the scale so text doesn't overlap violently */
}

/* ================= CONTROL BAR ================= */
.unified-toolbar {
  position: relative; /* Anchor for the sliding panel */
}

.control-bar {
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid rgba(0,0,0,0.05); /* Separator from text area */
  background: #FFFDF7;
  z-index: 10;
}

/* ================= SLIDING TOOLS PANEL ================= */
.tools-panel {
  display: flex;
  gap: 10px;
  position: absolute;
  bottom: 100%; /* Sits exactly above the control bar */
  left: 0;
  width: 100%;
  padding: 16px 20px;
  background: #ffffff;
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.05);
  border-radius: 16px 16px 0 0;
  box-sizing: border-box;
  
  /* Sliding Animation */
  transform: translateY(10px);
}

.hidden {
  display: none !important;
}

.tools-panel.active {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.btn-primary {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: linear-gradient(135deg, #a855f7 0%, #8b5cf6 100%);
  color: white;
  cursor: pointer;
  font-size: 14px;
  font-family: var(--dyslexic-font);
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.2);
  transition: transform .15s ease, box-shadow .15s ease;
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.3);
}

.btn-outline {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-strong);
  cursor: pointer;
  font-size: 14px;
  font-family: var(--dyslexic-font);
  font-weight: 500;
  transition: background .2s ease, border-color .2s ease, transform .12s ease;
}
.btn-outline:hover {
  background: linear-gradient(120deg, #F2EDFF, #ECF4FF);
  border-color: #DAD5FF;
}

.btn-outline.active-toggle {
  background: #F2EDFF;
  border-color: #DAD5FF;
  color: #6d28d9;
}

/* ================= MODE OVERLAY (Full-Screen) ================= */
.mode-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.mode-overlay.show {
  display: flex;
  opacity: 1;
}

.mode-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.mode-overlay-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 40px 36px 32px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 28px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255,255,255,0.3) inset;
  transform: scale(0.9);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mode-overlay.show .mode-overlay-content {
  transform: scale(1);
}

.mode-overlay-title {
  font-family: var(--dyslexic-font);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-strong);
  margin: 0;
  letter-spacing: 0.02em;
}

.mode-overlay-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 180px;
  height: 120px;
  border: 2px solid transparent;
  border-radius: 20px;
  cursor: pointer;
  color: #fff;
  font-family: var(--dyslexic-font);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  position: relative;
  overflow: hidden;
}

/* Shimmer overlay on hover */
.mode-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%);
  opacity: 0;
  transition: opacity 0.2s ease;
  border-radius: inherit;
}

.mode-card:hover::after {
  opacity: 1;
}

.mode-card:hover {
  transform: translateY(-4px) scale(1.03);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.2);
}

.mode-card:active {
  transform: translateY(-1px) scale(0.98);
}

/* Per-mode colors */
.mode-card[data-mode="book"]  { background: linear-gradient(135deg, #8b5cf6, #7c3aed); }
.mode-card[data-mode="form"]  { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.mode-card[data-mode="study"] { background: linear-gradient(135deg, #10b981, #059669); }
.mode-card[data-mode="write"] { background: linear-gradient(135deg, #f59e0b, #d97706); }

/* Hover glow per mode */
.mode-card[data-mode="book"]:hover  { box-shadow: 0 8px 28px rgba(139, 92, 246, 0.45); }
.mode-card[data-mode="form"]:hover  { box-shadow: 0 8px 28px rgba(59, 130, 246, 0.45); }
.mode-card[data-mode="study"]:hover { box-shadow: 0 8px 28px rgba(16, 185, 129, 0.45); }
.mode-card[data-mode="write"]:hover { box-shadow: 0 8px 28px rgba(245, 158, 11, 0.45); }

.mode-card-icon {
  font-size: 32px;
  line-height: 1;
}

.mode-card-label {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.mode-card-desc {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.85;
}

.mode-overlay-close {
  background: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 20px;
  font-family: var(--dyslexic-font);
  font-size: 13px;
  color: var(--text-strong);
  cursor: pointer;
  transition: background 0.2s ease;
}

.mode-overlay-close:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* ===== Snapshot thumbnail ===== */
#snapshot-thumb {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 230px;
  height: 170px;
  overflow: hidden;
  display: none;
  z-index: 100;
  border-radius: 12px;
  border: 1px solid transparent;
  background:
    linear-gradient(#fff, #fff) padding-box,
    linear-gradient(120deg, var(--g1), var(--g2)) border-box;
  box-shadow: var(--shadow-1);
}
#snapshot-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.modal.show {
  display: flex;
  opacity: 1;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 16px;
  width: 380px;
  text-align: center;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.modal.show .modal-content {
  transform: scale(1);
}


.inline-error {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  display: none;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  animation: fadeIn 0.2s ease;
}

.camera-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px 16px; /* Added breathing room as per user request */
  background: transparent;
  border: none;
  border-radius: 0;
}

.camera-controls .controls-left,
.camera-controls .controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.camera-controls .btn {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
}



/* ================= SMART ANALYSIS (Feature A) ================= */

/* Difficult Word with Tooltip */
.difficult-word {
  position: relative;
  text-decoration: underline;
  text-decoration-color: #A98CFF;
  text-decoration-thickness: 3px;
  text-underline-offset: 4px;
  cursor: help;
  color: #5b21b6;
  font-weight: 600;
  transition: background 0.2s;
  padding: 2px 4px;
  border-radius: 4px;
}

.difficult-word:hover {
  background: rgba(169, 140, 255, 0.25);
  border-radius: 4px;
}

/* Tooltip */
.difficult-word {
  cursor: help;
}
.tooltip {
  visibility: hidden;
  opacity: 0;
  position: fixed; /* Must be fixed since we use getBoundingClientRect values */
  margin-top: 8px; /* Adds space for the arrow */
  background: #1f2933;
  color: #fff;
  text-align: left;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  white-space: normal; /* Allow wrapping */
  width: max-content;
  max-width: 280px; /* Force wrap if too long */
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  transition: all 0.2s ease;
  z-index: 1000;
  pointer-events: none;
}

.tooltip::after {
  content: "";
  position: absolute;
  bottom: 100%; /* Arrow points up from the top edge */
  left: var(--arrow-left, 50%); 
  margin-left: var(--arrow-margin, -6px);
  border-width: 6px;
  border-style: solid;
  border-color: transparent transparent #1f2933 transparent;
}

.difficult-word:hover .tooltip {
  visibility: visible;
  opacity: 1;
}

/* View Toggles */
.active-toggle {
  background: linear-gradient(120deg, #F2EDFF, #ECF4FF) !important;
  border-color: #DAD5FF !important;
  font-weight: bold;
}

/* Selection Popup */
.selection-popup {
  position: fixed;
  display: none;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  border-radius: 12px;
  padding: 4px;
  z-index: 9999;
  transform: translate(-50%, -10px);
  animation: fadeInUp 0.2s ease forwards;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translate(-50%, 0); }
  to { opacity: 1; transform: translate(-50%, -10px); }
}

.selection-popup button {
  background: none;
  border: none;
  padding: 8px 14px;
  font-size: 13px;
  font-family: var(--dyslexic-font);
  font-weight: 500;
  color: var(--text-strong);
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.selection-popup button:hover {
  background: linear-gradient(120deg, #F2EDFF, #ECF4FF);
  color: #5b21b6;
}

/* ================= STATUS INDICATOR ================= */
#status-indicator {
  position: fixed;
  top: 15px;
  right: 15px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid var(--border);
  transition: all 0.3s ease;
  pointer-events: none;
}
#status-indicator::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
}
.status-online { color: #166534; }
.status-online::before { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
.status-offline { color: #991b1b; }
.status-offline::before { background: #ef4444; }
.status-reconnecting { color: #92400e; }
.status-reconnecting::before { background: #f59e0b; animation: lexi-blink 1s infinite; }
@keyframes lexi-blink {
  0% { opacity: 1; }
  50% { opacity: 0.4; }
  100% { opacity: 1; }
}

/* ================= READING RULER (SCREEN CURTAIN) ================= */
#reading-ruler {
  position: fixed;
  left: 0;
  right: 0;
  height: 50px;
  background: transparent;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4); 
  border-top: 2px solid rgba(169, 140, 255, 0.8);
  border-bottom: 2px solid rgba(169, 140, 255, 0.8);
  pointer-events: none;
  z-index: 50;
  display: none; 
}

#reading-ruler.active {
  display: block;
}

/* ================= URL INPUT ================= */
.url-field:focus {
  outline: none;
  border-color: #A98CFF !important;
  box-shadow: 0 0 0 2px rgba(169, 140, 255, 0.2);
}
.url-field {
  transition: all 0.2s ease;
  background: white;
}

/* ================= COLOR SWITCHER ================= */
.color-switcher {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto; /* Push to the right */
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.color-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.active {
  border-color: #A98CFF;
  box-shadow: 0 0 0 2px rgba(169, 140, 255, 0.3);
}

/* ================= PHASE 3 ADDITIONS ================= */

/* Mode Badge */
.mode-badge {
  position: fixed;
  top: 15px;
  right: 150px; /* Offset from status indicator */
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  background: #A98CFF;
  color: white;
  transition: all 0.3s ease;
}

.mode-badge.mode-book { background: #8b5cf6; } 
.mode-badge.mode-form { background: #3b82f6; } 
.mode-badge.mode-study { background: #10b981; } 
.mode-badge.mode-write { background: #f59e0b; } 

/* Modal Actions */
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

.modal-actions .btn-outline {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

/* Speed Indicator */
.speed-indicator {
  font-size: 12px;
  font-weight: bold;
  color: #6d28d9;
  margin-bottom: 4px;
  text-align: center;
}

/* Dictation UI */
.dictation-area {
  margin-top: 20px;
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow-2);
  border: 1px solid var(--border);
}

.dictation-text {
  font-family: Arial, sans-serif;
  font-size: 22px;
  line-height: 2.0;
  color: #1a1a1a;
  min-height: 120px;
  margin-bottom: 20px;
  white-space: pre-wrap;
}

.dictation-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Mobile Responsiveness */

/* ================= WRITE MODE (Enhanced) ================= */
.write-mode-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 10px;
  margin-top: -10px;
  animation: fadeIn 0.3s ease;
}

.write-header h3 {
  margin: 0 0 4px 0;
  color: #6d28d9;
}

.write-header p {
  margin: 0;
  font-size: 14px;
  color: var(--text-subtle);
}

.write-controls-top {
  display: flex;
  justify-content: flex-end;
  margin-bottom: -4px;
}

.undo-redo-group {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 18px;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: #f8fafc;
  border-color: var(--g1);
  transform: translateY(-1px);
}

.write-input-area {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#write-textarea {
  position: relative;
  z-index: 2;
  background: transparent !important;
  width: 100%;
  min-height: 120px;
  padding: 16px;
  font-family: var(--dyslexic-font);
  font-size: 20px;
  line-height: 1.6;
  border: 2px solid var(--border);
  border-radius: 16px;
  resize: vertical;
  transition: border-color 0.2s;
  letter-spacing: 0.05em;
  color: #334155;
  caret-color: var(--g1);
}

.highlight-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 16px;
  font-family: var(--dyslexic-font);
  font-size: 20px;
  line-height: 1.6;
  letter-spacing: 0.05em;
  color: transparent;
  pointer-events: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  z-index: 3;
  border: 2px solid transparent;
  overflow: hidden;
}

.highlight-overlay * {
  pointer-events: auto;
}

.error-hint {
  text-decoration: underline wavy #ef4444;
  text-decoration-thickness: 2px;
  padding-bottom: 2px;
  cursor: help;
  display: inline;
  position: relative;
  z-index: 10;
  pointer-events: auto;
}

.prediction-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: -5px;
  min-height: 38px;
}

.prediction-item {
  padding: 6px 14px;
  background: #f3f4f6;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.prediction-item:hover {
  background: #e5e7eb;
}

.write-actions {
  display: flex;
  gap: 12px;
  margin-top: -5px;
}

/* Premium Suggestion Tooltip */
.suggestion-tooltip {
  position: fixed;
  z-index: 10000;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 2px solid var(--g1);
  padding: 14px 18px;
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  min-width: 180px;
  max-width: 280px;
  pointer-events: auto;
  font-family: var(--dyslexic-font);
  animation: tooltipAppear 0.3s ease-out;
}

@keyframes tooltipAppear {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.suggestion-tooltip .label {
  display: block;
  font-size: 12px;
  color: #7c3aed;
  font-weight: bold;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.suggestion-tooltip .value {
  display: block;
  font-size: 18px;
  color: #4c1d95;
  margin-bottom: 8px;
  cursor: pointer;
}

.suggestion-tooltip .value:hover {
  text-decoration: underline;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 768px) {
  .main-layout {
    flex-direction: column;
    height: auto;
    overflow-y: auto;
    padding: 12px;
  }
  
  .left-panel, .right-panel {
    width: 100%;
    max-width: 100%;
    resize: none;
    height: auto;
    padding: 0;
  }
  
  .left-panel { margin-bottom: 16px; }

  #status-indicator, .mode-badge {
    position: static;
    display: inline-flex;
    margin: 5px;
  }
  
  #app {
     padding-top: 60px; /* Space for sticky/static badges */
  }

  .camera-controls {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
  }
  
  .url-control-group {
    width: 100%;
    margin: 8px 0 !important;
  }
}

/* ================= SESSION RECALL BADGE (#24) ================= */
.recall-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, var(--brand-teal), #0ea5e9);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  margin-left: 6px;
  animation: fadeIn 0.3s ease;
}

/* ================= PAUSE INDICATOR (#25) ================= */
.pause-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 9000;
  backdrop-filter: blur(8px);
}

.pause-indicator.active { display: flex; }

.pause-dot {
  width: 10px;
  height: 10px;
  background: #f59e0b;
  border-radius: 50%;
  animation: pausePulse 1s infinite;
}

@keyframes pausePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* ================= PROGRESS SUMMARY CARD (#26) ================= */
.summary-card {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: linear-gradient(135deg, var(--brand-purple), #a855f7);
  color: white;
  padding: 24px 28px;
  border-radius: 20px;
  max-width: 320px;
  z-index: 9500;
  box-shadow: 0 12px 40px rgba(123, 45, 139, 0.35);
  animation: slideInCard 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: none;
}

.summary-card.active { display: block; }

.summary-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 700;
}

.summary-card p {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.5;
  opacity: 0.9;
}

.summary-card button {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 6px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--dyslexic-font);
}

.summary-card button:hover { background: rgba(255,255,255,0.3); }

@keyframes slideInCard {
  from { opacity: 0; transform: translateY(30px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ================= DARK THEME TOGGLE (#27) ================= */
.theme-toggle-btn {
  position: fixed;
  top: 15px;
  left: 15px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  box-shadow: var(--shadow-1);
  transition: all 0.3s ease;
}

.theme-toggle-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* ================= SOURCE CONTROLS (Empty State & Compact) ================= */
.source-controls-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  margin: 40px auto;
  max-width: 600px;
  transition: all 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  transform-origin: top center;
}

.source-controls-center h2 {
  color: #60a5fa; /* Light blue heading */
  font-size: 28px;
  margin: 0 0 16px 0;
  font-family: var(--dyslexic-font);
}

.source-controls-center p {
  color: var(--text-subtle);
  font-size: 16px;
  margin: 0 0 32px 0;
  max-width: 400px;
  line-height: 1.5;
}

.source-buttons-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.source-buttons-row .btn-primary,
.source-buttons-row .btn-outline {
  padding: 14px 24px;
  border-radius: 30px; /* Pill shape */
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.source-buttons-row .btn-primary {
  background: linear-gradient(135deg, #7c3aed, #60a5fa);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.25);
}

.source-controls-center .url-control-group {
  display: flex;
  width: 100%;
  max-width: 480px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 6px;
  box-shadow: var(--shadow-1);
}

.source-controls-center .url-control-group input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 16px;
  font-size: 15px;
  outline: none;
  font-family: inherit;
}

.source-controls-center .url-submit {
  border-radius: 20px;
  padding: 10px 24px;
  background: linear-gradient(135deg, #8b5cf6, #3b82f6);
}

/* Compact state (when reading text) */
.source-controls-center.compact {
  flex-direction: row;
  margin: 0 0 20px 0;
  padding: 12px 16px;
  max-width: 100%;
  background: white;
  border-radius: 16px;
  box-shadow: var(--shadow-1);
  justify-content: space-between;
  border: 1px solid var(--border);
}

.source-controls-center.compact h2,
.source-controls-center.compact p {
  display: none;
}

.source-controls-center.compact .source-buttons-row {
  margin: 0;
  gap: 10px;
}

.source-controls-center.compact .source-buttons-row button {
  padding: 8px 16px;
  font-size: 13px;
}

.source-controls-center.compact .url-control-group {
  max-width: 300px;
  margin-left: 10px;
  padding: 4px;
}

.source-controls-center.compact .url-submit {
  padding: 6px 16px;
  font-size: 13px;
}