/* sidebar.css */
:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 80px;
    --color-primary-50: #e6f4f3;
    --color-primary-100: #cce9e7;
    --color-primary-200: #99d3cf;
    --color-primary-500: #1b7c79;
    --color-primary-600: #0f4d4c;
    --color-primary-700: #0c3f3e;
    --color-accent-50: #fff8e5;
    --color-accent-100: #fff0c8;
    --color-accent-500: #E9BC32;
    --color-accent-600: #cfa323;
    --color-surface: #ffffff;
    --color-surface-soft: #f8fbfb;
    --color-background: #eef4f5;
    --color-muted: #5f6e77;
    --color-border: rgba(15, 77, 76, 0.14);
    --color-shadow: rgba(15, 77, 76, 0.35);

    --sidebar-bg: var(--color-primary-600);
    --sidebar-accent: var(--color-accent-500);
    --sidebar-text: rgba(255, 255, 255, 0.74);
    --sidebar-text-active: var(--color-accent-500);
    --sidebar-hover-bg: rgba(255, 255, 255, 0.1);
    --transition-speed: 0.3s;
    --premium-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --dark-gold: var(--color-accent-500);
    --dark-gold-soft: #f3d57a;
    --dark-text-main: #e7edf3;
    --dark-text-soft: #cfd9e2;
    --global-bottom-nav-offset: calc(86px + env(safe-area-inset-bottom));
}

/* Global Premium Bottom Navigation */
.global-bottom-nav {
    position: fixed;
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    z-index: 9999;
    padding: 0.5rem 0.75rem 0.75rem;
    background: #0F4D4C;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
}

body.has-global-bottom-nav {
    padding-bottom: var(--global-bottom-nav-offset);
}

/* FIX: was .swipe-container .card-media — that selector was too broad
   and was interfering with the card layout by forcing aspect-ratio
   on elements inside the swipe container unexpectedly.
   Now correctly scoped to only the image inside card faces. */
.face .card-media {
    aspect-ratio: 1 / 1 !important;
}

.global-bottom-nav-inner {
    max-width: 920px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.45rem;
}

.global-tab-item,
.global-dark-toggle {
    min-height: 52px;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    font-size: 11px;
    font-weight: 700;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: #0c4342;
    transition: transform 300ms var(--premium-ease), background-color 300ms var(--premium-ease), color 300ms var(--premium-ease), border-color 300ms var(--premium-ease), box-shadow 300ms var(--premium-ease);
}

.global-tab-item.active {
    background: linear-gradient(135deg, #0F4D4C, #1e7a78);
    color: #E9BC32;
    border-color: rgba(233, 188, 50, 0.3);
    box-shadow: 0 0 20px rgba(233, 188, 50, 0.2);
}

.global-tab-item:hover,
.global-dark-toggle:hover {
    background: #145a59;
    border-color: rgba(233, 188, 50, 0.3);
    color: #E9BC32;
    box-shadow: 0 0 0 1px rgba(233, 188, 50, 0.2), 0 8px 22px -14px rgba(15, 77, 76, 0.4);
}

.global-tab-item:active,
.global-dark-toggle:active {
    transform: scale(0.96);
}

.global-tab-item:focus-visible,
.global-dark-toggle:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--color-primary-600) 45%, transparent);
    outline-offset: 2px;
}

.global-dark-toggle {
    cursor: pointer;
    font-family: inherit;
}

.has-global-bottom-nav .main-content {
    padding-bottom: 86px;
}

.main-content .mode-nav {
    justify-content: center !important;
}

/* Premium card enhancement layer */
.edu-card,
.high-contrast-card,
.status-card {
    background-image: linear-gradient(160deg, color-mix(in srgb, var(--color-surface) 97%, transparent) 0%, color-mix(in srgb, var(--color-surface-soft) 92%, transparent) 100%);
    box-shadow:
        0 2px 4px color-mix(in srgb, var(--color-primary-600) 5%, transparent),
        0 10px 24px -16px color-mix(in srgb, var(--color-primary-600) 30%, transparent),
        inset 0 1px 0 color-mix(in srgb, var(--color-surface) 60%, transparent);
    transition:
        transform 300ms var(--premium-ease),
        box-shadow 300ms var(--premium-ease),
        border-color 300ms var(--premium-ease),
        filter 300ms var(--premium-ease);
}

