 /*
      ================================
      === 1. ROOT & THEME VARIABLES ===
      ================================
    */
    :root {
      /* Font */
      --font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";

      /* Brand Colors */
      --primary-600: #6366f1; /* Indigo-500 */
      --primary-700: #4f46e5; /* Indigo-600 */
      --primary-800: #4338ca; /* Indigo-700 */
      --primary-gradient: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
      
      /* Light Theme (Default) - IMPROVED */
      --bg-primary: #f6f8ff;         /* Lighter, slightly blueish */
      --bg-secondary: #edf2ff;      /* Light Indigo */
      --bg-card: #ffffff;
      --bg-app: linear-gradient(160deg, #f6f8ff 0%, #eef2ff 100%);  
      --text-primary: #1e293b;       /* Slate-800 for better contrast */
      --text-secondary: #475569;     /* Slate-600 */
      --text-muted: #64748b;         /* Slate-500 */
      --text-on-primary: #ffffff;
      --border-color: #e2e8f0;       /* Slate-200 */
      --border-focus: var(--primary-600);
      --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
      --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
      --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
      --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
      --shadow-focus: 0 0 0 3px rgba(99, 102, 241, 0.2);
      
      /* Semantic Colors */
      --success-bg: #f0fdf4;  --success-text: #15803d; --success-border: #bbf7d0;
      --danger-bg: #fef2f2;   --danger-text: #b91c1c;  --danger-border: #fecaca;
      --warning-bg: #fffbeb;  --warning-text: #b45309; --warning-border: #fde68a;
      --info-bg: #eff6ff;     --info-text: #1d4ed8;   --info-border: #bfdbfe;

      /* Radii */
      --radius-sm: 8px;
      --radius-md: 12px;
      --radius-lg: 16px;
      --radius-xl: 20px;
      --radius-full: 9999px;

      /* NEW: Layout Variables */
      --sidebar-width: 260px;
      --sidebar-width-collapsed: 0px;
      --topbar-height: 72px;
    }

    [data-theme="dark"] {
      /* Dark Theme - IMPROVED */
      --bg-primary: #0d1117;         /* Darker, GitHub-like */
      --bg-secondary: #161b22;       /* Darker card hover */
      --bg-card: #1c2128;           /* Slightly lighter card */
      --bg-app: radial-gradient(circle at 1% 1%, #29344b 0%, #0d1117 40%);
      --text-primary: #c9d1d9;         /* Lighter text */
      --text-secondary: #8b949e;       /* Muted text */
      --text-muted: #6e7681;         /* More muted text */
      --border-color: #30363d;         /* Softer border */
      --border-focus: var(--primary-600);
      --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.1);
      --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.2), 0 2px 4px -2px rgb(0 0 0 / 0.2);
      --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.2), 0 4px 6px -4px rgb(0 0 0 / 0.2);
      --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.2), 0 8px 10px -6px rgb(0 0 0 / 0.2);
      --shadow-focus: 0 0 0 3px rgba(99, 102, 241, 0.25);

      --success-bg: #0d2818;  --success-text: #30a14e; --success-border: #2ea043;
      --danger-bg: #2c0b0e;   --danger-text: #f85149;  --danger-border: #da3633;
      --warning-bg: #3b2809;  --warning-text: #fde68a; --warning-border: #b45309;
      --info-bg: #172554;     --info-text: #bfdbfe;   --info-border: #1d4ed8;
    }
    
    /*
      ================================
      === 2. BASE & NEW LAYOUT ===
      ================================
    */
    * { box-sizing: border-box; }

    html {
      scroll-behavior: smooth;
    }

    body {
      margin: 0;
      font-family: var(--font-family);
      color: var(--text-primary);
      background: var(--bg-app); /* This background is now on the main wrapper */
      min-height: 100vh;
      display: flex; /* NEW: Flex layout */
    }

    /* NEW: Sidebar */
    #sidebar {
      width: var(--sidebar-width);
      flex-shrink: 0;
      background: var(--bg-card);
      border-right: 1px solid var(--border-color);
      padding: 20px;
      transition: all 0.3s ease;
      overflow-y: auto;
      z-index: 10;
      display: flex;
      flex-direction: column;
    }
    
    .sidebar-header {
      display: flex;
      align-items: center;
      gap: 12px;
      padding-bottom: 16px;
      margin-bottom: 20px;
      border-bottom: 1px solid var(--border-color);
    }
	
    .sidebar-header .app-icon img{
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 44px;
      height: 44px;
      border-radius: var(--radius-md);
      
      color: var(--text-on-primary);
      font-size: 22px;
      flex-shrink: 0;
    }
    .sidebar-header h2 {
      margin: 0;
      font-size: 1.15rem;
      font-weight: 700;
      color: var(--text-primary);
    }

    .nav-links {
      list-style: none;
      padding: 0;
      margin: 0;
    }
    .nav-link {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 14px;
      border-radius: var(--radius-md);
      color: var(--text-secondary);
      text-decoration: none;
      font-weight: 600;
      font-size: 1rem;
      margin-bottom: 6px;
      transition: all 0.2s ease;
    }
    .nav-link .bi {
      font-size: 1.2rem;
      width: 24px;
      text-align: center;
      transition: all 0.2s ease;
    }
    .nav-link:hover {
      background: var(--bg-secondary);
      color: var(--text-primary);
    }
    .nav-link.active {
      background: var(--primary-600);
      color: var(--text-on-primary);
      box-shadow: var(--shadow-md);
    }
    .nav-link.active .bi {
      color: var(--text-on-primary);
    }

    /* NEW: Main Wrapper */
    #main-wrapper {
      flex-grow: 1;
      display: flex;
      flex-direction: column;
      height: 100vh;
      overflow-y: auto;
      background: var(--bg-app); /* Moved background here */
    }

    /* NEW: Topbar (replaces old .header) */
    .topbar {
      height: var(--topbar-height);
      background: var(--bg-card);
      border-bottom: 1px solid var(--border-color);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 24px;
      flex-shrink: 0;
      z-index: 5;
    }
    
    .topbar-left {
      display: flex;
      align-items: center;
      gap: 16px;
    }
    
    #sidebarToggleBtn {
      width: 40px;
      height: 40px;
      border-radius: var(--radius-full);
      background: var(--bg-secondary);
      border: 1px solid var(--border-color);
      color: var(--text-secondary);
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 1.1rem;
      transition: all 0.2s ease;
    }
    #sidebarToggleBtn:hover {
      background: var(--bg-card);
      border-color: var(--border-focus);
      color: var(--primary-600);
    }
    
    .topbar-title {
      font-size: 1.5rem;
      font-weight: 800;
      color: var(--text-primary);
      letter-spacing: -0.2px;
    }
    [data-theme="dark"] .topbar-title {
      color: var(--primary-600);
    }

    .topbar-right {
      display: flex;
      align-items: center;
      gap: 16px;
    }

    /* NEW: User Dropdown */
    .user-dropdown {
      position: relative;
    }
    .user-dropdown-toggle {
      width: 44px;
      height: 44px;
      border-radius: var(--radius-full);
      background: var(--primary-gradient);
      color: var(--text-on-primary);
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 20px;
      border: 2px solid var(--bg-card);
      box-shadow: var(--shadow-sm);
    }
    .user-dropdown-menu {
      position: absolute;
      top: 110%;
      right: 0;
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-md);
      box-shadow: var(--shadow-lg);
      width: 220px;
      padding: 8px;
      z-index: 100;
      opacity: 0;
      visibility: hidden;
      transform: translateY(10px);
      transition: all 0.2s ease;
    }
    .user-dropdown:hover .user-dropdown-menu {
      opacity: 1;
      visibility: visible;
      transform: translateY(0);
    }
    .user-dropdown-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 10px 12px;
      border-radius: var(--radius-sm);
      text-decoration: none;
      color: var(--text-secondary);
      font-weight: 500;
      cursor: pointer;
    }
    .user-dropdown-item:hover {
      background: var(--bg-secondary);
      color: var(--text-primary);
    }
    .user-dropdown-item .bi {
      font-size: 1.1rem;
    }
    .user-dropdown-divider {
      height: 1px;
      background: var(--border-color);
      margin: 8px 0;
    }


    /* (Old #app is now #main-content) */
    #main-content {
      max-width: 1200px;
      width: 100%;
      margin: 0 auto;
      padding: 24px;
    }

    .content {
      /* padding: 24px; */ /* Padding is now on #main-content */
    }

    /*
      ================================
      === 3. HEADER & FOOTER (REMOVED/MERGED) ===
      ================================
    */
    /* .header styles are now in .topbar */
    
    .theme-toggle {
      width: 44px;
      height: 44px;
      border-radius: var(--radius-full);
      background: var(--bg-secondary);
      border: 1px solid var(--border-color);
      color: var(--text-secondary);
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 20px;
      transition: all 0.2s ease;
    }
    .theme-toggle:hover {
      background: var(--bg-card);
      border-color: var(--border-focus);
      color: var(--primary-600);
    }
    .theme-toggle .bi-sun-fill,
    .theme-toggle .bi-moon-stars-fill { display: none; }
    
    [data-theme="light"] .theme-toggle .bi-moon-stars-fill { display: block; }
    [data-theme="dark"] .theme-toggle .bi-sun-fill { display: block; }


    .footer {
      text-align: center;
      padding: 20px;
      margin-top: 24px;
      font-size: 0.9rem;
      color: var(--text-muted);
      border-top: 1px solid var(--border-color);
      background: var(--bg-card);
      border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    }
    
    .footer-link {
      color: var(--primary-600);
      text-decoration: none;
      font-weight: 600;
      cursor: pointer;
    }
    .footer-link:hover { text-decoration: underline; }

    /*
      ================================
      === 4. CARD & FORM CONTROLS ===
      ================================
    */
    .card {
      background: var(--bg-card);
      border-radius: var(--radius-lg);
      padding: 24px;
      margin-bottom: 20px;
      border: 1px solid var(--border-color);
      box-shadow: var(--shadow-md);
      transition: all 0.2s ease-in-out;
    }
    
    .card:hover {
      /* border-color: var(--border-focus); */ /* Removed hover effect for cleaner UI */
      /* box-shadow: var(--shadow-lg); */
      /* transform: translateY(-2px); */
    }

    .card h3 {
      margin: 0 0 16px 0;
      color: var(--text-primary);
      font-size: 1.25rem;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .card h3 .bi {
      color: var(--primary-600);
    }
	
	.input-group {
      display: flex;
      gap: 8px; /* Adds a small space between the input and the button */
      align-items: center;
    }
    .input-group .form-control {
      flex-grow: 1; /* Allows the input field to take up available space */
    }
    .input-group .btn {
      flex-shrink: 0; /* Prevents the button from shrinking */
    }
    
    .form-group {
      margin-bottom: 16px;
    }

    .form-group label {
      display: block;
      margin-bottom: 8px;
      font-weight: 600;
      color: var(--text-secondary);
      font-size: 0.9rem;
      /* ADDED: Icons in labels */
      display: flex;
      align-items: center;
      gap: 8px;
    }
    
    .form-group label .bi {
      width: 20px;
      text-align: center;
    }

    /* Styled Select */
    .select-wrapper {
      position: relative;
    }
    .select-wrapper::after {
      content: '\f282'; /* bi-chevron-down */
      font-family: "bootstrap-icons";
      position: absolute;
      top: 50%;
      right: 14px;
      transform: translateY(-50%);
      pointer-events: none;
      color: var(--text-muted);
    }

    .form-control, select {
      width: 100%;
      padding: 12px 14px;
      border: 1px solid var(--border-color);
      border-radius: var(--radius-md);
      font-size: 1rem;
      font-family: var(--font-family);
      transition: all 0.25s ease;
      background: var(--bg-primary);
      color: var(--text-primary);
      appearance: none;
      -webkit-appearance: none;
    }
    
    select option {
      background: var(--bg-card);
      color: var(--text-primary);
      padding: 8px; /* Note: padding on options not well supported */
    }

    .form-control:focus, select:focus {
      outline: none;
      border-color: var(--border-focus);
      box-shadow: var(--shadow-focus);
    }
    
    input[type="number"] { appearance: textfield; -moz-appearance: textfield; }

    .inline {
      display: flex;
      gap: 16px;
      align-items: center;
      flex-wrap: wrap;
    }

    .inline-checkbox {
      display: flex;
      align-items: center;
      gap: 8px;
      cursor: pointer;
    }
    .inline-checkbox input {
      width: 18px;
      height: 18px;
      accent-color: var(--primary-600);
    }
    
    .disclaimer {
      font-size: 0.85rem;
      color: var(--text-muted);
      background: var(--bg-secondary);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-md);
      padding: 12px;
      margin-top: 10px;
    }
    
    /* NEW: Dropdown Styles */
    .dropdown { position: relative; }
    .dropdown .btn.dropdown-toggle {
      width: 100%;
      justify-content: space-between;
      text-align: left;
      font-weight: 500;
      background: var(--bg-primary);
      color: var(--text-primary);
      border: 1px solid var(--border-color);
    }
    .dropdown .btn.dropdown-toggle:hover {
      background: var(--bg-secondary);
      border-color: var(--border-focus);
    }
    .dropdown .btn.dropdown-toggle::after {
        display: inline-block;
        margin-left: .255em;
        vertical-align: .255em;
        content: "";
        border-top: .3em solid;
        border-right: .3em solid transparent;
        border-bottom: 0;
        border-left: .3em solid transparent;
        transition: transform 0.2s ease;
    }
    .dropdown.show .btn.dropdown-toggle::after {
      transform: rotate(180deg);
    }
    .dropdown-menu {
        position: absolute;
        top: 100%;
        left: 0;
        z-index: 1021;
        display: none;
        min-width: 100%;
        padding: 8px;
        margin-top: 4px;
        background-color: var(--bg-card);
        background-clip: padding-box;
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-lg);
        max-height: 300px;
        overflow-y: auto;
    }
    .dropdown-menu.show { display: block; }
    .dropdown-item {
        display: block;
        width: 100%;
        padding: 10px 12px;
        clear: both;
        font-weight: 500;
        color: var(--text-secondary);
        text-align: inherit;
        white-space: nowrap;
        background-color: transparent;
        border: 0;
        border-radius: var(--radius-sm);
        cursor: pointer;
        text-decoration: none;
        font-size: 0.95rem;
    }
    .dropdown-item:hover, .dropdown-item.active {
        background-color: var(--bg-secondary);
        color: var(--text-primary);
    }


    /*
      ================================
      === 5. BUTTONS ===
      ================================
    */
    .btn {
      border: none;
      border-radius: var(--radius-md);
      font-weight: 700;
      padding: 12px 18px;
      cursor: pointer;
      transition: all 0.2s ease;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      font-size: 1rem;
      font-family: var(--font-family);
      text-decoration: none;
    }

    .btn:active {
      transform: scale(0.98);
    }
    
    .btn:hover:not(:disabled) {
      transform: translateY(-2px);
      filter: brightness(1.05);
    }
    
    .btn:disabled {
      opacity: 0.6;
      cursor: not-allowed;
    }

    .btn-primary {
      background: var(--primary-gradient);
      color: var(--text-on-primary);
      box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
    }
    .btn-primary:hover:not(:disabled) {
      box-shadow: 0 6px 18px rgba(99, 102, 241, 0.4);
    }

    .btn-secondary {
      background: var(--bg-secondary);
      color: var(--text-primary);
      border: 1px solid var(--border-color);
    }
    .btn-secondary:hover:not(:disabled) {
      background: var(--bg-card);
      border-color: var(--border-focus);
    }
    [data-theme="dark"] .btn-secondary {
      background: #334155;
      color: #f1f5f9;
      border-color: #475569;
    }
    [data-theme="dark"] .btn-secondary:hover:not(:disabled) {
      background: #475569;
      border-color: var(--border-focus);
    }

    .btn-danger {
      background: var(--danger-bg);
      color: var(--danger-text);
      border: 1px solid var(--danger-border);
    }
    .btn-danger:hover:not(:disabled) {
      background: var(--danger-text);
      color: var(--text-on-primary);
    }
    
    .btn-success {
      background: var(--success-bg);
      color: var(--success-text);
      border: 1px solid var(--success-border);
    }
    .btn-success:hover:not(:disabled) {
      background: var(--success-text);
      color: var(--text-on-primary);
    }

    .btn-full { width: 100%; }

    .btn-link {
      background: none;
      border: none;
      color: var(--primary-600);
      cursor: pointer;
      padding: 0;
      font-weight: 600;
      font-size: 0.9rem;
    }
    .btn-link:hover { text-decoration: underline; }

    /*
      ================================
      === 6. SETUP SCREEN ===
      ================================
    */
    /* ADDED: Intro Animation */
    @keyframes fadeInSlideUp {
      from { opacity: 0; transform: translateY(15px); }
      to { opacity: 1; transform: translateY(0); }
    }
    #setupScreen .card, #aiSettingsScreen .card {
      animation: fadeInSlideUp 0.5s ease-out both;
    }
    #setupScreen .card:nth-child(1) { animation-delay: 0.1s; }
    #setupScreen .card:nth-child(2) { animation-delay: 0.2s; }
    #setupScreen .card:nth-child(3) { animation-delay: 0.3s; }
    #setupScreen .card:nth-child(4) { animation-delay: 0.4s; }
    /* End Animation */
    
    /* NEW: Button Group Select */
    .button-group-select {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
    }
    .button-group-select.wide {
      grid-template-columns: 1fr 1fr;
    }
    .button-group-select .btn {
      padding: 12px 10px;
      font-weight: 600;
      border: 1px solid var(--border-color);
      background: var(--bg-primary);
      color: var(--text-secondary);
      transition: all 0.2s ease;
    }
    .button-group-select .btn:hover {
      background: var(--bg-secondary);
      border-color: var(--border-focus);
      transform: none; /* Override default button hover */
    }
    .button-group-select .btn.active {
      background: var(--primary-600);
      color: var(--text-on-primary);
      border-color: var(--primary-600);
      box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
    }
    
    #aiProviderGroup .btn {
      border-width: 2px;
    }
    #aiProviderGroup .btn.active {
      box-shadow: var(--shadow-lg), var(--shadow-focus);
    }


    .topic-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      gap: 12px;
      margin-top: 16px;
    }

    .topic-item {
      display: flex;
      align-items: center;
      gap: 12px;
      background: var(--bg-primary);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-md);
      padding: 12px 14px;
      cursor: pointer;
      transition: all 0.2s ease;
      position: relative;
    }

    .topic-item:hover {
      transform: translateY(-1px);
      border-color: var(--primary-600);
      box-shadow: var(--shadow-focus);
    }
    
    /* ADDED: Visual highlight for selected topics */
    .topic-item:has(.topic-checkbox:checked) {
        border-color: var(--info-border);
        background: var(--info-bg);
    }
    .topic-item:has(.topic-checkbox:checked) .topic-label {
        color: var(--info-text);
    }
    .topic-item:has(.topic-checkbox:checked) .topic-icon {
        background: var(--info-text);
        color: var(--bg-card);
    }
    /* --- */

    .topic-checkbox {
      width: 20px;
      height: 20px;
      border-radius: 6px;
      border: 1.8px solid var(--text-muted);
      appearance: none;
      cursor: pointer;
      display: inline-block;
      position: relative;
      flex: 0 0 20px;
      transition: all 0.2s ease;
      background: var(--bg-card);
    }

    .topic-checkbox:checked {
      border-color: var(--primary-600);
      background: var(--primary-600);
    }

    .topic-checkbox:checked::after {
      content: "\f272"; /* bi-check-lg */
      font-family: "bootstrap-icons";
      color: var(--text-on-primary);
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      font-size: 14px;
    }

    .topic-label {
      display: flex;
      align-items: center;
      gap: 10px;
      font-weight: 600;
      color: var(--text-secondary);
      user-select: none;
      /* ADDED: Transition */
      transition: all 0.2s ease;
    }
    
    .topic-icon {
      width: 30px;
      height: 30px;
      border-radius: var(--radius-sm);
      background: var(--info-bg);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      color: var(--info-text);
      font-size: 16px;
      /* ADDED: Transition */
      transition: all 0.2s ease;
    }

    .topic-actions {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-top: 8px;
      gap: 12px;
      flex-wrap: wrap;
    }
    
    /* Difficulty Buttons */
    .difficulty-options {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      gap: 10px;
    }
    .difficulty-btn {
      padding: 12px 10px;
      font-weight: 600;
      border: 1px solid var(--border-color);
      background: var(--bg-primary);
      color: var(--text-secondary);
      border-radius: var(--radius-md);
    }
    .difficulty-btn:hover {
      background: var(--bg-secondary);
      border-color: var(--border-focus);
      transform: none; /* Override btn hover */
    }
    .difficulty-btn.active {
      background: var(--primary-600);
      color: var(--text-on-primary);
      border-color: var(--primary-600);
      box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
    }
    .difficulty-btn .bi { font-size: 1.1rem; }
    

    /*
      ================================
      === 7. QUIZ SCREEN ===
      ================================
    */
    .quiz-container { max-width: 930px; margin: 0 auto; }

    .quiz-header {
      display: flex;
      justify-content: space-between;
      gap: 12px;
      align-items: stretch;
      flex-wrap: wrap;
      margin-bottom: 16px;
    }

    .panel {
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-lg);
      padding: 12px 16px;
      box-shadow: var(--shadow-sm);
      display: flex;
      align-items: center;
      gap: 12px;
      flex-wrap: wrap;
    }

    .info-badge {
      background: var(--bg-secondary);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-md);
      padding: 8px 12px;
      font-weight: 700;
      color: var(--text-secondary);
      display: inline-flex;
      align-items: center;
      gap: 8px;
    }

    .timer {
      background: var(--success-bg);
      color: var(--success-text);
      border: 1px solid var(--success-border);
      padding: 10px 16px;
      border-radius: var(--radius-md);
      font-weight: 800;
      font-size: 1.05rem;
      display: inline-flex;
      align-items: center;
      gap: 8px;
    }
    .timer.global-timer {
      background: var(--info-bg);
      color: var(--info-text);
      border-color: var(--info-border);
      font-size: 1.1rem;
    }

    .progress-container {
      background: var(--bg-secondary);
      height: 10px;
      border-radius: var(--radius-full);
      overflow: hidden;
      margin-bottom: 16px;
      border: 1px solid var(--border-color);
    }

    .progress-bar {
      height: 100%;
      background: var(--primary-gradient);
      transition: width 0.45s ease;
    }

    .question-card {
      position: relative;
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-lg);
      padding: 24px;
      box-shadow: var(--shadow-md);
    }

    .bookmark-btn {
      position: absolute;
      top: 16px;
      right: 16px;
      background: var(--bg-secondary);
      border: 1px solid var(--border-color);
      padding: 8px 10px;
      border-radius: var(--radius-md);
      cursor: pointer;
      transition: all 0.2s ease;
      color: var(--text-secondary);
    }
    .bookmark-btn:hover {
      background: var(--bg-primary);
      color: var(--primary-600);
    }
    .bookmark-btn .bi { font-size: 18px; }
    .bookmark-btn.bookmarked {
      background: var(--warning-bg);
      border-color: var(--warning-border);
      color: var(--warning-text);
    }

    .question-meta {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      margin-bottom: 14px;
    }

    .meta-badge {
      padding: 6px 12px;
      border-radius: var(--radius-full);
      font-weight: 700;
      font-size: 0.8rem;
      border: 1px solid var(--border-color);
      background: var(--bg-secondary);
      color: var(--text-secondary);
      display: inline-flex;
      gap: 6px;
      align-items: center;
      text-transform: uppercase;
    }

    .badge-hard { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
    .badge-difficulty { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
    .badge-section { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }

    .question-text {
      font-size: 1.25rem;
      line-height: 1.6;
      color: var(--text-primary);
      font-weight: 600;
      margin-bottom: 20px;
    }

    .options-container {
      display: grid;
      gap: 10px;
      margin-top: 12px;
    }

    .option {
      display: grid;
      grid-template-columns: 40px 1fr auto;
      align-items: center;
      gap: 12px;
      padding: 14px 14px;
      border: 1.5px solid var(--border-color);
      border-radius: var(--radius-md);
      cursor: pointer;
      transition: all 0.18s ease;
      background: var(--bg-card);
    }
    .option:hover:not(.disabled) {
      border-color: var(--primary-600);
      transform: translateX(4px);
      box-shadow: var(--shadow-focus);
    }

    .option-letter {
      width: 40px;
      height: 40px;
      border-radius: var(--radius-md);
      background: var(--bg-secondary);
      color: var(--text-primary);
      font-weight: 900;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      transition: all 0.2s ease;
    }
    
    .option-text {
      color: var(--text-secondary);
      font-weight: 500;
    }
    
    .option-indicator {
      font-size: 20px;
      color: var(--border-color);
    }

    .option.selected {
      border-color: var(--primary-600);
      background: var(--info-bg);
    }
    .option.selected .option-letter {
      background: var(--primary-600);
      color: var(--text-on-primary);
    }
    .option.selected .option-text { color: var(--text-primary); font-weight: 600; }
    .option.selected .option-indicator { color: var(--primary-600); }


    .option.correct {
      border-color: var(--success-text);
      background: var(--success-bg);
    }
    .option.correct .option-text { color: var(--success-text); font-weight: 700; }
    .option.correct .option-letter { background: var(--success-text); color: var(--text-on-primary); }

    .option.incorrect {
      border-color: var(--danger-text);
      background: var(--danger-bg);
    }
    .option.incorrect .option-text { color: var(--danger-text); font-weight: 700; }
    .option.incorrect .option-letter { background: var(--danger-text); color: var(--text-on-primary); }
    
    .option.disabled { cursor: not-allowed; opacity: 0.9; }

    .feedback {
      margin-top: 16px;
      padding: 14px;
      border-radius: var(--radius-md);
      font-size: 1rem;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 10px;
      border: 1px solid;
    }

    .feedback.correct {
      background: var(--success-bg);
      color: var(--success-text);
      border-color: var(--success-border);
    }

    .feedback.incorrect {
      background: var(--danger-bg);
      color: var(--danger-text);
      border-color: var(--danger-border);
    }

    .explanation {
      margin-top: 14px;
      padding: 16px;
      border-radius: var(--radius-md);
      background: var(--info-bg);
      border: 1px solid var(--info-border);
      color: var(--info-text);
      line-height: 1.55;
    }
    .explanation strong {
      color: var(--info-text);
      display: inline-flex;
      align-items: center;
      gap: 8px;
    }
    [data-theme="dark"] .explanation strong { color: var(--text-on-primary); }
    
    .explanation .hint {
      margin-top: 8px;
      padding-top: 8px;
      border-top: 1px dashed var(--info-border);
    }

    .action-buttons {
      display: flex;
      gap: 12px;
      margin-top: 20px;
      flex-wrap: wrap;
    }
    
    .action-buttons #nextBtn {
      
    }

    /*
      ================================
      === 8. RESULTS SCREEN ===
      ================================
    */
    .results-card {
      /* UPDATED Gradient */
      background: radial-gradient(circle at 50% 0%, #818cf8 0%, var(--primary-700) 100%);
      color: var(--text-on-primary);
      padding: 30px;
      border-radius: var(--radius-xl);
      text-align: center;
      box-shadow: 0 10px 26px rgba(99, 102, 241, 0.45);
      position: relative;
      overflow: hidden;
    }

    .results-score {
      font-size: 4rem;
      font-weight: 900;
      margin: 10px 0 0;
      line-height: 1;
    }

    .results-percentage {
      font-size: 1.5rem;
      opacity: 0.9;
    }
    .results-message {
      margin-top: 10px;
      font-size: 1.1rem;
      font-weight: 500;
    }
    
    .weighted-score-card {
      background: var(--bg-card);
      border: 2px solid var(--primary-600);
      border-radius: var(--radius-lg);
      padding: 24px;
      margin: 24px 0;
      text-align: center;
      box-shadow: var(--shadow-md);
      color: var(--text-primary);
    }

    .stats-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
      gap: 16px;
      margin: 24px 0;
    }

    .stat-card {
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-lg);
      padding: 20px;
      text-align: center;
      box-shadow: var(--shadow-md);
    }

    .stat-value {
      font-size: 2.5rem;
      font-weight: 900;
      color: var(--primary-600);
    }
    [data-theme="dark"] .stat-value { color: var(--primary-600); }

    .stat-label {
      color: var(--text-muted);
      margin-top: 6px;
      font-weight: 600;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }
    
    .stat-label .bi-check-circle-fill { color: var(--success-text); }
    .stat-label .bi-x-octagon-fill { color: var(--danger-text); }
    .stat-label .bi-bullseye { color: var(--primary-600); }
    .stat-label .bi-clock-history { color: var(--info-text); }

    /*
      ================================
      === 9. REVIEW & HISTORY (NEW ACCORDION) ===
      ================================
    */
    /* NEW: Accordion styles */
    .accordion-item {
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-lg);
      margin-bottom: 12px;
      box-shadow: var(--shadow-sm);
      overflow: hidden;
      transition: all 0.2s ease;
    }
    .accordion-item.correct { border-left: 5px solid var(--success-text); }
    .accordion-item.incorrect { border-left: 5px solid var(--danger-text); }
    
    .accordion-header {
      padding: 18px;
      cursor: pointer;
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 12px;
    }
    .accordion-header:hover {
      background: var(--bg-secondary);
    }
    
    .accordion-question {
      font-size: 1.1rem;
      font-weight: 700;
      color: var(--text-primary);
      flex: 1;
    }
    
    .accordion-icon {
      font-size: 1.2rem;
      color: var(--text-muted);
      transition: transform 0.25s ease;
    }
    .accordion-item.active .accordion-icon {
      transform: rotate(180deg);
      color: var(--primary-600);
    }
    
    .accordion-body {
      max-height: 0;
      overflow: hidden;
      transition: max-height 0.3s ease-out, padding 0.3s ease-out;
      padding: 0 18px;
    }
    .accordion-item.active .accordion-body {
      max-height: 2000px; /* Large enough for content */
      padding: 0 18px 18px 18px;
    }
    
    .accordion-content {
      border-top: 1px solid var(--border-color);
      padding-top: 16px;
    }
    /* --- End Accordion styles --- */
    
    .review-options { display: grid; gap: 8px; margin: 12px 0; }
    
    .review-answer {
      font-weight: 700;
      border-radius: var(--radius-md);
      padding: 10px 12px;
    }
    .review-answer.correct { background: var(--success-bg); color: var(--success-text); }
    .review-answer.incorrect { background: var(--danger-bg); color: var(--danger-text); }
    
    /* MOVED: History container is now its own screen */
    .history-container {
      margin-top: 0; /* No longer inside another card */
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-lg);
      padding: 20px;
      box-shadow: var(--shadow-md);
    }
    
    #historyContainer {
      max-height: 600px; /* Increased height */
      overflow-y: auto;
      padding-right: 10px;
    }

    .history-item {
      /* This is now an accordion item, styles are merged */
    }

    .history-score {
      font-size: 1.1rem;
      font-weight: 900;
      color: var(--primary-600);
      display: inline-flex;
      align-items: center;
      gap: 8px;
    }
    
    .history-details-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 12px;
    }
    .history-detail-item {
        background-color: var(--bg-secondary);
        padding: 8px 12px;
        border-radius: var(--radius-md);
        font-size: 0.9rem;
    }

    /*
      ================================
      === 10. LOADING & MODAL ===
      ================================
    */
    .loading-overlay, .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.42);
      display: none;
      align-items: center;
      justify-content: center;
      z-index: 999;
      backdrop-filter: blur(4px);
    }
    [data-theme="dark"] .loading-overlay, [data-theme="dark"] .modal-overlay {
      background: rgba(15, 23, 42, 0.7);
    }
    
    #initialLoader {
      display: flex; /* Show by default */
    }

    .loading-card, .modal-card {
      background: var(--bg-card);
      border: 1px solid var(--border-color);
      border-radius: var(--radius-lg);
      padding: 24px;
      width: min(520px, 92vw);
      box-shadow: var(--shadow-lg);
      position: relative;
    }
    
    .modal-card {
      text-align: center;
    }
    
    .modal-close-btn {
      position: absolute;
      top: 12px;
      right: 12px;
      width: 32px;
      height: 32px;
      border-radius: var(--radius-full);
      background: var(--bg-secondary);
      border: 1px solid var(--border-color);
      color: var(--text-muted);
      cursor: pointer;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-size: 16px;
    }
    .modal-close-btn:hover { background: var(--bg-primary); }

    .spinner {
      width: 28px;
      height: 28px;
      border: 4px solid var(--border-color);
      border-top-color: var(--primary-600);
      border-radius: 50%;
      animation: spin 1s linear infinite;
      margin: 0 auto 12px;
    }
    
    .loading-card h3 {
      font-weight: 800;  
      font-size: 1.1rem;  
      color: var(--text-primary);  
      margin-bottom: 6px;
      text-align: center;
    }
    .loading-card p {
      color: var(--text-muted);
      text-align: center;
      margin: 0;
      min-height: 20px; /* Reserve space for text change */
      transition: opacity 0.3s ease;
    }

    @keyframes spin {
      to { transform: rotate(360deg); }
    }
    
    @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
    
    /* API Key Info Page Styles */
    #apiKeyInfoScreen .card, #groqApiKeyInfoScreen .card, #cerebrasApiKeyInfoScreen .card {
      text-align: left;
    }
    #apiKeyInfoScreen h3, #groqApiKeyInfoScreen h3, #cerebrasApiKeyInfoScreen h3 {
      text-align: center;
      margin-bottom: 16px;
    }
    #apiKeyInfoScreen ol, #groqApiKeyInfoScreen ol, #cerebrasApiKeyInfoScreen ol {
      line-height: 1.6;
      padding-left: 20px;
    }
    #apiKeyInfoScreen ol li, #groqApiKeyInfoScreen ol li, #cerebrasApiKeyInfoScreen ol li {
      display: flex;
      align-items: flex-start;
      gap: 10px;
      margin-bottom: 12px;
    }
    #apiKeyInfoScreen ol li .bi, #groqApiKeyInfoScreen ol li .bi, #cerebrasApiKeyInfoScreen ol li .bi {
      color: var(--primary-600);
      font-size: 1.2rem;
      margin-top: 2px;
    }
    #apiKeyInfoScreen code, #groqApiKeyInfoScreen code, #cerebrasApiKeyInfoScreen code {
      background: var(--bg-secondary);
      color: var(--danger-text);
      padding: 2px 6px;
      border-radius: 4px;
      font-family: monospace;
    }
    [data-theme="dark"] #apiKeyInfoScreen code, [data-theme="dark"] #groqApiKeyInfoScreen code, [data-theme="dark"] #cerebrasApiKeyInfoScreen code {
      color: var(--danger-text);
    }
    #apiKeyInfoScreen table, #groqApiKeyInfoScreen table, #cerebrasApiKeyInfoScreen table {
      width: 100%;
      border-collapse: collapse;
      margin-top: 12px;
      font-size: 0.9rem;
    }
    #apiKeyInfoScreen th, #apiKeyInfoScreen td, #groqApiKeyInfoScreen th, #groqApiKeyInfoScreen td, #cerebrasApiKeyInfoScreen th, #cerebrasApiKeyInfoScreen td {
      border: 1px solid var(--border-color);
      padding: 8px;
      text-align: left;
    }
    #apiKeyInfoScreen th, #groqApiKeyInfoScreen th, #cerebrasApiKeyInfoScreen th {
      background: var(--bg-secondary);
      font-weight: 700;
    }

    /*
      ================================
      === 11. RESPONSIVE & UTILITY ===
      ================================
    */
    .hidden { display: none !important; }

    /* Sidebar collapsed state */
    body.sidebar-collapsed #sidebar {
      width: var(--sidebar-width-collapsed);
      padding: 20px 0;
      overflow: hidden;
    }

    @media (max-width: 992px) {
      /* On tablet and smaller, collapse sidebar by default */
      body:not(.sidebar-expanded) #sidebar {
         width: var(--sidebar-width-collapsed);
         padding: 20px 0;
         overflow: hidden;
      }
      /* Force expand on click */
      body.sidebar-expanded #sidebar {
         width: var(--sidebar-width);
         padding: 20px;
      }
      #sidebarToggleBtn { display: inline-flex; }
    }

    @media (max-width: 768px) {
      body {
        /* Keep flex-direction row for sidebar logic, but it will mostly be overlay */
      }
      #sidebar {
        position: fixed;
        left: calc(var(--sidebar-width) * -1); /* Hide off-screen by default */
        height: 100vh;
        z-index: 1000;
        box-shadow: var(--shadow-lg);
        transition: all 0.3s ease;
      }
      body.sidebar-expanded #sidebar {
        left: 0;
        width: var(--sidebar-width);
      }
      /* Add an overlay when sidebar is open on mobile */
      .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 999;
        display: none;
      }
      body.sidebar-expanded .sidebar-overlay {
        display: block;
      }

      #main-wrapper {
        width: 100%;
      }
      #main-content {
        padding: 16px;
        max-width: 100%;
      }
      .topbar {
        padding: 0 16px;
      }
      .topbar-title {
        display: none; /* Hide title on mobile, too cluttered */
      }
      
      .results-score { font-size: 3rem; }
      .option { grid-template-columns: 36px 1fr auto; }
      .option-letter { width: 36px; height: 36px; }
      
      .difficulty-options {
        grid-template-columns: 1fr 1fr;
      }
      .action-buttons {
        flex-direction: column;
      }
      .action-buttons .btn {
        width: 100%;
      }
      .action-buttons #nextBtn {
        margin-left: 0;
      }
      .modal-card {
        padding: 20px;
      }
      .button-group-select.wide {
        grid-template-columns: 1fr;
      }
      #tutorModal.modal-overlay {
        align-items: flex-end;
      }
      #tutorModal .modal-card {
        padding: 0;
        width: 100%;
        height: 75vh;
        max-height: 75vh;
        margin: auto 0 0 0;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        animation: slideUpFromBottom 0.3s ease-out;
      }
    }
    
    /*
      ================================
      === 12. TOAST NOTIFICATIONS & ANIMATIONS ===
      ================================
    */
    @keyframes shake {
      10%, 90% { transform: translate3d(-1px, 0, 0); }
      20%, 80% { transform: translate3d(2px, 0, 0); }
      30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
      40%, 60% { transform: translate3d(4px, 0, 0); }
    }
    #sidebarToggleBtn .bi-list {
      animation: shake 1.2s cubic-bezier(.36,.07,.19,.97) 1.5s 1;
    }

    #toast-container {
      position: fixed;
      top: 20px;
      right: 20px;
      z-index: 10000;
      display: flex;
      flex-direction: column;
      gap: 10px;
    }
    .toast {
      background: var(--bg-card);
      color: var(--text-primary);
      padding: 14px 18px;
      border-radius: var(--radius-md);
      box-shadow: var(--shadow-lg);
      border: 1px solid var(--border-color);
      display: flex;
      align-items: center;
      gap: 10px;
      opacity: 0;
      transform: translateX(100%);
      animation: slideInAndOut 4s ease-in-out forwards;
    }
    .toast .bi {
        font-size: 1.2rem;
    }
    .toast.success .bi {
        color: var(--success-text);
    }
    .toast.info .bi {
        color: var(--info-text);
    }
    @keyframes slideInAndOut {
      0% { opacity: 0; transform: translateX(100%); }
      15% { opacity: 1; transform: translateX(0); }
      85% { opacity: 1; transform: translateX(0); }
      100% { opacity: 0; transform: translateX(100%); }
    }
    
    @keyframes slideUpFromBottom {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    /*
      ================================
      === 13. AI TUTOR CHAT MODAL (NEW) ===
      ================================
    */
	
	.tutor-message-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    align-self: flex-start;
    max-width: 90%; /* Prevent the wrapper from being too wide */
}

