/* ========================================================================
   SKEMI POLISH — global production-level finish
   Loaded on every page AFTER Global.css. Only enhances SHARED base elements
   (scrollbars, focus, selection, transitions, entrance) + opt-in utilities,
   so it lifts the whole app cohesively without overriding section styles.
   Every color comes from design-tokens.css → works in light / dark / galaxy.
======================================================================== */

/* ---- Smooth, calm theme switching -------------------------------------- */
/* NOTE: do NOT transition `background-color` here. On a theme switch the page
   background is `var(--bg-*)`, and transitioning a var-based background-color
   across a class swap gets STUCK at the old (dark) value in Chromium — the page
   background stayed dark while token-based cards flipped light ("frames change
   but the background doesn't"). Flip backgrounds instantly; only ease the
   subtler border/text colors so the switch still feels calm, never broken. */
html { scroll-behavior: smooth; }
body,
.navbar, .app-sidebar, .main-content-wrapper,
.card, .panel, .insight-panel, .settings-card, .lab-console, .lg-command {
    transition: border-color var(--transition-normal),
                color var(--transition-fast);
}

/* ---- Branded text selection -------------------------------------------- */
::selection      { background: color-mix(in srgb, var(--brand-primary) 32%, transparent); color: var(--text-primary); }
::-moz-selection { background: color-mix(in srgb, var(--brand-primary) 32%, transparent); color: var(--text-primary); }

/* Keep wheel, touch, and keyboard scrolling while removing visible browser bars. */
html, body, * {
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar,
*::-webkit-scrollbar,
*::-webkit-scrollbar-corner {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
}

/* ---- Accessible, on-brand focus ring ----------------------------------- */
:where(a, button, input, textarea, select, [tabindex], [role="button"], [role="tab"]):focus-visible {
    outline: 2px solid var(--brand-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}
/* Kill the ugly default focus outline where focus-visible is supported. */
:where(a, button, input, textarea, select, [tabindex], [role="button"]):focus:not(:focus-visible) { outline: none; }

/* ---- Interactive micro-motion (generic only; section classes still win) - */
a { transition: color var(--transition-fast); }
button, [role="button"] { transition: transform var(--transition-fast), filter var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast); }
/* A gentle press feedback on any button that doesn't opt out. */
button:not(:disabled):not(.no-press):active { transform: translateY(1px) scale(0.99); }

/* ---- Form controls: consistent, calm focus ----------------------------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
textarea, select {
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
}
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
textarea:focus, select:focus {
    outline: none;
    border-color: var(--brand-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 16%, transparent);
}

/* ---- Page entrance — subtle, once, non-blocking ------------------------ */
@keyframes skemiPageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.main-content-wrapper > main,
.search-page, .lab-main, .lg-main, .studio-page {
    animation: skemiPageIn 0.45s cubic-bezier(0.23, 1, 0.32, 1) both;
}

/* ---- Opt-in utility animations (add the class to use) ------------------ */
@keyframes skemiFadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes skemiPop    { from { opacity: 0; transform: scale(0.96); }     to { opacity: 1; transform: none; } }
.u-fade-up { animation: skemiFadeUp 0.5s cubic-bezier(0.23, 1, 0.32, 1) both; }
.u-pop     { animation: skemiPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.u-stagger > * { animation: skemiFadeUp 0.5s cubic-bezier(0.23, 1, 0.32, 1) both; }
.u-stagger > *:nth-child(1) { animation-delay: 0.04s; }
.u-stagger > *:nth-child(2) { animation-delay: 0.08s; }
.u-stagger > *:nth-child(3) { animation-delay: 0.12s; }
.u-stagger > *:nth-child(4) { animation-delay: 0.16s; }
.u-stagger > *:nth-child(5) { animation-delay: 0.20s; }
.u-stagger > *:nth-child(6) { animation-delay: 0.24s; }

/* ---- Card lift utility (opt-in) ---------------------------------------- */
.u-lift { transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast); }
.u-lift:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--brand-primary) 40%, var(--border-light)); }

/* ========================================================================
   ELEVATED CHROME — a premium, cohesive redesign of the frame every page
   shares (left rail + top account strip). Token-based → correct in all themes.
======================================================================== */