.edu-card:hover,
.high-contrast-card:hover,
.status-card:hover {
    transform: translateY(-3px);
    filter: saturate(1.03);
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--color-primary-600) 16%, transparent),
        0 10px 20px -14px color-mix(in srgb, var(--color-primary-600) 35%, transparent),
        0 18px 34px -22px color-mix(in srgb, var(--color-primary-500) 50%, transparent),
        0 0 18px color-mix(in srgb, var(--color-accent-500) 18%, transparent);
}

.edu-card:active,
.high-contrast-card:active,
.status-card:active {
    transform: translateY(0) scale(0.992);
}

.layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    color: white;
    height: 100dvh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 1000;
    transition: width var(--transition-speed) ease, transform var(--transition-speed) ease;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1.5rem 0 1.5rem;
    overflow-x: hidden;
    overflow-y: auto;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    padding: 1.5rem 0.75rem;
}

body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
    padding: 1.5rem 0.75rem;
}

/* Logo Section */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2.5rem;
    white-space: nowrap;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background-color: var(--sidebar-accent);
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: bold;
    color: var(--sidebar-bg);
    font-size: 1.25rem;
}

.logo-text {
    transition: opacity var(--transition-speed);
}

/* Prevent page-level h1 browser defaults from inflating the sidebar logo text */
.sidebar h1 {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
}

.sidebar h2,
.sidebar h3 {
    margin: 0;
    font-size: inherit;
}

.sidebar.collapsed .logo-text {
    opacity: 0;
    pointer-events: none;
}

/* ── Inbox notification badge ─────────────────────────────── */
.sidebar-notif-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #E9BC32;
    color: #0F4D4C;
    font-size: 10px;
    font-weight: 800;
    line-height: 1;
    margin-left: auto;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(15,77,76,0.35);
    animation: badgePop 0.3s cubic-bezier(0.22,1,0.36,1);
}

/* Collapsed sidebar: badge floats top-right of the icon */
body.sidebar-collapsed .sidebar .sidebar-notif-badge,
.sidebar.collapsed .sidebar-notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    margin-left: 0;
    min-width: 16px;
    height: 16px;
    font-size: 9px;
    padding: 0 4px;
}

@keyframes badgePop {
    0%   { transform: scale(0.5); opacity: 0; }
    70%  { transform: scale(1.2); }
    100% { transform: scale(1);   opacity: 1; }
}

/* Navigation Links */
.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
    position: relative;
}

.sidebar-item:hover {
    background-color: var(--sidebar-hover-bg);
    color: white;
}

.sidebar-item.active {
    background-color: var(--sidebar-hover-bg);
    color: var(--sidebar-text-active);
}

.sidebar-item svg {
    flex-shrink: 0;
}

.nav-text {
    font-weight: 500;
    transition: opacity var(--transition-speed);
}

.sidebar.collapsed .nav-text {
    opacity: 0;
    pointer-events: none;
}

body.sidebar-collapsed .sidebar .nav-text,
body.sidebar-collapsed .sidebar .nav-label {
    opacity: 0;
    pointer-events: none;
    display: none;
}

.sidebar.collapsed .sidebar-item {
    justify-content: center;
    padding: 0.75rem;
}

body.sidebar-collapsed .sidebar .sidebar-item {
    justify-content: center;
    padding: 0.75rem;
}

/* Tooltip for Collapsed State */
.sidebar.collapsed .sidebar-item::after {
    content: attr(data-title);
    position: absolute;
    left: 100%;
    margin-left: 1rem;
    padding: 0.5rem 0.75rem;
    background: color-mix(in srgb, var(--color-primary-700) 92%, transparent);
    color: var(--color-surface);
    border-radius: 0.5rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
    z-index: 1001;
}

body.sidebar-collapsed .sidebar .sidebar-item::after {
    content: attr(data-title);
    position: absolute;
    left: 100%;
    margin-left: 1rem;
    padding: 0.5rem 0.75rem;
    background: color-mix(in srgb, var(--color-primary-700) 92%, transparent);
    color: var(--color-surface);
    border-radius: 0.5rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
    z-index: 1001;
}

.sidebar.collapsed .sidebar-item:hover::after {
    opacity: 1;
    visibility: visible;
}

body.sidebar-collapsed .sidebar .sidebar-item:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Sidebar Footer Icons */
.sidebar-footer {
    margin-top: auto;
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0;
}

.sidebar-icon-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.75rem;
    color: var(--color-accent-500);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.sidebar-icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: var(--color-accent-500);
    transform: translateY(-2px);
}

