:root {
      --bg: #000000;
      --panel: #0a0a0a;
      --panel-right: #050505;
      --border: #1a1a1a;
      --accent: #ffffff;
      --accent-hover: #e0e0e0;
      --text: #ffffff;
      --text-muted: #888888;
      --text-input: #cccccc;
      --error: #ef4444;
      --warning: #fbbf24;
      --correct: #34d399;
      --incorrect: #fb7185;
      --glow: 0 0 10px rgba(255, 255, 255, 0.8), 0 0 5px rgba(255, 255, 255, 0.5);
      
      --heatmap-0: #1a1a1a;
      --heatmap-1: rgba(255, 255, 255, 0.3);
      --heatmap-2: rgba(255, 255, 255, 0.6);
      --heatmap-3: rgba(255, 255, 255, 0.8);
      --heatmap-4: rgba(255, 255, 255, 1);
    }

    :root[data-theme="light"] {
      --bg: #f9fafb;
      --panel: #ffffff;
      --panel-right: #f3f4f6;
      --border: #e5e7eb;
      --accent: #000000;
      --accent-hover: #374151;
      --text: #111827;
      --text-muted: #6b7280;
      --text-input: #374151;
      --glow: 0 0 10px rgba(0, 0, 0, 0.2), 0 0 5px rgba(0, 0, 0, 0.1);
      
      --heatmap-0: #ebedf0;
      --heatmap-1: rgba(0, 0, 0, 0.2);
      --heatmap-2: rgba(0, 0, 0, 0.4);
      --heatmap-3: rgba(0, 0, 0, 0.7);
      --heatmap-4: rgba(0, 0, 0, 1);
    }

    :root[data-theme="light"] .input-group label {
      color: rgba(0, 0, 0, 0.7);
    }

    :root[data-theme="light"] input::placeholder,
    :root[data-theme="light"] textarea::placeholder {
      color: rgba(0, 0, 0, 0.35);
    }

    :root[data-theme="light"] textarea {
      color: #111827;
    }

    :root[data-theme="light"] .markdown-body {
      color: #374151;
    }

    :root[data-theme="light"] .markdown-body strong { color: #111827; }
    :root[data-theme="light"] .markdown-body em { color: #374151; }
    :root[data-theme="light"] .markdown-body h1,
    :root[data-theme="light"] .markdown-body h2,
    :root[data-theme="light"] .markdown-body h3 { color: #111827; }
    :root[data-theme="light"] .markdown-body li { color: #374151; }
    :root[data-theme="light"] select { color: #111827; }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    body {
      background-color: var(--bg);
      color: var(--text);
      font-family: 'Google Sans', 'DM Sans', 'Product Sans', ui-sans-serif, system-ui, sans-serif;
      height: 100dvh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    nav {
      height: 56px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 24px;
      background-color: var(--bg);
      flex-shrink: 0;
    }

    .logo {
      font-weight: 700;
      font-size: 20px;
      letter-spacing: -0.05em;
      color: var(--text);
      text-shadow: var(--glow);
    }

    .nav-controls {
      display: flex;
      gap: 16px;
      align-items: center;
    }

    input, select, textarea, button {
      font-family: 'Google Sans', 'DM Sans', 'Product Sans', ui-sans-serif, system-ui, sans-serif;
      outline: none;
      transition: border-color 0.15s ease, background-color 0.15s ease, opacity 0.15s ease;
    }

    input, select {
      background: var(--panel);
      border: 1px solid var(--border);
      color: var(--text-input);
      border-radius: 8px;
      padding: 6px 12px;
      font-size: 12px;
    }
    
    select {
      font-size: 13px;
      color: #d1d1d1;
      padding: 4px 12px;
      cursor: pointer;
    }

    input:focus, select:focus, textarea:focus {
      border-color: var(--accent);
    }

    input::placeholder, textarea::placeholder {
      color: rgba(255, 255, 255, 0.4);
    }

    button {
      height: 40px;
      border-radius: 20px;
      padding: 0 20px;
      font-size: 13px;
      font-weight: 500;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      cursor: pointer;
      border: none;
      transition: opacity 0.15s ease, transform 0.1s ease;
    }
    
    button:active {
      transform: scale(0.98);
    }

    button.primary {
      background: var(--accent);
      color: var(--bg);
      font-weight: 600;
      box-shadow: var(--glow);
    }

    button.primary:hover:not(:disabled) {
      background: var(--accent-hover);
    }

    button.secondary {
      background: transparent;
      border: 1px solid var(--border);
      color: var(--text);
    }

    button.secondary:hover:not(:disabled) {
      background: var(--panel);
    }

    button:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    .main-container {
      display: flex;
      flex: 1;
      overflow: hidden;
      position: relative;
    }

    .panel {
      display: flex;
      flex-direction: column;
    }

    .resizer {
      width: 4px;
      background: transparent;
      cursor: col-resize;
      flex-shrink: 0;
      z-index: 10;
      transition: background 0.15s ease;
    }

    .resizer:hover, .resizer.dragging {
      background: rgba(255, 255, 255, 0.2);
    }

    .history-sidebar {
      width: 240px;
      background: var(--panel-right);
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      flex-shrink: 0;
      transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
      overflow: hidden;
    }
    
    .history-sidebar.collapsed {
      width: 0;
      border-right: none;
    }

    .history-header {
      padding: 16px;
      border-bottom: 1px solid var(--border);
      display: flex;
      justify-content: center;
    }

    #newChatBtn {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      padding: 0;
      flex: none;
    }

    .history-list {
      flex: 1;
      overflow-y: auto;
      padding: 12px;
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .history-item {
      padding: 10px 12px;
      border-radius: 8px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: space-between;
      transition: background 0.15s ease;
      font-size: 13px;
    }

    .history-item:hover {
      background: var(--panel);
    }
    
    .history-item.active {
      background: rgba(255, 255, 255, 0.1);
      box-shadow: 0 0 10px rgba(255, 255, 255, 0.05) inset;
    }

    .history-item-title {
      flex: 1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      text-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
    }

    .history-item-actions {
      display: flex;
      gap: 4px;
      opacity: 0;
      transition: opacity 0.15s ease;
    }

    .history-item:hover .history-item-actions, .history-item.active .history-item-actions {
      opacity: 1;
    }

    .history-item-actions button {
      width: 24px;
      height: 24px;
      padding: 0;
      background: transparent;
      border: none;
      color: var(--text-muted);
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .history-item-actions button:hover {
      background: var(--border);
      color: var(--text);
    }

    .history-item-actions button svg {
      width: 14px;
      height: 14px;
    }

    .history-item-edit-input {
      flex: 1;
      background: var(--bg);
      border: 1px solid var(--accent);
      color: var(--text);
      font-size: 13px;
      padding: 4px 8px;
      border-radius: 4px;
      margin-right: 8px;
    }

    .panel-left {
      width: 480px;
      flex-shrink: 0;
      border-right: 1px solid var(--border);
      background: var(--bg);
      padding: 20px;
      gap: 20px;
      overflow-y: auto;
    }

    .panel-right {
      flex: 1;
      background: var(--panel-right);
      overflow: hidden;
    }
    
    .workspace-header {
      height: 48px;
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 24px;
      flex-shrink: 0;
    }

    .workspace-header span {
      font-size: 11px;
      color: var(--text);
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.15em;
      text-shadow: var(--glow);
    }

    .workspace-body {
      flex: 1;
      padding: 32px;
      overflow-y: auto;
    }

    .input-group {
      display: flex;
      flex-direction: column;
      gap: 6px;
      flex: 1;
      min-height: 0;
    }

    .label-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .input-group label {
      font-size: 10px;
      font-weight: 700;
      color: rgba(255, 255, 255, 0.85);
      text-transform: uppercase;
      letter-spacing: 0.1em;
    }

    button.icon-btn {
      flex: none;
      height: 20px;
      width: 24px;
      background: transparent;
      border: none;
      color: var(--text);
      cursor: pointer;
      padding: 0;
      transition: color 0.15s ease;
    }

    button.icon-btn:hover {
      color: var(--text-muted);
      background: transparent;
    }
    
    button.icon-btn svg, .nav-controls svg {
      width: 16px;
      height: 16px;
      color: var(--text);
    }

    .hidden-input {
      display: none;
    }

    .drop-zone {
      position: relative;
    }

        .drop-zone::after, .fc-drop-zone::after, .chat-drop-zone::after {
      content: 'Drop files here';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(30, 30, 30, 0.85);
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 15px;
      font-weight: 600;
      border-radius: 8px;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s ease;
      z-index: 100;
      backdrop-filter: blur(2px);
    }

    

    .drop-zone.dragover::after, .fc-drop-zone.dragover::after, .chat-drop-zone.dragover::after {
      opacity: 1;
    }

    .drop-zone.dragover textarea {
      border-color: var(--accent);
      background: rgba(99, 102, 241, 0.05);
    }


    .drop-zone.invalid-drop, .chat-drop-zone.invalid-drop, .fc-drop-zone.invalid-drop,
    .drop-zone.too-big-drop, .chat-drop-zone.too-big-drop, .fc-drop-zone.too-big-drop,
    .drop-zone.invalid-fadeout, .chat-drop-zone.invalid-fadeout, .fc-drop-zone.invalid-fadeout,
    .drop-zone.too-big-fadeout, .chat-drop-zone.too-big-fadeout, .fc-drop-zone.too-big-fadeout {
      border: 2px dashed rgba(239, 68, 68, 0.8) !important;
      background: rgba(239, 68, 68, 0.05) !important;
      border-radius: 12px;
    }
    
    .drop-zone.invalid-fadeout, .chat-drop-zone.invalid-fadeout, .fc-drop-zone.invalid-fadeout,
    .drop-zone.too-big-fadeout, .chat-drop-zone.too-big-fadeout, .fc-drop-zone.too-big-fadeout {
      border-color: transparent !important;
      background: transparent !important;
      transition: border-color 0.5s ease-out, background 0.5s ease-out;
    }

    .drop-zone.invalid-drop::after, .chat-drop-zone.invalid-drop::after, .fc-drop-zone.invalid-drop::after,
    .drop-zone.too-big-drop::after, .chat-drop-zone.too-big-drop::after, .fc-drop-zone.too-big-drop::after,
    .drop-zone.invalid-fadeout::after, .chat-drop-zone.invalid-fadeout::after, .fc-drop-zone.invalid-fadeout::after,
    .drop-zone.too-big-fadeout::after, .chat-drop-zone.too-big-fadeout::after, .fc-drop-zone.too-big-fadeout::after {
      top: auto;
      bottom: 20px;
      left: 50%;
      right: auto;
      transform: translateX(-50%);
      background: rgba(239, 68, 68, 1);
      padding: 4px 8px;
      border-radius: 4px;
      font-size: 13px;
      font-weight: 600;
      backdrop-filter: none;
      display: block;
    }

    .drop-zone.invalid-drop::after, .chat-drop-zone.invalid-drop::after, .fc-drop-zone.invalid-drop::after {
      content: 'Unsupported format';
      opacity: 1;
      transition: opacity 0s;
    }

    .drop-zone.invalid-fadeout::after, .chat-drop-zone.invalid-fadeout::after, .fc-drop-zone.invalid-fadeout::after {
      content: 'Unsupported format';
      opacity: 0;
      transition: opacity 0.5s ease-out;
    }

    .drop-zone.too-big-drop::after, .chat-drop-zone.too-big-drop::after, .fc-drop-zone.too-big-drop::after {
      content: 'File size too big (Max 10MB)';
      opacity: 1;
      transition: opacity 0s;
    }

    .drop-zone.too-big-fadeout::after, .chat-drop-zone.too-big-fadeout::after, .fc-drop-zone.too-big-fadeout::after {
      content: 'File size too big (Max 10MB)';
      opacity: 0;
      transition: opacity 0.5s ease-out;
    }

    .image-preview-container {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
    }
    
    .image-preview-container:not(:empty) {
      margin-top: 2px;
    }

    .image-thumbnail {
      position: relative;
      width: 48px;
      height: 48px;
      border-radius: 4px;
      overflow: hidden;
      border: 1px solid var(--border);
    }

      .image-thumbnail img {
      width: 100%;
      height: 100%;
      object-fit: contain;
    }

    .image-thumbnail .pdf-icon {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      background: var(--panel);
      color: var(--text-muted);
      font-size: 11px;
      font-weight: 600;
      flex-direction: column;
    }

    button.remove-btn {
      position: absolute;
      top: 2px;
      right: 2px;
      background: rgba(255, 255, 255, 0.9);
      color: black;
      border: none;
      border-radius: 50%;
      width: 16px;
      height: 16px;
      font-size: 12px;
      font-weight: bold;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      line-height: 1;
      flex: none;
      padding: 0;
    }
    
    button.remove-btn:hover {
      background: #ffffff;
      color: #ef4444;
    }

    textarea {
      flex: 1;
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 12px;
      font-family: 'Google Sans', 'DM Sans', 'Product Sans', ui-sans-serif, system-ui, sans-serif;
      font-size: 13px;
      color: var(--text-input);
      resize: none;
    }

    .button-group {
      display: flex;
      gap: 12px;
      padding-top: 16px;
      padding-bottom: 16px;
      flex-shrink: 0;
      position: sticky;
      bottom: -1px;
      background: var(--bg);
      z-index: 10;
      margin-top: auto;
      border-top: 1px solid var(--border);
    }

    .button-group button {
      flex: 1;
    }

    .error-msg {
      color: var(--error);
      font-size: 13px;
      display: none;
      background: rgba(239, 68, 68, 0.1);
      border: 1px solid rgba(239, 68, 68, 0.2);
      padding: 8px 12px;
      border-radius: 4px;
      flex-shrink: 0;
    }

    .markdown-body {
      white-space: normal;
      color: #a1a1aa;
      font-size: 14.5px;
      line-height: 1.7;
    }
    .output-content {
      max-width: 42rem;
      margin: 0 auto;
    }
    .markdown-body p { margin-bottom: 12px; }
    .markdown-body p:last-child { margin-bottom: 0; }
    .markdown-body strong { color: #e0e0e0; font-weight: 600; }
    .markdown-body em { color: #c0c0c0; }
    .markdown-body h1, .markdown-body h2, .markdown-body h3 {
      color: #e0e0e0; font-weight: 600; margin: 20px 0 8px;
    }
    .markdown-body h1 { font-size: 16px; }
    .markdown-body h2 { font-size: 15px; }
    .markdown-body h3 { font-size: 14px; }
    .markdown-body ul, .markdown-body ol {
      padding-left: 20px; margin: 6px 0 12px;
    }
    .markdown-body li { margin-bottom: 6px; color: #a1a1aa; }
    .markdown-body hr {
      border: none; border-top: 1px solid var(--border); margin: 20px 0;
    }
    .markdown-body code {
      font-family: 'JetBrains Mono', ui-monospace, monospace; background: var(--panel);
      padding: 2px 6px; border-radius: 3px; font-size: 13px; color: #c0c0c0;
    }
    .markdown-body .katex { color: var(--text); }

    /* Custom Code Block Styling */
    .code-block-wrapper {
      background: #0d0d0d;
      border: 1px solid var(--border);
      border-radius: 12px;
      margin: 16px 0;
      overflow: hidden;
    }
    .code-block-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 16px;
      background: #151515;
      border-bottom: 1px solid var(--border);
      color: #a1a1a1;
      font-size: 12px;
      font-weight: 500;
    }
    .code-block-lang {
      display: flex;
      align-items: center;
      gap: 8px;
      text-transform: capitalize;
    }
    .code-block-copy {
      background: transparent;
      border: none;
      color: #a1a1a1;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 4px;
      border-radius: 6px;
      transition: background 0.2s, color 0.2s;
    }
    .code-block-copy:hover {
      background: #222;
      color: #fff;
    }
    .code-block-wrapper pre {
      margin: 0 !important;
      padding: 16px !important;
      overflow-x: auto;
      background: transparent !important;
    }
    .code-block-wrapper pre code {
      font-family: 'JetBrains Mono', ui-monospace, monospace;
      font-size: 13px;
      background: transparent;
      padding: 0;
      color: inherit;
    }

    .katex { color: var(--text); }
    .katex-display {
      display: block;
      background: var(--panel);
      padding: 16px;
      border-radius: 8px;
      margin: 16px 0 !important;
      overflow-x: auto;
      border: 1px solid var(--border);
    }

    .spinner {
      width: 14px;
      height: 14px;
      border: 2px solid rgba(255, 255, 255, 0.3);
      border-radius: 50%;
      border-top-color: currentColor;
      animation: spin 0.8s linear infinite;
      display: none;
    }

    @keyframes spin {
      to { transform: rotate(360deg); }
    }

    .loading-text {
      color: var(--text-muted);
      font-size: 13px;
      margin-top: 8px;
      display: none;
      flex-shrink: 0;
    }

    ::-webkit-scrollbar {
      width: 8px;
      height: 8px;
    }
    ::-webkit-scrollbar-track {
      background: transparent;
    }
    ::-webkit-scrollbar-thumb {
      background: var(--border);
      border-radius: 4px;
    }
    ::-webkit-scrollbar-thumb:hover {
      background: var(--text-muted);
    }

    .chat-sidebar {
      width: 0;
      background: var(--panel-right);
      border-left: 1px solid var(--border);
      transition: width 0.2s ease, opacity 0.2s ease, background-color 0.15s ease;
      display: flex;
      flex-direction: column;
      flex-shrink: 0;
      opacity: 0;
      pointer-events: none;
      overflow: hidden;
      position: relative;
    }

    .chat-sidebar.dragover {
      background: rgba(255, 255, 255, 0.03);
    }

    .chat-sidebar.open {
      width: 380px;
      opacity: 1;
      pointer-events: auto;
    }

    .chat-sidebar.expanded {
      width: 100%;
      position: absolute;
      top: 0;
      right: 0;
      height: 100%;
      z-index: 50;
      border-left: none;
    }

    .chat-history {
      flex: 1;
      padding: 24px;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 16px;
      -webkit-overflow-scrolling: touch;
      transform: translateZ(0);
      will-change: transform, scroll-position;
      overscroll-behavior: contain;
    }

    .chat-placeholder {
      font-size: 13px;
      color: var(--text-muted);
      text-align: center;
      margin-top: 40px;
    }

    .chat-message {
      font-size: 13.5px;
      line-height: 1.6;
      padding: 12px 16px;
      border-radius: 8px;
      max-width: 95%;
      word-break: break-word;
    }

    .chat-message.user {
      align-self: flex-end;
      background: var(--panel);
      color: var(--text);
      border: 1px solid var(--border);
    }

    .chat-message.model {
      align-self: flex-start;
      background: transparent;
      padding: 0 8px;
    }

    .chat-drop-zone {
      border-top: 1px solid var(--border);
      background: var(--bg);
      display: flex;
      flex-direction: column;
      position: relative;
      transition: background-color 0.15s ease;
    }

    .chat-drop-zone.dragover {
      background: rgba(99, 102, 241, 0.05);
    }
    
    .chat-preview-container {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      padding: 0 16px;
    }
    
    .chat-preview-container:not(:empty) {
      padding-top: 12px;
    }

    .chat-input-container {
      margin: 12px 16px;
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 20px;
      display: flex;
      flex-direction: column;
      transition: border-color 0.15s ease;
    }
    .chat-input-container:focus-within {
      border-color: var(--accent);
    }
    .chat-context-pill {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px 16px 4px 16px;
      font-size: 13px;
      color: #e0e0e0;
    }
    .chat-context-pill span {
      flex: 1;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .chat-input-row {
      display: flex;
      gap: 8px;
      align-items: flex-end;
      padding: 8px 12px;
    }
    .chat-input-row textarea {
      flex: 1;
      background: transparent;
      border: none;
      padding: 6px 0;
      font-size: 13.5px;
      color: var(--text);
      resize: none;
      min-height: 32px;
      max-height: 120px;
      font-family: inherit;
      line-height: 1.4;
      overflow-y: auto;
    }
    .chat-input-row textarea:focus {
      outline: none;
    }
    .chat-input-row button.primary {
      flex: none;
      width: 32px;
      height: 32px;
      border-radius: 50%;
      padding: 0;
      margin-bottom: 2px;
    }
    .chat-input-row button.icon-btn {
      flex: none;
      width: 28px;
      height: 28px;
      padding: 0;
      margin-bottom: 4px;
    }
    .global-progress-container {
      position: absolute;
      top: 56px;
      left: 0;
      width: 100%;
      height: 2px;
      z-index: 1000;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.3s ease;
    }

    .global-progress-container.active {
      opacity: 1;
    }

    .global-progress-bar {
      height: 100%;
      width: 0%;
      background: #fff;
      box-shadow: 0 0 10px rgba(255, 255, 255, 0.8), 0 0 5px rgba(255, 255, 255, 0.5);
      transition: width 0.3s ease;
    }

    .ask-tooltip {
      position: absolute;
      background: var(--text);
      color: var(--bg);
      padding: 6px 12px;
      border-radius: 6px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      box-shadow: 0 8px 24px rgba(0,0,0,0.4);
      display: none;
      z-index: 100;
      align-items: center;
      gap: 6px;
      transform: translate(-50%, -10px);
      pointer-events: auto;
      transition: background-color 0.15s ease;
    }
    
    .ask-tooltip:hover {
      background: #fff;
    }
    .ai-glow-overlay {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      pointer-events: none;
      z-index: 9999;
      opacity: 0;
      transition: opacity 0.5s ease;
      overflow: hidden;
      -webkit-mask-image: 
        linear-gradient(to bottom, black 0px, transparent 16px, transparent calc(100% - 16px), black 100%),
        linear-gradient(to right, black 0px, transparent 16px, transparent calc(100% - 16px), black 100%);
      -webkit-mask-composite: source-over;
      /* iOS Safari has a known bug where mix-blend-mode on descendants stops
         blending (renders flat/opaque) when an ancestor uses mask-image. The
         actual fix is forcing this element to establish its own proper
         isolated blending context, which restores correct screen-blend
         rendering under the mask on iPhone while keeping the exact original
         look (same soft fade, same thickness) everywhere else. */
      isolation: isolate;
    }

    .ai-glow-overlay.active {
      opacity: 1;
    }

    .glow-blob {
      position: absolute;
      filter: blur(90px);
      border-radius: 50%;
      animation: float-blob 12s cubic-bezier(0.4, 0, 0.2, 1) infinite alternate;
      mix-blend-mode: screen;
      opacity: 0.8;
    }

    .glow-blob.blob1 {
      top: -100px; left: -100px; width: 600px; height: 600px;
      background: #ff007f;
      animation-duration: 14s;
    }
    .glow-blob.blob2 {
      top: -150px; right: 20%; width: 700px; height: 600px;
      background: #7f00ff;
      animation-duration: 16s;
    }
    .glow-blob.blob3 {
      bottom: -150px; right: -100px; width: 700px; height: 700px;
      background: #00d4ff;
      animation-duration: 13s;
    }
    .glow-blob.blob4 {
      bottom: -100px; left: 20%; width: 600px; height: 600px;
      background: #00ffaa;
      animation-duration: 15s;
    }
    .glow-blob.blob5 {
      top: 30%; left: -200px; width: 500px; height: 800px;
      background: #ffaa00;
      animation-duration: 17s;
    }
    .glow-blob.blob6 {
      top: 40%; right: -200px; width: 500px; height: 800px;
      background: #ff00ff;
      animation-duration: 14.5s;
    }

    @keyframes float-blob {
      0% { transform: translate(0, 0) scale(1) rotate(0deg); }
      33% { transform: translate(30vw, 15vh) scale(1.3) rotate(45deg); }
      66% { transform: translate(-15vw, 30vh) scale(0.8) rotate(90deg); }
      100% { transform: translate(20vw, -20vh) scale(1.2) rotate(135deg); }
    }

    @media (max-width: 600px) {
      .glow-blob {
        filter: blur(50px);
        opacity: 0.55;
      }
      .glow-blob.blob1, .glow-blob.blob2, .glow-blob.blob3,
      .glow-blob.blob4, .glow-blob.blob5, .glow-blob.blob6 {
        width: 260px;
        height: 260px;
      }
      .glow-blob.blob1 { top: -80px; left: -80px; }
      .glow-blob.blob2 { top: -100px; right: -60px; }
      .glow-blob.blob3 { bottom: -100px; right: -80px; }
      .glow-blob.blob4 { bottom: -80px; left: -60px; }
      .glow-blob.blob5 { top: 40%; left: -140px; width: 220px; height: 320px; }
      .glow-blob.blob6 { top: 40%; right: -140px; width: 220px; height: 320px; }
    }

    .auth-tab {
      background: transparent;
      border: none;
      border-radius: 0;
      color: var(--text-muted);
      padding: 8px 0;
      font-size: 14px;
      cursor: pointer;
      border-bottom: 2px solid transparent;
      transition: color 0.15s ease, border-color 0.15s ease;
      flex: 1;
      height: auto;
    }
    .auth-tab.active {
      color: var(--text);
      border-bottom-color: var(--accent);
    }
    
    .nav-view-btn {
      background: transparent;
      border: none;
      border-radius: 0;
      font-size: 13px;
      color: var(--text-muted);
      cursor: pointer;
      padding: 6px 0;
      border-bottom: 2px solid transparent;
      transition: color 0.15s ease, border-color 0.15s ease;
      font-weight: 500;
    }
    .nav-view-btn.active {
      color: var(--text);
      border-bottom-color: var(--accent);
    }
    
    .xp-bar-container {
      height: 40px;
      background: var(--bg);
      border-bottom: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      font-family: 'DM Sans', 'Google Sans', ui-sans-serif, system-ui, sans-serif;
      font-size: 12px;
      gap: 16px;
    }
    .xp-level-text {
      font-weight: 700;
      color: var(--text);
      text-shadow: var(--glow);
    }
    .xp-bar-wrapper {
      width: 200px;
      height: 6px;
      background: var(--border);
      border-radius: 3px;
      overflow: hidden;
      display: flex;
    }
    .xp-bar-fill {
      height: 100%;
      background: var(--accent);
      box-shadow: var(--glow);
      transition: width 0.3s ease;
    }
    .xp-text {
      color: var(--text-muted);
    }
    .streak-text {
      color: var(--text-muted);
    }
    
    .xp-float-anim {
      position: absolute;
      color: var(--correct);
      font-weight: 700;
      font-size: 14px;
      pointer-events: none;
      animation: xpFloat 1.2s ease-out forwards;
      z-index: 1000;
      text-shadow: 0 0 10px rgba(52,211,153,0.6);
    }
    @keyframes xpFloat {
      0% { opacity: 1; transform: translateY(0); }
      100% { opacity: 0; transform: translateY(-40px); }
    }
    @keyframes levelUpPulse {
      0% { box-shadow: inset 0 0 0 0 rgba(255,255,255,0); }
      50% { box-shadow: inset 0 0 20px 4px rgba(255,255,255,0.6); }
      100% { box-shadow: inset 0 0 0 0 rgba(255,255,255,0); }
    }
    
    #dashboardView {
      display: none;
      flex: 1;
      overflow: hidden;
      background: var(--bg);
    }
    .dashboard-sidebar {
      width: 300px;
      border-right: 1px solid var(--border);
      display: flex;
      flex-direction: column;
      background: var(--panel-right);
      flex-shrink: 0;
    }
    .dashboard-main {
      flex: 1;
      overflow-y: auto;
      padding: 32px;
    }
    .subject-row {
      padding: 14px 20px;
      font-size: 13.5px;
      color: var(--text-muted);
      cursor: pointer;
      border-left: 3px solid transparent;
      transition: background 0.15s ease, color 0.15s ease;
      display: flex;
      align-items: center;
      justify-content: space-between;
    }
    .subject-row:hover {
      background: rgba(255,255,255,0.03);
      color: var(--text);
    }
    .subject-row.active {
      color: var(--text);
      background: rgba(255,255,255,0.05);
      border-left-color: var(--accent);
      font-weight: 500;
    }
    .review-badge {
      margin: 16px 20px;
      padding: 12px 16px;
      background: rgba(251,191,36,0.1);
      border: 1px solid rgba(251,191,36,0.3);
      border-radius: 8px;
      color: var(--warning);
      font-size: 13px;
      font-weight: 600;
      display: flex;
      align-items: center;
      gap: 8px;
      cursor: pointer;
      transition: background 0.15s ease;
    }
    .review-badge:hover {
      background: rgba(251,191,36,0.15);
    }
    .heatmap-group {
      margin-bottom: 32px;
    }
    .heatmap-header {
      font-family: 'JetBrains Mono', ui-monospace, monospace;
      font-size: 10px;
      text-transform: uppercase;
      color: var(--text-dim);
      margin-bottom: 8px;
      letter-spacing: 0.05em;
    }
    .heatmap-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
      gap: 8px;
    }
    .heatmap-cell {
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 12px;
      font-size: 12px;
      color: var(--text);
      cursor: pointer;
      transition: filter 0.15s ease;
      display: flex;
      align-items: center;
      justify-content: center;
      text-align: center;
      min-height: 60px;
    }
    .heatmap-cell:hover {
      filter: brightness(1.2);
    }
    .heatmap-cell.state-due {
      background: rgba(251,191,36,0.15);
      border-color: var(--warning);
    }
    .heatmap-cell.state-mistake {
      background: rgba(251,113,133,0.15);
      border-color: var(--incorrect);
    }
    .heatmap-cell.state-mastered {
      background: rgba(52,211,153,0.15);
      border-color: var(--correct);
    }
    
    .boss-fight-card {
      border: 1px solid rgba(251,113,133,0.3);
      background: rgba(251,113,133,0.05);
      border-radius: 12px;
      padding: 20px;
      margin-top: 24px;
      transition: border-color 0.3s ease;
      position: relative;
    }
    .boss-fight-card.correct-anim {
      border-color: var(--correct);
    }
    .boss-fight-card.incorrect-anim {
      border-color: var(--incorrect);
    }
    .boss-fight-header {
      font-family: 'JetBrains Mono', ui-monospace, monospace;
      font-size: 12px;
      font-weight: 700;
      color: var(--incorrect);
      margin-bottom: 12px;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .boss-fight-question {
      font-size: 14px;
      line-height: 1.5;
      margin-bottom: 16px;
      text-align: center;
    }
    .boss-fight-question p {
      margin: 0;
    }
    .boss-option p {
      margin: 0;
    }
    .boss-option {
      padding: 10px 14px;
      border: 1px solid var(--border);
      background: var(--panel);
      border-radius: 8px;
      margin-bottom: 8px;
      cursor: pointer;
      font-size: 13.5px;
      transition: background 0.15s ease;
      display: flex;
      gap: 12px;
    }
    .boss-option:hover {
      background: rgba(255,255,255,0.05);
    }
    .boss-option.selected {
      border-color: var(--accent);
      background: rgba(255,255,255,0.1);
    }
    .boss-option.correct-reveal {
      border-color: var(--correct);
      background: rgba(52,211,153,0.1);
    }
    .boss-option.incorrect-reveal {
      border-color: var(--incorrect);
      background: rgba(251,113,133,0.1);
    }
    .boss-explanation {
      margin-top: 16px;
      padding-top: 16px;
      border-top: 1px solid rgba(255,255,255,0.1);
      font-size: 13.5px;
      line-height: 1.5;
      display: none;
    }
    .boss-explanation.show {
      display: block;
    }
    .review-modal-overlay {
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      background: rgba(0,0,0,0.8);
      backdrop-filter: blur(4px);
      z-index: 10000;
      display: none;
      align-items: center;
      justify-content: center;
    }
    .review-modal {
      width: 100%;
      max-width: 500px;
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 24px;
    }
    .toast {
      position: fixed;
      bottom: 24px;
      left: 50%;
      transform: translateX(-50%);
      background: var(--text);
      color: var(--bg);
      padding: 10px 20px;
      border-radius: 20px;
      font-size: 13px;
      font-weight: 600;
      z-index: 9999;
      box-shadow: 0 4px 12px rgba(0,0,0,0.3);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.3s ease;
    }
    .toast.show { opacity: 1; }
    
    /* Home View and New Styles */
    .hero-xp-bar {
      margin: 0 auto 32px auto;
      max-width: 480px;
      width: 100%;
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 24px;
    }
    .hero-level {
      font-size: 32px;
      font-weight: 700;
      color: var(--text);
      text-shadow: var(--glow);
    }
    .hero-streak {
      font-size: 16px;
      color: var(--warning);
      align-self: center;
    }
    .hero-bar-wrapper {
      width: 100%;
      height: 8px;
      background: var(--border);
      border-radius: 4px;
      overflow: hidden;
      display: flex;
    }
    .hero-bar-fill {
      height: 100%;
      background: var(--accent);
      box-shadow: var(--glow);
      transition: width 0.3s ease;
    }
    .hero-xp-text {
      color: var(--text-muted);
      font-size: 14px;
    }
    
    .home-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
      gap: 20px;
    }
    .home-card {
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 20px;
      cursor: pointer;
      transition: transform 0.2s ease, border-color 0.2s ease;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      min-height: 160px;
    }
    .home-card:hover {
      transform: translateY(-4px);
      border-color: rgba(255,255,255,0.18);
    }
    .home-card.unit-card {
      min-height: 130px;
    }

    .proficiency-gauge {
      width: 112px;
      height: 112px;
      position: relative;
      margin: 12px auto 0;
    }
    .proficiency-gauge-segments {
      position: absolute;
      inset: 0;
    }
    .proficiency-gauge-segment {
      position: absolute;
      top: 3px;
      left: calc(50% - 2px);
      width: 4px;
      height: 11px;
      border-radius: 999px;
      background: rgba(255, 255, 255, 0.4);
      box-shadow: 0 0 5px rgba(255, 255, 255, 0.16);
      transform: rotate(calc(var(--segment) * 10deg));
      transform-origin: 2px 53px;
      transition: background 0.3s ease, box-shadow 0.3s ease;
    }
    .proficiency-gauge-segment.is-filled {
      background: #fff;
      box-shadow: 0 0 7px rgba(255, 255, 255, 0.8), 0 0 14px rgba(255, 255, 255, 0.35);
    }
    :root[data-theme="light"] .proficiency-gauge-segment {
      background: rgba(17, 24, 39, 0.28);
      box-shadow: 0 0 4px rgba(17, 24, 39, 0.12);
    }
    :root[data-theme="light"] .proficiency-gauge-segment.is-filled {
      background: #111827;
      box-shadow: 0 0 7px rgba(17, 24, 39, 0.45), 0 0 14px rgba(17, 24, 39, 0.18);
    }
    .proficiency-gauge-label {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      text-align: center;
      pointer-events: none;
    }
    .proficiency-gauge-label span {
      color: var(--text-muted);
      font-size: 11px;
      font-weight: 600;
      letter-spacing: 0.04em;
    }
    .proficiency-gauge-label strong {
      margin-top: 2px;
      color: var(--text);
      font-size: 24px;
      line-height: 1;
      letter-spacing: -0.04em;
      text-shadow: 0 0 14px rgba(255, 255, 255, 0.2);
    }
    .proficiency-score {
      color: var(--text);
      text-shadow: var(--glow);
    }
    .prof-fill.proficiency-fill {
      background: var(--text) !important;
      box-shadow: var(--glow);
    }
    
    .topic-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 20px;
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 12px;
      margin-bottom: 12px;
      transition: transform 0.2s ease, border-color 0.2s ease;
    }
    .topic-row:hover {
      transform: translateY(-2px);
      border-color: rgba(255,255,255,0.18);
    }
    
    .revise-card {
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 20px;
      padding: 32px;
      cursor: pointer;
      transition: transform 0.2s ease, border-color 0.2s ease;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      min-height: 200px;
      min-width: 220px;
      text-align: center;
    }
    .revise-card:hover {
      transform: translateY(-4px);
      border-color: rgba(255,255,255,0.18);
    }
    
    .flashcard-scene {
      width: 100%;
      max-width: 400px;
      height: 260px;
      perspective: 1000px;
      cursor: pointer;
    }
    .flashcard-inner {
      width: 100%;
      height: 100%;
      transition: transform 0.4s ease;
      transform-style: preserve-3d;
      position: relative;
    }
    .flashcard-inner.is-flipped {
      transform: rotateY(180deg);
    }
    .flashcard-front, .flashcard-back {
      position: absolute;
      width: 100%;
      height: 100%;
      -webkit-backface-visibility: hidden;
      backface-visibility: hidden;
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 20px;
      padding: 24px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
    .flashcard-back {
      transform: rotateY(180deg);
    }
    
    .medal-card {
      background: var(--panel);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 16px;
      width: 120px;
      display: flex;
      flex-direction: column;
      align-items: center;
      text-align: center;
      gap: 8px;
    }
    
    .prof-bar {
      height: 4px;
      border-radius: 2px;
      background: var(--border);
      overflow: hidden;
      display: flex;
      width: 100%;
    }
    .prof-fill {
      height: 100%;
      transition: width 0.3s ease;
    }
    
    .medal-animation {
      position: fixed;
      top: 0; left: 0; right: 0; bottom: 0;
      pointer-events: none;
      z-index: 10000;
      background: radial-gradient(circle at center, rgba(251,191,36,0.2) 0%, transparent 70%);
      opacity: 0;
      animation: flashGold 1s ease-out;
    }
    @keyframes flashGold {
      0% { opacity: 0; transform: scale(0.9); }
      30% { opacity: 1; transform: scale(1.05); }
      100% { opacity: 0; transform: scale(1.1); }
    }
    .activity-day {
      width: 13px;
      height: 13px;
      border-radius: 2px;
      background: var(--heatmap-0);
      cursor: pointer;
      flex-shrink: 0;
    }
    .activity-day:hover { opacity: 0.8; }
    .activity-day[data-level="1"] { background: var(--heatmap-1); }
    .activity-day[data-level="2"] { background: var(--heatmap-2); }
    .activity-day[data-level="3"] { background: var(--heatmap-3); }
    .activity-day[data-level="4"] { background: var(--heatmap-4); }
    .fc-drop-zone {
      border: 2px dashed var(--border);
      border-radius: 12px;
      padding: 20px;
      text-align: center;
      cursor: pointer;
      transition: border-color 0.2s ease, background 0.2s ease;
      position: relative;
      margin-bottom: 12px;
      min-height: 80px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }
    .fc-drop-zone:hover,
    .fc-drop-zone.dragover {
      border-color: var(--accent);
      background: rgba(255, 255, 255, 0.03);
    }
    .fc-drop-zone input[type="file"] {
      position: absolute;
      inset: 0;
      opacity: 0;
      cursor: pointer;
      width: 100%;
      height: 100%;
    }
    .fc-drop-zone svg {
      color: var(--text-muted);
      flex-shrink: 0;
    }
    .fc-drop-zone .fc-drop-label {
      font-size: 13px;
      color: var(--text-muted);
    }
    .fc-drop-zone .fc-drop-hint {
      font-size: 11px;
      color: var(--text-dim, #4f4f4f);
    }
    .fc-image-preview {
      width: 100%;
      max-height: 120px;
      object-fit: contain;
      border-radius: 8px;
      border: 1px solid var(--border);
      margin-top: 8px;
      display: none;
    }
    
    @keyframes fadeSlideUp {
      0% { opacity: 0; transform: translateY(20px); }
      100% { opacity: 1; transform: translateY(0); }
    }
    .pro-anim {
      animation: fadeSlideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
      opacity: 0;
    }
    .pro-anim-1 { animation-delay: 0.1s; }
    .pro-anim-2 { animation-delay: 0.2s; }
    .pro-anim-3 { animation-delay: 0.3s; }
    .pro-anim-4 { animation-delay: 0.4s; }
    .pro-anim-5 { animation-delay: 0.5s; }

    /* Custom Toggle Switch for Cram Mode */
    .theme-toggle-switch {
      position: relative;
      display: inline-block;
      width: 44px;
      height: 24px;
      flex-shrink: 0;
    }
    .theme-toggle-switch input {
      opacity: 0;
      width: 0;
      height: 0;
    }
    .theme-toggle-slider {
      position: absolute;
      cursor: pointer;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: var(--panel);
      transition: .3s;
      border-radius: 24px;
      border: 2px solid var(--border);
      box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
    }
    .theme-toggle-slider:before {
      position: absolute;
      content: "";
      height: 16px;
      width: 16px;
      left: 2px;
      bottom: 2px;
      background-color: var(--text-muted);
      transition: .3s;
      border-radius: 50%;
      box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    }
    .theme-toggle-switch input:checked + .theme-toggle-slider {
      background-color: var(--accent);
      border-color: var(--accent);
    }
    .theme-toggle-switch input:checked + .theme-toggle-slider:before {
      transform: translateX(20px);
      background-color: var(--bg);
    }

    @media (max-width: 1024px) {
      .panel-left {
        width: 320px !important;
      }
      .panel-left textarea {
        min-height: 80px;
      }
      nav {
        overflow-x: auto;
      }
      nav::-webkit-scrollbar {
        display: none;
      }
      nav > div:first-child {
        min-width: max-content;
      }
      .history-sidebar {
        position: absolute;
        left: 0;
        z-index: 100;
        height: 100%;
        background: var(--bg);
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
      }
      .chat-sidebar {
        position: absolute;
        right: 0;
        z-index: 100;
        height: 100%;
        background: var(--panel-right);
        box-shadow: -2px 0 10px rgba(0,0,0,0.1);
      }
      .chat-sidebar.open {
        width: 380px !important;
        max-width: 100% !important;
      }
    }

    @media (max-width: 640px) {
      nav {
        padding: 0 12px;
      }
      .logo {
        font-size: 18px;
      }
      nav > div:first-child > div:nth-child(3) {
        gap: 8px !important;
        margin-left: 12px !important;
      }
      .nav-view-btn {
        padding: 4px;
        font-size: 13px;
      }
      .nav-controls span#userEmail {
        display: none;
      }
      .main-container {
        flex-direction: column !important;
        overflow-y: auto !important;
      }
      .panel-left, .panel-right {
        width: 100% !important;
        flex: none !important;
        height: auto !important;
        border-right: none !important;
      }
      .panel-left {
        border-bottom: 1px solid var(--border);
        padding-bottom: 24px;
      }
      .panel-right {
        min-height: 100vh;
        overflow: visible !important;
      }
      .resizer {
        display: none !important;
      }
      .history-sidebar.open, .chat-sidebar.open {
        width: 100% !important;
        max-width: 100% !important;
      }
      .button-group {
        position: static !important;
        padding-top: 24px;
        border-top: none;
        margin-top: 0;
      }
      #proView h1 {
        font-size: 32px !important;
      }
    }