.tutor-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: var(--text-on-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    margin-bottom: 4px;
}

#tutorModal .modal-header h3 {
    display: flex;
    align-items: center;
    gap: 12px;
}

    #tutorModal .modal-card {
        width: min(600px, 95vw);
        height: min(700px, 85vh);
        padding: 0;
        display: flex;
        flex-direction: column;
    }
    #tutorModal .modal-header {
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-color);
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-shrink: 0;
    }
    #tutorModal .modal-header h3 {
        margin: 0; font-size: 1.1rem;
    }
    .chat-history {
        flex-grow: 1;
        overflow-y: auto;
        padding: 16px;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    .chat-bubble {
        padding: 10px 14px;
        border-radius: var(--radius-lg);
        max-width: 80%;
        line-height: 1.5;
    }
    .chat-bubble.user {
        background: var(--primary-600);
        color: var(--text-on-primary);
        align-self: flex-end;
        border-bottom-right-radius: var(--radius-sm);
    }
    .chat-bubble.tutor {
		background: var(--bg-secondary);
		color: var(--text-secondary);
		border-bottom-left-radius: var(--radius-sm);
	}
    .chat-bubble.tutor.thinking {
      display: flex;
      gap: 8px;
      align-items: center;
    }
    .chat-bubble.tutor.thinking .dot {
        width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted);
        animation: typing-bounce 1s infinite;
    }
    .chat-bubble.tutor.thinking .dot:nth-child(2) { animation-delay: 0.2s; }
    .chat-bubble.tutor.thinking .dot:nth-child(3) { animation-delay: 0.4s; }
    @keyframes typing-bounce {
        0%, 60%, 100% { transform: translateY(0); }
        30% { transform: translateY(-4px); }
    }

    .suggested-questions {
        padding: 0 16px 8px;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    .suggested-q {
        background: transparent;
        border: 1px solid var(--border-color);
        color: var(--text-secondary);
        padding: 6px 10px;
        border-radius: var(--radius-full);
        cursor: pointer;
        font-size: 0.85rem;
        transition: all 0.2s ease;
        animation: fadeIn 0.5s ease both;
    }
    .suggested-q:hover {
        background: var(--bg-secondary);
        border-color: var(--primary-600);
        color: var(--primary-600);
    }
    @keyframes fadeOut { to { opacity: 0; transform: scale(0.9); } }
    .suggested-q.fade-out {
        animation: fadeOut 0.3s ease forwards;
    }

    .chat-input-area {
        padding: 16px;
        border-top: 1px solid var(--border-color);
        display: flex;
        gap: 10px;
    }
    .chat-input-area input {
        flex-grow: 1;
    }
	#aiSettingsScreen .card .bi {
      color: var(--primary-600);
    }
	
	  .coffeeModal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
  }

  .qr-container {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
    margin-top: 18px;
  }

  .qr-item {
    position: relative;
    display: inline-block;
    text-align: center;
  }

  .qr-item img {
    width: 180px;
    height: 180px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.25s ease;
  }

  .qr-item img:hover {
    transform: scale(1.05);
  }

  .download-link {
    display: block;
    font-size: 0.85rem;
    color: var(--primary-600);
    margin-top: 5px;
    text-decoration: none;
  }

  .download-link:hover {
    text-decoration: underline;
  }

  /* Enlarged view */
  .qr-fullscreen {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
  }

  .qr-fullscreen img {
    width: 90%;
    max-width: 400px;
    border-radius: 12px;
  }
  