.sidebar.collapsed .sidebar-icon-btn::after,
body.sidebar-collapsed .sidebar .sidebar-icon-btn::after {
    content: attr(data-title);
    position: absolute;
    left: 100%;
    margin-left: 1rem;
    padding: 0.5rem 0.75rem;
    background: color-mix(in srgb, var(--color-primary-700) 92%, transparent);
    color: var(--color-surface);
    border-radius: 0.5rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
    z-index: 1001;
}

.sidebar.collapsed .sidebar-icon-btn:hover::after,
body.sidebar-collapsed .sidebar .sidebar-icon-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Theme Modal */
.theme-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.theme-modal.active {
    opacity: 1;
    visibility: visible;
}

.theme-modal-content {
    background: var(--color-surface);
    border-radius: 1.25rem;
    padding: 1.5rem;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9);
    transition: transform 0.3s;
}

.theme-modal.active .theme-modal-content {
    transform: scale(1);
}

.theme-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.theme-modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-primary-600);
}

.theme-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    color: var(--color-muted);
    transition: all 0.2s;
}

.theme-close-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-primary-600);
}

.theme-options {
    display: grid;
    gap: 0.75rem;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--color-surface-soft);
    border: 2px solid var(--color-border);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-muted);
}

.theme-option:hover {
    border-color: var(--color-primary-500);
    background: var(--color-surface);
    transform: translateY(-2px);
}

.theme-option.active {
    border-color: var(--color-accent-500);
    background: var(--color-accent-50);
    color: var(--color-primary-600);
}

.theme-option svg {
    flex-shrink: 0;
}

body.theme-dark .theme-modal-header h3 {
    color: var(--text-primary);
}

body.theme-dark .theme-close-btn {
    color: var(--text-muted);
}

body.theme-dark .theme-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

body.theme-dark .theme-option {
    color: var(--text-primary);
}

body.theme-dark .theme-option.active {
    background: var(--bg-surface-hover);
    border-color: var(--color-accent-500);
    color: var(--color-accent-500);
}

/* Premium Card in Sidebar */
.sidebar-premium {
    margin-top: auto;
    padding: clamp(0.6rem, 3vw, 0.75rem);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all var(--transition-speed);
    box-sizing: border-box;
    width: 100%;
}

.sidebar-premium svg {
    width: clamp(18px, 4vw, 24px);
    height: clamp(18px, 4vw, 24px);
    flex-shrink: 0;
}

.sidebar-premium h3 {
    margin: 0 0 0.2rem 0;
    font-size: clamp(0.75rem, 2.5vw, 0.85rem);
    line-height: 1.2;
}

.sidebar-premium p {
    margin: 0 0 0.5rem 0;
    font-size: clamp(0.65rem, 2vw, 0.72rem);
    line-height: 1.35;
}

.upgrade-btn {
    display: block;
    width: 100%;
    background-color: var(--color-accent-500);
    color: #121013;
    border: none;
    cursor: pointer;
    font-weight: 700;
    border-radius: 0.5rem;
    transition: background-color 0.2s;
    box-sizing: border-box;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upgrade-btn:hover {
    background-color: #CFA323;
}

.sidebar-premium .upgrade-btn {
    padding: clamp(0.35rem, 2vw, 0.4rem) 0.5rem !important;
    font-size: clamp(0.65rem, 2vw, 0.72rem) !important;
    line-height: 1.2;
}

.sidebar.collapsed .sidebar-premium {
    padding: 0.5rem;
    text-align: center;
}

body.sidebar-collapsed .sidebar .sidebar-premium {
    padding: 0.5rem;
    text-align: center;
}

.sidebar.collapsed .sidebar-premium h3,
.sidebar.collapsed .sidebar-premium p {
    display: none;
}

body.sidebar-collapsed .sidebar .sidebar-premium h3,
body.sidebar-collapsed .sidebar .sidebar-premium p {
    display: none;
}

.sidebar.collapsed .sidebar-premium .upgrade-btn span {
    display: none;
}

body.sidebar-collapsed .sidebar .sidebar-premium .upgrade-btn span {
    display: none;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition-speed) ease;
    min-width: 0;
}