/* ---- Left rail: refined surface, spacing, brand ------------------------ */
.app-sidebar {
    width: 258px;
    padding: 14px 12px 16px;
    gap: 2px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-light);
    box-shadow: inset -1px 0 0 var(--border-light);
}
.app-sidebar.collapsed { width: 76px; padding: 14px 10px; }
.app-sidebar + .main-content-wrapper,
.main-content-wrapper { margin-left: 258px; }
.app-sidebar.collapsed + .main-content-wrapper { margin-left: 76px; }

.app-sidebar .sidebar-brand { padding: 8px 12px 16px; margin-bottom: 6px; border-bottom: 1px solid var(--border-light); }
.app-sidebar .sidebar-brand .logo { font-size: 1.3rem; font-weight: 800; letter-spacing: -0.01em; }

/* ---- Left rail: premium pill links with icon chips --------------------- */
.sidebar-links { gap: 3px; }
.sidebar-links li a {
    gap: 12px; padding: 9px 11px; border-radius: 12px;
    font-size: 0.92rem; font-weight: 500; color: var(--text-secondary);
    position: relative; overflow: visible;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}
.sidebar-links li a .icon {
    width: 32px; height: 32px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 9px; font-size: 1rem;
    background: var(--bg-tertiary);
    transition: transform var(--transition-fast), background var(--transition-fast), box-shadow var(--transition-fast), color var(--transition-fast);
}
.sidebar-links li a:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.sidebar-links li a:hover .icon { transform: translateY(-1px) scale(1.04); }
.sidebar-links li a.active {
    background: var(--brand-light);
    color: var(--brand-primary);
    font-weight: 650;
}
.sidebar-links li a.active .icon {
    background: var(--brand-gradient);
    color: #fff;
    box-shadow: 0 6px 16px -4px color-mix(in srgb, var(--brand-primary) 60%, transparent);
}
.sidebar-links li a.active::before {
    content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
    width: 4px; height: 22px; border-radius: 0 6px 6px 0; background: var(--brand-gradient);
}
.app-sidebar.collapsed .sidebar-links li a { justify-content: center; padding: 9px 0; }
/* Dark/galaxy: --brand-primary is too deep on the dark rail (~3.2:1) — lift the
   active nav label to a lighter violet so it stays AA-readable (matches the Chat rail). */
body.dark-mode .sidebar-links li a.active, body.galaxy-mode .sidebar-links li a.active { color: #a78bfa; }

/* ---- Top account strip: slimmer, cleaner ------------------------------- */
.navbar { height: 62px; padding: 0 22px; }
.navbar .logo { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; }
.main-content-wrapper { padding-top: 70px; }

/* ---- Premium auth / primary buttons (account strip + generic) --------- */
#auth-buttons .btn-primary, #auth-buttons .btn-secondary,
.btn-primary {
    border-radius: 11px; font-weight: 600; letter-spacing: 0; border: 1px solid transparent;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), filter var(--transition-fast);
}
#auth-buttons .btn-primary, .btn-primary {
    background: var(--brand-gradient); color: #fff;
    box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--brand-primary) 70%, transparent);
}
#auth-buttons .btn-primary:hover, .btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 12px 26px -8px color-mix(in srgb, var(--brand-primary) 75%, transparent); }
#auth-buttons .btn-secondary {
    background: var(--bg-secondary); color: var(--text-primary); border-color: var(--border-medium);
}
#auth-buttons .btn-secondary:hover { border-color: var(--brand-primary); color: var(--brand-primary); transform: translateY(-1px); }