/*
  ================================
  === 14. LOGIN/AUTH SCREEN (MODERN) ===
  ================================
*/
@keyframes landingpageScreenFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Hides the main app when auth is active */
body.auth-active #sidebar,
body.auth-active #main-wrapper {
  display: none;
}

#landingpageScreen {
  display: none;
  align-items: center;
  justify-content: center;
  position: fixed;
  inset: 0;
  background-image: var(--bg-app);
  z-index: 10000;
  width: 100%;
  height: 100%;
  padding: 16px; /* Add padding for smaller viewports */
  animation: landingpageScreenFadeIn 0.5s ease-out forwards;
}

body.auth-active #landingpageScreen {
  display: flex;
}

.landingpage-container {
  width: 100%;
  max-width: 960px;
  height: 95vh;
  max-height: 720px;
  min-height: 640px;
  display: flex;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

/* === Left Panel (Visual Branding) === */
.auth-panel.left {
  flex-basis: 45%;
  background-image: radial-gradient(circle at 1% 1%, #5a62f1 0%, var(--primary-800) 90%);
  color: var(--text-on-primary);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
  padding: 40px;
}
.left-header {
  display: flex;
  align-items: center;
  gap: 16px;
}
.left-header img {
  width: 52px;
  height: 52px;
  background: rgba(255,255,255,0.15);
  padding: 8px;
  border-radius: var(--radius-md);
}
.left-header h1 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
}
.left-content h2 {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1.3;
  margin-bottom: 16px;
}
.left-content p {
  font-size: 1rem;
  line-height: 1.6;
  opacity: 0.9;
}
.features-list {
  list-style: none;
  padding: 0;
  margin-top: 32px;
}
.features-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  font-weight: 500;
  opacity: 0.95;
}
.features-list .bi {
  font-size: 1.3rem;
  opacity: 1;
}