.main-content.expanded {
    margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .global-bottom-nav {
    left: var(--sidebar-collapsed-width);
}

/* Topbar */
.topbar {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: #0f4d4c;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: sticky;
    top: 0;
    z-index: 100;
}

.global-topbar {
    gap: 1rem;
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-stats {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-right: 0.25rem;
}

.streak,
.xp-total {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 0.22rem 0.5rem;
    line-height: 1;
    white-space: nowrap;
}

.streak {
   background: rgba(234,179,8,0.15);
color: #a84109;
border: 1px solid #FDBA74;
box-shadow: 0 0 10px rgba(249,115,22,0.4);
border: 1px solid #FDBA74;
}

.streak-icon {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    flex: 0 0 16px;
}

.streak-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.xp-total {
    background: #b3b303;
    color: #1F2937;
    border: 1px solid rgba(234,179,8,0.35);
    box-shadow: 0 0 10px rgba(249,115,22,0.4);
    background: linear-gradient(135deg, #FACC15, #EAB308);
color: #1f2937;
box-shadow: 0 0 8px rgba(234,179,8,0.35);
}

.topbar-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
    color: #ffffff;
}

.topbar-toggle,
#sidebarToggle,
#sidebar-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    color: #a67e07;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.topbar-toggle:hover,
#sidebarToggle:hover,
#sidebar-toggle:hover {
    background: #145a59;
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    height: 40px;
    min-width: 220px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 12px;
    padding: 0 12px;
    color: #ffffff;
    background: #0c4342;
}

.topbar-search input {
    border: none;
    outline: none;
    background: #0c4342;
    font-size: 0.92rem;
    width: 100%;
    color: #ffffff;
}

.topbar-search input::placeholder {
    color: #cfe1e1;
}

.topbar-search:focus-within {
    border-color: #E9BC32;
}

.topbar-icon-btn,
.topbar-avatar {
    width: 40px;
    height: 40px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    background: #0c4342;
    text-decoration: none;
}

.topbar-icon-btn:hover,
.topbar-avatar:hover {
    background: #145a59;
}

.topbar-avatar-image {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    object-fit: cover;
    display: block;
}

/* Mobile Overlay */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  visibility: hidden;
  transition: 0.3s;
  z-index: 998;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Responsive Queries */
@media (max-width: 768px) {
    :root {
        --global-bottom-nav-offset: calc(92px + env(safe-area-inset-bottom));
    }

    body.has-global-bottom-nav .sidebar {
        height: 100dvh;
        padding-bottom: var(--global-bottom-nav-offset);
    }

    body.has-global-bottom-nav .sidebar-overlay {
        bottom: 0;
    }

    .sidebar {
        position: fixed;
        left: -260px;
        transition: 0.3s;
        z-index: 999;
        width: 260px !important;
        transform: none !important;
    }

    .sidebar.active {
        left: 0;
    }

    .main-content {
        margin-left: 0 !important;
    }
    
    .sidebar.collapsed .nav-text,
    .sidebar.collapsed .logo-text {
        opacity: 1 !important;
        display: block !important;
    }
    
    .sidebar.collapsed .sidebar-item {
        justify-content: flex-start !important;
        padding: 0.75rem 1rem !important;
    }

    .global-bottom-nav {
        left: 0;
        padding: 0.45rem 0.55rem calc(0.55rem + env(safe-area-inset-bottom));
    }

    .global-bottom-nav-inner {
        gap: 0.35rem;
    }

    .global-tab-item,
    .global-dark-toggle {
        min-height: 48px;
        font-size: 10px;
    }

    .has-global-bottom-nav .main-content {
        padding-bottom: 92px;
    }

    .topbar {
        padding: 0 12px;
    }

    .topbar-title {
        font-size: 1.35rem;
    }

    .topbar-search {
        min-width: 0;
        width: 44px;
        padding: 0;
        justify-content: center;
    }

    .topbar-stats {
        display: inline-flex;
        gap: 0.3rem;
    }

    .topbar-stats .streak,
    .topbar-stats .xp-total {
        font-size: 0.65rem;
        padding: 0.18rem 0.4rem;
        gap: 0.2rem;
    }

    .topbar-icon-btn {
        display: none;
    }

    .topbar-search input {
        display: none;
    }

    /* Premium section on mobile — full width, compact, always visible text */
    .sidebar-premium {
        padding: 0.65rem 0.75rem;
        border-radius: 0.75rem;
    }

    .sidebar-premium h3 {
        font-size: 0.8rem;
    }

    .sidebar-premium p {
        font-size: 0.68rem;
        margin-bottom: 0.45rem;
    }

    .sidebar-premium .upgrade-btn {
        padding: 0.45rem 0.5rem !important;
        font-size: 0.72rem !important;
        border-radius: 0.5rem;
        width: 100%;
    }

    /* Always show premium text on mobile even when sidebar was collapsed on desktop */
    .sidebar.collapsed .sidebar-premium h3,
    .sidebar.collapsed .sidebar-premium p {
        display: block !important;
    }

    .sidebar.collapsed .sidebar-premium .upgrade-btn span {
        display: inline !important;
    }
}

/* Settings Modal */
.settings-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s var(--premium-ease), visibility 0.3s var(--premium-ease);
}

