/* ==========================================================================
   Lingua World Path — navigation.css
   Two sidebars: left (main nav + Moje Zestawy + Nauczyciel),
   right (learning modes + study progress).
   ========================================================================== */

/* ── Design tokens — DARK GAMING THEME ──────────────────────────────────────
   Quest/RPG-inspired palette: deep purple-black bg, neon purple accents,
   glowing surfaces. All elements that use these tokens auto-adopt the theme.
   Hardcoded #fff/#f8f9fa in app.js inline styles are overridden via
   .ag-main-content rules below.
   ============================================================================ */
:root {
    --sidebar-width:           240px;
    --sidebar-width-collapsed: 72px;
    --right-sidebar-width:     240px;

    /* Background layers — darkest at app level, lighter for cards/modals */
    --bg-app:                  #0d0b1f;
    --bg-surface:              #1a1736;          /* cards, modals, sections */
    --bg-surface-2:            #25214a;          /* hover state, inputs */
    --bg-elevated:             #2a2654;          /* dropdowns, popovers */

    /* Borders — subtle, glowing on focus */
    --border-subtle:           rgba(167,139,250,.12);
    --border-strong:           rgba(167,139,250,.3);

    /* Text */
    --text-primary:            #f1edff;
    --text-secondary:          #a8a3c7;
    --text-muted:              #6b6588;

    /* Accent — neon purple/violet, the "quest energy" colour */
    --accent:                  #a78bfa;          /* violet-400 */
    --accent-strong:           #8b5cf6;          /* violet-500 */
    --accent-gradient:         linear-gradient(135deg, #a78bfa 0%, #ec4899 100%);
    --accent-glow:             0 0 20px rgba(167, 139, 250, .35);

    /* Quest-style state colours */
    --gold:                    #fbbf24;
    --gold-glow:               0 0 16px rgba(251, 191, 36, .4);
    --success:                 #34d399;
    --danger:                  #f87171;

    /* Left sidebar — dark, matches main */
    --sidebar-bg:              #100d24;
    --sidebar-border:          var(--border-subtle);
    --sidebar-text:            var(--text-secondary);
    --sidebar-text-muted:      var(--text-muted);
    --sidebar-text-active:     var(--accent);
    --sidebar-hover-bg:        rgba(167, 139, 250, .08);
    --sidebar-active-bg:       linear-gradient(135deg, rgba(167,139,250,.18), rgba(236,72,153,.12));

    /* Right sidebar — same dark family */
    --right-sidebar-bg:        #100d24;
    --right-sidebar-border:    var(--border-subtle);
    --right-sidebar-text:      var(--text-secondary);
    --right-sidebar-text-active: var(--text-primary);
    --right-sidebar-hover:     rgba(167, 139, 250, .08);
    --right-sidebar-muted:     var(--text-muted);

    --radius-md:               12px;
    --radius-lg:               16px;
    --transition-fast:         0.15s ease;
    --transition-slow:         0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --z-sidebar:        160; 
    --z-mobile-overlay: 150;
    --z-mobile-toggle:  200;
    --z-modal:          8000;
    --z-auth-gateway:   9000;
    --z-toast:          9500;
}

/* Body + app background */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}
body {
    background: radial-gradient(ellipse at top, #1a1640 0%, #0d0b1f 50%, #08071a 100%);
    color: var(--text-primary);
}

/* ── App layout: 3-column flex (sidebar | main | right sidebar) ──────────── */
.ag-app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* =========================================================================
   LEFT SIDEBAR
   ========================================================================= */
.ag-sidebar {
    width:           var(--sidebar-width);
    min-width:       var(--sidebar-width);
    background:      var(--sidebar-bg);
    border-right:    1px solid var(--sidebar-border);
    display:         flex;
    flex-direction:  column;
    overflow-y:      auto;
    overflow-x:      hidden;
    z-index:         var(--z-sidebar);
    transition:      width var(--transition-slow), min-width var(--transition-slow);
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,.1) transparent;
}

.ag-sidebar.is-collapsed {
    width:     var(--sidebar-width-collapsed);
    min-width: var(--sidebar-width-collapsed);
}

/* Header (logo + collapse toggle) */
.ag-sidebar-header {
    display:      flex;
    align-items:  center;
    gap:          12px;
    padding:      24px 20px 16px;
    flex-shrink:  0;
}

.ag-sidebar-logo {
    flex:                 1;
    font-size:            18px;
    font-weight:          800;
    letter-spacing:       2px;
    background:           var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip:      text;
    -webkit-text-fill-color: transparent;
    color:                transparent;
    white-space:          nowrap;
    overflow:             hidden;
    transition:           opacity var(--transition-slow);
}

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

.ag-sidebar-toggle {
    background:    none;
    border:        none;
    color:         var(--sidebar-text-muted);
    cursor:        pointer;
    padding:       6px;
    display:       flex;
    align-items:   center;
    justify-content: center;
    border-radius: 8px;
    transition:    background var(--transition-fast), color var(--transition-fast);
    flex-shrink:   0;
}
.ag-sidebar-toggle:hover { background: var(--sidebar-hover-bg); color: var(--sidebar-text); }
.ag-sidebar-toggle:focus-visible { outline: 2px solid var(--sidebar-text-active); outline-offset: 2px; }
.ag-sidebar-toggle svg { width: 18px; height: 18px; transition: transform var(--transition-slow); }
.ag-sidebar.is-collapsed .ag-sidebar-toggle svg { transform: rotate(180deg); }