/* Background Animation Orbs */
.orb {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  filter: blur(30px);
}
.orb1 {
  width: 300px;
  height: 300px;
  bottom: -150px;
  left: -150px;
  animation: float 15s infinite alternate;
}
.orb2 {
  width: 200px;
  height: 200px;
  top: -100px;
  right: -100px;
  animation: float 12s infinite alternate-reverse;
}

/* === Right Panel (Form) === */
.auth-panel.right {
  flex-basis: 55%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 32px 48px;
}

/* This class handles the fade in/out transitions */
.auth-view-item {
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
}
.auth-view-item.is-switching {
  opacity: 0;
  transform: translateY(10px);
  transition-duration: 0.15s;
}
#name-group {
  max-height: 0;
  opacity: 0;
  margin-bottom: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, opacity 0.35s ease, margin-bottom 0.35s ease;
}
#name-group.visible {
  max-height: 82px; /* Adjust if needed */
  opacity: 1;
  margin-bottom: 24px;
}

/* Initial Load Animations */
@keyframes fadeInSlideUp {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}
.auth-view .auth-view-item {
  animation: fadeInSlideUp 0.5s ease-out forwards;
  opacity: 0;
}
.auth-view .auth-view-item:nth-child(1) { animation-delay: 0.1s; }
.auth-view .auth-view-item:nth-child(2) { animation-delay: 0.2s; }
.auth-view .auth-view-item:nth-child(3) { animation-delay: 0.3s; }
.auth-view .auth-view-item:nth-child(4) { animation-delay: 0.4s; }
.auth-view .auth-view-item:nth-child(5) { animation-delay: 0.5s; }
.auth-view .auth-view-item:nth-child(6) { animation-delay: 0.6s; }

