/* ============================================
   MALEK LEARNS — core styles
   Portfolio editorial theme, dark and warm-paper light.
   Tokens, base, shared pieces, header, footer.
   ============================================ */

:root {
    color-scheme: dark;

    --bg: #07090d;
    --bg-deep: #040507;
    --bg-soft: #0c1016;
    --surface: #10151d;
    --surface-soft: #141b24;
    --surface-strong: #19212c;
    --surface-card: rgba(8, 10, 14, 0.9);
    --surface-inset: rgba(255, 255, 255, 0.035);

    --text: #f4f1e9;
    --text-soft: #c5c7cb;
    --text-muted: #8a9099;
    --on-accent: #05070b;

    --border: rgba(255, 255, 255, 0.09);
    --border-soft: rgba(255, 255, 255, 0.05);
    --border-strong: rgba(255, 255, 255, 0.16);

    /* Accent: keep --accent-rgb in sync with --accent */
    --accent: #2f8cff;
    --accent-hover: #5aa6ff;
    --accent-deep: #1a5fd0;
    --accent-rgb: 47, 140, 255;
    --glow-rgb: 124, 92, 255;
    --success: #35d07f;
    --success-rgb: 53, 208, 127;

    /* Callout colours: keep each -rgb in sync */
    --warn: #f5b041;
    --warn-rgb: 245, 176, 65;
    --imp: #a78bfa;
    --imp-rgb: 167, 139, 250;
    --ex: #35d07f;
    --ex-rgb: 53, 208, 127;
    --tint: 0.08;
    --callout-base: transparent;

    --header-bg: rgba(4, 5, 7, 0.86);
    --header-solid: rgb(4, 5, 7);
    --menu-bg: rgba(7, 9, 13, 0.98);
    --footer-bg: rgba(4, 5, 7, 0.7);
    --backdrop: rgba(0, 0, 0, 0.55);
    --grid-line: rgba(255, 255, 255, 0.022);
    --glow-a: rgba(var(--accent-rgb), 0.09);
    --glow-b: rgba(var(--glow-rgb), 0.07);
    --hero-glow: rgba(var(--accent-rgb), 0.16);

    --card-bg:
        radial-gradient(circle at 82% 12%, rgba(var(--accent-rgb), 0.12), transparent 42%),
        linear-gradient(160deg, rgba(14, 18, 27, 0.98), rgba(7, 9, 13, 0.98));
    --panel-bg: linear-gradient(160deg, rgba(16, 21, 29, 0.92), rgba(8, 10, 14, 0.92));
    --shadow-card:
        0 30px 75px rgba(0, 0, 0, 0.42),
        0 0 42px rgba(var(--accent-rgb), 0.09),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    --cover-shadow:
        0 30px 70px rgba(0, 0, 0, 0.5),
        0 0 50px rgba(var(--accent-rgb), 0.18);

    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    --font-display: 'Roboto Condensed', 'Arial Narrow', Impact, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;

    --header-h: 72px;
    --container: 1240px;
    --gutter: 36px;
    --r-sm: 8px;
    --r-md: 14px;
    --r-lg: 18px;
    --r-xl: 22px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* Warm paper: same layout, only colours change */
:root[data-theme="light"] {
    color-scheme: light;

    --bg: #f6f2e9;
    --bg-deep: #efe9dc;
    --bg-soft: #f1ece1;
    --surface: #fffdf8;
    --surface-soft: #faf6ee;
    --surface-strong: #f0eadf;
    --surface-card: rgba(255, 253, 248, 0.92);
    --surface-inset: rgba(60, 45, 20, 0.04);

    --text: #1f1d1a;
    --text-soft: #46423b;
    --text-muted: #6b6656;
    --on-accent: #ffffff;

    --border: rgba(40, 30, 10, 0.12);
    --border-soft: rgba(40, 30, 10, 0.07);
    --border-strong: rgba(40, 30, 10, 0.2);

    --accent: #1a62cc;
    --accent-hover: #2a6fd6;
    --accent-deep: #134a9c;
    --accent-rgb: 26, 98, 204;
    --success: #157a45;
    --success-rgb: 21, 122, 69;

    --warn: #9a5800;
    --warn-rgb: 196, 120, 10;
    --imp: #6a3fd0;
    --imp-rgb: 106, 63, 208;
    --ex: #157a45;
    --ex-rgb: 21, 122, 69;
    --tint: 0.07;
    --callout-base: var(--surface);

    --header-bg: rgba(246, 242, 233, 0.88);
    --header-solid: #f6f2e9;
    --menu-bg: rgba(250, 247, 240, 0.98);
    --footer-bg: rgba(239, 233, 220, 0.7);
    --backdrop: rgba(30, 25, 15, 0.35);
    --grid-line: rgba(60, 45, 20, 0.035);
    --glow-a: rgba(var(--accent-rgb), 0.06);
    --glow-b: rgba(var(--glow-rgb), 0.05);
    --hero-glow: rgba(var(--accent-rgb), 0.09);

    --card-bg:
        radial-gradient(circle at 82% 12%, rgba(var(--accent-rgb), 0.06), transparent 42%),
        linear-gradient(160deg, #fffdf8, #f9f5ec);
    --panel-bg: linear-gradient(160deg, #fffdf8, #f8f3e9);
    --shadow-card:
        0 24px 60px rgba(60, 45, 20, 0.12),
        0 0 0 1px rgba(var(--accent-rgb), 0.05),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
    --cover-shadow:
        0 24px 50px rgba(60, 45, 20, 0.2),
        0 0 40px rgba(var(--accent-rgb), 0.1);
}

@media (max-width: 760px) {
    :root { --header-h: 64px; --gutter: 20px; }
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-h) + 20px);
    -webkit-text-size-adjust: 100%;
}

@media (max-width: 760px) {
    html { scroll-padding-top: var(--header-h); }
}

html.nav-open { overflow: hidden; }

html.theme-switching,
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.65;
    color: var(--text);
    background-color: var(--bg);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image:
        radial-gradient(circle at 10% 0%, var(--glow-a), transparent 34%),
        radial-gradient(circle at 95% 18%, var(--glow-b), transparent 30%),
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: auto, auto, 64px 64px, 64px 64px;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.1; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
ul, ol { margin: 0; padding: 0; list-style: none; }
figure { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
::selection { background: rgba(var(--accent-rgb), 0.35); color: var(--text); }

.accent { color: var(--accent); }

.skip-link {
    position: fixed;
    left: 16px;
    top: -60px;
    z-index: 300;
    padding: 10px 16px;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 800;
    transition: top 0.2s;
}
.skip-link:focus { top: 12px; }

/* ============ Shared pieces ============ */
.container {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.section { position: relative; padding: 88px 0; }

.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
}
.eyebrow::before {
    content: '';
    width: 28px;
    height: 2px;
    border-radius: 2px;
    background: currentColor;
}

.section-title {
    font-size: clamp(2.1rem, 3.9vw, 3.42rem);
    font-weight: 850;
    letter-spacing: -0.05em;
    line-height: 1.02;
    text-wrap: balance;
}

.section-head { max-width: 860px; margin-bottom: 44px; }

.section-lead {
    max-width: 720px;
    margin-top: 18px;
    font-size: 1.05rem;
    color: var(--text-soft);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 15px 24px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    font-size: 0.9rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.01em;
    white-space: nowrap;
    transition: transform 0.2s var(--ease), box-shadow 0.2s, background 0.2s, border-color 0.2s, color 0.2s;
}
.btn:hover { transform: translateY(-2px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: var(--on-accent);
    box-shadow: 0 14px 34px rgba(var(--accent-rgb), 0.22);
}
.btn-primary:hover { box-shadow: 0 18px 40px rgba(var(--accent-rgb), 0.34); }

.btn-outline {
    border-color: rgba(var(--accent-rgb), 0.6);
    background: rgba(var(--accent-rgb), 0.06);
    color: var(--text);
}
.btn-outline:hover { border-color: var(--accent); background: rgba(var(--accent-rgb), 0.13); }

.btn-dark {
    border-color: var(--border-strong);
    background: var(--surface-strong);
    color: var(--text);
}
.btn-dark:hover { border-color: rgba(var(--accent-rgb), 0.55); }

.btn-sm { gap: 8px; padding: 11px 16px; font-size: 0.8rem; }

.icon-btn {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-inset);
    color: var(--text-soft);
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.icon-btn:hover { color: var(--accent); border-color: rgba(var(--accent-rgb), 0.5); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn:disabled:hover { color: var(--text-soft); border-color: var(--border); }

.text-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    color: var(--accent);
}
.text-link i { font-size: 0.7rem; transition: transform 0.2s; }
.text-link:hover i { transform: translateX(3px); }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips li,
.k-tag {
    padding: 6px 11px;
    border: 1px solid rgba(var(--accent-rgb), 0.22);
    border-radius: 999px;
    background: rgba(var(--accent-rgb), 0.07);
    font-size: 0.74rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-soft);
}

.status-dot {
    position: relative;
    display: inline-block;
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(var(--success-rgb), 0.18);
}
.status-dot::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--success);
    animation: ping 2.2s ease-out infinite;
}
@keyframes ping {
    0% { transform: scale(1); opacity: 0.6; }
    80%, 100% { transform: scale(2.6); opacity: 0; }
}

