body { font-family: 'Inter', system-ui, -apple-system, sans-serif; }
    .digest-bg-pattern {
      background-color: #f9fafb;
      background-image: radial-gradient(#e5e7eb 1px, transparent 1px);
      background-size: 24px 24px;
    }
    .hover-lift {
      transition: all 0.2s ease;
    }
    .hover-lift:hover {
      transform: translateY(-2px);
      box-shadow: 0 14px 24px -14px rgba(15, 23, 42, 0.18);
    }
    .tap-target { min-height: 44px; min-width: 44px; }
    .subject-gradient { background: linear-gradient(135deg, #f0f4ff 0%, #ffffff 100%); }
    .chapter-card {
      transition: all 0.2s ease;
      background: #ffffff;
      border-radius: 1.5rem;
      box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
    }
    .chapter-footer {
      color: #64748b;
    }
    .chapter-card.chapter-card-focused {
      border-color: #93c5fd;
      box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14), 0 18px 30px rgba(37, 99, 235, 0.08);
    }
    @media (min-width: 768px) {
      #chaptersGrid,
      #globalSearchResults {
        align-items: stretch;
      }

      #chaptersGrid > .chapter-card,
      #globalSearchResults > .chapter-card {
        display: flex;
        flex-direction: column;
      }

      #chaptersGrid .chapter-card-header,
      #globalSearchResults .chapter-card-header {
        display: grid;
        grid-template-columns: 48px minmax(0, 1fr) auto;
        column-gap: 14px;
        align-items: center;
      }

      #chaptersGrid .chapter-title-group,
      #globalSearchResults .chapter-title-group {
        display: contents;
      }

      #chaptersGrid .chapter-title-wrap,
      #globalSearchResults .chapter-title-wrap {
        display: flex;
        min-height: 48px;
        min-width: 0;
        flex-direction: column;
        justify-content: center;
      }

      #chaptersGrid .chapter-title,
      #globalSearchResults .chapter-title {
        display: -webkit-box;
        max-height: 48px;
        overflow: hidden;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        font-size: 1.125rem;
        line-height: 1.33;
        letter-spacing: -0.015em;
      }

      #chaptersGrid .state-pill,
      #globalSearchResults .state-pill {
        align-self: center;
        white-space: nowrap;
      }
    }
    .chapter-free-badge {
      flex: 0 0 auto;
    }
    .chapter-free-badge-label {
      flex: 0 0 auto;
      white-space: nowrap;
    }
    .chapter-free-badge-label svg {
      flex-shrink: 0;
    }
    .chapter-progress-track {
      height: 8px;
      background: #eef2f6;
      border-radius: 9999px;
      overflow: hidden;
    }
    .chapter-progress-fill {
      height: 100%;
      border-radius: 9999px;
      background: linear-gradient(90deg, #2563eb, #60a5fa);
      transition: width 0.35s cubic-bezier(0.2, 0.9, 0.4, 1.1);
    }
    .subject-progress-panel {
      display: flex;
      flex-direction: column;
      gap: 0.55rem;
    }
    .subject-progress-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
      min-width: 0;
    }
    .subject-progress-label {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
      color: #4b5563;
      font-size: 0.75rem;
      font-weight: 700;
      line-height: 1rem;
      white-space: nowrap;
    }
    .subject-progress-track {
      position: relative;
      width: 100%;
      height: 0.625rem;
      overflow: hidden;
      border-radius: 9999px;
      background: rgba(226, 232, 240, 0.9);
      box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
    }
    .subject-progress-fill {
      height: 100%;
      border-radius: inherit;
      background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 100%);
      box-shadow: 0 0 14px rgba(37, 99, 235, 0.28);
      transition: width 0.5s cubic-bezier(0.2, 0.9, 0.4, 1);
    }
    .subject-progress-value {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      min-width: 2.75rem;
      padding: 0.2rem 0.6rem;
      border: 1px solid rgba(37, 99, 235, 0.22);
      border-radius: 9999px;
      background: rgba(255, 255, 255, 0.78);
      color: #1d4ed8;
      font-size: 0.75rem;
      font-weight: 800;
      line-height: 1rem;
      box-shadow: 0 6px 14px rgba(15, 23, 42, 0.06);
    }
    .resource-tile {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 0.25rem;
      min-height: 86px;
      padding: 0.75rem 0.5rem;
      border-radius: 0.875rem;
      background-color: #fafcff;
      border: 1px solid #edf2f7;
      text-decoration: none;
      cursor: pointer;
      transition: all 0.2s ease;
      min-width: 0;
    }
    .resource-tile:hover {
      background-color: #ffffff;
      border-color: #bfdbfe;
      transform: translateY(-1px);
      box-shadow: 0 4px 12px -4px rgba(37, 99, 235, 0.12);
    }
    .resource-tile.completed-tile {
      background-color: #eff6ff;
      border-color: #93c5fd;
    }
    .resource-tile.completed-tile:hover {
      background-color: #dbeafe;
      border-color: #60a5fa;
    }
    .check-badge {
      position: absolute;
      top: -6px;
      right: -6px;
      width: 18px;
      height: 18px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #ffffff;
      border: 1px solid #bfdbfe;
      border-radius: 9999px;
      box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    }
    .check-badge.hidden {
      display: none;
    }
    .check-badge i {
      width: 12px;
      height: 12px;
      color: #2563eb;
      stroke-width: 2.5;
    }
    .check-badge svg {
      width: 12px;
      height: 12px;
      color: #2563eb;
      stroke-width: 2.5;
    }
    .state-pill {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 0.25rem 0.875rem;
      border-radius: 9999px;
      font-size: 0.75rem;
      font-weight: 600;
      line-height: 1.25rem;
      letter-spacing: 0.01em;
      white-space: nowrap;
      flex-shrink: 0;
      transition: all 0.2s ease;
    }
    .state-pill i {
      width: 12px;
      height: 12px;
      flex-shrink: 0;
      stroke-width: 2;
    }
    .state-pill svg {
      width: 12px;
      height: 12px;
      flex-shrink: 0;
      stroke-width: 2;
    }
    .state-notstarted {
      background: #f1f5f9;
      color: #334155;
      border: 1px solid #e2e8f0;
    }
    .state-progress {
      background: #fffbeb;
      color: #b45309;
      border: 1px solid #fde68a;
    }
    .state-completed {
      background: #eff6ff;
      color: #1d4ed8;
      border: 1px solid #bfdbfe;
    }
    .chapter-chip-button {
      transition: all 0.2s ease;
    }
    .chapter-chip-button:hover {
      background: #eff6ff;
      border-color: #93c5fd;
      color: #1d4ed8;
    }
    .chapter-chip-button.active {
      background: #eff6ff;
      border-color: #93c5fd;
      color: #1e40af;
      font-weight: 600;
    }
    .swipe-chip-row {
      overflow-x: auto;
      overflow-y: hidden;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior-x: contain;
      touch-action: pan-x;
      scroll-behavior: smooth;
    }
    .swipe-chip-row > * {
      flex: 0 0 auto;
    }
    .pill-scrollbar {
      padding-bottom: 0.45rem;
      scrollbar-width: thin;
      scrollbar-color: #94a3b8 #eef2f7;
    }
    .pill-scrollbar::-webkit-scrollbar {
      height: 8px;
    }
    .pill-scrollbar::-webkit-scrollbar-track {
      background: #eef2f7;
      border-radius: 9999px;
    }
    .pill-scrollbar::-webkit-scrollbar-thumb {
      background: #94a3b8;
      background-clip: content-box;
      border: 2px solid transparent;
      border-radius: 9999px;
    }
    .pill-scrollbar::-webkit-scrollbar-thumb:hover {
      background: #3b82f6;
      background-clip: content-box;
    }
    .pill-scrollbar::-webkit-scrollbar-thumb:active {
      background: #2563eb;
      background-clip: content-box;
    }
    .pill-scrollbar::-webkit-scrollbar-button {
      display: none;
      width: 0;
      height: 0;
    }
    .no-scrollbar::-webkit-scrollbar { display: none; }
    .no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
    @media (min-width: 1024px) {
      .subject-hero-stats-grid {
        flex: 0 0 320px;
        width: 320px;
      }
    }
    @media (min-width: 1280px) {
      .subject-hero-stats-grid {
        flex-basis: 440px;
        width: 440px;
      }
    }
    @media (max-width: 640px) {
      main {
        padding-top: 1rem;
      }
      .subject-breadcrumb {
        display: none;
      }
      .subject-header-mobile-back {
        display: none !important;
      }
      .subject-mobile-back {
        display: inline-flex;
        align-self: flex-start;
        position: relative;
        z-index: 10;
        margin-bottom: 0.875rem;
      }
      .subject-mobile-subtitle {
        display: none;
      }
      #chapterPills {
        display: none;
      }
      .subject-hero-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
        min-width: 0;
        width: 100%;
      }
      .hero-stats-card {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.35rem;
        padding: 0.7rem 0.55rem;
        text-align: center;
      }
      .hero-stats-card i,
      .hero-stats-card svg {
        display: none;
      }
      .hero-stats-card .stat-number,
      .hero-stats-card .hero-stat-label {
        display: inline;
        margin: 0;
        line-height: 1.1;
        white-space: nowrap;
      }
      .hero-stats-card .stat-number {
        font-size: 0.95rem;
      }
      .hero-stats-card .hero-stat-label {
        font-size: 0.72rem;
      }
    }
    .subject-mobile-back {
      display: none;
      align-items: center;
      justify-content: center;
      width: 2.5rem;
      height: 2.5rem;
      border-radius: 9999px;
      margin-bottom: 1rem;
      color: #2563eb;
      background: #ffffff;
      border: 1px solid #e5e7eb;
      box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    }
    .subject-header-mobile-back {
      display: none;
      align-items: center;
      justify-content: center;
      width: 2.5rem;
      height: 2.5rem;
      border-radius: 9999px;
      margin-right: 0.5rem;
      color: #2563eb;
      background: #ffffff;
      border: 1px solid #e5e7eb;
      box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    }
    @media (max-width: 640px) {
      .subject-header-mobile-back {
        display: none !important;
      }
      .subject-mobile-back {
        display: inline-flex;
      }
    }
    .chapter-resource-grid {
      display: grid;
      gap: 0.75rem;
      margin-top: 1rem;
      text-align: center;
      font-size: 0.75rem;
      grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
    }
    .resource-tile span {
      max-width: 100%;
      text-align: center;
      overflow-wrap: normal;
      word-break: normal;
      line-height: 1.15;
    }
    .resource-tile-label {
      display: block;
      font-size: 0.875rem;
      line-height: 1.2;
    }
    .resource-tile-meta {
      display: block;
      font-size: 0.625rem;
      line-height: 1.15;
      white-space: nowrap;
    }
    .chapter-resource-grid.three-up {
      grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    @media (min-width: 640px) {
      .chapter-resource-grid {
        gap: 1rem;
      }
    }
    @media (min-width: 768px) {
      .chapter-resource-grid[data-resource-count="2"] {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: 560px;
      }
    }
    @media (max-width: 480px) {
      .chapter-card {
        padding: 1rem;
        border-radius: 1.125rem;
      }
      .chapter-card-header {
        flex-direction: column;
        align-items: flex-start;
      }
      .chapter-card-header .state-pill {
        align-self: flex-start;
      }
      .chapter-resource-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.625rem;
        margin-top: 1rem;
      }
      .resource-tile {
        min-height: 78px;
        padding: 0.625rem 0.45rem;
        border-radius: 0.75rem;
      }
      .resource-tile-label {
        font-size: 0.8125rem;
      }
    }
    .hero-glow {
      background: radial-gradient(ellipse at 70% 30%, rgba(37, 99, 235, 0.10) 0%, rgba(249,250,251,0) 70%);
    }
    .hero-stats-card {
      transition: transform 0.2s ease, box-shadow 0.2s ease;
    }
    .hero-stats-card:hover {
      transform: translateY(-3px);
      box-shadow: 0 12px 20px -12px rgba(0,0,0,0.15);
    }
    .subject-icon-orb {
      background: linear-gradient(145deg, #ffffff 0%, #eff6ff 100%);
      box-shadow: 0 12px 24px -12px rgba(37, 99, 235, 0.25);
    }
    .hero-cta-pulse {
      animation: subtle-pulse 2s infinite;
    }
    .global-search-card {
      background: rgba(255, 255, 255, 0.96);
      border: 1px solid #e5e7eb;
      border-radius: 1rem;
      box-shadow: 0 10px 25px -18px rgba(15, 23, 42, 0.22);
    }
    .global-search-chip {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
      border-radius: 9999px;
      border: 1px solid #93c5fd;
      background: #eff6ff;
      color: #1e40af;
      font-size: 0.75rem;
      font-weight: 600;
      line-height: 1rem;
      padding: 0.4rem 0.7rem;
      transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    }
    .global-search-chip:hover {
      background: #bfdbfe;
      border-color: #93c5fd;
      transform: translateY(-1px);
    }
    .global-search-open-link {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
      border-radius: 9999px;
      border: 1px solid #e5e7eb;
      background: #ffffff;
      color: #2563eb;
      font-size: 0.75rem;
      font-weight: 600;
      padding: 0.45rem 0.8rem;
      white-space: nowrap;
    }
    .global-search-open-link:hover {
      background: #eff6ff;
      border-color: #93c5fd;
    }
    .global-search-empty {
      border: 1px solid #e5e7eb;
      border-radius: 1rem;
      background: rgba(255, 255, 255, 0.96);
      padding: 1.25rem;
      text-align: center;
      color: #6b7280;
    }
    .global-search-status-loading {
      color: #2563eb;
    }
    .chapter-filter-select-wrap { position: relative; min-width: 13rem; flex: 0 0 auto; }
    .chapter-card-actions { display: flex; align-items: center; gap: .5rem; flex: 0 0 auto; }
    .chapter-pin-button {
      width: 2.5rem;
      height: 2.5rem;
      border: 0;
      border-radius: .75rem;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      color: #94a3b8;
      background: #f1f5f9;
      transition: background .15s ease, color .15s ease, transform .15s ease;
    }
    .chapter-pin-button i, .chapter-pin-button svg { width: 19px; height: 19px; }
    .chapter-pin-button:hover { color: #1d4ed8; background: #eff6ff; }
    .chapter-pin-button:active { transform: scale(.92); }
    .chapter-pin-button.is-pinned { color: #1d4ed8; background: #dbeafe; }
    @media (max-width: 520px) {
      .chapter-filter-select-wrap { width: 100%; min-width: 0; }
      .chapter-card-actions .state-pill span { display: none; }
      .chapter-card-actions .state-pill { width: 2.25rem; height: 2.25rem; padding: 0; justify-content: center; }
    }
    @keyframes subtle-pulse {
      0% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.2); }
      70% { box-shadow: 0 0 0 8px rgba(37, 99, 235, 0); }
      100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
    }
    .stat-number {
      font-feature-settings: "tnum";
      font-variant-numeric: tabular-nums;
    }

    .dark .digest-bg-pattern {
      background-color: #09090b !important;
      background-image: radial-gradient(rgba(63, 63, 70, 0.58) 1px, transparent 1px) !important;
    }
    .dark .subject-gradient,
    .dark .hero-glow {
      background: linear-gradient(135deg, rgba(30, 58, 138, 0.24) 0%, rgba(24, 24, 27, 0.96) 100%) !important;
      border-color: rgba(37, 99, 235, 0.48) !important;
      box-shadow: 0 20px 42px rgba(0, 0, 0, 0.28) !important;
    }
    .dark .subject-gradient .absolute.bg-blue-100\/30,
    .dark .subject-gradient .absolute.bg-amber-100\/20 {
      opacity: 0.28;
    }
    .dark .subject-icon-orb {
      background: linear-gradient(145deg, rgba(30, 58, 138, 0.62) 0%, #18181b 100%) !important;
      border-color: rgba(59, 130, 246, 0.32) !important;
      box-shadow: 0 16px 26px rgba(0, 0, 0, 0.26) !important;
    }
    .dark #subjectTitle {
      background-image: linear-gradient(90deg, #f4f4f5, #93c5fd) !important;
    }
    .dark .hero-stats-card,
    .dark .chapter-card,
    .dark .global-search-card,
    .dark .global-search-empty {
      background: #18181b !important;
      border-color: #27272a !important;
      box-shadow: 0 16px 32px rgba(0, 0, 0, 0.28) !important;
    }
    .dark .hero-stats-card:hover,
    .dark .chapter-card:hover,
    .dark .global-search-card:hover {
      box-shadow: 0 18px 36px rgba(0, 0, 0, 0.34) !important;
    }
    .dark .chapter-card.chapter-card-focused {
      border-color: rgba(96, 165, 250, 0.7) !important;
      box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2), 0 18px 34px rgba(0, 0, 0, 0.34) !important;
    }
    .dark .chapter-pin-button { background: #27272a; color: #d4d4d8; }
    .dark .chapter-pin-button.is-pinned { background: rgba(30,58,138,.55); color: #93c5fd; }
    .dark .chapter-progress-track,
    .dark .subject-gradient .bg-gray-200\/80 {
      background: #27272a !important;
    }
    .dark .subject-progress-panel {
      border-color: rgba(63, 63, 70, 0.86) !important;
    }
    .dark .subject-progress-label {
      color: #d4d4d8 !important;
    }
    .dark .subject-progress-track {
      background: #27272a !important;
      box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.38) !important;
    }
    .dark .subject-progress-fill {
      background: linear-gradient(90deg, #2563eb 0%, #60a5fa 100%) !important;
      box-shadow: 0 0 18px rgba(37, 99, 235, 0.35) !important;
    }
    .dark .subject-progress-value {
      background: rgba(30, 58, 138, 0.48) !important;
      border-color: rgba(59, 130, 246, 0.4) !important;
      color: #93c5fd !important;
      box-shadow: none !important;
    }
    .dark .resource-tile {
      background-color: #111113 !important;
      border-color: #27272a !important;
      color: #e4e4e7 !important;
    }
    .dark .resource-tile:hover {
      background-color: #18181b !important;
      border-color: #3f3f46 !important;
      box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28) !important;
    }
    .dark .resource-tile.completed-tile {
      background-color: rgba(30, 58, 138, 0.34) !important;
      border-color: rgba(59, 130, 246, 0.4) !important;
    }
    .dark .resource-tile.completed-tile:hover {
      background-color: rgba(30, 58, 138, 0.48) !important;
    }
    .dark .check-badge {
      background: #18181b !important;
      border-color: rgba(59, 130, 246, 0.4) !important;
    }
    .dark .state-notstarted {
      background: #27272a !important;
      color: #d4d4d8 !important;
      border-color: #3f3f46 !important;
    }
    .dark .state-progress {
      background: rgba(120, 53, 15, 0.32) !important;
      color: #fbbf24 !important;
      border-color: rgba(245, 158, 11, 0.38) !important;
    }
    .dark .state-completed {
      background: rgba(30, 58, 138, 0.38) !important;
      color: #93c5fd !important;
      border-color: rgba(59, 130, 246, 0.4) !important;
    }
    .dark .chapter-chip-button,
    .dark .global-search-open-link {
      background: #27272a !important;
      border-color: #3f3f46 !important;
      color: #d4d4d8 !important;
    }
    .dark .chapter-chip-button:hover,
    .dark .chapter-chip-button.active,
    .dark .global-search-chip,
    .dark .global-search-open-link:hover {
      background: rgba(30, 58, 138, 0.45) !important;
      border-color: #1d4ed8 !important;
      color: #93c5fd !important;
    }
    .dark .pill-scrollbar {
      scrollbar-color: #64748b #27272a;
    }
    .dark .pill-scrollbar::-webkit-scrollbar-track {
      background: #27272a;
    }
    .dark .pill-scrollbar::-webkit-scrollbar-thumb {
      background: #64748b;
      background-clip: content-box;
    }
    .dark .pill-scrollbar::-webkit-scrollbar-thumb:hover {
      background: #60a5fa;
      background-clip: content-box;
    }
    .dark .subject-mobile-back,
    .dark .subject-header-mobile-back {
      background: #18181b !important;
      border-color: #27272a !important;
      color: #60a5fa !important;
    }