.right-header {
  text-align: center;
  margin-bottom: 24px;
}
.right-header h3 {
  font-size: 2rem;
  font-weight: 800;
  margin: 0;
}
.right-header p {
  color: var(--text-secondary);
  margin-top: 8px;
  font-size: 1rem;
}

/* Floating Label Form Group */
.auth-panel .form-group {
  position: relative;
  margin-bottom: 24px;
}
.auth-panel .form-control {
  width: 100%;
  padding: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: all 0.2s ease;
}
.auth-panel .form-control::placeholder {
  color: transparent;
}
.form-label {
  position: absolute;
  top: 16px;
  left: 16px;
  font-size: 1rem;
  color: var(--text-muted);
  pointer-events: none;
  transition: all 0.2s ease;
}
.auth-panel .form-control:focus + .form-label,
.auth-panel .form-control:not(:placeholder-shown) + .form-label {
  top: -10px;
  left: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary-600);
  background-color: var(--bg-card);
  padding: 0 4px;
}
.auth-panel .form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

.auth-panel .btn {
  border-radius: var(--radius-md);
  padding: 16px 20px;
  width: 100%;
  margin-top: 8px;
  font-size: 1rem;
}
.social-buttons .btn-secondary {
  background: var(--bg-card);
  border-width: 1px;
}
.social-buttons .btn-secondary:hover {
  background: var(--bg-secondary);
}

