:root{
    --bg:#0f172a;
    --card:#0b1220;
    --accent:#38bdf8;
    --accent-soft:#e0f2fe;
    --primary:#0ea5e9;
    --text:#e5e7eb;
}
*{box-sizing:border-box}
body{
    margin:0;
    font-family:system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
    background:radial-gradient(circle at top,#1f2937,#020617);
    color:var(--text);
}
.container{
    max-width:960px;
    margin:0 auto;
    padding:20px 16px 60px;
}
.header-graphic img{
    max-width:260px;
    display:block;
    margin:0 auto 10px;
}
.slogan{
    text-align:center;
    font-size:18px;
    color:#cbd5f5;
    margin-bottom:8px;
}
.header{
    display:flex;
    justify-content:space-between;
    align-items:center;
    margin-bottom:20px;
}
.brand h1{
    margin:0;
    font-size:22px;
    letter-spacing:0.08em;
}
.nav-controls{
    display:flex;
    align-items:center;
    gap:12px;
}
.btn{
    display:inline-flex;
    align-items:center;
    gap:6px;
    padding:8px 16px;
    border-radius:999px;
    border:none;
    background:var(--primary);
    color:white;
    font-weight:600;
    font-size:13px;
    cursor:pointer;
    text-decoration:none;
    box-shadow:0 10px 25px rgba(56,189,248,0.35);
    transition:transform 0.15s,box-shadow 0.15s,background 0.15s;
}
.btn:hover{
    transform:translateY(-1px);
    box-shadow:0 18px 40px rgba(56,189,248,0.55);
    background:#0284c7;
}
.btn-secondary{
    background:red;
    box-shadow:none;
}
.btn-secondary:hover{
    background:#334155;
}
.lang-switch{
    display:flex;
    gap:4px;
    background:#020617;
    padding:3px;
    border-radius:999px;
}
.lang-switch a{
    padding:6px 12px;
    text-decoration:none;
    border-radius:6px;
    background:#1e293b;
    color:#e5e7eb;
    font-size:12px;
    font-weight:500;
    transition:all 0.2s;
}
.lang-switch a.active{
    background:var(--primary);
    color:white;
}
.category-grid{
    display:grid;
    grid-template-columns:repeat(auto-fit,minmax(160px,1fr));
    gap:12px;
    margin:20px 0 24px;
}
.category-card{
    background:linear-gradient(145deg,#020617,#020617);
    border-radius:16px;
    padding:12px 12px 14px;
    border:1px solid rgba(148,163,184,0.2);
    cursor:pointer;
    transition:transform 0.15s,box-shadow 0.15s,border-color 0.15s,background 0.15s;
    position:relative;
    overflow:hidden;
}
.category-card::before{
    content:"";
    position:absolute;
    inset:-60%;
    background:radial-gradient(circle at top,var(--accent-soft),transparent 55%);
    opacity:0;
    transition:opacity 0.2s;
}
.category-card:hover::before,
.category-card.active::before{
    opacity:0.7;
}
.category-card:hover{
    transform:translateY(-2px);
    box-shadow:0 15px 40px rgba(15,23,42,0.8);
    border-color:rgba(56,189,248,0.8);
}
.category-card.active{
    border-color:var(--primary);
    box-shadow:0 0 0 1px rgba(56,189,248,0.7),0 20px 60px rgba(15,23,42,0.9);
}
.category-icon{
    font-size:22px;
    margin-bottom:6px;
}
.category-title{
    font-size:14px;
    font-weight:600;
    margin-bottom:3px;
}
.category-count{
    font-size:12px;
    color:#cbd5f5;
}
.input-form{
    border-radius:20px;
    padding:18px 16px 18px;
    border:1px solid rgba(148,163,184,0.25);
    box-shadow:0 18px 60px rgba(15,23,42,0.9);
    margin-bottom:26px;
}
.input-form.active{
    display:block;
}
.form-group{
    margin-bottom:14px;
}
label{
    display:block;
    font-size:13px;
    color:#e2e8f0;
    margin-bottom:6px;
}
select,textarea{
    width:100%;
    padding:8px 10px;
    border-radius:10px;
    border:1px solid rgba(148,163,184,0.4);
    background:#020617;
    color:#e5e7eb;
    font-size:13px;
    font-family:inherit;
    resize:vertical;
    min-height:48px;
}
select:focus,textarea:focus{
    outline:none;
    border-color:var(--primary);
    box-shadow:0 0 0 1px rgba(56,189,248,0.4);
}
.alert{
    padding:10px 12px;
    border-radius:10px;
    background:#fee2e2;
    color:#991b1b;
    font-size:13px;
    margin-bottom:16px;
}
.loading-overlay{
    position:fixed;
    inset:0;
    background:rgba(15,23,42,0.85);
    display:flex;
    flex-direction:column;
    justify-content:center;
    align-items:center;
    z-index:50;
    opacity:0;
    pointer-events:none;
    transition:opacity 0.2s;
}
.loading-overlay.active{
    opacity:1;
    pointer-events:auto;
}
.spinner{
    width:36px;
    height:36px;
    border-radius:999px;
    border:3px solid rgba(148,163,184,0.5);
    border-top-color:var(--primary);
    animation:spin 0.8s linear infinite;
    margin-bottom:12px;
}
@keyframes spin{
    to{transform:rotate(360deg)}
}
.loading-text{
    color:#e5e7eb;
    font-size:14px;
}
.result-section{
    border-radius:16px;
    padding:14px 14px 14px;
    margin-bottom:16px;
    border:1px solid rgba(148,163,184,0.3);
    background:radial-gradient(circle at top left,#0b1220,#020617);
    animation: fadeIn 0.4s ease-out;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.result-title{
    font-size:13px;
    font-weight:600;
    margin-bottom:6px;
}
.result-content{
    font-size:14px;
    color:#e5e7eb;
    white-space:pre-wrap;
}
.footer{
    margin-top:40px;
    text-align:auto;
    padding-top:22px;
    border-top:1px solid rgba(148,163,184,0.3);
    color:#94a3b8;
    font-size:11px;
}

.audio-play-btn {
    margin-left: 8px;
    border: none;
    background: transparent;
    color: #ef4444;
    cursor: pointer;
    font-size: 18px;
    padding: 0 4px;
}
.audio-play-btn:hover {
    color: #f97316;
}

.meta-bar{
    text-align:center;
    font-size:12px;
    color:#9ca3af;
    margin-bottom:12px;
}

@media (max-width:640px){
    .header{
        flex-direction:column;
        align-items:flex-start;
        gap:8px;
    }
    .nav-controls{
        width:100%;
        justify-content:space-between;
    }
} 

/* === Prominent search bar === */
.search-bar {
    margin: 0 auto 16px;
    max-width: 700px;
    position: relative;
}

.search-bar input[type="text"] {
    width: 100%;
    padding: 14px 46px 14px 16px;
    border-radius: 999px;
    border: 1px solid #0ea5e9;
    background: #020617;
    color: #e5e7eb;
    font-size: 15px;
    box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.3);
}

.search-bar input[type="text"]::placeholder {
    color: #64748b;
}

.search-bar input[type="text"]:focus {
    outline: none;
    box-shadow: 0 0 0 2px #0ea5e9;
}

/* Search submit button */
.search-submit-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--primary);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.15s, transform 0.15s;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.search-submit-btn:hover {
    background: #0284c7;
    transform: translateY(-50%) scale(1.05);
}

/* === Topic selector step === */
.category-header {
    max-width: 700px;
    margin: 0 auto 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #9ca3af;
    font-size: 13px;
}

.category-header .step-label {
    padding: 2px 6px;
    border-radius: 999px;
    background: #111827;
    color: #e5e7eb;
    font-size: 11px;
    font-weight: 600;
}

/* === Current topic pill (shown after first run) === */
.context-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(14, 165, 233, 0.12);
    color: #0ea5e9;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 12px;
    border: 1px solid rgba(14, 165, 233, 0.2);
}

/* === Ask again CTA === */
.ask-again-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 999px;
    border: none;
    background: #0ea5e9;
    color: #0b1120;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    margin-top: 8px;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
    transition: all 0.2s;
}