.diamond-list li,
.k-takeaways li,
.box.rules li {
    position: relative;
    padding-left: 20px;
}
.diamond-list li::before,
.k-takeaways li::before,
.box.rules li::before {
    content: '';
    position: absolute;
    left: 1px;
    top: 0.6em;
    width: 7px;
    height: 7px;
    border-radius: 2px;
    background: var(--accent);
    transform: rotate(45deg);
}

.stars { color: var(--accent); letter-spacing: 2px; }

/* ============ Reading progress ============ */
.scroll-progress {
    position: fixed;
    top: var(--header-h);
    left: 0;
    z-index: 65;
    width: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--accent-deep), var(--accent-hover));
    pointer-events: none;
}

/* ============ Header ============ */
.site-header {
    position: fixed;
    inset: 0 0 auto;
    z-index: 60;
    height: var(--header-h);
    border-bottom: 1px solid var(--border-soft);
    background: var(--header-bg);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 24px;
    height: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 var(--gutter);
}

.brand {
    margin-right: auto;
    font-size: 1.02rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    text-transform: uppercase;
    white-space: nowrap;
}

.site-nav { display: flex; align-items: center; gap: clamp(18px, 2vw, 30px); }

.nav-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 0;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-soft);
    transition: color 0.2s;
}
.nav-link::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -4px;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s var(--ease);
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--accent); }
.nav-link.active::after { transform: scaleX(1); }
.nav-link .fa-arrow-up-right-from-square { font-size: 0.6rem; }

