/* =============================================================
   KNIGHTORIA V2 — Premium Arabic Chess Analysis
   Modern dark theme · gold + crimson · cinematic · RTL
   ============================================================= */

/* ===== Tokens ===== */
:root {
    /* Surfaces */
    --bg:            #06050a;
    --bg-soft:       #0d0a14;
    --surface:       #131022;
    --surface-2:     #1b1730;
    --surface-3:     #241e3f;
    --surface-glass: rgba(27, 23, 48, 0.65);

    /* Text */
    --text:          #f5f3fa;
    --text-soft:     #c8c2dc;
    --text-muted:    #837e98;
    --text-dim:      #5a566e;

    /* Brand — royal gold + crimson */
    --gold:          #e6b955;
    --gold-bright:   #ffcf6e;
    --gold-soft:     rgba(230, 185, 85, 0.12);
    --gold-glow:     rgba(230, 185, 85, 0.4);

    --crimson:       #c8284b;
    --crimson-bright:#ed4067;
    --crimson-soft:  rgba(237, 64, 103, 0.12);
    --crimson-glow:  rgba(237, 64, 103, 0.35);

    --indigo:        #5b62ff;
    --indigo-soft:   rgba(91, 98, 255, 0.12);

    /* Borders */
    --border:        rgba(255, 255, 255, 0.08);
    --border-strong: rgba(230, 185, 85, 0.32);
    --border-soft:   rgba(255, 255, 255, 0.04);

    /* States */
    --success:       #4dd190;
    --success-soft:  rgba(77, 209, 144, 0.14);
    --warning:       #f5b242;
    --danger:        #ed4067;

    /* Move classifications */
    --c-brilliant:   #6cf2ee;
    --c-best:        #4dd190;
    --c-excellent:   #82d669;
    --c-good:        #c5cd62;
    --c-inaccuracy:  #f5b242;
    --c-mistake:     #f57842;
    --c-blunder:     #ed4067;

    /* Effects */
    --shadow-sm:     0 1px 3px rgba(0,0,0,0.4);
    --shadow:        0 8px 28px rgba(0,0,0,0.5);
    --shadow-lg:     0 24px 60px rgba(0,0,0,0.65);
    --shadow-gold:   0 0 36px rgba(230,185,85,0.18);
    --shadow-crimson:0 0 36px rgba(237,64,103,0.22);

    --radius-sm:     6px;
    --radius:        12px;
    --radius-lg:     20px;
    --radius-xl:     28px;

    --t:             200ms cubic-bezier(.2,.8,.2,1);
    --t-slow:        400ms cubic-bezier(.2,.8,.2,1);

    /* Layout */
    --container:     1240px;
    --header-h:      72px;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
    min-height: 100vh;
    font-family: 'IBM Plex Sans Arabic', 'Tajawal', system-ui, -apple-system, sans-serif;
    font-size: 16px;
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    direction: rtl;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
img, svg { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
input, textarea, select { font-family: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }

/* ===== Page atmosphere ===== */
body::before {
    content: "";
    position: fixed; inset: 0;
    background:
        radial-gradient(ellipse 900px 600px at 80% -10%, rgba(230,185,85,0.06), transparent 60%),
        radial-gradient(ellipse 700px 500px at 10% 100%, rgba(200,40,75,0.05), transparent 60%);
    pointer-events: none;
    z-index: -1;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
    font-family: 'Cinzel', 'IBM Plex Sans Arabic', serif;
    font-weight: 800;
    line-height: 1.2;
    color: var(--text);
    letter-spacing: -0.005em;
}
h1 { font-size: clamp(2rem, 5vw, 3.5rem); font-weight: 900; }
h2 { font-size: clamp(1.6rem, 3.5vw, 2.4rem); }
h3 { font-size: clamp(1.2rem, 2.5vw, 1.6rem); }
h4 { font-size: 1.1rem; }
.eyebrow {
    display: inline-block;
    font-family: 'Cinzel', serif;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--gold);
    padding: 0.35rem 0.85rem;
    background: var(--gold-soft);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
}

/* ===== Layout primitives ===== */
.container { max-width: var(--container); margin: 0 auto; padding: 0 1.5rem; }
.section { padding: 4rem 0; }
.section-lg { padding: 6rem 0; }
.section-sm { padding: 2.5rem 0; }

.stack > * + * { margin-top: 1rem; }
.stack-sm > * + * { margin-top: 0.5rem; }
.stack-lg > * + * { margin-top: 2rem; }

.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.row-between { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.grid { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ===== Skip link ===== */
.skip-link {
    position: absolute; top: -100px; right: 1rem;
    padding: 0.65rem 1rem;
    background: var(--gold); color: var(--bg);
    border-radius: 6px;
    font-weight: 700;
    z-index: 100;
}
.skip-link:focus { top: 0.5rem; }

/* ===== Navbar ===== */
.navbar {
    position: sticky; top: 0; z-index: 50;
    background: rgba(6, 5, 10, 0.85);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border-bottom: 1px solid var(--border);
    height: var(--header-h);
}
.navbar__inner {
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 100%;
    display: flex; align-items: center; justify-content: space-between;
    gap: 1.5rem;
}
.brand {
    display: flex; align-items: center; gap: 0.75rem;
    flex-shrink: 0;
}
.brand__mark {
    width: 40px; height: 40px;
    display: grid; place-items: center;
    background: linear-gradient(160deg, var(--gold), #b58731);
    color: var(--bg);
    border-radius: 10px;
    font-family: 'Cinzel', serif;
    font-weight: 900;
    font-size: 1.4rem;
    box-shadow: var(--shadow-gold);
}
.brand__text { display: flex; flex-direction: column; line-height: 1.05; }
.brand__name {
    font-family: 'Cinzel', serif;
    font-weight: 900;
    font-size: 1.15rem;
    letter-spacing: 0.04em;
    background: linear-gradient(180deg, var(--text), var(--gold));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.brand__tag { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; }

.nav-menu { display: flex; align-items: center; gap: 0.25rem; }
.nav-link {
    padding: 0.6rem 0.9rem;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-soft);
    border-radius: 8px;
    transition: var(--t);
    position: relative;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-link.active { color: var(--gold); }
.nav-link.active::after {
    content: "";
    position: absolute; bottom: 4px; left: 25%; right: 25%;
    height: 2px;
    background: var(--gold);
    border-radius: 2px;
}
.nav-link--cta {
    background: linear-gradient(135deg, var(--crimson), #962039);
    color: #fff !important;
    padding: 0.55rem 1.1rem;
    box-shadow: var(--shadow-sm), var(--shadow-crimson);
}
.nav-link--cta:hover {
    background: linear-gradient(135deg, var(--crimson-bright), var(--crimson));
    transform: translateY(-1px);
}

.nav-actions {
    display: flex; align-items: center; gap: 0.5rem;
    margin-inline-start: 0.75rem;
}
.user-chip {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.4rem 0.85rem;
    background: var(--gold-soft);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 700;
}
.user-chip__star { color: var(--gold); }

.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    padding: 0.55rem;
    border-radius: 6px;
    margin-inline-start: auto;
}
.nav-toggle span {
    display: block;
    width: 22px; height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: var(--t);
}

@media (max-width: 980px) {
    .nav-toggle { display: flex; }
    .nav-menu {
        position: fixed;
        top: var(--header-h); right: 0;
        width: 320px; max-width: 92vw;
        height: calc(100vh - var(--header-h));
        flex-direction: column;
        gap: 0.4rem;
        align-items: stretch;
        padding: 1.5rem 1.25rem;
        background: rgba(13, 10, 20, 0.98);
        backdrop-filter: blur(20px);
        border-inline-start: 1px solid var(--border);
        transform: translateX(100%);
        transition: transform var(--t-slow);
        overflow-y: auto;
    }
    .nav-menu.is-open { transform: translateX(0); }
    .nav-link { padding: 0.85rem 1rem; font-size: 1rem; }
    .nav-actions { flex-direction: column; align-items: stretch; margin: 1rem 0 0; }
    .nav-actions .btn, .nav-actions form { width: 100%; }
    .user-chip { justify-content: center; }
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.85rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: var(--radius);
    transition: var(--t);
    border: 1px solid transparent;
    white-space: nowrap;
    user-select: none;
    cursor: pointer;
}
.btn-sm { padding: 0.5rem 1rem; font-size: 0.85rem; border-radius: 8px; }
.btn-lg { padding: 1.05rem 1.85rem; font-size: 1.05rem; }
.btn-block { width: 100%; }

.btn-primary {
    background: linear-gradient(135deg, var(--crimson), #962039);
    color: #fff;
    box-shadow: var(--shadow-sm), var(--shadow-crimson);
}
.btn-primary:hover {
    background: linear-gradient(135deg, var(--crimson-bright), var(--crimson));
    transform: translateY(-2px);
    box-shadow: var(--shadow), 0 0 50px var(--crimson-glow);
}
.btn-primary:active { transform: translateY(0); }

.btn-gold {
    background: linear-gradient(135deg, var(--gold), #b58731);
    color: var(--bg);
    box-shadow: var(--shadow-sm), var(--shadow-gold);
}
.btn-gold:hover {
    background: linear-gradient(135deg, var(--gold-bright), var(--gold));
    transform: translateY(-2px);
    box-shadow: var(--shadow), 0 0 50px var(--gold-glow);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-soft);
    border-color: var(--border);
}
.btn-ghost:hover {
    background: rgba(255,255,255,0.04);
    color: var(--text);
    border-color: var(--border-strong);
}

.btn-icon {
    padding: 0.6rem;
    width: 40px; height: 40px;
    border-radius: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ===== Cards ===== */
.card {
    background: linear-gradient(160deg, var(--surface), var(--surface-2));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: var(--t);
}
.card-hover:hover {
    transform: translateY(-3px);
    border-color: var(--border-strong);
    box-shadow: var(--shadow);
}
.card-feature {
    background: linear-gradient(160deg, var(--surface-2), var(--surface-3));
    border-color: var(--border-strong);
    box-shadow: var(--shadow), var(--shadow-gold);
}

/* ===== Forms ===== */
.field { margin-bottom: 1.25rem; }
.field-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--text-soft);
}
.field-control {
    width: 100%;
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
    color: var(--text);
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: var(--t);
}
.field-control:focus {
    outline: none;
    border-color: var(--gold);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--gold-soft);
}
.field-control::placeholder { color: var(--text-muted); }
textarea.field-control { resize: vertical; min-height: 120px; line-height: 1.6; font-family: 'Courier New', monospace; font-size: 0.88rem; }

.field-hint { display: block; margin-top: 0.4rem; color: var(--text-muted); font-size: 0.82rem; }
.field-error { display: block; margin-top: 0.4rem; color: var(--danger); font-size: 0.85rem; font-weight: 600; }

.input-group {
    display: flex; align-items: center;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: var(--t);
}
.input-group:focus-within {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-soft);
}
.input-group__prefix {
    padding: 0 0.85rem;
    color: var(--text-muted);
    font-size: 1rem;
    border-inline-end: 1px solid var(--border);
}
.input-group .field-control {
    border: none;
    background: transparent;
    box-shadow: none;
}

/* ===== Alerts ===== */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    font-size: 0.92rem;
    font-weight: 600;
    border: 1px solid transparent;
}
.alert-error { background: var(--crimson-soft); color: var(--crimson-bright); border-color: rgba(237,64,103,0.3); }
.alert-success { background: var(--success-soft); color: var(--success); border-color: rgba(77,209,144,0.3); }
.alert-info { background: var(--indigo-soft); color: var(--text-soft); border-color: rgba(91,98,255,0.25); }
.alert-warning { background: rgba(245,178,66,0.12); color: var(--warning); border-color: rgba(245,178,66,0.3); }

/* ===== Badges ===== */
.badge {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.3rem 0.7rem;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-soft);
    border: 1px solid var(--border);
    line-height: 1;
}
.badge-gold { background: var(--gold-soft); color: var(--gold); border-color: var(--border-strong); }
.badge-crimson { background: var(--crimson-soft); color: var(--crimson-bright); border-color: rgba(237,64,103,0.3); }
.badge-success { background: var(--success-soft); color: var(--success); border-color: rgba(77,209,144,0.3); }
.badge-indigo { background: var(--indigo-soft); color: var(--indigo); border-color: rgba(91,98,255,0.3); }

/* ===== Footer ===== */
.footer {
    margin-top: 4rem;
    padding: 3rem 1.5rem 2rem;
    background: linear-gradient(180deg, transparent, var(--bg-soft));
    border-top: 1px solid var(--border);
}
.footer__inner {
    max-width: var(--container);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1fr;
    gap: 2.5rem;
    margin-bottom: 2rem;
}
@media (max-width: 720px) {
    .footer__inner { grid-template-columns: 1fr 1fr; gap: 1.5rem; }
}
.footer__col h4 {
    font-size: 0.95rem;
    margin-bottom: 0.85rem;
    color: var(--text);
}
.footer__col a {
    display: block;
    padding: 0.3rem 0;
    color: var(--text-muted);
    font-size: 0.88rem;
    transition: var(--t);
}
.footer__col a:hover { color: var(--gold); }
.footer__brand {
    color: var(--text-soft);
    font-size: 0.92rem;
    line-height: 1.7;
    margin-top: 0.5rem;
    max-width: 280px;
}
.footer__copy {
    max-width: var(--container);
    margin: 0 auto;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ===== Animations ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes glow {
    0%, 100% { box-shadow: 0 0 30px var(--gold-glow); }
    50%      { box-shadow: 0 0 60px var(--gold-glow); }
}
@keyframes spin { to { transform: rotate(360deg); } }

.fade-in    { animation: fadeIn 0.5s var(--t) both; }
.slide-up   { animation: slideUp 0.7s var(--t) both; }
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
.delay-4 { animation-delay: 0.4s; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ===== Utilities ===== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-soft { color: var(--text-soft); }
.text-muted { color: var(--text-muted); }
.text-gold { color: var(--gold); }
.text-crimson { color: var(--crimson-bright); }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; } .mt-4 { margin-top: 2rem; } .mt-6 { margin-top: 3rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; } .mb-4 { margin-bottom: 2rem; } .mb-6 { margin-bottom: 3rem; }
.gap-1 { gap: 0.5rem; } .gap-2 { gap: 1rem; } .gap-3 { gap: 1.5rem; } .gap-4 { gap: 2rem; }
.w-full { width: 100%; }

/* ===== Loading spinner ===== */
.spinner {
    width: 36px; height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.spinner-lg { width: 56px; height: 56px; border-width: 4px; }
