﻿    :root {
      --accent: #fd7e14;
      --bg1: #ffffff;
      --bg2: #f8f9fa;
      --card: #ffffff;
      --text: #212529;
      --muted: #6c757d;
      --border: #e9ecef;
    }
    body.theme-explorer {
      --accent: #ca8a04;
      --bg1: #0f172a;
      --bg2: #1e293b;
      --card: #020617;
      --text: #e2e8f0;
      --muted: #94a3b8;
      --border: #334155;
    }
    body {
      font-family: 'Inter', system-ui, sans-serif;
      background-color: var(--bg1);
      color: var(--text);
      line-height: 1.6;
      margin: 0;
      padding: 0;
    }
    
    html { overflow-y: scroll; }
    ::-webkit-scrollbar { width: 12px; }
    ::-webkit-scrollbar-track { background: #f1f1f1; }
    ::-webkit-scrollbar-thumb { background: #888; border-radius: 6px; }
    ::-webkit-scrollbar-thumb:hover { background: #555; }
    
    /* Header */
    .header {
      padding: 16px 40px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid var(--border);
      background: var(--card);
      position: sticky;
      top: 0;
      z-index: 100;
    }
    
    .header-title {
      font-size: 24px;
      font-weight: 700;
      font-family: 'Playfair Display', serif;
      color: var(--text);
    }
    
    .header-accent {
      color: var(--accent);
    }
    
    .header-nav {
      display: flex;
      gap: 8px;
      align-items: center;
    }
    
    .nav-btn {
      padding: 10px 20px;
      background: transparent;
      border: 1px solid transparent;
      border-radius: 8px;
      cursor: pointer;
      font-size: 14px;
      font-weight: 500;
      color: var(--text);
      transition: all 0.2s ease;
      text-decoration: none;
      display: inline-block;
      height: 40px;
      line-height: 20px;
      box-sizing: border-box;
      position: relative;
    }
    
    .nav-btn:hover {
      background: var(--bg2);
      color: var(--accent);
    }
    
    .nav-btn.active {
      color: var(--accent);
      font-weight: 600;
    }
    
    .nav-btn.active::after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 20px;
      right: 20px;
      height: 3px;
      background: var(--accent);
      border-radius: 2px 2px 0 0;
    }
    
    /* Hamburger Menu */
    .hamburger {
      display: none;
      width: 40px;
      height: 40px;
      background: var(--bg2);
      border: 1px solid var(--border);
      border-radius: 8px;
      cursor: pointer;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      gap: 4px;
    }
    
    .hamburger span {
      width: 20px;
      height: 2px;
      background: var(--text);
      transition: all 0.3s ease;
    }
    
    .hamburger.active span:nth-child(1) {
      transform: rotate(45deg) translate(5px, 5px);
    }
    
    .hamburger.active span:nth-child(2) {
      opacity: 0;
    }
    
    .hamburger.active span:nth-child(3) {
      transform: rotate(-45deg) translate(5px, -5px);
    }
    
    /* Page Container */
    .page {
      display: none;
      min-height: calc(100vh - 80px);
    }
    
    .page.active {
      display: block;
    }
    
    .page-content {
      max-width: 1400px;
      margin: 0 auto;
      padding: 24px 32px;
    }
    
    /* Search Bar - PROMINENT */
    .search-container {
      max-width: 900px;
      margin: 0 auto 24px;
    }
    
    .search-wrapper {
      position: relative;
    }
    
    .autocomplete-box {
      position: absolute;
      top: 100%;
      left: 0;
      right: 0;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 12px;
      margin-top: 4px;
      box-shadow: 0 8px 24px rgba(0,0,0,0.08);
      display: none;
      z-index: 50;
      max-height: 320px;
      overflow-y: auto;
    }
    
    .autocomplete-item {
      padding: 10px 16px;
      cursor: pointer;
      border-bottom: 1px solid var(--border);
      font-size: 15px;
      color: var(--text);
      transition: background 0.2s;
    }
    
    .autocomplete-item:last-child {
      border-bottom: none;
    }
    
    .autocomplete-item:hover {
      background: var(--bg);
    }
    
    .autocomplete-meta {
      font-size: 12px;
      color: var(--muted);
      margin-top: 4px;
    }
    
    .search-icon {
      position: absolute;
      left: 24px;
      top: 50%;
      transform: translateY(-50%);
      color: var(--muted);
      width: 24px;
      height: 24px;
    }
    
    .search-input {
      width: 100%;
      padding: 20px 28px 20px 64px;
      font-size: 18px;
      border: 2px solid var(--border);
      border-radius: 16px;
      background: var(--card);
      color: var(--text);
      transition: all 0.3s ease;
      box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    }
    
    .search-input:focus {
      outline: none;
      border-color: var(--accent);
      box-shadow: 0 8px 24px rgba(253, 126, 20, 0.2);
      transform: translateY(-2px);
    }
    
    .search-input::placeholder {
      color: var(--muted);
      opacity: 0.7;
    }
    
    /* Alphabet Navigation */
    .alphabet-nav {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      justify-content: center;
      margin-bottom: 32px;
    }
    
    .alphabet-btn {
      width: 40px;
      height: 40px;
      border-radius: 8px;
      background: var(--card);
      border: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      font-size: 14px;
      font-weight: 600;
      color: var(--text);
      transition: all 0.2s ease;
    }
    
    .alphabet-btn:hover,
    .alphabet-btn.active {
      background: var(--accent);
      color: white;
      border-color: var(--accent);
      transform: translateY(-2px);
      box-shadow: 0 4px 12px rgba(253, 126, 20, 0.3);
    }
    
    /* Results Header */
    .results-header {
      margin-bottom: 20px;
    }
    
    .results-title {
      font-size: 24px;
      font-weight: 600;
      margin-bottom: 8px;
      color: var(--text);
    }
    
    .results-stats {
      font-size: 14px;
      color: var(--muted);
    }
    
    /* Unified chip style (used in zero-results suggestions and elsewhere) */
    .chip {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 6px 10px;
      border: 1px solid var(--border);
      border-radius: 999px;
      background: var(--bg2);
      color: var(--text);
      cursor: pointer;
      font-size: 12px;
      line-height: 1;
      transition: all 0.15s ease;
      text-decoration: none;
    }
    .chip:hover {
      background: var(--accent);
      color: #fff;
      border-color: var(--accent);
      transform: translateY(-1px);
      box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    }
    .chip:focus { outline: none; }
    
    /* Results Grid - RESTORED ELEGANT DESIGN */
    .results-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
      gap: 20px;
      margin-bottom: 40px;
    }
    
    @media (max-width: 768px) {
      .results-grid {
        grid-template-columns: 1fr;
        gap: 16px;
      }
    }
    
    /* Pagination */
    .pagination {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 20px;
      margin: 40px 0;
      padding: 20px;
    }
    
    .pagination-btn {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 12px 24px;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 8px;
      color: var(--text);
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s ease;
    }
    
    .pagination-btn:hover:not(:disabled) {
      background: var(--accent);
      color: white;
      border-color: var(--accent);
      transform: translateY(-2px);
    }
    
    .pagination-btn:disabled {
      opacity: 0.4;
      cursor: not-allowed;
    }
    
    .pagination-btn svg {
      width: 16px;
      height: 16px;
    }
    
    .pagination-info {
      padding: 12px 20px;
      background: var(--bg2);
      border-radius: 8px;
      font-size: 14px;
      font-weight: 500;
      color: var(--text);
      min-width: 120px;
      text-align: center;
    }
    
    @media (max-width: 768px) {
      .pagination {
        gap: 12px;
        margin: 30px 0;
      }
      
      .pagination-btn {
        padding: 10px 16px;
        font-size: 13px;
      }
      
      .pagination-info {
        padding: 10px 16px;
        min-width: 100px;
        font-size: 13px;
      }
    }
    
    /* Quote Card - RESTORED ORIGINAL ELEGANCE */
    .quote-card {
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 20px;
      cursor: pointer;
      transition: all 0.3s ease;
      position: relative;
      overflow: hidden;
    }
    
    .quote-card::before {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 3px;
      background: linear-gradient(90deg, var(--accent), transparent);
      opacity: 0;
      transition: opacity 0.3s ease;
    }
    
    .quote-card:hover {
      box-shadow: 0 12px 28px rgba(0,0,0,0.12);
      transform: translateY(-4px);
      border-color: var(--accent);
    }
    
    .quote-card:hover::before {
      opacity: 1;
    }
    
    .quote-card-inner {
      display: flex;
      gap: 16px;
    }
    
    .quote-avatar {
      width: 48px;
      height: 48px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 24px;
      flex-shrink: 0;
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    }
    
    .quote-content {
      flex: 1;
      min-width: 0;
    }
    
    .quote-text {
      font-family: 'Playfair Display', serif;
      font-size: 16px;
      line-height: 1.6;
      margin-bottom: 12px;
      color: var(--text);
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
    
    .quote-author {
      font-size: 14px;
      font-weight: 600;
      margin-bottom: 8px;
      color: var(--text);
    }
    
    .quote-essence {
      font-size: 13px;
      color: var(--accent);
      font-weight: 600;
      margin-bottom: 8px;
      display: -webkit-box;
      -webkit-line-clamp: 1;
      -webkit-box-orient: vertical;
      overflow: hidden;
    }
    
    .quote-meta {
      display: flex;
      gap: 8px;
      font-size: 12px;
      color: var(--muted);
      align-items: center;
    }
    
    .quote-meta span {
      display: inline-flex;
      align-items: center;
    }

    /* Quote Card Inline Actions in Meta Row */
    .quote-meta { display:flex; justify-content: space-between; align-items:center; flex-wrap: wrap; row-gap: 8px; }
    .quote-meta .meta-left { display:flex; gap: 8px; align-items:center; flex: 1 1 auto; min-width: 0; }
    .quote-meta .meta-actions { display:flex; gap: 8px; align-items:center; margin-left: auto; flex: 0 0 auto; }
    .quote-action-btn { width: 24px; height: 24px; display:grid; place-items:center; background:#ffffff; border:1px solid var(--border); color:var(--text); border-radius:999px; font-size:14px; line-height:1; cursor:pointer; }
    .quote-action-btn:hover { border-color: var(--accent); color: var(--accent); }
    
    /* Items Grid (for Topics/Authors pages) */
    .items-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
      gap: 16px;
      margin-bottom: 40px;
    }
    
    @media (max-width: 768px) {
      .items-grid {
        grid-template-columns: 1fr;
      }
    }
    
    .item-card {
      padding: 20px;
      background: var(--card);
      border: 1px solid var(--border);
      border-radius: 10px;
      cursor: pointer;
      transition: all 0.2s ease;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    
    .item-card:hover {
      background: var(--accent);
      color: white;
      border-color: var(--accent);
      transform: translateY(-2px);
      box-shadow: 0 8px 20px rgba(253, 126, 20, 0.25);
    }
    
    .item-name {
      font-weight: 600;
      font-size: 15px;
    }
    
    .item-count {
      font-size: 13px;
      opacity: 0.8;
      background: var(--bg2);
      padding: 4px 10px;
      border-radius: 12px;
    }
    
    .item-card:hover .item-count {
      background: rgba(255,255,255,0.2);
    }
    
    /* Settings Panel */
    .settings-overlay {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(0,0,0,0.5);
      z-index: 999;
      display: none;
    }
    
    .settings-overlay.active {
      display: block;
    }
    
    .settings-panel {
      position: fixed;
      top: 0;
      right: -420px;
      width: 420px;
      height: 100vh;
      background: var(--card);
      border-left: 1px solid var(--border);
      z-index: 1000;
      overflow-y: auto;
      transition: right 0.3s ease;
      box-shadow: -8px 0 32px rgba(0,0,0,0.15);
    }
    
    .settings-panel.active {
      right: 0;
    }
    
    @media (max-width: 768px) {
      .settings-panel {
        width: 100%;
        right: -100%;
      }
    }
    
    .settings-header {
      padding: 24px;
      border-bottom: 1px solid var(--border);
      display: flex;
      justify-content: space-between;
      align-items: center;
      position: sticky;
      top: 0;
      background: var(--card);
      z-index: 10;
    }
    
    .settings-title {
      font-size: 20px;
      font-weight: 600;
    }
    
    .close-btn {
      width: 36px;
      height: 36px;
      border-radius: 8px;
      background: var(--bg2);
      border: 1px solid var(--border);
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      font-size: 20px;
      color: var(--text);
      transition: all 0.2s ease;
    }
    
    .close-btn:hover {
      background: var(--accent);
      color: white;
      border-color: var(--accent);
    }
    
    .settings-content {
      padding: 24px;
      padding-right: 16px; /* Extra space on right for easier scrollbar access */
      margin-right: 8px; /* Push content away from edge */
    }
    
    .settings-section {
      margin-bottom: 32px;
    }
    
    .settings-section-title {
      font-size: 12px;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      color: var(--muted);
      margin-bottom: 16px;
    }
    
    .settings-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 14px 0;
      border-bottom: 1px solid var(--border);
    }
    
    .settings-item:last-child {
      border-bottom: none;
    }
    
    .settings-label {
      font-size: 14px;
      color: var(--text);
      font-weight: 500;
    }
    
    .settings-control {
      display: flex;
      gap: 8px;
    }
    
    .theme-btn {
      padding: 8px 16px;
      border-radius: 8px;
      border: 1px solid var(--border);
      background: var(--bg2);
      font-size: 13px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s ease;
      color: var(--text);
    }
    
    .theme-btn.active {
      background: var(--accent);
      color: white;
      border-color: var(--accent);
    }
    
    .toggle-switch {
      width: 48px;
      height: 26px;
      background: var(--border);
      border-radius: 13px;
      position: relative;
      cursor: pointer;
      transition: all 0.2s ease;
    }
    
    .toggle-switch.active {
      background: var(--accent);
    }
    
    .toggle-switch::after {
      content: '';
      position: absolute;
      width: 22px;
      height: 22px;
      background: white;
      border-radius: 50%;
      top: 2px;
      left: 2px;
      transition: all 0.2s ease;
      box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    }
    
    .toggle-switch.active::after {
      left: 24px;
    }
    
    /* Modal - RESTORED ELEGANT DESIGN */
    .modal {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(0,0,0,0.75);
      z-index: 2000;
      display: none;
      overflow-y: auto;
      padding: 20px;
      backdrop-filter: blur(4px);
    }
    
    .modal.active {
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
    .modal-content {
      background: #fef7ed;
      border: 2px solid #fed7aa;
      border-radius: 20px;
      padding: 48px;
      max-width: 900px;
      width: 100%;
      max-height: 90vh;
      overflow-y: auto;
      position: relative;
      box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    }
    
    @media (max-width: 768px) {
      .modal-content {
        padding: 32px 24px;
      }
    }
    
    .modal-close {
      position: absolute;
      top: 20px;
      right: 20px;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background: rgba(107, 114, 128, 0.1);
      border: none;
      cursor: pointer;
      color: #6b7280;
      font-size: 24px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.2s ease;
    }
    
    .modal-close:hover {
      background: #f97316;
      color: white;
      transform: rotate(90deg);
    }
    
    /* Voice Modal - separate overlay, no inheritance */
    .voice-overlay {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(0,0,0,0.75);
      backdrop-filter: blur(4px);
      z-index: 2000;
      display: none;
      align-items: center;
      justify-content: center;
    }
    
    .voice-overlay.active {
      display: flex;
    }
    
    .voice-modal-box {
      background: #fef7ed;
      border: 2px solid #fed7aa;
      border-radius: 20px;
      padding: 24px;
      max-width: 580px;
      width: 86vw;
      position: relative;
      box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    }
    
    .voice-title {
      font-size: 18px;
      font-weight: 800;
      text-align: center;
      margin-bottom: 20px;
      color: #1f2937;
    }
    
    .voice-stage {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 32px;
      margin-bottom: 16px;
    }
    
    .voice-speaker {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
    }
    
    .voice-avatar {
      font-size: 42px;
    }
    
    .voice-name {
      font-weight: 700;
      font-size: 14px;
      color: #1f2937;
    }
    
    .voice-badge {
      font-size: 11px;
      padding: 5px 10px;
      border-radius: 8px;
      background: #ffe9d7;
      color: #7a2e0e;
      font-weight: 700;
    }
    
    .voice-play {
      width: 80px;
      height: 80px;
      border-radius: 50%;
      background: #f97316;
      color: #fff;
      border: none;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 800;
      font-size: 14px;
      cursor: pointer;
      box-shadow: 0 8px 30px rgba(249,115,22,0.3);
      transition: all 0.2s ease;
    }
    
    .voice-play:hover {
      transform: scale(1.05);
      box-shadow: 0 10px 35px rgba(249,115,22,0.4);
    }
    
    .voice-play:disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }
    
    .voice-progress {
      height: 4px;
      width: 100%;
      max-width: 420px;
      background: #eee;
      border-radius: 6px;
      margin: 0 auto;
      overflow: hidden;
    }
    
    .voice-bar {
      height: 100%;
      width: 0%;
      background: linear-gradient(90deg, #f97316, #fb923c);
      transition: width 150ms linear;
    }
    
    .voice-close {
      position: absolute;
      top: 10px;
      right: 10px;
      width: 36px;
      height: 36px;
      border-radius: 50%;
      background: rgba(107, 114, 128, 0.1);
      border: none;
      cursor: pointer;
      color: #6b7280;
      font-size: 22px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.2s ease;
      z-index: 10;
    }
    
    .voice-close:hover {
      background: #f97316;
      color: white;
      transform: rotate(90deg);
    }
    
    .modal-quote {
      font-size: 32px;
      margin-bottom: 20px;
      font-family: 'Playfair Display', serif;
      line-height: 1.4;
      color: #1f2937;
    }
    
    @media (max-width: 768px) {
      .modal-quote {
        font-size: 24px;
      }
    }
    
    .modal-author {
      font-size: 18px;
      color: #6b7280;
      margin-bottom: 12px;
      font-weight: 500;
    }
    
    .modal-essence {
      font-size: 15px;
      color: #f97316;
      font-weight: 700;
      margin-bottom: 6px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }
    
    .modal-interp {
      font-size: 15px;
      color: #374151;
      line-height: 1.7;
      margin-bottom: 32px;
    }
    
    .modal-tabs {
      border-bottom: 2px solid #e5e7eb;
      margin-bottom: 28px;
      display: flex;
      gap: 4px;
    }
    
    .modal-tab {
      padding: 14px 24px;
      border: none;
      background: none;
      font-size: 14px;
      font-weight: 600;
      color: #9ca3af;
      border-bottom: 3px solid transparent;
      margin-bottom: -2px;
      cursor: pointer;
      transition: all 0.2s ease;
    }
    
    .modal-tab:hover {
      color: #6b7280;
    }
    
    .modal-tab.active {
      color: #f97316;
      border-bottom-color: #f97316;
    }
    
    .modal-tab-content {
      display: none;
    }
    
    .modal-tab-content.active {
      display: block;
      animation: fadeIn 0.3s ease;
    }
    
    @keyframes fadeIn {
      from { opacity: 0; transform: translateY(10px); }
      to { opacity: 1; transform: translateY(0); }
    }
    
    /* Mobile adjustments */
    @media (max-width: 768px) {
      .header {
        padding: 12px 16px;
      }
      
      .header-title {
        font-size: 18px;
      }
      
      .header-nav {
        position: fixed;
        top: 60px;
        right: -100%;
        width: 280px;
        height: calc(100vh - 60px);
        background: var(--card);
        border-left: 1px solid var(--border);
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 20px;
        box-shadow: -4px 0 20px rgba(0,0,0,0.1);
        transition: right 0.3s ease;
        z-index: 200;
      }
      
      .header-nav.active {
        right: 0;
      }
      
      .nav-btn {
        width: 100%;
        text-align: left;
        margin-bottom: 8px;
      }
      
      .hamburger {
        display: flex;
      }
      
      .page-content {
        padding: 24px 16px;
      }
      
      .search-container {
        margin-bottom: 24px;
      }
      
      .search-input {
        padding: 16px 20px 16px 52px;
        font-size: 16px;
      }
      
      .search-icon {
        left: 16px;
        width: 20px;
        height: 20px;
      }
      
      .alphabet-nav {
        gap: 6px;
      }
      
      .alphabet-btn {
        width: 36px;
        height: 36px;
        font-size: 13px;
      }
    }

    /* ============================================
       HOP 1: HEADER & NAVIGATION MOBILE FIXES
       ============================================ */

    /* Small mobile devices */
    @media (max-width: 480px) {
      .header {
        padding: 10px 12px;
        gap: 8px;
      }

      .header-title {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 200px;
      }

      .header-accent {
        display: inline;
      }

      /* Hamburger touch-friendly */
      .hamburger {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
      }

      .hamburger span {
        width: 22px;
        height: 2.5px;
      }
    }

    /* Mobile nav improvements */
    @media (max-width: 768px) {
      /* Ensure nav has smooth scrolling */
      .header-nav {
        overflow-y: auto;
        overscroll-behavior: contain;
      }

      /* Nav buttons touch-friendly */
      .nav-btn {
        min-height: 48px;
        padding: 14px 20px;
        font-size: 15px;
        display: flex;
        align-items: center;
        border-radius: 10px;
        margin-bottom: 8px;
        transition: all 0.2s ease;
      }

      .nav-btn:active {
        background: var(--accent);
        color: white;
        transform: scale(0.98);
      }

      .nav-btn.active::after {
        display: none;
      }

      .nav-btn.active {
        background: var(--accent);
        color: white;
        border-radius: 10px;
      }

      /* Search limit badge in mobile nav */
      #searchLimitBadge {
        width: 100%;
        justify-content: flex-start;
        margin: 8px 0;
      }

      #searchLimitBadgeBtn {
        width: 100%;
        justify-content: flex-start;
        padding: 14px 20px;
        font-size: 15px;
        border-radius: 10px;
        background: var(--bg2);
      }

      #searchLimitTooltip {
        position: fixed;
        top: auto;
        bottom: 20px;
        left: 20px;
        right: 20px;
        width: auto;
        max-width: none;
      }

      /* Overlay for mobile menu backdrop */
      .header-nav::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        z-index: -1;
        pointer-events: none;
      }

      .header-nav.active::before {
        opacity: 1;
        visibility: visible;
      }
    }

    /* Prevent body scroll when mobile menu is open */
    body.menu-open {
      overflow: hidden;
      position: fixed;
      width: 100%;
    }

    /* ============================================
       HOP 2: SEARCH AREA & TOGGLE CONTROLS
       ============================================ */

    @media (max-width: 768px) {
      /* Search toggles container - SINGLE ROW layout */
      #searchToggles {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        flex-wrap: nowrap !important;
      }

      /* Type toggle group - compact */
      #typeToggleGroup {
        flex: 1 !important;
        max-width: none !important;
        justify-content: center !important;
        padding: 3px !important;
      }

      #typeToggleGroup .type-toggle {
        flex: 1 !important;
        min-width: 0 !important;
        padding: 8px 10px !important;
        font-size: 12px !important;
      }

      /* Views, Advanced, Help - icon-only pill group */
      #viewsBtn,
      #advancedBtn,
      #helpBtn {
        padding: 8px 12px !important;
        font-size: 16px !important;
        min-width: 40px !important;
        min-height: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: var(--bg2) !important;
        border: 1px solid var(--border) !important;
        border-radius: 8px !important;
      }

      /* Hide text labels on mobile, show only icons */
      .mobile-hide {
        display: none !important;
      }

      .mobile-icon {
        font-size: 18px !important;
        line-height: 1 !important;
      }

      /* Group the 3 buttons together visually */
      #viewsBtn {
        border-radius: 8px 0 0 8px !important;
        border-right: none !important;
      }

      #advancedBtn {
        border-radius: 0 !important;
        border-right: none !important;
      }

      #helpBtn {
        border-radius: 0 8px 8px 0 !important;
      }

      /* Active state for tool buttons */
      #viewsBtn:active,
      #advancedBtn:active,
      #helpBtn:active {
        background: var(--accent) !important;
        color: white !important;
      }

      /* Active search badge */
      #activeSearchBadge {
        width: 100% !important;
        max-width: none !important;
        justify-content: space-between !important;
        padding: 10px 14px !important;
        margin-top: 8px !important;
      }

      /* Views panel mobile */
      #viewsPanel {
        padding: 16px !important;
      }

      #viewsPanel h3 {
        font-size: 14px !important;
      }

      #viewsPanel .view-option {
        padding: 12px 14px !important;
      }

      #viewsPanel .view-option > div > span:first-child {
        font-size: 20px !important;
      }

      #viewsPanel .view-option div div:first-of-type {
        font-size: 14px !important;
      }

      #viewsPanel .view-option div div:last-of-type {
        font-size: 11px !important;
      }

      /* Advanced panel mobile */
      #advancedPanel {
        padding: 14px !important;
      }

      #advancedPanel > div:first-child {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
      }

      #advancedPanel label {
        font-size: 12px !important;
      }

      #advancedPanel input {
        padding: 12px !important;
        font-size: 15px !important;
      }

      #advSearchBtn {
        width: 100% !important;
        padding: 12px 20px !important;
      }

      /* Stronger text colors for mobile readability */
      .results-stats,
      .quote-meta,
      .autocomplete-meta,
      #viewsPanel .view-option div div:last-of-type {
        color: #4b5563 !important;
      }
    }

    /* Extra small screens - stack type toggles if needed */
    @media (max-width: 420px) {
      #searchToggles {
        flex-wrap: wrap !important;
        gap: 10px !important;
      }

      #typeToggleGroup {
        flex: 0 0 100% !important;
        order: 1 !important;
      }

      /* Tool buttons stay as row, centered below */
      #viewsBtn,
      #advancedBtn,
      #helpBtn {
        order: 2 !important;
      }
    }

    /* Autocomplete box mobile */
    @media (max-width: 768px) {
      .autocomplete-box {
        max-height: 50vh;
        border-radius: 10px;
      }

      .autocomplete-item {
        padding: 12px 14px;
        font-size: 14px;
        color: #1f2937;
      }

      .autocomplete-meta {
        font-size: 11px;
        color: #4b5563;
      }
    }

    /* ============================================
       HOP 3: CARDS, GRIDS & CONTENT DISPLAY
       ============================================ */

    @media (max-width: 768px) {
      /* Results header */
      .results-header {
        margin-bottom: 16px;
      }

      .results-title {
        font-size: 20px;
      }

      .results-stats {
        font-size: 13px;
      }

      /* Quote cards */
      .quote-card {
        padding: 16px;
        border-radius: 10px;
      }

      .quote-card-inner {
        gap: 12px;
      }

      .quote-avatar {
        width: 40px;
        height: 40px;
        font-size: 20px;
      }

      .quote-text {
        font-size: 15px;
        line-height: 1.5;
        margin-bottom: 10px;
        -webkit-line-clamp: 4;
      }

      .quote-author {
        font-size: 13px;
        margin-bottom: 6px;
      }

      .quote-essence {
        font-size: 12px;
        margin-bottom: 6px;
      }

      .quote-meta {
        font-size: 11px;
        gap: 6px;
        color: #4b5563;
      }

      /* Stronger muted text for mobile readability */
      .quote-essence {
        color: var(--accent);
      }

      /* Action buttons - larger touch targets */
      .quote-action-btn {
        width: 36px !important;
        height: 36px !important;
        font-size: 16px !important;
        min-width: 36px;
        min-height: 36px;
      }

      .meta-actions {
        gap: 10px !important;
      }

      /* Item cards (topics/authors) */
      .item-card {
        padding: 16px;
        min-height: 56px;
      }

      .item-name {
        font-size: 14px;
      }

      .item-count {
        font-size: 12px;
        padding: 4px 8px;
      }

      /* Alphabet navigation */
      .alphabet-nav {
        gap: 4px;
        padding: 0 8px;
        margin-bottom: 20px;
      }

      .alphabet-btn {
        width: 32px;
        height: 32px;
        font-size: 12px;
        border-radius: 6px;
      }

      /* Pagination */
      .pagination {
        flex-wrap: wrap;
        gap: 10px;
        padding: 16px 12px;
      }

      .pagination-btn {
        padding: 10px 14px;
        font-size: 13px;
        flex: 1;
        min-width: 100px;
        justify-content: center;
      }

      .pagination-info {
        order: -1;
        flex-basis: 100%;
        margin-bottom: 4px;
      }
    }

    /* Extra small screens */
    @media (max-width: 380px) {
      .quote-card {
        padding: 14px;
      }

      .quote-card-inner {
        flex-direction: column;
        gap: 10px;
      }

      .quote-avatar {
        align-self: flex-start;
      }

      .quote-text {
        font-size: 14px;
      }

      .quote-meta {
        flex-wrap: wrap;
      }

      .meta-left {
        flex-basis: 100%;
        margin-bottom: 8px;
      }

      .meta-actions {
        flex-basis: 100%;
        justify-content: flex-start !important;
      }

      /* Alphabet - 2 rows on very small screens */
      .alphabet-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
      }
    }

    /* Touch device optimizations */
    @media (hover: none) and (pointer: coarse) {
      .quote-card:hover {
        transform: none;
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
      }

      .quote-card:active {
        transform: scale(0.98);
        border-color: var(--accent);
      }

      .item-card:hover {
        transform: none;
      }

      .item-card:active {
        background: var(--accent);
        color: white;
        transform: scale(0.98);
      }

      .alphabet-btn:hover {
        transform: none;
      }

      .alphabet-btn:active {
        background: var(--accent);
        color: white;
        transform: scale(0.95);
      }

      .quote-action-btn:active {
        background: var(--accent);
        color: white;
        border-color: var(--accent);
      }
    }

    /* ============================================
       HOP 4: MODALS & OVERLAYS
       ============================================ */

    @media (max-width: 768px) {
      /* Base modal styles */
      .modal {
        padding: 12px;
        align-items: flex-start;
        padding-top: 60px;
      }

      .modal-content {
        padding: 24px 18px;
        border-radius: 16px;
        max-height: calc(100vh - 80px);
        width: 100%;
        max-width: none;
        margin: 0;
      }

      .modal-close {
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        font-size: 20px;
      }

      /* Quote modal content */
      .modal-quote {
        font-size: 20px;
        line-height: 1.4;
        margin-bottom: 16px;
        padding-right: 30px;
      }

      .modal-author {
        font-size: 15px;
        margin-bottom: 10px;
      }

      .modal-essence {
        font-size: 13px;
        margin-bottom: 4px;
      }

      .modal-interp {
        font-size: 14px;
        line-height: 1.6;
        margin-bottom: 24px;
      }

      /* Modal tabs */
      .modal-tabs {
        margin-bottom: 20px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        margin-left: -18px;
        margin-right: -18px;
        padding-left: 18px;
        padding-right: 18px;
      }

      .modal-tabs::-webkit-scrollbar {
        display: none;
      }

      .modal-tab {
        padding: 12px 16px;
        font-size: 13px;
        white-space: nowrap;
        flex-shrink: 0;
      }

      /* Help modal */
      #helpModal .modal-content {
        padding: 20px 16px;
      }

      #helpModal h2 {
        font-size: 18px;
        margin-bottom: 16px;
      }

      #helpModal h3 {
        font-size: 14px;
      }

      #helpModal p {
        font-size: 13px;
      }

      /* Analytics modal */
      #analyticsModal .modal-content {
        padding: 20px 14px;
        max-height: calc(100vh - 60px);
      }

      #analyticsModal h2 {
        font-size: 18px;
        margin-bottom: 16px;
      }

      #analyticsTableContainer {
        font-size: 12px;
      }

      /* Search Limit modal */
      #searchLimitModal .modal-content {
        padding: 24px 20px;
        width: calc(100% - 24px);
        max-width: none;
      }

      #searchLimitModal h2 {
        font-size: 20px;
      }

      #searchLimitModal p {
        font-size: 14px;
      }

      /* Variants Table modal - critical fix for horizontal scroll */
      #variantsTableModal .modal-content {
        padding: 16px 12px;
        max-width: none;
        width: 100%;
      }

      #variantsTableModal h2 {
        font-size: 16px;
        flex-wrap: wrap;
      }

      #variantsTableModal h2 span:first-child {
        font-size: 20px;
      }

      /* Filter controls stack vertically */
      #variantsTableModal > .modal-content > div:nth-child(3) {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
      }

      #variantsTableModal select {
        width: 100%;
        padding: 10px 12px;
        font-size: 14px;
      }

      /* Table scroll container */
      #variantsTableModal > .modal-content > div:nth-child(4) {
        margin-left: -12px;
        margin-right: -12px;
        border-radius: 0;
        border-left: none;
        border-right: none;
      }

      #variantsTable {
        min-width: 600px;
        font-size: 12px;
      }

      #variantsTable th,
      #variantsTable td {
        padding: 8px 10px;
      }

      /* Footer buttons */
      #variantsTableModal > .modal-content > div:last-child {
        flex-direction: column;
        gap: 10px;
      }

      #variantsTableModal > .modal-content > div:last-child button {
        width: 100%;
        justify-content: center;
      }

      /* Voice modal */
      .voice-modal-box {
        width: calc(100% - 24px);
        max-width: none;
        padding: 20px 16px;
      }

      .voice-title {
        font-size: 16px;
        margin-bottom: 16px;
      }

      .voice-stage {
        gap: 16px;
        flex-wrap: wrap;
        justify-content: center;
      }

      .voice-speaker {
        flex: 0 0 auto;
      }

      .voice-avatar {
        font-size: 32px;
      }

      .voice-name {
        font-size: 12px;
      }

      .voice-badge {
        font-size: 10px;
        padding: 4px 8px;
      }

      .voice-play {
        width: 64px;
        height: 64px;
        font-size: 12px;
        order: 3;
        flex-basis: 100%;
        margin: 12px auto 0;
      }

      .voice-progress {
        max-width: 100%;
      }

      .voice-close {
        top: 8px;
        right: 8px;
        width: 32px;
        height: 32px;
        font-size: 18px;
      }

      /* Settings panel */
      .settings-panel {
        width: 100%;
        right: -100%;
      }

      .settings-header {
        padding: 16px 18px;
      }

      .settings-title {
        font-size: 18px;
      }

      .settings-content {
        padding: 18px 16px;
      }

      .settings-section-title {
        font-size: 11px;
      }

      .settings-item {
        padding: 12px 0;
        flex-wrap: wrap;
        gap: 10px;
      }

      .settings-label {
        font-size: 13px;
        flex: 1;
        min-width: 120px;
      }

      .settings-control {
        flex-wrap: wrap;
        gap: 6px;
      }

      .toggle-switch {
        width: 44px;
        height: 24px;
      }

      .toggle-switch::after {
        width: 20px;
        height: 20px;
      }

      .toggle-switch.active::after {
        left: 22px;
      }

      /* Live server warning */
      #liveServerWarning > div {
        padding: 20px 16px;
        max-width: calc(100% - 24px);
      }

      #liveServerWarning h2 {
        font-size: 18px;
      }

      #liveServerWarning p,
      #liveServerWarning ol {
        font-size: 13px;
      }
    }

    /* Extra small screens for modals */
    @media (max-width: 380px) {
      .modal-content {
        padding: 20px 14px;
      }

      .modal-quote {
        font-size: 18px;
      }

      .modal-tabs {
        gap: 0;
      }

      .modal-tab {
        padding: 10px 12px;
        font-size: 12px;
      }

      .voice-stage {
        gap: 12px;
      }

      .voice-avatar {
        font-size: 28px;
      }

      .voice-play {
        width: 56px;
        height: 56px;
        font-size: 11px;
      }
    }

    /* Safe area insets for notched devices */
    @supports (padding: max(0px)) {
      @media (max-width: 768px) {
        .modal {
          padding-left: max(12px, env(safe-area-inset-left));
          padding-right: max(12px, env(safe-area-inset-right));
          padding-bottom: max(12px, env(safe-area-inset-bottom));
        }

        .header {
          padding-left: max(16px, env(safe-area-inset-left));
          padding-right: max(16px, env(safe-area-inset-right));
        }

        .page-content {
          padding-left: max(16px, env(safe-area-inset-left));
          padding-right: max(16px, env(safe-area-inset-right));
        }
      }
    }