/* Menu */
.ag-sidebar-menu {
    flex:       1;
    padding:    8px 12px;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.ag-menu-item {
    display:        flex;
    align-items:    center;
    gap:            12px;
    padding:        11px 14px;
    border-radius:  var(--radius-md);
    color:          var(--sidebar-text);
    text-decoration: none;
    font-size:      14px;
    font-weight:    500;
    margin-bottom:  2px;
    transition:     background var(--transition-fast), color var(--transition-fast);
    white-space:    nowrap;
}
.ag-menu-item:hover { background: var(--sidebar-hover-bg); }
.ag-menu-item:focus-visible { outline: 2px solid var(--sidebar-text-active); outline-offset: -2px; }
.ag-menu-item svg { flex-shrink: 0; width: 18px; height: 18px; }
.ag-menu-item.is-active {
    background:  var(--sidebar-active-bg);
    color:       var(--sidebar-text-active);
    font-weight: 700;
}
.ag-menu-item.ag-menu-add { color: var(--sidebar-text-active); font-weight: 700; }

.ag-menu-label {
    flex:          1;
    overflow:      hidden;
    text-overflow: ellipsis;
    transition:    opacity var(--transition-slow);
}

.ag-sidebar.is-collapsed .ag-menu-label { opacity: 0; pointer-events: none; }
.ag-sidebar.is-collapsed .ag-menu-item { justify-content: center; padding: 11px; gap: 0; }

.ag-menu-divider {
    height:     1px;
    background: var(--sidebar-border);
    margin:     8px 0;
}

.ag-menu-section-header {
    font-size:      11px;
    font-weight:    700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color:          var(--sidebar-text-muted);
    padding:        8px 14px 4px;
    white-space:    nowrap;
    overflow:       hidden;
    transition:     opacity var(--transition-slow), height var(--transition-slow), padding var(--transition-slow);
}
.ag-sidebar.is-collapsed .ag-menu-section-header {
    opacity: 0; height: 0; padding: 0; margin: 0;
}

/* ── Sub-menu items: deck list + class list ──────────────────────────────── */
.ag-sidebar-list {
    margin-bottom: 4px;
    transition:    opacity var(--transition-slow);
}
.ag-sidebar.is-collapsed .ag-sidebar-list { opacity: 0; pointer-events: none; height: 0; overflow: hidden; }

.ag-menu-item-sub {
    padding:       8px 14px 8px 24px;
    font-size:     13px;
    font-weight:   500;
    color:         var(--sidebar-text);
    border-radius: 8px;
    margin-bottom: 1px;
}
.ag-menu-item-sub:hover { background: var(--sidebar-hover-bg); }
.ag-menu-item-sub svg { width: 14px; height: 14px; opacity: 0.65; }
.ag-menu-item-sub .ag-sub-meta {
    font-size: 11px;
    color: var(--sidebar-text-muted);
    margin-left: auto;
    flex-shrink: 0;
}

.ag-sidebar-empty {
    padding:    8px 14px 8px 24px;
    font-size:  12px;
    color:      var(--sidebar-text-muted);
    font-style: italic;
}

/* Deck search input */
.ag-sidebar-search {
    position: relative;
    margin: 4px 4px 8px;
    transition: opacity var(--transition-slow), height var(--transition-slow), margin var(--transition-slow);
}
.ag-sidebar.is-collapsed .ag-sidebar-search {
    opacity: 0; pointer-events: none; height: 0; margin: 0; overflow: hidden;
}

.ag-sidebar-search-icon {
    position: absolute;
    left: 12px; top: 50%;
    width: 14px; height: 14px;
    color: var(--sidebar-text-muted);
    pointer-events: none;
    transform: translateY(-50%);
}

.ag-sidebar-search-input {
    width: 100%;
    padding: 8px 12px 8px 34px;
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    background: var(--sidebar-hover-bg);
    font-size: 13px;
    font-family: 'Poppins', sans-serif;
    color: var(--sidebar-text);
    outline: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    box-sizing: border-box;
}
.ag-sidebar-search-input::placeholder { color: var(--sidebar-text-muted); }
.ag-sidebar-search-input:focus {
    border-color: var(--sidebar-text-active);
    background: #fff;
}
/* Hide the native search input "X" clear button — we don't need browser chrome here */
.ag-sidebar-search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

/* Footer / user profile */
.ag-sidebar-footer {
    padding:     16px;
    border-top:  1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.ag-user-profile {
    display:       flex;
    align-items:   center;
    gap:           12px;
    cursor:        pointer;
    border-radius: var(--radius-md);
    padding:       6px;
    margin:        -6px;
    transition:    background var(--transition-fast);
}
.ag-user-profile:hover { background: var(--sidebar-hover-bg); }

.ag-user-avatar {
    width:           36px;
    height:          36px;
    border-radius:   50%;
    background:      var(--accent-gradient);
    display:         flex;
    align-items:     center;
    justify-content: center;
    color:           #fff;
    font-weight:     700;
    font-size:       14px;
    flex-shrink:     0;
}

.ag-user-info {
    flex:       1;
    min-width:  0;
    overflow:   hidden;
    transition: opacity var(--transition-slow);
}
.ag-sidebar.is-collapsed .ag-user-info { opacity: 0; pointer-events: none; }

.ag-user-name {
    font-weight:   600;
    font-size:     13px;
    color:         #343a40;
    display:       block;
    white-space:   nowrap;
    overflow:      hidden;
    text-overflow: ellipsis;
}

.ag-logout-link {
    font-size:       12px;
    color:           var(--sidebar-text-muted);
    text-decoration: none;
    transition:      color var(--transition-fast);
}
.ag-logout-link:hover { color: #ff6b6b; }

/* =========================================================================
   MAIN CONTENT
   ========================================================================= */
.ag-main-content {
    flex:       1;
    overflow-y: auto;
    padding:    36px;
    background: #f8f9fa;
}

/* =========================================================================
   RIGHT SIDEBAR (learning modes + progress)
   ========================================================================= */
.ag-right-sidebar {
    width:           280px;
    min-width:       280px;
    height:          100vh;
    background:      var(--right-sidebar-bg);
    display:         flex;
    flex-direction:  column;
    flex-shrink:     0;
    overflow-y:      auto;
    overflow-x:      hidden;
    border-left:     1px solid var(--right-sidebar-border);
    padding:         28px 14px;
    box-sizing:      border-box;
}

.ag-right-sidebar-header {
    font-size:      10px;
    font-weight:    700;
    text-transform: uppercase;
    letter-spacing: 1.8px;
    color:          var(--right-sidebar-muted);
    margin-bottom:  16px;
    padding:        0 6px;
}

.ag-mode-nav {
    display:        flex;
    flex-direction: column;
    gap:            6px;
}

.ag-mode-btn {
    width:           100%;
    padding:         12px 14px;
    border-radius:   var(--radius-md);
    border:          none;
    cursor:          pointer;
    background:      var(--right-sidebar-hover);
    color:           var(--right-sidebar-text);
    font-weight:     600;
    font-size:       13px;
    font-family:     'Poppins', sans-serif;
    text-align:      left;
    display:         flex;
    align-items:     center;
    gap:             10px;
    transition:      background var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}
.ag-mode-btn:hover {
    background: rgba(255,255,255,0.12);
    color:      var(--right-sidebar-text-active);
}
.ag-mode-btn:active { transform: scale(0.98); }
.ag-mode-btn:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: -2px;
}

.ag-mode-btn.is-active {
    background: var(--accent-gradient);
    color:      var(--right-sidebar-text-active);
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(102,126,234,0.35);
}
.ag-mode-btn.is-active:hover { background: var(--accent-gradient); }

.ag-mode-icon { font-size: 17px; flex-shrink: 0; }
.ag-mode-label { flex: 1; }

/* Footer: progress display */
.ag-right-sidebar-footer {
    margin-top:    auto;
    padding:       16px;
    border-radius: 12px;
    background:    rgba(167, 139, 250, .06);
    border:        1px solid rgba(167, 139, 250, .15);
    margin-left:   6px;
    margin-right:  6px;
    margin-bottom: 6px;
}

/* ── ACTIVE state (during study session) ────────────────────────────────── */
.ag-progress-active {
    background: linear-gradient(135deg, rgba(167,139,250,.12), rgba(236,72,153,.08));
    border:     1px solid rgba(167, 139, 250, .35);
    box-shadow: 0 0 16px rgba(167, 139, 250, .15);
}

.ag-progress-header {
    display:        flex;
    align-items:    center;
    gap:            10px;
    margin-bottom:  10px;
}

.ag-progress-icon {
    width:           36px;
    height:          36px;
    border-radius:   10px;
    background:      var(--accent-gradient);
    display:         flex;
    align-items:     center;
    justify-content: center;
    font-size:       18px;
    flex-shrink:     0;
    box-shadow:      0 4px 12px rgba(167, 139, 250, .35);
}

.ag-progress-label {
    font-size:      9px;
    font-weight:    700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color:          var(--accent);
    margin-bottom:  2px;
}

.ag-progress-count {
    font-size:    22px;
    font-weight:  900;
    color:        #fff;
    line-height:  1;
}
.ag-progress-count #study-progress-total,
.ag-progress-count .ag-progress-divider {
    font-size:   13px;
    font-weight: 600;
    color:       rgba(255, 255, 255, .5);
}

/* Progress bar — animated gradient fill */
.ag-progress-bar-track {
    height:        6px;
    background:    rgba(255, 255, 255, .08);
    border-radius: 3px;
    overflow:      hidden;
    margin:        10px 0 8px;
}
.ag-progress-bar-fill {
    height:           100%;
    width:            0%;
    background:       linear-gradient(90deg, #a78bfa, #ec4899);
    border-radius:    3px;
    transition:       width .5s cubic-bezier(.4, 0, .2, 1);
    box-shadow:       0 0 8px rgba(236, 72, 153, .5);
}

.ag-progress-detail {
    font-size:  11px;
    color:      rgba(255, 255, 255, .55);
    font-weight: 600;
}

/* ── EMPTY state (no session active) ────────────────────────────────────── */
.ag-progress-empty {
    text-align: center;
    padding:    20px 14px;
}

.ag-progress-empty-icon {
    font-size:     32px;
    margin-bottom: 8px;
    display:       inline-block;
    animation:     emptyPulse 2.5s ease-in-out infinite;
    filter:        drop-shadow(0 0 12px rgba(167, 139, 250, .4));
}

@keyframes emptyPulse {
    0%, 100% { transform: scale(1); opacity: .85; }
    50%      { transform: scale(1.1); opacity: 1; }
}

.ag-progress-empty .ag-progress-label {
    color:          var(--accent);
    margin-bottom:  6px;
}

.ag-empty-detail {
    font-size:   11px;
    color:       rgba(255, 255, 255, .55);
    line-height: 1.45;
    font-weight: 500;
}

/* Reduced motion respects preference */
@media (prefers-reduced-motion: reduce) {
    .ag-progress-empty-icon { animation: none; }
}

/* =========================================================================
   MOBILE HAMBURGER + OVERLAY
   ========================================================================= */
.ag-mobile-nav-toggle { display: none; }

.ag-mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: var(--z-mobile-overlay);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity var(--transition-slow);
}
.ag-mobile-overlay.is-active { display: block; opacity: 1; }

/* =========================================================================
   MOBILE BREAKPOINT (≤992px) — left sidebar becomes drawer, right hidden
   ========================================================================= */
@media (max-width: 992px) {
    .ag-app-layout {
        display: block;
        height: auto;
        overflow: visible;
    }

    .ag-sidebar {
        position:        fixed;
        top:             0;
        left:            0;
        bottom:          0;
        width:           min(280px, 85vw);          /* don't overflow tiny screens */
        min-width:       min(280px, 85vw);
        height:          100vh;
        height:          100dvh;                     /* dynamic viewport — better on iOS */
        transform:       translateX(-100%);
        transition:      transform var(--transition-slow);
        box-shadow:      0 0 40px rgba(0, 0, 0, 0.5);
        display:         flex;
        flex-direction:  column;
        overflow-y:      auto;                       /* allow scroll if menu is long */
        overflow-x:      hidden;
        -webkit-overflow-scrolling: touch;           /* momentum scroll on iOS */
        padding-top:     env(safe-area-inset-top);   /* iPhone X+ notch */
        padding-bottom:  env(safe-area-inset-bottom);
    }
    .ag-sidebar.is-mobile-open { transform: translateX(0); }

    /* Lock body scroll while the drawer is open — prevents background
       from scrolling under user's finger while they're navigating menu */
    body.has-mobile-drawer-open { overflow: hidden; }

    /* Disable collapse mode on mobile — drawer pattern wins */
    .ag-sidebar.is-collapsed { width: min(280px, 85vw); min-width: min(280px, 85vw); }
    .ag-sidebar.is-collapsed .ag-sidebar-logo,
    .ag-sidebar.is-collapsed .ag-menu-label,
    .ag-sidebar.is-collapsed .ag-user-info,
    .ag-sidebar.is-collapsed .ag-sidebar-list { opacity: 1; pointer-events: auto; height: auto; overflow: visible; }
    .ag-sidebar.is-collapsed .ag-menu-section-header { opacity: 1; height: auto; padding: 8px 14px 4px; }
    .ag-sidebar.is-collapsed .ag-menu-item { justify-content: flex-start; padding: 11px 14px; gap: 12px; }

    .ag-sidebar-toggle { display: none; }

    .ag-mobile-nav-toggle {
        display:         flex;
        position:        fixed;
        top:             16px;
        left:            16px;
        z-index:         var(--z-mobile-toggle);
        width:           44px;
        height:          44px;
        background:      var(--accent-gradient);
        color:           #fff;
        border:          none;
        border-radius:   12px;
        cursor:          pointer;
        box-shadow:      0 4px 16px rgba(102, 126, 234, 0.35);
        align-items:     center;
        justify-content: center;
        transition:      transform var(--transition-fast);
    }
    .ag-mobile-nav-toggle:active { transform: scale(0.95); }
    .ag-mobile-nav-toggle svg { width: 20px; height: 20px; }

    .ag-main-content {
        height:     auto;
        min-height: 100vh;
        padding:    80px 16px 100px;          /* extra bottom for FAB + safe area */
        padding-bottom: calc(100px + env(safe-area-inset-bottom));
    }

    /* Quest grid → single column on small phones for breathing room */
    .ag-main-content [style*="grid-template-columns:repeat(auto-fill,minmax(280px"] {
        grid-template-columns: 1fr !important;
    }

    /* Badge grid → 3 cols on phones, was 4 */
    .ag-main-content [style*="grid-template-columns:repeat(auto-fill,minmax(120px"] {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    /* Stat cards 4-column grid → 2 cols on mobile */
    .ag-main-content [style*="grid-template-columns:repeat(4,1fr)"],
    .ag-main-content [style*="grid-template-columns:repeat(4, 1fr)"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Modals — full screen on tiny phones */
    .ag-modal-content {
        max-width: calc(100vw - 32px) !important;
        margin: 16px;
    }

    /* Hide the right sidebar on mobile — it would crowd the screen */
    .ag-right-sidebar { display: none; }
}

@media (min-width: 993px) {
    .ag-mobile-nav-toggle,
    .ag-mobile-overlay { display: none !important; }
}

/* =========================================================================
   REDUCED MOTION
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
    .ag-sidebar,
    .ag-sidebar-logo,
    .ag-menu-label,
    .ag-menu-section-header,
    .ag-user-info,
    .ag-sidebar-list,
    .ag-sidebar-toggle svg,
    .ag-mobile-overlay,
    .ag-main-content,
    .ag-mode-btn {
        transition: none !important;
    }
}

/* =========================================================================
   DARK THEME OVERRIDES
   These rules target inline styles in app.js that hardcode #fff/#f8f9fa.
   Keeping them scoped to .ag-main-content so the auth gateway and other
   shells aren't affected.
   ========================================================================= */

.ag-main-content {
    background: transparent !important;   /* let body's radial-gradient show through */
    color: var(--text-primary);
}

/* Cards: anything with "background:#fff" inline → become surface colour.
   We use [style*="..."] attribute selectors which are inefficient but the
   only way to override inline styles without rewriting all inline JS. */
.ag-main-content [style*="background:#fff"],
.ag-main-content [style*="background: #fff"],
.ag-main-content [style*="background:#ffffff"],
.ag-main-content [style*="background:white"] {
    background: var(--bg-surface) !important;
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}



/* ── FLASHCARD EXCEPTION ──────────────────────────────────────────────────
   Cards in study modes (Fiszki/Wybór/Pisanie/Rozsypanka) keep their light
   background and dark text — designed for vocabulary readability. The
   surrounding app stays dark; only the card itself is light.

   We use a class (.ag-flashcard) instead of fighting [style*="..."]
   selectors because attribute selectors match descendants too, leading to
   "white-on-white" failures. A class beats inline-style overrides cleanly. */

.ag-main-content .ag-flashcard,
.ag-main-content .ag-flashcard * {
    background-color: transparent;
    border-color: transparent;
}

/* Force the card itself to be white, regardless of inline style overrides */
.ag-main-content .ag-flashcard {
    background-color: #fff !important;
    color: #212529 !important;
    border: 1px solid #e9ecef !important;
}

/* Inner panels (front face, back face, options) — front white, back gradient */
.ag-main-content .ag-flashcard > div {
    background-color: transparent !important;
}
.ag-main-content .ag-flashcard [style*="background:#fff"]:not([style*="background:#fff0"]):not([style*="background:#ffe"]):not(button) {
    background-color: #fff !important;
    color: #212529 !important;
}

/* Back face of the flip card stays gradient */
.ag-main-content .ag-flashcard [style*="linear-gradient(135deg,#667eea,#764ba2)"] {
    background: linear-gradient(135deg,#667eea,#764ba2) !important;
}

/* Text colours inside the card — preserve original design */
.ag-main-content .ag-flashcard h1,
.ag-main-content .ag-flashcard h2,
.ag-main-content .ag-flashcard h3,
.ag-main-content .ag-flashcard p,
.ag-main-content .ag-flashcard div {
    color: #212529;
}
/* Speaker button on a gradient background (not used on flashcard anymore but
   kept defensively) */
.ag-main-content .ag-flashcard [style*="color:#fff"] {
    color: #fff !important;
}
/* Question/answer label (smaller purple text) */
.ag-main-content .ag-flashcard [style*="color:#667eea"] {
    color: #667eea !important;
}
/* Hint text under question */
.ag-main-content .ag-flashcard [style*="color:#adb5bd"] {
    color: #adb5bd !important;
}

/* Speaker buttons — keep light theme inside the card */
.ag-main-content .ag-flashcard button[data-tts-front] {
    background: #f1f3f5 !important;
    color: #667eea !important;
    border: none !important;
}
.ag-main-content .ag-flashcard button[data-tts-back] {
    background: rgba(255,255,255,.2) !important;
    color: #fff !important;
    border: none !important;
}

/* Multiple choice option buttons */
.ag-main-content .ag-flashcard button[data-mc-option] {
    background: #fff !important;
    color: #212529 !important;
    border: 2px solid #e9ecef !important;
}

/* Inputs inside flashcard (Pisanie mode) */
.ag-main-content .ag-flashcard input[type="text"] {
    background: #fff !important;
    color: #212529 !important;
    border: 2px solid #e9ecef !important;
}

/* Scrabble letter tiles */
.ag-main-content .ag-flashcard [style*="background:#f1f3f5"] {
    background: #f1f3f5 !important;
    color: #212529 !important;
}

/* Light backgrounds → slightly elevated surface */
.ag-main-content [style*="background:#f8f9fa"],
.ag-main-content [style*="background: #f8f9fa"],
.ag-main-content [style*="background:#f1f3f5"],
.ag-main-content [style*="background: #f1f3f5"] {
    background: var(--bg-surface-2) !important;
    color: var(--text-secondary);
}

/* Hardcoded text colors → adjust to dark theme */
.ag-main-content [style*="color:#212529"],
.ag-main-content [style*="color: #212529"],
.ag-main-content [style*="color:#343a40"],
.ag-main-content [style*="color: #343a40"] {
    color: var(--text-primary) !important;
}

.ag-main-content [style*="color:#495057"],
.ag-main-content [style*="color: #495057"] {
    color: var(--text-secondary) !important;
}

.ag-main-content [style*="color:#868e96"],
.ag-main-content [style*="color: #868e96"],
.ag-main-content [style*="color:#adb5bd"],
.ag-main-content [style*="color: #adb5bd"] {
    color: var(--text-muted) !important;
}

/* Inputs, textareas, selects in main content */
.ag-main-content input[type="text"],
.ag-main-content input[type="email"],
.ag-main-content input[type="password"],
.ag-main-content input[type="number"],
.ag-main-content textarea,
.ag-main-content select {
    background:    var(--bg-surface-2) !important;
    color:         var(--text-primary) !important;
    border:        1.5px solid var(--border-subtle) !important;
    border-radius: 10px;
    transition:    border-color .15s, box-shadow .15s;
}
.ag-main-content input[type="text"]:focus,
.ag-main-content input[type="email"]:focus,
.ag-main-content input[type="password"]:focus,
.ag-main-content input[type="number"]:focus,
.ag-main-content textarea:focus,
.ag-main-content select:focus {
    border-color: var(--accent) !important;
    box-shadow:   var(--accent-glow);
    outline:      none;
}
.ag-main-content input::placeholder,
.ag-main-content textarea::placeholder {
    color: var(--text-muted);
}

/* Primary button — quest-style glow */
.ag-btn-primary {
    background:     var(--accent-gradient) !important;
    color:          #fff !important;
    border:         none;
    border-radius:  10px;
    padding:        12px 24px;
    font-weight:    700;
    cursor:         pointer;
    box-shadow:     0 4px 16px rgba(139, 92, 246, .3);
    transition:     transform .15s, box-shadow .15s;
}
.ag-btn-primary:hover:not(:disabled) {
    transform:  translateY(-1px);
    box-shadow: 0 6px 24px rgba(139, 92, 246, .5);
}
.ag-btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

/* Modals — glassy dark with neon border */
.ag-modal {
    background: rgba(13, 11, 31, .85);
    backdrop-filter: blur(8px);
}
.ag-modal-content {
    background:   var(--bg-surface) !important;
    color:        var(--text-primary);
    border:       1px solid var(--border-strong);
    border-radius: 16px;
    box-shadow:   0 20px 60px rgba(0,0,0,.5), 0 0 40px rgba(167,139,250,.15);
}
.ag-modal-content h2 {
    color: var(--text-primary);
}
.ag-modal-close {
    color: var(--text-muted);
    transition: color .15s;
}
.ag-modal-close:hover {
    color: var(--text-primary);
}

/* Form labels in main content */
.ag-form-group label {
    color: var(--text-secondary);
}

/* Stat cards — the 4 dashboard tiles get a subtle quest glow */
.ag-stat-card {
    background:    var(--bg-surface) !important;
    border:        1px solid var(--border-subtle);
    color:         var(--text-primary);
}
.ag-stat-card:hover {
    border-color: var(--border-strong);
    box-shadow:   0 0 30px rgba(167, 139, 250, .15);
}

/* Headers on dashboard */
.ag-main-content h1,
.ag-main-content h2,
.ag-main-content h3 {
    color: var(--text-primary);
}

/* Fix any inline border colors that look bad on dark bg */
.ag-main-content [style*="border:1px solid #f1f3f5"],
.ag-main-content [style*="border: 1px solid #f1f3f5"],
.ag-main-content [style*="border-bottom:1px solid #f1f3f5"],
.ag-main-content [style*="border-bottom: 1px solid #f1f3f5"],
.ag-main-content [style*="border-bottom:1px solid #f8f9fa"],
.ag-main-content [style*="border-top:1px solid #eee"] {
    border-color: var(--border-subtle) !important;
}

/* Auth gateway stays light/centered for contrast against dark app */
#ag-auth-container {
    background: radial-gradient(ellipse at top, #1a1640, #08071a) !important;
}

/* =========================================================================
   BADGES — quest-style with clear owned/locked states
   ========================================================================= */

.ag-badge {
    display:        flex;
    flex-direction: column;
    align-items:    center;
    gap:            6px;
    padding:        16px 10px;
    border-radius:  14px;
    text-align:     center;
    cursor:         help;
    position:       relative;
    transition:     transform .2s, box-shadow .2s, border-color .2s;
}

.ag-badge-emoji {
    font-size: 36px;
    line-height: 1;
    transition: filter .2s, transform .2s;
}
.ag-badge-label {
    font-size:   11px;
    font-weight: 700;
    line-height: 1.2;
    transition:  color .2s;
}

/* OWNED — gold glow, full saturation, slight float on hover */
.ag-badge[data-badge-owned="true"] {
    background:   linear-gradient(135deg, rgba(251, 191, 36, .18), rgba(245, 158, 11, .12));
    border:       1.5px solid rgba(251, 191, 36, .45);
    box-shadow:   0 0 16px rgba(251, 191, 36, .15);
}
.ag-badge[data-badge-owned="true"] .ag-badge-emoji {
    filter: drop-shadow(0 0 8px rgba(251, 191, 36, .5));
}
.ag-badge[data-badge-owned="true"] .ag-badge-label {
    color: var(--gold);
}
.ag-badge[data-badge-owned="true"]:hover {
    transform:   translateY(-2px);
    border-color: rgba(251, 191, 36, .7);
    box-shadow:   0 4px 24px rgba(251, 191, 36, .35);
}
.ag-badge[data-badge-owned="true"]:hover .ag-badge-emoji {
    transform: scale(1.1);
}

/* LOCKED — dim, desaturated emoji, muted label */
.ag-badge[data-badge-owned="false"] {
    background:   var(--bg-surface-2);
    border:       1.5px solid var(--border-subtle);
    opacity:      0.6;
}
.ag-badge[data-badge-owned="false"] .ag-badge-emoji {
    filter: grayscale(100%) brightness(0.7);
    opacity: 0.7;
}
.ag-badge[data-badge-owned="false"] .ag-badge-label {
    color: var(--text-muted);
}

/* =========================================================================
   MOBILE FAB — Speed-dial for study modes
   Hidden on desktop. On mobile, replaces the right sidebar.
   Tap main FAB → 4 mode buttons fan upward with stagger animation.
   ========================================================================= */

.ag-mode-fab {
    position:        fixed;
    right:           20px;
    bottom:          20px;
    z-index:         var(--z-mobile-toggle);
    display:         none;          /* shown via media query below */
    flex-direction:  column;
    align-items:     center;
    gap:             14px;
    pointer-events:  none;            /* container is non-interactive; only buttons receive clicks */
}

/* Main FAB — always interactive, visible */
.ag-fab-main {
    width:           60px;
    height:          60px;
    border-radius:   50%;
    background:      var(--accent-gradient);
    color:           #fff;
    border:          none;
    cursor:          pointer;
    box-shadow:      0 8px 24px rgba(167, 139, 250, .5);
    display:         flex;
    align-items:     center;
    justify-content: center;
    font-size:       26px;
    font-weight:     900;
    pointer-events:  auto;
    transition:      transform .25s cubic-bezier(.34, 1.56, .64, 1), box-shadow .25s;
    position:        relative;
    order:           999;             /* keep main button at bottom of flex column */
}
.ag-fab-main:active { transform: scale(0.92); }
.ag-fab-main .ag-fab-icon-close {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px; line-height: 1;
    opacity: 0; transform: rotate(-90deg);
    transition: opacity .2s, transform .25s;
}
.ag-mode-fab.is-open .ag-fab-main {
    transform: rotate(135deg);
    box-shadow: 0 8px 24px rgba(236, 72, 153, .55);
}
.ag-mode-fab.is-open .ag-fab-main .ag-fab-icon-default { opacity: 0; }
.ag-mode-fab.is-open .ag-fab-main .ag-fab-icon-close   { opacity: 1; transform: rotate(0); }

/* Mode action buttons — hidden when closed, fan upward with stagger when open */
.ag-fab-action {
    width:            48px;
    height:           48px;
    border-radius:    50%;
    background:       var(--bg-surface);
    color:            var(--text-primary);
    border:           1.5px solid var(--border-strong);
    box-shadow:       0 4px 16px rgba(0,0,0,.4);
    cursor:           pointer;
    display:          flex;
    align-items:      center;
    justify-content:  center;
    font-size:        22px;
    pointer-events:   none;
    opacity:          0;
    transform:        translateY(20px) scale(.6);
    transition:       opacity .22s ease-out, transform .28s cubic-bezier(.34, 1.56, .64, 1);
    position:         relative;
}
/* Tooltip label that floats to the LEFT of the action button */
.ag-fab-action::before {
    content:           attr(data-label);
    position:          absolute;
    right:             56px;
    top:               50%;
    transform:         translateY(-50%);
    background:        var(--bg-surface);
    color:             var(--text-primary);
    border:            1px solid var(--border-strong);
    padding:           4px 10px;
    border-radius:     8px;
    font-size:         12px;
    font-weight:       700;
    white-space:       nowrap;
    pointer-events:    none;
    opacity:           0;
    transition:        opacity .2s;
    box-shadow:        0 2px 8px rgba(0,0,0,.3);
    font-family:       'Poppins', sans-serif;
}

.ag-mode-fab.is-open .ag-fab-action {
    opacity:        1;
    transform:      translateY(0) scale(1);
    pointer-events: auto;
}
.ag-mode-fab.is-open .ag-fab-action::before { opacity: 1; }

/* Active mode highlight — same purple gradient as the desktop right-sidebar */
.ag-fab-action.is-active {
    background: var(--accent-gradient);
    color:      #fff;
    border-color: transparent;
    box-shadow: 0 4px 20px rgba(167, 139, 250, .55);
}

/* Stagger reveal — top button appears LAST when opening so the eye follows it */
.ag-mode-fab.is-open .ag-fab-action:nth-child(4) { transition-delay: 60ms; }
.ag-mode-fab.is-open .ag-fab-action:nth-child(3) { transition-delay: 110ms; }
.ag-mode-fab.is-open .ag-fab-action:nth-child(2) { transition-delay: 160ms; }
.ag-mode-fab.is-open .ag-fab-action:nth-child(1) { transition-delay: 210ms; }

/* Show FAB only on mobile */
@media (max-width: 992px) {
    .ag-mode-fab:not([hidden]) { display: flex; }
}

/* Hide FAB completely on desktop — right sidebar handles modes there */
@media (min-width: 993px) {
    .ag-mode-fab { display: none !important; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .ag-fab-main,
    .ag-fab-action,
    .ag-fab-action::before { transition: none !important; }
}


/* =========================================================================
   SCROLLBARS — unified slim dark style across all scrollable areas
   ========================================================================= */

/* Firefox */
.ag-main-content,
.ag-right-sidebar,
.ag-sidebar,
.ag-modal-content {
    scrollbar-width: thin;
    scrollbar-color: rgba(167, 139, 250, .25) transparent;
}

/* Chrome / Safari / Edge */
.ag-main-content::-webkit-scrollbar,
.ag-right-sidebar::-webkit-scrollbar,
.ag-sidebar::-webkit-scrollbar,
.ag-modal-content::-webkit-scrollbar {
    width:  8px;
    height: 8px;
}
.ag-main-content::-webkit-scrollbar-track,
.ag-right-sidebar::-webkit-scrollbar-track,
.ag-sidebar::-webkit-scrollbar-track,
.ag-modal-content::-webkit-scrollbar-track {
    background: transparent;
}
.ag-main-content::-webkit-scrollbar-thumb,
.ag-right-sidebar::-webkit-scrollbar-thumb,
.ag-sidebar::-webkit-scrollbar-thumb,
.ag-modal-content::-webkit-scrollbar-thumb {
    background:    rgba(167, 139, 250, .25);
    border-radius: 4px;
    border:        2px solid transparent;
    background-clip: content-box;
    transition:    background .2s;
}
.ag-main-content::-webkit-scrollbar-thumb:hover,
.ag-right-sidebar::-webkit-scrollbar-thumb:hover,
.ag-sidebar::-webkit-scrollbar-thumb:hover,
.ag-modal-content::-webkit-scrollbar-thumb:hover {
    background:    rgba(167, 139, 250, .55);
    background-clip: content-box;
}

/* Hide scrollbar entirely on flashcards — they shouldn't scroll */
.ag-flashcard,
.ag-flashcard * {
    scrollbar-width: none;
}
.ag-flashcard::-webkit-scrollbar,
.ag-flashcard *::-webkit-scrollbar {
    display: none;
}


/* ── MAP VIEW ─────────────────────────────────────────────────────────────
   Vertical timeline of levels grouped by realm. Phase 1 layout. */
.ag-map-realm { animation: fadeInUp .4s ease-out; }
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ag-map-node {
    transition: background .2s;
    border-radius: 10px;
}
.ag-map-node:hover { background: rgba(167,139,250,.05); }
.ag-map-node.is-current::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    background: var(--accent-gradient);
    border-radius: 2px;
}


/* Boss test entry animation — used for boss icon reveal */
@keyframes bossEntry {
    0%   { transform: scale(0) rotate(-180deg); opacity: 0; }
    60%  { transform: scale(1.15) rotate(10deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    @keyframes bossEntry { from, to { transform: none; opacity: 1; } }
}


/* =========================================================================
   CHEST OPENING ANIMATIONS — used by _renderChestOpening
   ========================================================================= */

/* PHASE A — chest shakes (anticipation moment, like a creature coming alive) */
@keyframes chestShake {
    10%, 90%       { transform: translateX(-1px) rotate(-1deg); }
    20%, 80%       { transform: translateX(2px) rotate(1deg); }
    30%, 50%, 70%  { transform: translateX(-3px) rotate(-2deg); }
    40%, 60%       { transform: translateX(3px) rotate(2deg); }
}

/* PHASE A — glow pulse, syncs with shake */
@keyframes chestPulseGlow {
    0%, 100% { filter: drop-shadow(0 0 16px currentColor) brightness(1); }
    50%      { filter: drop-shadow(0 0 32px currentColor) brightness(1.2); }
}

/* PHASE B — chest bursts open: scale up, slight rotate, fade-out */
@keyframes chestBurst {
    0%   { transform: scale(1) rotate(0); opacity: 1; }
    30%  { transform: scale(1.5) rotate(-8deg); opacity: 1; }
    60%  { transform: scale(1.7) rotate(5deg); opacity: .8; }
    100% { transform: scale(0.3) rotate(25deg); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    @keyframes chestShake     { from, to { transform: none; } }
    @keyframes chestPulseGlow { from, to { filter: none; } }
    @keyframes chestBurst     { from { opacity: 1; } to { opacity: 0; transform: none; } }
}


/* =========================================================================
   UI THEMES — apply via body[data-theme="..."]
   Default theme uses the existing :root palette; other themes override
   --accent, --accent-gradient, --accent-strong and related colours.
   ========================================================================= */

body[data-theme="forest"] {
    --accent:                  #34d399;
    --accent-strong:           #10b981;
    --accent-gradient:         linear-gradient(135deg, #34d399 0%, #059669 100%);
    --accent-glow:             0 0 20px rgba(52, 211, 153, .35);
    --right-sidebar-bg:        #0f1f1a;
    --right-sidebar-border:    rgba(52, 211, 153, .15);
    --bg-dark:                 #0a1614;
    --bg-surface:              #102822;
    --bg-surface-2:            #14342c;
    --border-strong:           rgba(52, 211, 153, .25);
    --border-subtle:           rgba(52, 211, 153, .12);
}

body[data-theme="crystal"] {
    --accent:                  #c084fc;
    --accent-strong:           #a855f7;
    --accent-gradient:         linear-gradient(135deg, #c084fc 0%, #06b6d4 100%);
    --accent-glow:             0 0 22px rgba(192, 132, 252, .4);
    --right-sidebar-bg:        #1a0f2e;
    --right-sidebar-border:    rgba(192, 132, 252, .18);
    --bg-dark:                 #0f0a1f;
    --bg-surface:              #1a1230;
    --bg-surface-2:            #251a44;
    --border-strong:           rgba(192, 132, 252, .25);
    --border-subtle:           rgba(192, 132, 252, .12);
}

body[data-theme="fire"] {
    --accent:                  #f87171;
    --accent-strong:           #ef4444;
    --accent-gradient:         linear-gradient(135deg, #f87171 0%, #fbbf24 100%);
    --accent-glow:             0 0 20px rgba(248, 113, 113, .4);
    --right-sidebar-bg:        #1f0f0a;
    --right-sidebar-border:    rgba(248, 113, 113, .18);
    --bg-dark:                 #1a0808;
    --bg-surface:              #2a1410;
    --bg-surface-2:            #381a18;
    --border-strong:           rgba(248, 113, 113, .25);
    --border-subtle:           rgba(248, 113, 113, .12);
}

body[data-theme="ocean"] {
    --accent:                  #3b82f6;
    --accent-strong:           #2563eb;
    --accent-gradient:         linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
    --accent-glow:             0 0 20px rgba(59, 130, 246, .4);
    --right-sidebar-bg:        #0a1428;
    --right-sidebar-border:    rgba(59, 130, 246, .18);
    --bg-dark:                 #061021;
    --bg-surface:              #0f1d38;
    --bg-surface-2:            #14274a;
    --border-strong:           rgba(59, 130, 246, .25);
    --border-subtle:           rgba(59, 130, 246, .12);
}

/* =========================================================================
   AVATAR FRAMES — decorative wrappers around _avatarHtml output
   Each frame uses ::before / ::after pseudo-elements for particles, plus
   keyframe animations for movement. All frames sized relative to wrapper,
   so they scale with avatar size automatically.
   ========================================================================= */

.ag-avatar-frame {
    position: relative;
    isolation: isolate;   /* contain pseudo-elements within wrapper */
}

/* ── flame: rotating fire ring ── */
.ag-avatar-frame.ag-frame-flame::before,
.ag-avatar-frame.ag-frame-flame::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, #f87171, #fbbf24, #f87171, #fb923c, #f87171);
    z-index: -1;
    animation: frameRotate 3s linear infinite;
    filter: blur(4px);
    opacity: 0.85;
}
.ag-avatar-frame.ag-frame-flame::after {
    animation-direction: reverse;
    animation-duration: 2.2s;
    inset: -4px;
    opacity: 0.45;
}

/* ── ice: shimmering blue ring ── */
.ag-avatar-frame.ag-frame-ice::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, #06b6d4, #67e8f9, #a5f3fc, #67e8f9, #06b6d4);
    z-index: -1;
    animation: frameRotate 4s linear infinite;
    filter: blur(2px);
}
.ag-avatar-frame.ag-frame-ice::after {
    content: '✦';
    position: absolute;
    top: -6px;
    right: -2px;
    font-size: 14px;
    color: #67e8f9;
    text-shadow: 0 0 8px #67e8f9;
    animation: frameShimmer 2s ease-in-out infinite;
    z-index: 1;
}

/* ── crown: small gold crown above the avatar ── */
.ag-avatar-frame.ag-frame-crown::before {
    content: '👑';
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 18px;
    z-index: 2;
    filter: drop-shadow(0 2px 4px rgba(251, 191, 36, .6));
    animation: frameCrownBob 2.5s ease-in-out infinite;
}
.ag-avatar-frame.ag-frame-crown::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 16px rgba(251, 191, 36, .5);
    z-index: -1;
}

/* ── thorns: dark thorny ring ── */
.ag-avatar-frame.ag-frame-thorns::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px dashed rgba(220, 38, 127, .7);
    animation: frameRotate 8s linear infinite;
    z-index: -1;
}
.ag-avatar-frame.ag-frame-thorns::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(220, 38, 127, .55);
    z-index: -1;
}

/* ── crystal: pulsing diamond corners ── */
.ag-avatar-frame.ag-frame-crystal::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: conic-gradient(from 45deg, #c084fc, transparent 25%, #06b6d4, transparent 50%, #c084fc, transparent 75%, #06b6d4);
    z-index: -1;
    animation: frameRotate 5s linear infinite;
    filter: blur(2px);
    opacity: .9;
}
.ag-avatar-frame.ag-frame-crystal::after {
    content: '◈';
    position: absolute;
    top: -3px;
    right: -3px;
    font-size: 12px;
    color: #c084fc;
    text-shadow: 0 0 6px #c084fc;
    animation: framePulse 1.5s ease-in-out infinite;
    z-index: 1;
}

/* ── light: rotating beams ── */
.ag-avatar-frame.ag-frame-light::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent 0deg, #fef3c7 30deg, transparent 60deg, transparent 120deg, #fef3c7 150deg, transparent 180deg, transparent 240deg, #fef3c7 270deg, transparent 300deg);
    z-index: -1;
    animation: frameRotate 6s linear infinite;
    filter: blur(3px);
    opacity: .8;
}
.ag-avatar-frame.ag-frame-light::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 18px rgba(254, 243, 199, .7);
    z-index: -1;
}

/* ── shadow: dark pulsing aura ── */
.ag-avatar-frame.ag-frame-shadow::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: radial-gradient(circle, transparent 50%, rgba(88, 28, 135, .8) 70%, transparent 100%);
    z-index: -1;
    animation: frameShadowPulse 2.5s ease-in-out infinite;
    filter: blur(3px);
}
.ag-avatar-frame.ag-frame-shadow::after {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: 50%;
    border: 1px solid rgba(88, 28, 135, .4);
    z-index: -1;
}

/* ── rainbow: rotating rainbow ring ── */
.ag-avatar-frame.ag-frame-rainbow::before {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, #ef4444, #fbbf24, #34d399, #06b6d4, #3b82f6, #c084fc, #ec4899, #ef4444);
    z-index: -1;
    animation: frameRotate 4s linear infinite;
    filter: blur(2px);
}
.ag-avatar-frame.ag-frame-rainbow::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 14px rgba(192, 132, 252, .6);
    z-index: -1;
}

/* ── frame keyframes ── */
@keyframes frameRotate {
    from { transform: rotate(0); }
    to   { transform: rotate(360deg); }
}
@keyframes frameShimmer {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: .5; transform: scale(0.85); }
}
@keyframes frameCrownBob {
    0%, 100% { transform: translateX(-50%) translateY(0) rotate(-3deg); }
    50%      { transform: translateX(-50%) translateY(-2px) rotate(3deg); }
}
@keyframes framePulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%      { transform: scale(1.3); opacity: .6; }
}
@keyframes frameShadowPulse {
    0%, 100% { opacity: .8; transform: scale(1); }
    50%      { opacity: .4; transform: scale(1.1); }
}

@media (prefers-reduced-motion: reduce) {
    .ag-avatar-frame::before,
    .ag-avatar-frame::after { animation: none !important; }
}