.ask-again-btn:hover {
    background: #38bdf8;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
}

/* Hide selectors when returning with context */
.selectors-hidden .category-grid,
.selectors-hidden #subtopicGroup {
    display: none !important;
}

.selectors-hidden .category-header {
    display: none;
}

.quick-search-mode {
    margin-top: 10px;
}

/* ================= MAGICAL LOADING ANIMATION ================= */

/* Hide the old spinner completely */
.loading-overlay .spinner {
    display: none !important;
}

/* Magical container replaces spinner */
.magic-orb-container {
    position: relative;
    width: 200px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
}

/* The central crystalline orb */
.orb {
    position: relative;
    width: 80px;
    height: 80px;
    transform-style: preserve-3d;
    animation: orbFloat 6s ease-in-out infinite;
}

.orb-core {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, 
        rgba(56, 189, 248, 0.9), 
        rgba(14, 165, 233, 0.4), 
        rgba(139, 92, 246, 0.2));
    box-shadow: 
        0 0 60px rgba(56, 189, 248, 0.6),
        inset 0 0 20px rgba(255, 255, 255, 0.3),
        0 0 100px rgba(168, 85, 247, 0.3);
    animation: corePulse 3s ease-in-out infinite;
    backdrop-filter: blur(2px);
}

/* Sacred geometry rings */
.orb-ring {
    position: absolute;
    border-radius: 50%;
    border: 2px solid transparent;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.orb-ring.r1 {
    width: 120px;
    height: 120px;
    border-top-color: rgba(56, 189, 248, 0.8);
    border-bottom-color: rgba(168, 85, 247, 0.6);
    animation: ringSpin1 4s linear infinite;
    box-shadow: 0 0 30px rgba(56, 189, 248, 0.2);
}

.orb-ring.r2 {
    width: 160px;
    height: 160px;
    border-left-color: rgba(236, 72, 153, 0.7);
    border-right-color: rgba(251, 191, 36, 0.5);
    animation: ringSpin2 6s linear infinite reverse;
}

.orb-ring.r3 {
    width: 200px;
    height: 200px;
    border: 1px dashed rgba(255, 255, 255, 0.2);
    animation: ringSpin3 8s linear infinite;
}

/* Energy ripple field behind orb */
.energy-field {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle, 
        rgba(56, 189, 248, 0.1) 0%, 
        transparent 70%);
    animation: energyRipple 3s ease-out infinite;
}