.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }
.font-sm { font-size: 0.9rem; }

.link { color: var(--primary-600); font-weight: 600; text-decoration: none; cursor: pointer; }
.link:hover { text-decoration: underline; }

#auth-message {
  margin-bottom: 16px;
  padding: 12px;
  border-radius: 8px;
  color: var(--danger-text);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  display: none;
  text-align: left;
  line-height: 1.5;
}

/* Validation View Styling */
#validation-view h3 {
  font-weight: 800; font-size: 1.5rem; color: var(--text-primary);
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
#validation-view h3 .bi { color: var(--success-text); }
#validation-view p { color: var(--text-secondary); line-height: 1.6; max-width: 350px; margin: 16px auto 0; }


@keyframes float {
  0% { transform: translateY(0px) translateX(0px); }
  50% { transform: translateY(-20px) translateX(20px); }
  100% { transform: translateY(0px) translateX(0px); }
}

@media (max-width: 900px) {
  #landingpageScreen {
    align-items: flex-start;
    padding: 0;
  }
  .landingpage-container {
    flex-direction: column;
    height: 100%;
    min-height: 100vh;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }
  .auth-panel.left {
    flex-basis: auto;
    padding: 24px;
    min-height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
  .left-content {
    margin-top: 0;
}
.left-content p, .left-content .features-list {
    display: none; /* Hide these specific elements */
}
.left-content h2 {
    font-size: 0.8rem;
    text-align: right;
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 0;
    max-width: 180px;
}
  .auth-panel.right {
    flex-grow: 1;
    padding: 32px 24px;
    justify-content: flex-start;
    overflow-y: auto;
  }
}
    /*
      ================================
      === 15. USER PROFILE & FOOTER (NEW) ===
      ================================
    */
