/* --- GLOBAL RESET --- */
* { box-sizing: border-box; }

:root {
  --bg: #0f172a;       
  --card: #1e293b;     
  --primary: #6366f1;  
  --success: #10b981;  
  --danger: #ef4444;   
  --warning: #f59e0b;
  --text: #f1f5f9;     
  --text-muted: #94a3b8;
  --border: #334155;   
  --hover: #3e4c66;    
  --input-bg: #0f172a;
  
  /* Dynamic Preferences Defaults */
  --q-font-size: 20px;
  --exp-font-size: 17px; /* Default ~1.05rem */
  --q-font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body { 
  margin: 0; 
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; 
  background: var(--bg); 
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

/* --- LAYOUT --- */
.app-container { 
  display: block; 
  width: 96%;        
  max-width: none;   
  margin: 30px auto; 
  padding: 0; 
  transition: all 0.3s ease; 
}

/* Default Quiz Mode: Grid */
.app-container.quiz-mode {
  display: grid;
  grid-template-columns: 1fr 260px; 
  gap: 25px; 
  max-width: 1280px;
  padding: 0 20px;
}

/* COLLAPSED STATE */
.app-container.quiz-mode.collapsed {
    grid-template-columns: 1fr 0px;
    gap: 0;
}

.app-container.quiz-mode.collapsed .sidebar {
    padding: 0;
    width: 0;
    overflow: hidden;
    opacity: 0;
    border: none;
    margin: 0;
}

.main-content { min-width: 0; width: 100%; }

.card { 
  background: var(--card); 
  padding: 25px; 
  border-radius: 16px; 
  border: 1px solid var(--border); 
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); 
}

h1, h2, h3, h4 { margin-top: 0; color: white; }

/* --- HOME SCREEN --- */
.hero-title { font-size: 2rem; margin-bottom: 20px; text-align: center; font-weight: 800; letter-spacing: -0.5px; background: linear-gradient(to right, #6366f1, #a855f7); background-clip: text; -webkit-background-clip: text; color: transparent; -webkit-text-fill-color: transparent; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0; width: 100%; }
.action-card { padding: 25px; background: rgba(255,255,255,0.02); border-radius: 12px; border: 1px solid var(--border); transition: all 0.3s ease; display: flex; flex-direction: column; }
.action-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: 0 10px 25px -5px rgba(99, 102, 241, 0.15); }
.action-card h3 { font-size: 1.2rem; margin-bottom: 10px; text-align: center; }
.custom-file-upload { display: flex; align-items: center; justify-content: center; padding: 12px; background: var(--input-bg); border: 2px dashed #475569; border-radius: 8px; cursor: pointer; margin-bottom: 15px; font-size: 0.9rem; color: var(--text-muted); transition: all 0.2s; }
.custom-file-upload:hover { border-color: var(--primary); color: var(--text); background: rgba(99, 102, 241, 0.05); }
input[type="file"] { display: none; }
.settings-group { background: rgba(0,0,0,0.2); padding: 15px; border-radius: 10px; margin-bottom: 15px; }
.input-row { display: flex; gap: 15px; margin-bottom: 10px; }
.input-wrap { flex: 1; }
.input-wrap label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; text-transform: uppercase; font-weight: 600; }
.input-wrap input { width: 100%; background: var(--input-bg); border: 1px solid var(--border); color: white; padding: 8px 10px; border-radius: 6px; font-size: 0.9rem; box-sizing: border-box; transition: border-color 0.2s; }
.input-wrap input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2); }
.checkbox-wrapper { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 0.9rem; color: var(--text-muted); cursor: pointer; }
.checkbox-wrapper input[type="checkbox"] { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }
.radio-group { display: flex; flex-direction: column; gap: 10px; margin: 15px 0; }
.radio-card { display: flex; align-items: flex-start; gap: 15px; padding: 12px; border-radius: 10px; border: 1px solid var(--border); cursor: pointer; transition: all 0.2s; background: rgba(255,255,255,0.02); }
.radio-card:hover { background: var(--hover); border-color: var(--primary); }
.radio-card input { margin-top: 4px; accent-color: var(--primary); transform: scale(1.1); }
.radio-title { display: block; font-weight: 700; font-size: 0.95rem; color: var(--text); }
.radio-sub { display: block; font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* --- RECENT SESSIONS --- */
.recent-section { margin-top: 30px; }

.recent-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.recent-header h4 {
    margin: 0;
}

#clearAllBtn {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    text-decoration: none;
}