.settings-modal.active {
    opacity: 1;
    visibility: visible;
}

.settings-modal-content {
    background: var(--color-surface);
    border-radius: 1.25rem;
    padding: 1.5rem;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: translateY(12px) scale(0.97);
    transition: transform 0.35s var(--premium-ease);
    max-height: 90dvh;
    overflow-y: auto;
}

.settings-modal.active .settings-modal-content {
    transform: translateY(0) scale(1);
}

.settings-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.settings-modal-title {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--color-primary-600);
}

.settings-modal-title svg {
    flex-shrink: 0;
}

.settings-modal-header h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-primary-600);
    margin: 0;
}

.settings-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    color: var(--color-muted);
    transition: background 0.2s, color 0.2s;
    line-height: 0;
}

.settings-close-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-primary-600);
}

.settings-section {
    margin-bottom: 1.25rem;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-muted);
    margin: 0 0 0.5rem 0.25rem;
    opacity: 0.7;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 0.85rem;
    border-radius: 0.75rem;
    background: var(--color-surface-soft);
    border: 1px solid var(--color-border);
    margin-bottom: 0.4rem;
    text-decoration: none;
    color: inherit;
    transition: background 0.2s, border-color 0.2s, transform 0.2s var(--premium-ease);
    width: 100%;
    cursor: pointer;
}

.settings-row:last-child {
    margin-bottom: 0;
}

a.settings-row:hover,
.settings-row--btn:hover {
    background: var(--color-surface);
    border-color: var(--color-primary-200);
    transform: translateY(-1px);
}

.settings-row--toggle {
    cursor: default;
}

.settings-row--toggle:hover {
    transform: none;
}

.settings-row-icon {
    width: 34px;
    height: 34px;
    border-radius: 0.6rem;
    background: rgba(27, 124, 121, 0.1);
    color: var(--color-primary-500);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.settings-row-icon--gold {
    background: rgba(233, 188, 50, 0.12);
    color: var(--color-accent-600);
}

.settings-row-icon--danger {
    background: rgba(220, 38, 38, 0.08);
    color: #dc2626;
}

.settings-row-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.settings-row-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-primary-600);
    line-height: 1.3;
}

.settings-row-desc {
    font-size: 0.72rem;
    color: var(--color-muted);
    line-height: 1.3;
    opacity: 0.8;
}

.settings-row-arrow {
    flex-shrink: 0;
    color: var(--color-muted);
    opacity: 0.5;
}

.settings-row--danger .settings-row-title {
    color: #dc2626;
}

.settings-row--danger .settings-row-desc {
    color: #dc2626;
    opacity: 0.7;
}

.settings-row--danger {
    background: rgba(220, 38, 38, 0.04);
    border-color: rgba(220, 38, 38, 0.12);
    text-align: left;
    font-family: inherit;
}

.settings-row--danger:hover {
    background: rgba(220, 38, 38, 0.08);
    border-color: rgba(220, 38, 38, 0.25);
}

/* Toggle Switch */
.settings-toggle {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
    cursor: pointer;
}

.settings-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.settings-toggle-track {
    position: absolute;
    inset: 0;
    background: var(--color-border);
    border-radius: 100px;
    transition: background 0.25s var(--premium-ease);
}

.settings-toggle-track::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    transition: transform 0.25s var(--premium-ease);
}

.settings-toggle input:checked + .settings-toggle-track {
    background: var(--color-primary-500);
}

.settings-toggle input:checked + .settings-toggle-track::after {
    transform: translateX(18px);
}

/* Dark mode overrides for settings modal */
body.theme-dark .settings-modal-header h3,
body.theme-dark .settings-modal-title {
    color: var(--text-primary);
}

body.theme-dark .settings-modal-title svg {
    color: var(--color-accent-500);
}