/* Prevents content flashing while checking session */
body.loading-session #main-wrapper,
body.loading-session #sidebar .sidebar-footer {
  visibility: hidden;
}

.sidebar-footer {
  margin-top: auto; /* Pushes this section to the bottom */
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-profile.hidden {
  display: none;
}

#user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background-color: var(--bg-secondary);
}

.user-details {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  flex-grow: 1;
  overflow: hidden;
}

#user-fullname {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#user-email {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sign-out-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 5px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.sign-out-btn:hover {
  color: var(--danger-text);
  background-color: var(--danger-bg);
}

.sidebar-legal-links {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legal-link {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}
.legal-link:hover {
  color: var(--text-primary);
  background-color: var(--bg-secondary);
}
.legal-link .bi {
  font-size: 1rem;
}

/* Guest Ad Container */
.guest-ad-container {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: var(--card-bg);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
    z-index: 1000;
}

.collapse-ad-btn {
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 28px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--text-muted);
    z-index: 1001;
}
.collapse-ad-btn:hover {
    color: var(--text-primary);
}
.collapse-ad-btn i {
    transition: transform 0.3s ease-in-out;
}

.ad-content {
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    max-height: 350px;
    overflow-y: auto;
    transition: max-height 0.35s ease-in-out, padding 0.35s ease-in-out, opacity 0.3s;
    opacity: 1;
}

/* Collapsed State */
.guest-ad-container.collapsed .ad-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
    opacity: 0;
}

