
    /* Student Mode: hide auth UI when in student mode */
    html[data-student="1"] #authContainer,
    html[data-student="1"] #authContainerMobile { display: none !important; }

    /* Hide Student Mode workflow UI (WIP feature) */
    #workflowStages,
    .workflow-stages-container,
    #stageTransitionContainer,
    #studentModeToggleContainer,
    #readyToCheckBtn,
    #finishGrammarBtn,
    #wordCountRequirement { display: none !important; }

    :root{
      --border:#2a2f45;
      --card-border: #2a2f45;
      --card-shadow: 0 2px 8px rgba(0,0,0,0.2), 0 1px 3px rgba(0,0,0,0.15);
      --card-shadow-hover: 0 4px 12px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2);
      /* Header design tokens */
      --hdr-bg: #181c27;
      --hdr-border: #2a2f45;
      --hdr-accent: #AA151B;
      --hdr-accent2: #F1BF00;
      --hdr-muted: #7a8099;
      --hdr-input-bg: #0f1117;
      /* Dark theme tokens */
      --body-bg: #12151e;
      --surface: #1a1f2e;
      --surface-raised: #1e2333;
      --text-primary: #e2e8f0;
      --text-secondary: #94a3b8;
      --text-muted: #64748b;
    }

    /* ── NEW HEADER ── */
    .wif-header {
      display: none;            /* hidden on mobile; shown at lg */
      align-items: center;
      justify-content: space-between;
      padding: 0 20px;
      height: 54px;
      background: var(--hdr-bg);
      border-bottom: 1px solid var(--hdr-border);
      flex-shrink: 0;
      gap: 16px;
    }
    @media (min-width: 1024px) {
      .wif-header { display: flex; }
    }
    .wif-header .logo {
      font-family: 'DM Serif Display', serif;
      font-size: 1.2rem;
      letter-spacing: -0.02em;
      flex-shrink: 0;
      color: #fff;
      text-decoration: none;
    }
    .wif-header .logo:hover { opacity: 0.95; }
    .wif-header .logo .logo-in { color: #F1BF00; font-style: italic; }
    .wif-header .logo-stripe {
      display: inline-flex;
      gap: 2px;
      align-items: center;
      margin-left: 6px;
      vertical-align: middle;
    }
    .wif-header .logo-stripe span {
      display: inline-block;
      width: 5px; height: 14px;
      border-radius: 1px;
    }
    .wif-header .ls-r { background: #AA151B; }
    .wif-header .ls-y { background: #F1BF00; }
    .wif-header .header-center {
      display: flex;
      align-items: center;
      gap: 8px;
      flex: 1;
      justify-content: center;
    }
    .wif-header .session-input {
      width: 140px;
      background: var(--hdr-input-bg);
      border: 1px solid var(--hdr-border);
      border-radius: 6px;
      color: #fff;
      font-family: 'DM Sans', sans-serif;
      font-size: 0.8rem;
      padding: 5px 10px;
      outline: none;
      transition: border-color 0.15s;
    }
    .wif-header .session-input:focus { border-color: var(--hdr-accent); box-shadow: none; }
    .wif-header .session-input::placeholder { color: var(--hdr-muted); }
    .wif-header .header-icons {
      display: flex;
      gap: 2px;
    }
    .wif-header .icon-btn {
      width: 30px; height: 30px;
      background: transparent;
      border: 1px solid var(--hdr-border);
      border-radius: 5px;
      cursor: pointer;
      font-size: 0.85rem;
      display: flex; align-items: center; justify-content: center;
      transition: background 0.12s;
      color: #fff;
      padding: 0;
    }
    .wif-header .icon-btn:hover { background: var(--hdr-border); }
    .wif-header .timer-group {
      display: flex;
      align-items: center;
      gap: 6px;
      margin-left: 4px;
    }
    .wif-header .btn-start {
      background: var(--hdr-accent2);
      color: #fff;
      border: none;
      border-radius: 5px;
      font-family: 'DM Sans', sans-serif;
      font-size: 0.72rem;
      font-weight: 700;
      padding: 4px 10px;
      height: 28px;
      cursor: pointer;
      transition: opacity 0.15s;
    }
    .wif-header .btn-start:hover { opacity: 0.85; }
    .wif-header .timer-display {
      font-size: 0.82rem;
      font-weight: 600;
      font-variant-numeric: tabular-nums;
      color: #fff;
      background: var(--hdr-input-bg);
      border: 1px solid var(--hdr-border);
      border-radius: 5px;
      padding: 4px 10px;
      letter-spacing: 0.05em;
    }
    .wif-header .header-right {
      display: flex;
      align-items: center;
      gap: 10px;
      flex-shrink: 0;
    }
    .wif-header .prompt-pill {
      font-size: 0.72rem;
      font-weight: 500;
      color: #fff;
      background: var(--hdr-accent);
      border: 1px solid var(--hdr-accent);
      padding: 3px 10px;
      border-radius: 20px;
      white-space: nowrap;
    }
    .wif-header .theme-toggle {
      width: 30px; height: 30px;
      background: var(--hdr-input-bg);
      border: 1px solid var(--hdr-border);
      border-radius: 5px;
      cursor: pointer;
      font-size: 0.85rem;
      display: flex; align-items: center; justify-content: center;
      transition: background 0.12s;
      color: #fff;
      padding: 0;
    }
    .wif-header .theme-toggle:hover { background: var(--hdr-border); }
    .wif-header .lang-select-wrap {
      display: flex;
      align-items: center;
      gap: 4px;
    }
    .wif-header .lang-select-wrap .lang-label {
      font-size: 0.68rem;
      color: var(--hdr-muted);
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }
    .wif-header .lang-select-wrap select {
      background: var(--hdr-input-bg);
      border: 1px solid var(--hdr-border);
      border-radius: 5px;
      color: #fff;
      font-family: 'DM Sans', sans-serif;
      font-size: 0.75rem;
      padding: 4px 6px;
      outline: none;
      cursor: pointer;
    }
    .wif-header .lang-select-wrap select option { background: #1e2333; }
    /* User dropdown */
    .wif-header .user-menu-wrap { position: relative; }
    .wif-header .user-btn {
      background: var(--hdr-input-bg);
      border: 1px solid var(--hdr-border);
      border-radius: 6px;
      color: #fff;
      font-family: 'DM Sans', sans-serif;
      font-size: 0.78rem;
      font-weight: 500;
      padding: 5px 12px;
      cursor: pointer;
      transition: background 0.12s;
      white-space: nowrap;
    }
    .wif-header .user-btn:hover { background: var(--hdr-border); }
    .wif-header .user-dropdown {
      display: none;
      position: absolute;
      top: calc(100% + 6px);
      right: 0;
      background: #1e2333;
      border: 1px solid var(--hdr-border);
      border-radius: 8px;
      min-width: 150px;
      z-index: 200;
      overflow: hidden;
      box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    }
    .wif-header .user-dropdown.open { display: block; }
    .wif-header .user-dropdown a {
      display: block;
      padding: 9px 14px;
      font-size: 0.8rem;
      color: #fff;
      text-decoration: none;
      transition: background 0.1s;
    }
    .wif-header .user-dropdown a:hover { background: var(--hdr-border); }
    .wif-header .user-dropdown a.logout { color: var(--hdr-accent2); }
    .wif-header .dropdown-divider { height: 1px; background: var(--hdr-border); margin: 2px 0; }

    /* Mobile header */
    .wif-header-mobile {
      display: block;             /* visible on mobile */
      background: var(--hdr-bg);
      border-bottom: 1px solid var(--hdr-border);
      padding: 10px 16px;
    }
    @media (min-width: 1024px) {
      .wif-header-mobile { display: none; }
    }
    .wif-header-mobile .mobile-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }
    .wif-header-mobile .mobile-row + .mobile-row { margin-top: 8px; }
    .wif-header-mobile .logo {
      font-family: 'DM Serif Display', serif;
      font-size: 1.1rem;
      color: #fff;
      text-decoration: none;
    }
    .wif-header-mobile .logo .logo-in { color: #F1BF00; font-style: italic; }
    .wif-header-mobile .session-input {
      flex: 1;
      background: var(--hdr-input-bg);
      border: 1px solid var(--hdr-border);
      border-radius: 6px;
      color: #fff;
      font-family: 'DM Sans', sans-serif;
      font-size: 0.8rem;
      padding: 5px 10px;
      outline: none;
    }
    .wif-header-mobile .session-input::placeholder { color: var(--hdr-muted); }
    .wif-header-mobile .icon-btn {
      width: 30px; height: 30px;
      background: transparent;
      border: 1px solid var(--hdr-border);
      border-radius: 5px;
      cursor: pointer;
      font-size: 0.85rem;
      display: flex; align-items: center; justify-content: center;
      color: #fff;
      padding: 0;
    }
    .wif-header-mobile .btn-start {
      background: var(--hdr-accent2);
      color: #fff;
      border: none;
      border-radius: 5px;
      font-family: 'DM Sans', sans-serif;
      font-size: 0.72rem;
      font-weight: 700;
      padding: 4px 10px;
      height: 28px;
      cursor: pointer;
    }
    .wif-header-mobile .timer-display {
      font-size: 0.82rem;
      font-weight: 600;
      font-variant-numeric: tabular-nums;
      color: #fff;
      background: var(--hdr-input-bg);
      border: 1px solid var(--hdr-border);
      border-radius: 5px;
      padding: 4px 10px;
    }

    /* Modern card styling – dark theme, square edges */
    .card{
      background: var(--surface);
      border:1px solid var(--card-border);
      border-radius:0;
      box-shadow: var(--card-shadow);
      transition: box-shadow 0.2s ease, transform 0.2s ease;
      color: var(--text-primary);
    }

    /* Responsive grid: tool panel + notebook side by side, full width */
    .layout-grid{
      display:grid;
      grid-template-columns: 340px minmax(0,1fr);
      gap:0;
      min-height: calc(100vh - 54px - 52px); /* viewport minus header minus tab bar */
    }
    @media (max-width:1023px){
      .layout-grid{ grid-template-columns: 1fr; min-height: auto; }
    }

    .note{ font-size:.8rem; color:#6b7280 }

    /* Sticky left rail only on large screens to avoid mobile oddities */
    @media (min-width:1024px){
      .left-rail .stick{ position:sticky; top:0; }
    }

    /* Left rail fills height with border divider */
    .left-rail {
      border-right: 1px solid var(--card-border);
      overflow-y: auto;
    }

    /* ── TAB BAR: two rows ── */
    .wif-tab-bar {
      background: var(--hdr-bg);
      border-bottom: 1px solid var(--hdr-border);
      padding: 0 20px;
    }
    /* Row 1: group labels */
    /* ── Tab bar: grouped columns layout ── */
    .wif-tab-columns {
      display: flex;
      align-items: stretch;
      max-width: 72rem;
      margin: 0 auto;
      padding: 6px 0 0;
    }
    .wif-tab-group {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    .wif-tab-group-label {
      font-size: 0.65rem;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      white-space: nowrap;
      font-weight: 600;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 5px;
      padding-bottom: 4px;
    }
    .wif-tab-group-label .step-num {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      color: #fff;
      font-size: 0.55rem;
      font-weight: 700;
      flex-shrink: 0;
    }
    .wif-tab-group-desc {
      font-size: 0.55rem;
      font-weight: 400;
      text-transform: none;
      letter-spacing: 0;
      opacity: 0.7;
      margin-left: 2px;
    }
    .wif-tab-group-buttons {
      display: flex;
      align-items: center;
      gap: 0;
    }

    /* Vertical separators between groups */
    .wif-tab-group-sep {
      width: 1px;
      align-self: stretch;
      background: var(--hdr-border);
      margin: 4px 10px;
    }
    /* Flow arrow between groups */
    .wif-tab-flow-arrow {
      display: flex;
      align-items: center;
      color: var(--hdr-muted);
      font-size: 0.75rem;
      margin: 0 6px;
      opacity: 0.4;
      padding-top: 14px; /* offset to align with tab row */
    }

    /* ── Group colors: Write=blue, Refine=sky, Test=indigo ── */
    .wif-tab-group[data-group="write"]  .wif-tab-group-label { color: #60a5fa; }
    .wif-tab-group[data-group="refine"] .wif-tab-group-label { color: #38bdf8; }
    .wif-tab-group[data-group="test"]   .wif-tab-group-label { color: #a5b4fc; }
    .wif-tab-group[data-group="write"]  .step-num { background: #3b82f6; }
    .wif-tab-group[data-group="refine"] .step-num { background: #0ea5e9; }
    .wif-tab-group[data-group="test"]   .step-num { background: #6366f1; }
    .wif-tab-group[data-group="write"]  .wif-tab-group-desc { color: #60a5fa; }
    .wif-tab-group[data-group="refine"] .wif-tab-group-desc { color: #38bdf8; }
    .wif-tab-group[data-group="test"]   .wif-tab-group-desc { color: #a5b4fc; }
    .wif-tab-group[data-group="other"]  .wif-tab-group-label { color: var(--hdr-muted); }
    .wif-tab-btn {
      font-family: 'DM Sans', sans-serif;
      font-size: 0.82rem;
      font-weight: 500;
      color: var(--hdr-muted);
      background: transparent;
      border: none;
      padding: 6px 14px 10px;
      border-radius: 0;
      cursor: pointer;
      white-space: nowrap;
      transition: color 0.15s;
      position: relative;
      display: inline-flex;
      align-items: center;
      gap: 5px;
    }
    .wif-tab-btn .tab-icon {
      font-size: 0.9rem;
      line-height: 1;
    }
    .wif-tab-btn:hover { color: #c8cfe0; }
    .wif-tab-btn.active { font-weight: 600; }
    .wif-tab-btn.active::after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 4px;
      right: 4px;
      height: 2px;
      border-radius: 2px 2px 0 0;
    }

    /* Tab button group colors – active text + underline */
    .wif-tab-btn[data-group="write"]:hover  { color: #93c5fd; }
    .wif-tab-btn[data-group="refine"]:hover { color: #7dd3fc; }
    .wif-tab-btn[data-group="test"]:hover   { color: #c7d2fe; }
    .wif-tab-btn[data-group="write"].active  { color: #60a5fa; }
    .wif-tab-btn[data-group="refine"].active { color: #38bdf8; }
    .wif-tab-btn[data-group="test"].active   { color: #a5b4fc; }
    .wif-tab-btn[data-group="other"].active  { color: #94a3b8; }
    .wif-tab-btn[data-group="write"].active::after  { background: #3b82f6; }
    .wif-tab-btn[data-group="refine"].active::after { background: #0ea5e9; }
    .wif-tab-btn[data-group="test"].active::after   { background: #6366f1; }
    .wif-tab-btn[data-group="other"].active::after  { background: #64748b; }

    /* Tool panels in left column: only show the active one */
    .tool-panel { display: none; }
    .tool-panel.active { display: block; }

    /* Grammar/Style section toggling within improve panel */
    #improveBox.show-grammar #grammarSection { display: block; }
    #improveBox.show-grammar #styleSection   { display: none; }
    #improveBox.show-style   #grammarSection { display: none; }
    #improveBox.show-style   #styleSection   { display: block; }
    /* Default (no class): show both (fallback for non-tabbed pages) */
    #improveBox:not(.show-grammar):not(.show-style) .improve-section { display: block; }

    /* Mobile tab bar – two rows, no group labels */
    @media (max-width:1023px) {
      .wif-tab-bar { padding: 0 8px; }
      .wif-tab-row {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0;
        padding: 4px 0 2px;
        overflow-x: visible;
      }
      .wif-tab-btn { font-size: 0.75rem; padding: 5px 8px 7px; }
    }

    /* Ensure long content wraps instead of forcing horizontal scroll */
    .minw0{ min-width:0; }
    .break-any{ overflow-wrap:anywhere; word-break:break-word; }

    /* ── DARK THEME OVERRIDES ── */

    /* Global text color overrides */
    .text-gray-900, .text-gray-800, .text-gray-700 { color: var(--text-primary) !important; }
    .text-gray-600, .text-gray-500 { color: var(--text-secondary) !important; }
    .text-gray-400, .text-gray-300 { color: var(--text-muted) !important; }
    .font-semibold, h2 { color: var(--text-primary); }

    /* Background overrides */
    .bg-white { background: var(--surface) !important; }
    .bg-gray-50, .bg-gray-100, .bg-sky-50 { background: var(--surface-raised) !important; }
    .bg-gray-200 { background: var(--hdr-border) !important; }
    .text-sky-800 { color: var(--text-primary) !important; }

    /* Lookup vocabulary results dark overrides */
    #lu-results .wif-chip {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    #lu-results .wif-chip:hover {
      background: #2a3040 !important;
      border-color: #4a5068 !important;
    }
    #lu-results .border-t { border-color: var(--card-border) !important; }
    #lu-results .border { border-color: var(--card-border) !important; }
    #lu-results .rounded-full { color: var(--text-primary) !important; }
    .hover\:bg-gray-50:hover { background: #2a3040 !important; }
    .hover\:bg-gray-100:hover { background: #2a3040 !important; }

    /* Border overrides */
    .border-gray-300, .border-gray-200, .border-gray-100 {
      border-color: var(--card-border) !important;
    }

    /* Form elements dark – catch ALL inputs including those without type attr */
    input[type="text"],
    input:not([type]),
    select,
    textarea {
      transition: all 0.2s ease;
      background: var(--hdr-input-bg) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    input[type="text"]::placeholder,
    input:not([type])::placeholder,
    textarea::placeholder {
      color: var(--text-muted) !important;
    }
    input[type="text"]:focus,
    input:not([type]):focus,
    select:focus,
    textarea:focus {
      border-color: #6366f1 !important;
      box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15) !important;
    }
    select option { background: var(--surface-raised); color: var(--text-primary); }

    /* Buttons dark */
    button, .btn { transition: all 0.2s ease; }
    button.bg-emerald-500, button.bg-green-600, button.bg-purple-600, button.bg-indigo-600, button.bg-blue-600 {
      box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }
    button.bg-emerald-500:hover, button.bg-green-600:hover, button.bg-purple-600:hover, button.bg-indigo-600:hover, button.bg-blue-600:hover {
      transform: translateY(-1px);
      box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    }
    button.border-gray-300 {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
      box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    }
    button.border-gray-300:hover {
      background: #2a3040 !important;
      box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    }

    /* Header enhancement */
    .wif-header { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); }

    /* Dividers / HRs dark */
    hr { border-color: var(--card-border) !important; }
    .border-gray-200 { border-color: var(--card-border) !important; }

    /* Accent buttons */
    .accent-btn {
      transition: all 0.15s ease;
      box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    }
    .accent-btn:hover {
      background: var(--surface-raised);
      transform: translateY(-1px);
      box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }

    /* Typography */
    h2 {
      letter-spacing: -0.01em;
      font-weight: 700;
      font-size: 1.125rem;
      color: var(--text-primary);
    }

    /* Better spacing for sections - more conservative */
    .card {
      padding: 1rem;
    }

    @media (min-width: 1024px) {
      .card {
        padding: 1.25rem;
      }
    }

    /* Tighter spacing for left rail cards to prevent overflow */
    .left-rail .card {
      padding: 0.875rem;
    }

    @media (min-width: 1024px) {
      .left-rail .card {
        padding: 1rem;
      }
    }

    /* Ensure left rail text doesn't overflow */
    .left-rail h2 {
      font-size: 1rem;
    }

    .left-rail .text-sm,
    .left-rail p {
      font-size: 0.875rem;
    }

    /* Tab buttons in left rail - ensure they fit */
    #avToggle button {
      font-size: 0.875rem;
      padding: 0.375rem 0.75rem;
    }

    /* Enhanced result panels in Improve section – dark */
    #improveBox .bg-gray-50 {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
      box-shadow: 0 1px 3px rgba(0,0,0,0.15) !important;
      transition: all 0.2s ease;
    }
    #improveBox .bg-gray-50:hover {
      box-shadow: 0 2px 6px rgba(0,0,0,0.2) !important;
    }

    /* Grammar check panel accent – dark */
    #gcOut {
      background: rgba(16, 185, 129, 0.08) !important;
      border-left: 3px solid #10b981 !important;
      padding: 0.875rem !important;
      border-radius: 8px !important;
      font-size: 0.875rem !important;
      color: var(--text-primary) !important;
    }
    #gcWhy {
      background: rgba(56, 189, 248, 0.06) !important;
      border-left: 3px solid #0ea5e9 !important;
      padding: 0.875rem !important;
      border-radius: 8px !important;
      font-size: 0.875rem !important;
      color: var(--text-primary) !important;
    }
    /* Style improve panel accent – dark */
    #siOut {
      background: rgba(16, 185, 129, 0.08) !important;
      border-left: 3px solid #10b981 !important;
      padding: 0.875rem !important;
      border-radius: 8px !important;
      font-size: 0.875rem !important;
      color: var(--text-primary) !important;
    }
    #siNotes {
      background: rgba(56, 189, 248, 0.06) !important;
      border-left: 3px solid #0ea5e9 !important;
      padding: 0.875rem !important;
      border-radius: 8px !important;
      font-size: 0.875rem !important;
      color: var(--text-primary) !important;
    }

    /* Notebook textarea – dark */
    #ta {
      background: var(--hdr-input-bg) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
      box-shadow: 0 1px 3px rgba(0,0,0,0.15) !important;
    }
    #ta:focus {
      border-color: #6366f1 !important;
      box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15), 0 1px 3px rgba(0,0,0,0.2) !important;
    }

    /* ========== COLOR ACCENTS FOR SECTIONS – DARK ========== */

    /* Conversation setup panel – dark override */
    #conversationPanel {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
    }
    #conversationPanel label,
    #conversationPanel h3,
    #conversationPanel .text-indigo-900,
    #conversationPanel .text-indigo-800,
    #conversationPanel .text-indigo-700 {
      color: var(--text-secondary) !important;
    }
    #conversationPanel #conversationStatus {
      color: var(--text-muted) !important;
    }
    /* Conversation buttons – dark */
    #btnConversationStart {
      background: #3b82f6 !important;
      border-color: #3b82f6 !important;
    }
    #btnConversationStart:hover {
      background: #2563eb !important;
    }
    #btnConversationResume {
      background: var(--surface) !important;
      border-color: var(--card-border) !important;
      color: #60a5fa !important;
    }
    #btnConversationReset {
      background: transparent !important;
      border-color: var(--card-border) !important;
      color: var(--text-muted) !important;
    }
    #btnConversationReset:hover {
      background: var(--surface) !important;
    }
    #conversationPanel .text-xs.text-indigo-800 {
      color: var(--text-muted) !important;
    }
    /* Conversation auto-read checkbox */
    #conversationAutoRead {
      border-color: var(--card-border) !important;
    }

    /* Indigo utility buttons in notebook – dark override */
    #notebookBox .bg-indigo-50,
    #conversationPanel .bg-indigo-50 {
      background-color: var(--surface) !important;
    }
    #notebookBox .bg-indigo-50:hover,
    #conversationPanel .bg-indigo-50:hover,
    #notebookBox .hover\:bg-indigo-100:hover,
    #conversationPanel .hover\:bg-indigo-100:hover {
      background-color: var(--surface-raised) !important;
    }
    #notebookBox .border-indigo-200,
    #notebookBox .border-indigo-100,
    #conversationPanel .border-indigo-200,
    #conversationPanel .border-indigo-100 {
      border-color: var(--card-border) !important;
    }
    #notebookBox .text-indigo-700,
    #notebookBox .text-indigo-600 {
      color: #818cf8 !important;
    }
    #notebookBox .bg-green-50 {
      background-color: var(--surface) !important;
    }
    #notebookBox .bg-green-50:hover,
    #notebookBox .hover\:bg-green-100:hover {
      background-color: var(--surface-raised) !important;
    }
    #notebookBox .border-green-200 {
      border-color: var(--card-border) !important;
    }
    #notebookBox .text-green-700 {
      color: #34d399 !important;
    }
    #notebookBox .bg-red-50 {
      background-color: var(--surface) !important;
    }
    #notebookBox .bg-red-50:hover,
    #notebookBox .hover\:bg-red-100:hover {
      background-color: var(--surface-raised) !important;
    }
    #notebookBox .border-red-200 {
      border-color: var(--card-border) !important;
    }
    #notebookBox .text-red-700 {
      color: #f87171 !important;
    }

    /* Notebook section - Blue theme */
    #notebookBox h2 {
      color: #60a5fa;
      border-bottom: 2px solid rgba(59,130,246,0.2);
      padding-bottom: 0.375rem;
      margin-bottom: 0.75rem;
    }
    #notebookBox {
      border-left: 3px solid #3b82f6;
      display: flex;
      flex-direction: column;
      min-height: 100%;
    }
    #notebookBox #ta {
      flex: 1;
      min-height: 300px;
      resize: vertical;
    }

    /* Conversation active: messages + textarea inside the notebook editor box */
    .notebook-editor.conversation-active {
      height: auto !important;
      min-height: 24rem;
      max-height: 70vh;
      background: var(--hdr-input-bg) !important;
      border: 1px solid var(--card-border) !important;
      border-radius: 0.75rem;
    }
    .notebook-editor.conversation-active .conversation-messages {
      display: block;
      padding: 0.75rem;
      overflow-y: auto;
      flex: 1 1 auto;
      min-height: 8rem;
    }
    .notebook-editor.conversation-active #ta {
      min-height: 4rem !important;
      max-height: 5rem !important;
      flex: 0 0 auto !important;
      border-top: 1px solid var(--card-border) !important;
      border-radius: 0 0 0.75rem 0.75rem !important;
      border-left: none !important;
      border-right: none !important;
      border-bottom: none !important;
      box-shadow: none !important;
    }

    /* Conversation panel collapse/expand toggle */
    #conversationPanelToggle {
      background: none;
      border: none;
      color: var(--text-muted);
      cursor: pointer;
      font-size: 0.75rem;
      padding: 2px 6px;
      border-radius: 4px;
      transition: all 0.15s;
    }
    #conversationPanelToggle:hover {
      color: var(--text-primary);
      background: var(--surface);
    }

    /* Verbs section - Sky theme */
    #verbsSection h2 {
      color: #38bdf8;
      border-bottom: 2px solid rgba(14,165,233,0.2);
      padding-bottom: 0.375rem;
      margin-bottom: 0.75rem;
    }
    #verbsSection { border-left: 3px solid #0ea5e9; }
    #v-out {
      background: rgba(14,165,233,0.08) !important;
      padding: 0.5rem 0.75rem !important;
      border-radius: 8px !important;
      border-left: 3px solid #0ea5e9 !important;
      color: var(--text-primary) !important;
    }

    /* Add Vocabulary section - Sky theme */
    #addVocabSection h2 {
      color: #38bdf8;
      border-bottom: 2px solid rgba(14,165,233,0.2);
      padding-bottom: 0.375rem;
      margin-bottom: 0.75rem;
    }
    #addVocabSection { border-left: 3px solid #0ea5e9; }

    /* Header info boxes – dark */
    .info-box {
      background: rgba(99,102,241,0.08);
      border: 1px solid rgba(99,102,241,0.2);
      color: #a5b4fc;
      border-radius: 10px;
      padding: 0.75rem 1rem;
    }

    /* Card hover */
    .card:hover {
      box-shadow: var(--card-shadow-hover);
    }

    /* Enhanced tab buttons – dark */
    #avToggle button.bg-white,
    #avToggle button.text-gray-800 {
      background: var(--surface-raised) !important;
      border: 1px solid var(--card-border) !important;
      color: var(--text-muted) !important;
      font-weight: 500;
      opacity: 0.7;
      box-shadow: none !important;
    }
    #avToggle button.bg-white:hover,
    #avToggle button.text-gray-800:hover {
      opacity: 1;
      background: #2a3040 !important;
    }

    /* All vocab tabs - unified Sky blue when selected */
    #avToggle button.bg-indigo-600,
    #avToggle button.text-white {
      background: #0ea5e9 !important;
      border-color: #0284c7 !important;
      color: white !important;
      font-weight: 700 !important;
      opacity: 1 !important;
      box-shadow: 0 2px 6px rgba(14, 165, 233, 0.4) !important;
      transform: translateY(-1px);
    }

    /* Expressions section - Indigo theme – dark */
    #exprSection h2 {
      color: #a5b4fc;
      border-bottom: 2px solid rgba(99,102,241,0.2);
      padding-bottom: 0.375rem;
      margin-bottom: 0.75rem;
    }
    #exprSection { border-left: 3px solid #6366f1; }

    /* Expressions panel dark overrides (loaded via AJAX with inline light styles) */
    .wif-expr .wif-panel {
      background: var(--surface) !important;
      border-color: var(--card-border) !important;
    }
    .wif-expr .wif-summary {
      color: var(--text-primary) !important;
    }
    .wif-expr .wif-chip {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    .wif-expr .wif-chip:hover {
      background: #2a3040 !important;
      border-color: #4a5068 !important;
    }
    .wif-expr .wif-ctrl-btn {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    .wif-expr .wif-ctrl-btn:hover {
      background: #2a3040 !important;
    }
    .wif-expr #wif-filter {
      background: var(--hdr-input-bg) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    .wif-expr .wif-meta,
    .wif-expr .wif-count {
      color: var(--text-muted) !important;
    }

    /* Improve section – Indigo theme dark */
    #improveBox h2 {
      color: #a5b4fc;
      border-bottom: 2px solid rgba(99,102,241,0.2);
      padding-bottom: 0.375rem;
      margin-bottom: 0.75rem;
    }
    #improveBox { border-left: 3px solid #6366f1; }

    /* AP Panel section – Indigo theme dark */
    #ap-panel h2 {
      color: #a5b4fc;
      border-bottom: 2px solid rgba(99,102,241,0.2);
      padding-bottom: 0.375rem;
      margin-bottom: 0.75rem;
    }
    #ap-panel {
      border-left: 3px solid #6366f1 !important;
      background: var(--surface) !important;
    }

    /* Grammar Explainer section – Indigo theme dark */
    #grammarExplainer h2 {
      color: #a5b4fc;
      border-bottom: 2px solid rgba(99,102,241,0.2);
      padding-bottom: 0.375rem;
      margin-bottom: 0.75rem;
    }
    #grammarExplainer { border-left: 3px solid #6366f1; }

    /* Grammar explainer output box – dark */
    #geOut {
      background: rgba(99,102,241,0.08) !important;
      border-left: 3px solid #6366f1 !important;
      padding: 0.875rem !important;
      border-radius: 8px !important;
      color: var(--text-primary) !important;
    }

    /* ===== Conversation Chat Bubbles & Floating Button ===== */

    /* Hidden by default */
    .conversation-messages { display: none; }

    /* Notebook editor needs position for floating button */
    .notebook-editor { position: relative; }

    /* Active conversation: flex column layout */
    .notebook-editor.conversation-active {
      display: flex !important;
      flex-direction: column !important;
      border: 1px solid var(--card-border) !important;
      border-radius: 0.75rem !important;
      background: var(--hdr-input-bg) !important;
      overflow: hidden !important;
      height: 24rem !important;
    }

    /* Messages area: scrollable flex child */
    .notebook-editor.conversation-active .conversation-messages {
      display: block !important;
      padding: 1rem !important;
      overflow-y: auto !important;
      flex: 1 1 auto !important;
      min-height: 0 !important;
    }

    /* Textarea: compact reply input */
    .notebook-editor.conversation-active #ta,
    .notebook-editor.conversation-active textarea {
      border: none !important;
      border-top: 1px solid var(--card-border) !important;
      border-radius: 0 !important;
      resize: none !important;
      height: 4.5rem !important;
      min-height: 3.5rem !important;
      max-height: 5rem !important;
      flex: 0 0 auto !important;
      box-shadow: none !important;
    }

    .notebook-editor.conversation-active #ta:focus,
    .notebook-editor.conversation-active textarea:focus {
      box-shadow: none !important;
      outline: none !important;
      border-color: var(--card-border) !important;
    }

    /* Bubble styles */
    .conversation-message {
      padding: 0.65rem 0.85rem;
      margin-bottom: 0.65rem;
      border-radius: 0.5rem;
      animation: slideIn 0.3s ease;
      font-size: 0.875rem;
      line-height: 1.5;
      white-space: pre-wrap;
      word-break: break-word;
    }
    .conversation-message:last-child { margin-bottom: 0; }
    .conversation-message .conversation-role {
      display: block;
      font-size: 0.7rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      margin-bottom: 0.2rem;
      opacity: 0.7;
    }
    .conversation-message.assistant {
      background: rgba(99,102,241,0.1);
      border-left: 3px solid #6366f1;
      margin-right: 2.5rem;
      color: var(--text-primary);
    }
    .conversation-message.user {
      background: rgba(34,197,94,0.1);
      border-left: 3px solid #22c55e;
      margin-left: 2.5rem;
      color: var(--text-primary);
    }
    @keyframes slideIn {
      from { opacity: 0; transform: translateY(10px); }
      to   { opacity: 1; transform: translateY(0); }
    }

    /* Floating send button */
    #btnConversationContinueFloating {
      position: absolute !important;
      z-index: 30;
      background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%) !important;
      color: #fff !important;
      border-radius: 999px !important;
      width: 2.75rem !important;
      height: 2.75rem !important;
      right: 0.85rem;
      display: flex;
      align-items: center;
      justify-content: center;
      line-height: 1;
      border: 1px solid rgba(255,255,255,0.2) !important;
      box-shadow: 0 8px 18px rgba(67,56,202,0.3) !important;
      transition: transform .12s ease, box-shadow .12s ease;
      padding: 0 !important;
    }
    #btnConversationContinueFloating.hidden { display: none !important; }
    .conversation-close {
      position: absolute;
      top: -0.35rem;
      right: -0.35rem;
      width: 1.1rem;
      height: 1.1rem;
      border-radius: 999px;
      background: #111827;
      color: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 0.75rem;
      line-height: 1;
      box-shadow: 0 2px 6px rgba(0,0,0,0.2);
      padding: 0;
    }
    #btnConversationContinueFloating:hover {
      transform: translateY(-1px);
      box-shadow: 0 10px 20px rgba(67,56,202,0.35) !important;
    }
    .conversation-send-icon {
      width: 1.2rem;
      height: 1.2rem;
      transform: scaleX(-1);
      transform-origin: center;
      transform-box: fill-box;
      display: block;
      flex-shrink: 0;
    }

    /* ========== TENSE INFO POPOVER ========== */

    .tense-info-inline-wrap {
      display: flex;
      align-items: center;
      gap: 0.4rem;
    }
    .tense-info-inline-wrap select { flex: 1; min-width: 0; }

    .tense-info-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 22px;
      height: 22px;
      border-radius: 50%;
      border: 1.5px solid rgba(99,102,241,0.4);
      background: rgba(99,102,241,0.1);
      color: #818cf8;
      font-size: 12px;
      font-weight: 700;
      font-style: italic;
      font-family: Georgia, serif;
      cursor: pointer;
      flex-shrink: 0;
      transition: all 0.15s;
      line-height: 1;
    }
    .tense-info-btn:hover {
      background: #6366f1;
      color: #fff;
      border-color: #6366f1;
      transform: scale(1.1);
    }

    /* Tense info popover */
    .tense-info-overlay {
      position: fixed;
      inset: 0;
      background: rgba(15, 23, 42, 0.4);
      z-index: 200;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 1.5rem;
      opacity: 0;
      transition: opacity 0.2s ease;
    }
    .tense-info-overlay.visible { opacity: 1; }

    .tense-info-card {
      background: var(--surface-raised);
      border-radius: 1rem;
      box-shadow:
        0 25px 60px rgba(0, 0, 0, 0.3),
        0 10px 30px rgba(0, 0, 0, 0.2);
      border: 1px solid var(--card-border);
      max-width: 380px;
      width: 100%;
      overflow: hidden;
      transform: translateY(10px) scale(0.97);
      transition: transform 0.2s ease;
    }
    .tense-info-overlay.visible .tense-info-card {
      transform: translateY(0) scale(1);
    }

    .tense-info-card-header {
      padding: 0.85rem 1.1rem;
      background: linear-gradient(135deg, rgba(99,102,241,0.1), rgba(99,102,241,0.05));
      border-bottom: 1px solid var(--card-border);
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .tense-info-card-header h3 {
      margin: 0;
      font-size: 1rem;
      font-weight: 700;
      color: #818cf8;
    }
    .tense-info-close {
      width: 26px;
      height: 26px;
      border-radius: 50%;
      border: none;
      background: transparent;
      color: var(--text-muted);
      font-size: 17px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.12s;
    }
    .tense-info-close:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }

    .tense-info-card-body {
      padding: 0.9rem 1.1rem;
      max-height: 65vh;
      overflow-y: auto;
    }
    .tense-info-card-body dt {
      font-size: 0.72rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      color: #94a3b8;
      margin-top: 0.65rem;
    }
    .tense-info-card-body dt:first-child { margin-top: 0; }
    .tense-info-card-body dd {
      margin: 0.2rem 0 0;
      font-size: 0.92rem;
      color: var(--text-primary);
      line-height: 1.5;
    }
    .tense-info-card-body dd.example {
      font-style: italic;
      color: var(--text-secondary);
    }
    .tense-info-card-body dd.english {
      color: #818cf8;
      font-weight: 500;
    }

    /* Expandable conjugation rules sections */
    .tense-rules-section {
      margin-top: 0.6rem;
      border-top: 1px solid var(--card-border);
      padding-top: 0.1rem;
    }
    .tense-rules-toggle {
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%;
      padding: 0.5rem 0;
      background: none;
      border: none;
      cursor: pointer;
      font-size: 0.8rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.04em;
      color: #818cf8;
      transition: color 0.15s;
    }
    .tense-rules-toggle:hover { color: #a5b4fc; }
    .tense-rules-toggle .arrow {
      display: inline-block;
      font-size: 0.65rem;
      transition: transform 0.25s ease;
      color: #a5b4fc;
    }
    .tense-rules-toggle.expanded .arrow { transform: rotate(180deg); }

    .tense-rules-content {
      max-height: 0;
      overflow: hidden;
      transition: max-height 0.35s ease, padding 0.25s ease;
      padding: 0;
    }
    .tense-rules-content.expanded {
      max-height: 600px;
      padding-bottom: 0.4rem;
    }
    .tense-rules-content p.formation-text {
      margin: 0 0 0.5rem;
      font-size: 0.88rem;
      color: var(--text-primary);
      line-height: 1.5;
    }

    .endings-table {
      width: 100%;
      border-collapse: collapse;
      font-size: 0.82rem;
      margin-bottom: 0.45rem;
    }
    .endings-table th {
      text-align: left;
      font-size: 0.72rem;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.03em;
      color: var(--text-muted);
      padding: 0.25rem 0.35rem;
      border-bottom: 1px solid var(--card-border);
    }
    .endings-table td {
      padding: 0.3rem 0.35rem;
      color: var(--text-primary);
      vertical-align: top;
      border-bottom: 1px solid rgba(42,47,69,0.5);
    }
    .endings-table td:first-child {
      font-weight: 600;
      color: #818cf8;
      white-space: nowrap;
      width: 38%;
    }
    .endings-table tr:last-child td { border-bottom: none; }

    .irregulars-list {
      list-style: none;
      margin: 0;
      padding: 0;
    }
    .irregulars-list li {
      padding: 0.22rem 0;
      font-size: 0.82rem;
      color: var(--text-primary);
      display: flex;
      gap: 0.35rem;
      line-height: 1.4;
    }
    .irregulars-list li .irreg-verb {
      font-weight: 700;
      color: #818cf8;
      white-space: nowrap;
      flex-shrink: 0;
    }
    .irregulars-list li .irreg-forms {
      color: var(--text-secondary);
    }

    /* ── ACCENT BAR DARK OVERRIDES ── */
    .accent-bar {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
    }
    .accent-btn {
      background: rgba(30, 35, 51, 0.9) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    .accent-btn:hover {
      background: #2a3040 !important;
      border-color: rgba(99, 102, 241, 0.4) !important;
    }
    .accent-sep {
      background: var(--card-border) !important;
    }

    /* ── VERBS SECTION DARK OVERRIDES ── */
    #verbsSection label,
    #verbsSection .text-sm {
      color: var(--text-secondary) !important;
    }
    #verbsSection small {
      color: var(--text-muted) !important;
    }
    #verbsSection #v-out {
      color: var(--text-primary) !important;
    }
    #verbsSection #v-status {
      color: var(--text-muted) !important;
    }
    /* Verb suggestions dropdown dark */
    #v-suggest {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    #v-suggest div:hover {
      background: #2a3040 !important;
    }

    /* ── EXPRESSION HOVER FIX ── */
    .wif-expr .wif-summary:hover {
      background: var(--surface-raised) !important;
    }
    .wif-expr .wif-summary:hover .wif-title {
      color: var(--text-primary) !important;
    }
    .wif-expr .wif-panel {
      background: var(--surface) !important;
      border-color: var(--card-border) !important;
    }
    .wif-expr .wif-title {
      color: var(--text-primary) !important;
    }
    .wif-expr .wif-chevron {
      color: var(--text-muted) !important;
    }
    .wif-expr .wif-count {
      color: var(--text-muted) !important;
    }
    .wif-expr .wif-chip {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    .wif-expr .wif-chip:hover {
      background: #2a3040 !important;
      border-color: #4a5068 !important;
    }
    .wif-expr .wif-ctrl-btn {
      background: var(--surface-raised) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    .wif-expr .wif-ctrl-btn:hover {
      background: #2a3040 !important;
    }
    .wif-expr #wif-filter {
      background: var(--hdr-input-bg) !important;
      border-color: var(--card-border) !important;
      color: var(--text-primary) !important;
    }
    .wif-expr .wif-meta {
      color: var(--text-muted) !important;
    }

    /* Footer – dark */
    footer {
      margin-top: 3rem;
      padding: 2rem 1rem;
      background-color: var(--surface);
      border-top: 1px solid var(--card-border);
      box-shadow: 0 -2px 8px rgba(0,0,0,0.15);
    }
    .footer-content {
      max-width: 1200px;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 1.5rem;
      text-align: center;
    }
    .footer-links {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 1.5rem;
    }
    .footer-links a {
      color: var(--text-secondary);
      text-decoration: none;
      font-size: 0.875rem;
      transition: color 0.2s;
    }
    .footer-links a:hover {
      color: var(--text-primary);
      text-decoration: underline;
    }

    /* ── MOBILE: full-width adjustments ── */
    @media (max-width: 1023px) {
      /* On mobile, notebook stacks below tools - give it breathing room */
      #notebookBox {
        min-height: 60vh;
      }
      #notebookBox #ta {
        min-height: 45vh;
      }
      /* Remove left-rail border on mobile (stacked layout) */
      .left-rail {
        border-right: none;
        border-bottom: 1px solid var(--card-border);
      }
      /* Cards get small horizontal padding on mobile */
      .card {
        padding: 0.75rem;
      }
      /* Prevent mobile header rows from overflowing */
      .wif-header-mobile .mobile-row {
        flex-wrap: wrap;
      }
      /* Prevent any element from overflowing viewport */
      body {
        overflow-x: hidden;
      }
      /* Notebook buttons wrap on mobile */
      #notebookBox .flex-wrap { gap: 4px; }
    }

    @media (max-width: 640px) {
      /* Tighter spacing on small phones */
      .card {
        padding: 0.5rem;
      }
      #notebookBox #ta {
        min-height: 40vh;
      }
      /* Mobile header icon buttons shrink */
      .wif-header-mobile .icon-btn {
        width: 28px;
        height: 28px;
        font-size: 0.78rem;
      }
      /* Expressions chips wrap properly */
      .wif-expr .wif-list {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 4px !important;
      }
      .wif-expr .wif-chip {
        font-size: 0.78rem !important;
        padding: 0.2rem 0.45rem !important;
      }
    }
    footer p {
      margin: 0;
      color: var(--text-muted);
      font-size: 0.875rem;
    }