.header-actions { display: flex; align-items: center; gap: 10px; }

.theme-toggle .fa-moon { display: none; }
:root[data-theme="light"] .theme-toggle .fa-sun { display: none; }
:root[data-theme="light"] .theme-toggle .fa-moon { display: inline-block; }

.menu-toggle { display: none; }
.nav-backdrop { display: none; }

@media (max-width: 760px) {
    /* A backdrop-filter would make the header the containing block of the fixed menu panel. */
    .site-header {
        background: var(--header-solid);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .header-inner { gap: 12px; }

    .menu-toggle {
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        width: 44px;
        height: 44px;
        border: 1px solid var(--border);
        border-radius: 10px;
        background: var(--surface-inset);
    }
    .menu-toggle span {
        width: 18px;
        height: 2px;
        border-radius: 2px;
        background: var(--text);
        transition: transform 0.3s var(--ease), opacity 0.3s;
    }
    .menu-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    .menu-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
    .menu-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

    .theme-toggle { width: 44px; height: 44px; }

    .site-nav {
        position: fixed;
        top: var(--header-h);
        right: 0;
        bottom: 0;
        z-index: 70;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        width: min(320px, 86vw);
        padding: 14px 22px 32px;
        overflow-y: auto;
        border-left: 1px solid var(--border);
        background: var(--menu-bg);
        transform: translateX(100%);
        visibility: hidden;
        transition: transform 0.4s var(--ease), visibility 0s linear 0.4s;
    }
    .site-nav.open {
        transform: none;
        visibility: visible;
        transition: transform 0.4s var(--ease), visibility 0s;
    }
    .nav-link {
        padding: 14px 4px;
        border-bottom: 1px solid var(--border-soft);
        font-size: 0.8rem;
    }
    .nav-link::after { display: none; }

    .nav-backdrop {
        display: block;
        position: fixed;
        inset: var(--header-h) 0 0;
        z-index: 55;
        background: var(--backdrop);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0s linear 0.3s;
    }
    .nav-backdrop.active { opacity: 1; visibility: visible; transition: opacity 0.3s, visibility 0s; }
}

/* ============ Footer ============ */
.site-footer {
    position: relative;
    border-top: 1px solid var(--border);
    background: var(--footer-bg);
}
.footer-route {
    height: 2px;
    background: linear-gradient(90deg, var(--accent-deep), var(--accent-hover) 60%, rgba(var(--accent-rgb), 0.1));
}

.footer-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 28px;
    padding-top: 36px;
    padding-bottom: 24px;
}
.footer-brand p { margin-top: 6px; font-size: 0.86rem; color: var(--text-muted); }

.footer-nav { display: flex; flex-wrap: wrap; gap: 22px; }
.footer-nav a {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-soft);
    transition: color 0.2s;
}
.footer-nav a:hover { color: var(--accent); }

.footer-socials { display: flex; align-items: center; gap: 8px; }

.back-top {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 38px;
    margin-left: 6px;
    padding: 0 14px;
    border: 1px solid rgba(var(--accent-rgb), 0.5);
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    transition: background 0.2s, color 0.2s;
}
.back-top:hover { background: var(--accent); color: var(--on-accent); }

.footer-bottom {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 10px 16px;
    padding-top: 18px;
    padding-bottom: 28px;
    border-top: 1px solid var(--border-soft);
    font-size: 0.64rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.footer-bottom .mono { font-family: var(--font-mono); letter-spacing: 0.04em; text-transform: none; }

@media (max-width: 900px) {
    .footer-inner { grid-template-columns: 1fr; justify-items: start; gap: 20px; }
}

/* ============ Motion ============ */
.hero-in { animation: heroIn 0.9s var(--ease) both; }
.hero-in.d1 { animation-delay: 0.08s; }
.hero-in.d2 { animation-delay: 0.16s; }
.hero-in.d3 { animation-delay: 0.24s; }
.hero-in.d4 { animation-delay: 0.32s; }
.hero-in.d5 { animation-delay: 0.4s; }
@keyframes heroIn { from { opacity: 0; transform: translateY(18px); } }

.scroll-reveal {
    opacity: 0;
    transform: translateY(28px);
    transition: opacity 0.8s ease, transform 0.9s var(--ease);
}
.scroll-reveal.revealed { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
    .scroll-reveal { opacity: 1; transform: none; }
}