.guest-ad-container.collapsed .collapse-ad-btn i {
    transform: rotate(180deg);
}

  .password-feedback {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    margin-top: 12px;
    padding: 10px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
  }
  .password-feedback.success {
    color: var(--success-text);
    background-color: var(--success-bg);
    border-color: var(--success-border);
  }
  .password-feedback.error {
    color: var(--danger-text);
    background-color: var(--danger-bg);
    border-color: var(--danger-border);
  }
  .timer-message {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 12px;
    text-align: center;
  }

.password-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
}
.password-indicator.warning {
  color: var(--warning-text);
  background-color: var(--warning-bg);
  border-color: var(--warning-border);
}
.password-indicator.success {
  color: var(--success-text);
  background-color: var(--success-bg);
  border-color: var(--success-border);
}
#otp-timer {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
  text-align: center;
  display: block;
}

.account-detail-value {
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin: 4px 0 0 0;
    font-size: 0.95rem;
}

      .hourglass {
        font-size: 3.5rem; /* Increased size */
        color: var(--primary-600); /* Theme color */
        margin: 0 auto 16px; /* Center horizontally, add space below */
        text-align: center;
      }
      .hourglass .bi-hourglass-split {
        display: inline-block; /* Ensure transform works correctly */
        animation: hourglass-rock 2.5s ease-in-out infinite;
      }
      @keyframes hourglass-rock {
        0% { transform: rotate(0deg); }
        25% { transform: rotate(15deg); }
        50% { transform: rotate(0deg); }
        75% { transform: rotate(-15deg); }
        100% { transform: rotate(0deg); }
      }


.app-title-block {
  line-height: 1.1;
}
.app-title-block h1 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 800;
}
.app-title-block span {
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0.8;
  display: block;
  margin-top: 2px;
}

    .auth-footer-legal {
  font-size: 0.75rem; /* smaller font */
}

.auth-footer-legal .link {
  font-size: 0.75rem; /* ensure links match smaller size */
  opacity: 0.9;
}

#auth-copyright {
  font-size: 0.7rem;
  margin-top: 4px;
  color: var(--text-muted);
}

/* Floating Subtopic Modal Styles */
      .topic-group {
        position: relative; /* Anchor for absolute positioning */
        transition: background-color 0.2s;
      }
      .topic-group:hover {
        background-color: var(--bg-primary);
      }
      
      .subtopic-popover {
        display: none;
        position: absolute;
        top: calc(100% + 8px); /* Space below the item */
        left: 0;
        right: 0; /* Spans full width of parent */
        width: 100%;
        z-index: 100; /* High Z-index to float over other elements */
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); /* Nice drop shadow */
        padding: 16px;
        
        /* Animation */
        transform-origin: top center;
        animation: popoverFadeIn 0.2s ease-out forwards;
      }
      
      @keyframes popoverFadeIn {
        from { opacity: 0; transform: translateY(-5px) scale(0.98); }
        to { opacity: 1; transform: translateY(0) scale(1); }
      }

      /* Triangle pointer at the top */
      .subtopic-popover::before {
        content: '';
        position: absolute;
        top: -6px;
        right: 20px; /* Align with the chevron usually */
        width: 10px;
        height: 10px;
        background: var(--bg-secondary);
        border-left: 1px solid var(--border-color);
        border-top: 1px solid var(--border-color);
        transform: rotate(45deg);
      }

      .subtopic-header-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 12px;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--border-color);
      }
      
      .subtopic-instruction {
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-muted);
      }
      
      .subtopic-actions {
        display: flex;
        gap: 8px;
      }
      
      .mini-action-btn {
        font-size: 0.7rem;
        padding: 2px 8px;
        border-radius: 12px;
        border: 1px solid var(--border-color);
        background: var(--bg-primary);
        color: var(--text-primary);
        cursor: pointer;
        transition: all 0.2s;
      }
      .mini-action-btn:hover {
        border-color: var(--primary-500);
        color: var(--primary-600);
        background: var(--primary-50);
      }
      
      .subtopic-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
        max-height: 300px;
        overflow-y: auto;
      }
      
      /* Scrollbar styling for the list */
      .subtopic-grid::-webkit-scrollbar { width: 4px; }
      .subtopic-grid::-webkit-scrollbar-track { background: transparent; }
      .subtopic-grid::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

      /* Specific label styling inside popover */
      .subtopic-item-label {
        display: flex; 
        align-items: center; 
        gap: 10px; 
        cursor: pointer; 
        font-size: 0.9rem; 
        padding: 6px;
        border-radius: var(--radius-sm);
        transition: background 0.1s;
      }
      .subtopic-item-label:hover {
        background: var(--bg-primary);
      }
	  
	   /* Fix stacking context so popovers float over the Settings card */
      #topicsCard {
        overflow: visible !important;
        position: relative;
        z-index: 10; 
      }
      
      /* Ensure active group with open popover is above other groups */
      .topic-group.z-active {
        z-index: 100;
        border-color: var(--primary-500) !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
      }
	  
	   /* Landing Page Styles */
      #landing-menu {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        height: 100%;
        text-align: center;
        padding: 20px;
        animation: fadeIn 0.4s ease;
      }
      .landing-logo {
        width: 80px;
        height: 80px;
        margin-bottom: 24px;
        border-radius: 20px;
        box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
      }
      .landing-title {
        font-size: 2rem;
        font-weight: 800;
        color: var(--text-primary);
        margin-bottom: 8px;
        line-height: 1.2;
      }
      .landing-subtitle {
        font-size: 1rem;
        color: var(--text-muted);
        margin-bottom: 32px;
        max-width: 300px;
      }
      .landing-btn-group {
        display: flex;
        flex-direction: column;
        gap: 12px;
        width: 100%;
        max-width: 320px;
      }
      .btn-landing {
        padding: 14px 20px;
        border-radius: 12px;
        font-weight: 600;
        font-size: 1rem;
        transition: all 0.2s;
        border: 1px solid transparent;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        cursor: pointer;
      }
      .btn-landing-primary {
        background: var(--primary-600);
        color: white;
        box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.2);
      }
      .btn-landing-primary:hover {
        background: var(--primary-700);
        transform: translateY(-1px);
      }
      .btn-landing-outline {
        background: transparent;
        border-color: var(--border-color);
        color: var(--text-primary);
      }
      .btn-landing-outline:hover {
        background: var(--bg-secondary);
        border-color: var(--text-muted);
      }
      .btn-landing-ghost {
        background: rgba(var(--primary-rgb), 0.1);
        color: var(--primary-600);
      }
      .btn-landing-ghost:hover {
        background: rgba(var(--primary-rgb), 0.15);
      }
      .landing-badges {
        display: flex;
        gap: 8px;
        margin-bottom: 24px;
        flex-wrap: wrap;
        justify-content: center;
      }
      .landing-badge {
        font-size: 0.75rem;
        padding: 4px 10px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 20px;
        color: var(--text-secondary);
        font-weight: 600;
      }
      .auth-back-btn {
        margin-bottom: 16px; 
        padding: 0; 
        background: none; 
        border: none; 
        color: var(--text-muted); 
        cursor: pointer; 
        display: flex; 
        align-items: center; 
        gap: 6px; 
        font-size: 0.9rem;
      }
      .auth-back-btn:hover { color: var(--text-primary); }
      
      @media (max-width: 768px) {
        .landing-logo { width: 60px; height: 60px; }
        .landing-title { font-size: 1.75rem; }
      }