body.theme-dark .settings-modal-content {
    background: var(--bg-surface);
}

body.theme-dark .settings-close-btn {
    color: var(--text-muted);
}

body.theme-dark .settings-close-btn:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text-primary);
}

body.theme-dark .settings-row {
    background: var(--bg-surface);
    border-color: var(--border);
}

body.theme-dark a.settings-row:hover,
body.theme-dark .settings-row--btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--color-accent-500);
}

body.theme-dark .settings-row-title {
    color: var(--text-primary);
}

body.theme-dark .settings-row-desc {
    color: var(--text-muted);
}

body.theme-dark .settings-toggle-track {
    background: var(--border);
}

body.theme-dark .settings-toggle input:checked + .settings-toggle-track {
    background: var(--color-primary-500);
}

body.theme-dark .settings-row--danger {
    background: rgba(220, 38, 38, 0.06);
    border-color: rgba(220, 38, 38, 0.15);
}

body.theme-dark .settings-row--danger:hover {
    background: rgba(220, 38, 38, 0.12);
    border-color: rgba(220, 38, 38, 0.3);
}

/* Theme pill group inside settings modal */
.settings-row--theme-picker {
    align-items: flex-start;
    cursor: default;
}

.settings-row--theme-picker:hover {
    transform: none;
    background: var(--color-surface-soft);
    border-color: var(--color-border);
}

.theme-pill-group {
    display: flex;
    gap: 0.4rem;
    margin-top: 0.45rem;
    flex-wrap: wrap;
}

.theme-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.7rem;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border: 1.5px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-muted);
    transition: all 0.2s var(--premium-ease);
    font-family: inherit;
    line-height: 1;
}

.theme-pill:hover {
    border-color: var(--color-primary-500);
    color: var(--color-primary-600);
    background: var(--color-primary-50);
}

.theme-pill.active {
    background: var(--color-primary-600);
    border-color: var(--color-primary-600);
    color: #fff;
}

body.theme-dark .theme-pill {
    background: var(--bg-surface);
    border-color: var(--border);
    color: var(--text-muted);
}

body.theme-dark .theme-pill:hover {
    border-color: var(--color-accent-500);
    color: var(--color-accent-500);
    background: var(--bg-surface-hover);
}

body.theme-dark .theme-pill.active {
    background: var(--color-accent-500);
    border-color: var(--color-accent-500);
    color: var(--color-primary-700);
}

body.theme-dark .settings-row--theme-picker:hover {
    background: var(--bg-surface);
    border-color: var(--border);
}

/* Settings footer button — full-width row style */
.sidebar-icon-btn--settings {
    flex: 1;
    justify-content: flex-start;
    gap: 1rem;
    padding: 0.75rem 1rem;
}

.sidebar.collapsed .sidebar-icon-btn--settings,
body.sidebar-collapsed .sidebar .sidebar-icon-btn--settings {
    justify-content: center;
    padding: 0.75rem;
}

/* Global Light Theme */
body:not(.theme-dark):not(.dark) {
    background: var(--color-background) !important;
    color: var(--color-muted) !important;
}

body:not(.theme-dark):not(.dark) .main-content,
body:not(.theme-dark):not(.dark) .topbar,
body:not(.theme-dark):not(.dark) header {
    background: var(--color-background) !important;
    color: var(--color-muted) !important;
    border-color: var(--color-border) !important;
}

body:not(.theme-dark):not(.dark) .topbar-title {
    color: var(--color-primary-600) !important;
}

body:not(.theme-dark):not(.dark) .bg-white:not([class*="bg-gradient"]),
body:not(.theme-dark):not(.dark) .high-contrast-card,
body:not(.theme-dark):not(.dark) .edu-card:not([class*="bg-gradient"]),
body:not(.theme-dark):not(.dark) .status-card {
    background: var(--color-surface) !important;
    border-color: var(--color-border) !important;
    color: var(--color-muted) !important;
}

body:not(.theme-dark):not(.dark) [class*="text-black"],
body:not(.theme-dark):not(.dark) [class*="text-gray"] {
    color: var(--color-muted) !important;
}

body:not(.theme-dark):not(.dark) .text-primary {
    color: var(--color-primary-600) !important;
}