#clearAllBtn:hover {
    background: #ef4444;
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
    border-color: #ef4444;
}

/* --- BUTTONS --- */
.btn { border: none; cursor: pointer; font-weight: 700; padding: 10px 24px; border-radius: 8px; font-size: 0.9rem; transition: all 0.3s; letter-spacing: 0.5px; text-transform: uppercase; }
.btn-primary.btn-glow { background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%); color: white; box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4); }
.btn-primary.btn-glow:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(79, 70, 229, 0.6); }
.btn-success.btn-glow { background: linear-gradient(135deg, #10b981 0%, #059669 100%); color: white; box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4); }
.btn-success.btn-glow:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6); }
.btn-danger { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); color: white; }
.btn-secondary { background: #334155; color: white; border: 1px solid #475569; }
.btn-secondary:hover { background: #475569; }
.btn-full { width: 100%; margin-top: 10px; padding: 12px; font-size: 1rem; }
.btn-exit { background: #f59e0b; color: #451a03; padding: 6px 12px; border-radius: 6px; font-weight: 700; font-size: 0.8rem; }
.btn-xs { padding: 4px 8px; font-size: 0.75rem; border-radius: 4px; cursor: pointer; text-transform: none; }

.sidebar-close-btn { 
    background: transparent; 
    border: 1px solid var(--border); 
    color: var(--text-muted); 
    font-size: 0.75rem; 
    padding: 2px 8px; 
    border-radius: 4px; 
    cursor: pointer;
}
.sidebar-close-btn:hover { background: var(--hover); color: white; }

/* --- QUIZ UI --- */
.quiz-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.header-left, .header-right { display: flex; align-items: center; gap: 12px; }
.badge { background: var(--primary); padding: 4px 10px; border-radius: 20px; font-weight: 700; font-size: 0.85rem; }
.section-badge { background: #334155; padding: 4px 10px; border-radius: 6px; font-size: 0.8rem; color: #e2e8f0; font-weight: 600; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border: 1px solid rgba(255,255,255,0.1); }
.timer-pill { background: rgba(251, 191, 36, 0.1); border: 1px solid rgba(251, 191, 36, 0.2); color: #fbbf24; padding: 4px 10px; border-radius: 6px; font-family: 'Roboto Mono', monospace; font-weight: 600; font-size: 0.9rem; }
.total-time { font-size: 0.85rem; color: var(--text-muted); }
.progress-bar-bg { height: 6px; background: var(--border); border-radius: 10px; margin-bottom: 25px; overflow: hidden; }
#progressBar { height: 100%; background: linear-gradient(to right, var(--success), #34d399); width: 0%; transition: width 0.3s ease; }

/* --- QUESTION FORMATTING --- */
.question-area { margin-bottom: 25px; }
#question { 
    font-size: var(--q-font-size); 
    font-family: var(--q-font-family);
    line-height: 1.6; font-weight: 500; 
}
.source-tag { display: block; font-size: 0.85rem; color: var(--text-muted); margin-top: 10px; font-style: italic; border-left: 3px solid var(--border); padding-left: 10px; }

/* Logic specific styles */
.q-point { display: inline-block; margin-left: 5px; font-weight: 600; color: #e2e8f0; }
.q-quote { display: block; margin: 15px 0 15px 10px; padding-left: 15px; border-left: 3px solid var(--primary); font-style: italic; color: #cbd5e1; background: rgba(255,255,255,0.03); padding: 10px; border-radius: 0 4px 4px 0; }
.ar-box { margin: 8px 0; padding: 8px 12px; background: rgba(255,255,255,0.05); border-radius: 6px; border-left: 3px solid #f59e0b; }

/* --- OPTIONS MATRIX --- */
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; width: 100%; }
.option-btn:last-child:nth-child(odd) { grid-column: span 2; }

.option-btn { 
  width: 100%; text-align: left; padding: 18px 24px; 
  background: rgba(40, 54, 77, 0.5); border: 2px solid #334155; 
  color: var(--text); border-radius: 14px; cursor: pointer; 
  font-size: calc(var(--q-font-size) * 0.9);
  font-family: var(--q-font-family);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); 
  box-shadow: 0 4px 6px rgba(0,0,0,0.1); height: 100%; display: flex; align-items: center; 
}
.option-btn:hover:not(:disabled) { background: rgba(99, 102, 241, 0.1); border-color: var(--primary); transform: translateY(-3px); box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.2); }
.option-btn.selected { border-color: var(--primary); background: rgba(99, 102, 241, 0.15); }
.option-btn.correct { background: var(--success) !important; color: #022c22; border-color: var(--success); font-weight: 700; }
.option-btn.wrong { background: var(--danger) !important; color: white; border-color: var(--danger); opacity: 0.95; }
.option-btn:disabled { cursor: default; opacity: 0.9; }

/* --- FEEDBACK & EXPLANATION STYLING --- */
/* UPDATED: Extremely Compact & Dynamic */
.feedback-box { 
    margin-top: 15px; 
    padding: 6px 12px; /* Very tight padding */
    background: rgba(30, 41, 59, 0.7); 
    border-radius: 8px; 
    border-left: 4px solid var(--success); 
    width: fit-content; 
    max-width: 100%;    
    display: inline-flex; /* Shrink-wrap exactly */
    flex-direction: column; /* Stack contents vertical */
    gap: 4px; /* Tiny gap between elements, no margins */
}

/* Strip margins from internal p/divs to allow Gap to control spacing */
.feedback-box div, .feedback-box p {
    margin: 0;
    line-height: 1.3;
}

/* Link styling inside box */
.exp-link { 
    color: var(--primary); 
    text-decoration: underline; 
    cursor: pointer; 
    font-weight: 700; 
    margin: 0; /* Remove margin, use gap */
    display: block; 
    font-size: 0.85rem; 
}

/* --- UPDATED FONT SIZES --- */
/* Uses configurable variable --exp-font-size */
#feedbackStatus strong {
    font-size: calc(var(--exp-font-size) * 1.2);
}

.beautified-explanation { 
    color: #cbd5e1; 
    line-height: 1.6; 
    font-size: var(--exp-font-size);
}

/* Highlight Classes */
.highlight-term { color: #818cf8; font-weight: 700; }
.highlight-statement { color: #34d399; font-weight: 600; background: rgba(16, 185, 129, 0.15); padding: 2px 6px; border-radius: 4px; }
.definition-header { font-weight: 800; color: #128064; text-decoration: underline; }

/* Formula Box */
.formula-box {
    background: rgba(0,0,0,0.3);
    padding: 12px;
    border-left: 4px solid var(--success);
    font-family: 'Consolas', 'Monaco', monospace;
    margin: 15px 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.95em;
    color: #e2e8f0;
}

/* --- FOOTER CONTROLS --- */
.controls { display: flex; justify-content: space-between; align-items: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--border); }
.btn-nav-secondary { background: transparent; color: var(--text-muted); border: 1px solid var(--border); padding: 10px 20px; min-width: 90px; }
.btn-nav-secondary:hover { border-color: var(--text); color: var(--text); background: rgba(255,255,255,0.05); }
.btn-nav-flag { background: transparent; color: var(--text-muted); border: 1px solid var(--border); padding: 10px 20px; min-width: 90px; }
.btn-nav-flag:hover { border-color: var(--primary); color: var(--primary); background: rgba(99, 102, 241, 0.05); }
.next-group { display: flex; gap: 10px; }
.footer-tools { margin-top: 15px; display: flex; justify-content: flex-end; }
.guess-label { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: var(--text-muted); cursor: pointer; padding: 8px; border-radius: 8px; transition: background 0.2s; }
.guess-label:hover { background: rgba(255,255,255,0.05); color: var(--warning); }
.guess-label input { accent-color: var(--warning); width: 16px; height: 16px; }

/* --- SIDEBAR --- */
.sidebar { 
    background: var(--card); padding: 20px; border-radius: 16px; border: 1px solid var(--border); 
    height: fit-content; display: flex; flex-direction: column; gap: 20px; 
    position: sticky; top: 20px; 
    transition: all 0.3s ease;
}
.sidebar-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.sidebar-title { font-weight: 700; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.toggle-btn { background: var(--border); color: white; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; border-radius: 4px; border: none; cursor: pointer; font-size: 0.8rem; }
.sidebar-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 8px; max-height: 110px; overflow-y: auto; padding-right: 4px; }
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb { background: #475569; border-radius: 4px; }
.flag-pill { background: #334155; color: #cbd5e1; border-radius: 6px; padding: 6px 0; text-align: center; font-size: 0.8rem; cursor: pointer; }
.flag-pill:hover { background: var(--hover); color: white; }
.sidebar-note { width: 100%; height: 90px; background: var(--input-bg); border: 1px solid var(--border); color: var(--text); padding: 10px; border-radius: 8px; resize: none; font-size: 0.9rem; line-height: 1.5; box-sizing: border-box; }
.sidebar-note:focus { outline: none; border-color: var(--primary); }
.word-count { text-align: right; font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
.settings-panel { background: rgba(0,0,0,0.2); padding: 10px; border-radius: 8px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 0.85rem; color: var(--text-muted); }
.setting-row:last-child { margin-bottom: 0; }
.setting-row select { background: var(--bg); border: 1px solid var(--border); color: white; padding: 2px 6px; border-radius: 4px; }

/* --- ANALYTICS TABLE --- */
.sectional-container { margin: 40px 0; overflow-x: auto; }
.subsection-title { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 20px; border-bottom: 2px solid var(--border); padding-bottom: 10px; display: inline-block; }
.dark-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.dark-table th { text-align: left; color: var(--text-muted); font-weight: 700; padding: 15px; border-bottom: 1px solid var(--border); text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.5px; }
.dark-table td { padding: 15px; border-bottom: 1px solid rgba(255,255,255,0.05); color: var(--text); }
.dark-table tr:last-child td { border-bottom: none; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 40px; }
.stat-card { background: #28364d; padding: 25px; border-radius: 16px; text-align: center; border: 1px solid rgba(255,255,255,0.05); }
.stat-card h2 { margin: 0; font-size: 2.5rem; color: white; }
.stat-card p { margin: 8px 0 0; font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; font-weight: 700; }
.mobile-notes-view { display: none; margin-top: 20px; }

/* --- MEDIA QUERIES --- */
@media (max-width: 900px) {
  .app-container.quiz-mode { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; flex-direction: row; flex-wrap: wrap; }
  .sidebar-section { flex: 1; min-width: 250px; }
  .mobile-notes-view { display: block; }
  .sidebar #noteInput, .sidebar #sidebarWordCount { display: none; }
  .sidebar-close-btn { display: none; }
  #showSidebarBtn { display: none !important; }
}
@media (max-width: 768px) {
    .options { grid-template-columns: 1fr; } 
    .option-btn:last-child:nth-child(odd) { grid-column: auto; }
}
@media (max-width: 650px) {
    .action-grid { grid-template-columns: 1fr; }
    .controls { flex-direction: column; gap: 12px; }
    .controls > button, .next-group, .next-group > button { width: 100%; }
}
.hidden { display: none !important; }