.energy-field::before,
.energy-field::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1px solid rgba(56, 189, 248, 0.3);
    animation: rippleExpand 3s ease-out infinite;
}

.energy-field::after {
    animation-delay: 1.5s;
    border-color: rgba(168, 85, 247, 0.3);
}

/* Floating magical particles */
.magic-particles {
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.magic-particles span {
    position: absolute;
    width: 4px;
    height: 4px;
    background: linear-gradient(135deg, #38bdf8, #a855f7, #fbbf24);
    border-radius: 50%;
    box-shadow: 0 0 10px currentColor;
    animation: particleFloat 8s linear infinite;
    animation-delay: calc(var(--i) * 0.7s);
    opacity: 0;
}

/* Position particles in circle around orb */
.magic-particles span:nth-child(1) { --i: 1; left: 10%; top: 80%; }
.magic-particles span:nth-child(2) { --i: 2; left: 80%; top: 20%; }
.magic-particles span:nth-child(3) { --i: 3; left: 20%; top: 30%; }
.magic-particles span:nth-child(4) { --i: 4; left: 70%; top: 70%; }
.magic-particles span:nth-child(5) { --i: 5; left: 50%; top: 10%; }
.magic-particles span:nth-child(6) { --i: 6; left: 90%; top: 50%; }
.magic-particles span:nth-child(7) { --i: 7; left: 5%; top: 40%; }
.magic-particles span:nth-child(8) { --i: 8; left: 60%; top: 90%; }
.magic-particles span:nth-child(9) { --i: 9; left: 85%; top: 85%; }
.magic-particles span:nth-child(10) { --i: 10; left: 15%; top: 60%; }
.magic-particles span:nth-child(11) { --i: 11; left: 40%; top: 25%; }
.magic-particles span:nth-child(12) { --i: 12; left: 75%; top: 35%; }

/* Rune symbols floating */
.magic-particles span::before {
    content: '✦';
    position: absolute;
    font-size: 12px;
    color: rgba(251, 191, 36, 0.8);
    animation: runeTwinkle 2s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.5s);
    top: -15px;
    left: -4px;
}

/* Random different runes for variety */
.magic-particles span:nth-child(3n)::before { content: '✧'; }
.magic-particles span:nth-child(3n+1)::before { content: '◈'; }
.magic-particles span:nth-child(3n+2)::before { content: '◇'; }

/* Enhanced magical text */
.loading-text.magical-text {
    font-size: 16px;
    letter-spacing: 0.2em;
    background: linear-gradient(90deg, #38bdf8, #a855f7, #fbbf24, #38bdf8);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: textShimmer 4s linear infinite;
    text-shadow: 0 0 30px rgba(56, 189, 248, 0.5);
    position: relative;
    margin-top: 20px;
}

.loading-text.magical-text::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 2px;
    background: linear-gradient(90deg, transparent, #38bdf8, transparent);
    animation: lineExpand 2s ease-in-out infinite;
}

/* Keyframes */
@keyframes orbFloat {
    0%, 100% { transform: translateY(0px) rotateX(0deg); }
    50% { transform: translateY(-10px) rotateX(5deg); }
}

@keyframes corePulse {
    0%, 100% { 
        transform: scale(1);
        box-shadow: 
            0 0 60px rgba(56, 189, 248, 0.6),
            inset 0 0 20px rgba(255, 255, 255, 0.3),
            0 0 100px rgba(168, 85, 247, 0.3);
    }
    50% { 
        transform: scale(1.1);
        box-shadow: 
            0 0 80px rgba(56, 189, 248, 0.8),
            inset 0 0 30px rgba(255, 255, 255, 0.5),
            0 0 120px rgba(168, 85, 247, 0.5);
    }
}

@keyframes ringSpin1 {
    0% { transform: translate(-50%, -50%) rotate(0deg) rotateX(60deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg) rotateX(60deg); }
}

@keyframes ringSpin2 {
    0% { transform: translate(-50%, -50%) rotate(0deg) rotateY(60deg); }
    100% { transform: translate(-50%, -50%) rotate(-360deg) rotateY(60deg); }
}

@keyframes ringSpin3 {
    0% { transform: translate(-50%, -50%) rotate(0deg) rotateZ(45deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg) rotateZ(45deg); }
}

@keyframes particleFloat {
    0% {
        transform: translateY(100px) translateX(0) scale(0);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    25% {
        transform: translateY(50px) translateX(20px) scale(1);
    }
    50% {
        transform: translateY(0px) translateX(-20px) scale(1.2);
    }
    75% {
        transform: translateY(-50px) translateX(15px) scale(1);
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(-120px) translateX(0) scale(0);
        opacity: 0;
    }
}

@keyframes runeTwinkle {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

@keyframes energyRipple {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.2); opacity: 0.8; }
}

@keyframes rippleExpand {
    0% { transform: scale(0.8); opacity: 0.6; }
    100% { transform: scale(2); opacity: 0; }
}

@keyframes textShimmer {
    0% { background-position: 0% 50%; }
    100% { background-position: 300% 50%; }
}

@keyframes lineExpand {
    0%, 100% { width: 20px; opacity: 0.3; }
    50% { width: 80px; opacity: 1; }
}

.loading-text {
    text-align: center;
    width: 100%;
    display: block;
    padding: 0 20px;        /* Prevents text touching edges on mobile */
    box-sizing: border-box; /* Ensures padding doesn't break width */
    margin-top: 30px;       /* Space between orb and text */
    font-size: 18px;
    line-height: 1.4;
}

/* If the parent overlay uses flexbox, ensure it stacks properly */
.loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;    /* Centers children horizontally */
    justify-content: center; /* Centers vertically if you want */
    text-align: center;     /* Fallback for older browsers */
}