/* Global Dark Theme */
:root.dark,
html.dark,
body.dark,
body.theme-dark,
html.theme-dark {
    --bg-main: #0B2F2E;
    --bg-surface: #154544;
    --bg-surface-hover: #1C5A58;
    --text-primary: #F5F7F6;
    --text-muted: #A7C3C1;
    --border: #2E6A68;

    --color-surface: var(--bg-surface);
    --color-surface-soft: var(--bg-surface-hover);
    --color-background: var(--bg-main);
    --color-muted: var(--text-muted);
    --color-border: var(--border);
    --color-shadow: rgba(0, 0, 0, 0.6);

    background: var(--color-background) !important;
    color: var(--text-primary) !important;
}

body.theme-dark .main-content,
body.theme-dark .topbar,
body.theme-dark header {
    background: var(--bg-main) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}

body.theme-dark .topbar-title {
    color: var(--text-primary) !important;
}

body.theme-dark .topbar-search,
body.theme-dark .topbar-icon-btn,
body.theme-dark .topbar-avatar {
    background: var(--bg-surface);
    border-color: var(--border);
    color: var(--text-primary);
}

body.theme-dark .topbar-search input {
    color: var(--text-primary);
    background: var(--bg-surface);
}

body.theme-dark .topbar-search input::placeholder {
    color: var(--text-muted);
}

body.theme-dark .bg-white:not([class*="bg-gradient"]),
body.theme-dark .high-contrast-card,
body.theme-dark .edu-card:not([class*="bg-gradient"]),
body.theme-dark .status-card {
    background: var(--color-surface) !important;
    color: var(--text-primary) !important;
    border-color: var(--color-border) !important;
}

body.theme-dark [class*="text-black"],
body.theme-dark [class*="text-gray"] {
    color: var(--text-primary) !important;
}

body.theme-dark .text-primary,
body.theme-dark h1,
body.theme-dark h2,
body.theme-dark h3,
body.theme-dark h4,
body.theme-dark .font-bold,
body.theme-dark .font-black {
    color: var(--text-primary) !important;
}

body.theme-dark p,
body.theme-dark span,
body.theme-dark small {
    color: var(--text-muted);
}

body.theme-dark .global-bottom-nav {
    background: var(--bg-main);
    border-top-color: var(--border);
}

body.theme-dark .global-tab-item,
body.theme-dark .global-dark-toggle {
    color: var(--text-primary);
    background: var(--bg-surface);
    border-color: var(--border);
}

body.theme-dark .global-tab-item:hover,
body.theme-dark .global-dark-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-surface-hover);
}

body.theme-dark .global-tab-item.active {
    background: var(--color-accent-500);
    color: var(--color-primary-600);
}

body.theme-dark .edu-card,
body.theme-dark .high-contrast-card,
body.theme-dark .status-card {
    background-image: linear-gradient(160deg, var(--color-surface) 0%, var(--color-surface-soft) 100%) !important;
    box-shadow:
        0 2px 4px color-mix(in srgb, var(--color-shadow) 55%, transparent),
        0 10px 24px -16px color-mix(in srgb, var(--color-shadow) 75%, transparent),
        inset 0 1px 0 color-mix(in srgb, var(--color-surface) 8%, transparent) !important;
}

body.theme-dark .chapter-tile:hover,
html.dark .chapter-tile:hover,
body.dark .chapter-tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
}

body.theme-dark .edu-card:hover,
body.theme-dark .high-contrast-card:hover,
body.theme-dark .status-card:hover {
    box-shadow:
    0 0 0 1px color-mix(in srgb, var(--color-accent-500) 30%, transparent),
    0 12px 28px -16px color-mix(in srgb, var(--color-shadow) 85%, transparent),
    0 0 22px color-mix(in srgb, var(--color-accent-500) 22%, transparent) !important;
}

body.theme-dark input,
body.theme-dark textarea,
body.theme-dark select {
    background: var(--color-surface) !important;
    color: var(--text-primary) !important;
    border-color: var(--color-border) !important;
}

@media (prefers-reduced-motion: reduce) {
    .global-tab-item,
    .global-dark-toggle {
        transition: none !important;
    }
    .global-tab-item:active,
    .global-dark-toggle:active {
        transform: none !important;
    }

    .edu-card,
    .high-contrast-card,
    .status-card {
        transition: none !important;
    }
    .edu-card:hover,
    .high-contrast-card:hover,
    .status-card:hover,
    .edu-card:active,
    .high-contrast-card:active,
    .status-card:active {
        transform: none !important;
        filter: none !important;
    }
}