/* ---- Cohesive surface hover for common panels (subtle lift) ------------ */
.insight-panel, .search-cap, .lab-card, .lg-command, .settings-card {
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

/* ---- Refined headings rhythm ------------------------------------------ */
h1, h2, h3, h4,
.hero-title, .page-title, .section-title, .logo {
    font-family: var(--font-heading);
    letter-spacing: -0.02em;
}
h1 { line-height: 1.1; }

/* ========================================================================
   PREMIUM COMPONENT LAYER — cohesive life for the primitives every section
   reuses. Hover states only where possible (won't disturb base look), all
   token-based → correct contrast in light / dark / galaxy.
======================================================================== */

/* ---- Universal card "life": lift + glow + brand border on hover -------- */
:is(.glass-card, .lab-card, .settings-card, .stats-card, .stat-card,
    .theme-card, .method-card, .chart-card, .lg-card, .pa-card, .sc-card,
    .search-cap, .insight-panel, .quiz-main-card, .quiz-rooms-card,
    .quiz-builder-card, .arena-launch-card, .rmt-access-card, .dr-section-card,
    .dr-tldr-card, .dr-outlook-card) {
    transition: transform var(--transition-fast),
                box-shadow var(--transition-fast),
                border-color var(--transition-fast),
                background-color var(--transition-fast);
}
:is(.glass-card, .lab-card, .settings-card, .stats-card, .stat-card,
    .theme-card, .method-card, .chart-card, .lg-card, .pa-card, .sc-card,
    .search-cap, .quiz-main-card, .quiz-rooms-card, .quiz-builder-card,
    .arena-launch-card, .rmt-access-card, .dr-section-card):hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: color-mix(in srgb, var(--brand-primary) 42%, var(--border-light));
}

/* ---- Premium badges / chips / pills ------------------------------------ */
:is(.hero-badge, .badge, .chip, .pill, .tag, .panel-tag) {
    border-radius: var(--radius-full);
    font-weight: 600;
    letter-spacing: 0.01em;
}
.hero-badge {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 15px;
    background: var(--brand-gradient-soft);
    border: 1px solid color-mix(in srgb, var(--brand-primary) 30%, transparent);
    color: var(--brand-primary);
    box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 12%, transparent);
}

/* ---- Section headers: cleaner rhythm ----------------------------------- */
.section-head { margin-bottom: 18px; }
.hero-title { font-size: clamp(2rem, 4vw, 3rem); line-height: 1.08; font-weight: 800; }
.hero-subtitle { color: var(--text-secondary); font-size: 1.02rem; line-height: 1.6; }

/* ---- Primary CTA gets the premium multi-stop gradient ------------------ */
:is(.btn-primary, .cta-primary, button.primary):not(:disabled):hover {
    background-image: var(--brand-premium-gradient);
}

/* ---- Inputs / textareas: premium resting + focus ----------------------- */
:is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea, select) {
    border-radius: var(--radius-md);
}

/* ---- Divider + code polish -------------------------------------------- */
hr { border: none; height: 1px; background: var(--border-light); margin: 20px 0; }
:is(code, kbd, pre) { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ========================================================================
   HERO SIGNATURE — one cohesive, dramatic treatment for every section's
   main title. Gradient wordmark + soft ambient glow. Guarded so the title
   is NEVER invisible if background-clip:text is unsupported.
======================================================================== */
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
    .search-hero-title,
    .sc-hero > h1, .pa-hero > h1, .rmt-title,
    .lg-title > b, .lab-title > b {
        background: var(--brand-premium-gradient);
        -webkit-background-clip: text; background-clip: text;
        -webkit-text-fill-color: transparent; color: transparent;
        /* keep descenders (g, y, đ) from clipping */
        padding-bottom: 0.06em;
    }
    /* Titles that highlight only a <b> phrase keep the rest solid + readable */
    .lg-title, .lab-title { color: var(--text-primary); }
}
/* Big, confident hero type */
.search-hero-title, .lg-title, .lab-title,
.sc-hero > h1, .pa-hero > h1, .rmt-title {
    font-family: var(--font-heading);
    font-weight: 800;
    letter-spacing: -0.025em;
    line-height: 1.1;
}

/* Soft ambient glow behind heroes (all themes, very subtle) */
.search-hero, .sc-hero, .pa-hero, .lab-hero, .lg-hero { position: relative; }
:is(.search-hero, .sc-hero, .pa-hero, .lab-hero, .lg-hero)::before {
    content: ""; position: absolute; z-index: 0; pointer-events: none;
    top: -40px; left: 50%; transform: translateX(-50%);
    width: min(680px, 90%); height: 220px;
    background: radial-gradient(ellipse at center,
        color-mix(in srgb, var(--brand-primary) 22%, transparent) 0%, transparent 70%);
    filter: blur(28px); opacity: 0.55;
}
:is(.search-hero, .sc-hero, .pa-hero, .lab-hero, .lg-hero) > * { position: relative; z-index: 1; }

/* ---- Respect reduced-motion ------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}
