/* Import fonts */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300..700&family=Space+Grotesk:wght@400..700&family=JetBrains+Mono:wght@400..700&display=swap");

/* Set CSS custom properties */
:root {
    --font-body: "Inter", system-ui, sans-serif;
    --font-heading: "Space Grotesk", var(--font-body);
    --font-code: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

/* Apply typography */
html {
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.55;
    font-size: 18px;
    font-size-adjust: 0.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-size: 18px;
}

h1,
h2,
h3 {
    font-family: var(--font-heading);
    font-weight: 600;
    letter-spacing: -0.01em;
}

pre,
code,
kbd,
samp {
    font-family: var(--font-code);
    font-size: 0.95em;
}

/* Optional: optical balance */
h1 {
    font-size: clamp(2.2rem, 4vw, 3.4rem);
}

h2 {
    font-size: clamp(1.7rem, 3vw, 2.4rem);
}

:root {
    /* Brand palette */
    --primary-color: #5f4d93;
    --secondary-color: #6b5b95;
    --accent-color: #e37682;

    /* Text & surfaces */
    --text-color: #1f2937; /* slate-800 */
    --text-light: #4b5563; /* slate-600 */
    --background: #f3f4f6; /* slate-100 */
    --surface: #ffffff; /* white */
    --surface-light: #f8fafc; /* slate-50 */
    --code-bg: #f5f7fb; /* very light indigo */
    --border-color: #e5e7eb; /* slate-200 */
    --highlight-bg: #fff5f5;

    /* FX */
    --ring-color: rgba(95, 77, 147, 0.2);
    --shadow-color: 0, 0, 0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-size-adjust: 0.5;
    line-height: 1.7;
    color: var(--text-color);
    /* Layered, soft gradient background */
    background:
        radial-gradient(1200px 600px at 70% -10%, rgba(140, 201, 240, 0.18), transparent 60%),
        radial-gradient(900px 500px at -10% 10%, rgba(239, 168, 176, 0.25), transparent 55%),
        linear-gradient(45deg, #fbe8ea 0%, #ece8f6 50%, #e9f4fc 100%);
}

.container {
    max-width: 920px;
    margin: 2rem auto;
    padding: 0;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 16px;
    box-shadow: none;
    overflow: hidden;
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.content-wrapper {
    padding: 2rem 1.75rem;
}

header {
    text-align: center;
    margin-bottom: 1.25rem;
    padding: 2.5rem 0 1.5rem;
}

header h1 {
    font-size: clamp(2.2rem, 5vw, 3.2rem);
    font-weight: 700;
    margin-bottom: 0.75rem;
    line-height: 1.12;
    letter-spacing: -0.02em;
    position: relative;
    background: linear-gradient(90deg, #5f4d93 0%, #e37682 50%, #5f4d93 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-light);
    margin-bottom: 1.75rem;
    font-weight: 400;
    line-height: 1.5;
}

/* Minimal theme toggle icons */
.theme-toggle-icons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.theme-toggle-icons button {
    appearance: none;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-light);
    padding: 0.25rem;
    border-radius: 6px;
    cursor: pointer;
    line-height: 0;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.theme-toggle-icons button:hover {
    color: var(--text-color);
    background: var(--surface-light);
    border-color: var(--border-color);
}

.theme-toggle-icons button[aria-pressed="true"] {
    color: var(--primary-color);
    background: var(--surface-light);
    border-color: var(--border-color);
}

.theme-toggle-icons svg {
    width: 16px;
    height: 16px;
}

/* Theme toggle */
.theme-toggle {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.theme-toggle .toggle-btn {
    appearance: none;
    border: 1px solid var(--border-color);
    background: var(--surface);
    color: var(--text-color);
    padding: 0.4rem 0.9rem;
    border-radius: 999px;
    cursor: pointer;
    font: inherit;
    font-size: 0.95rem;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
    box-shadow: none;
}

.theme-toggle .toggle-btn:hover {
    transform: translateY(-1px);
}

.theme-toggle .toggle-btn[aria-pressed="true"] {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #ffffff;
}

.quick-nav {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.quick-nav a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 400;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    transition: all 0.2s ease;
    background: var(--surface);
    box-shadow: none;
}

.quick-nav a:hover {
    /* Keep appearance stable on hover */
    background: var(--surface);
    color: var(--primary-color);
    border-color: var(--border-color);
    text-decoration: none;
}

/* Extra specific selector to ensure white color on navigation hover */
header .quick-nav a:hover {
    color: var(--primary-color);
}

.contribute-btn {
    border-color: var(--primary-color);
    font-weight: 600;
    box-shadow: none;
}

.contribute-btn:hover {
    background: var(--primary-color) !important;
    color: white !important;
    border-color: var(--primary-color) !important;
    box-shadow: none;
}

section {
    margin: 4rem 0;
    scroll-margin-top: 2rem;
}

section:first-of-type {
    margin-top: 1rem;
}

/* Content h1 elements (not the main header) */
main h1 {
    font-size: 2.2rem;
    margin: 2rem 0 1rem 0;
    color: var(--primary-color);
    font-weight: 400;
    position: relative;
    padding-top: 1rem;
}

main h1:before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 1px;
    background: linear-gradient(90deg, #efa8b0, #a89cc8, #8cc9f0);
}

h2 {
    font-size: 1.75rem;
    margin: 3rem 0 2rem 0;
    color: var(--primary-color);
    font-weight: 600;
    letter-spacing: -0.01em;
    position: relative;
    padding-bottom: 0.75rem;
}

h2:after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 3rem;
    height: 2px;
    background: var(--primary-color);
    border-radius: 1px;
}

h3 {
    font-size: 1.3rem;
    margin: 3.5rem 0 1.5rem 0;
    color: var(--text-color);
    font-weight: 600;
}

h4 {
    font-size: 1.1rem;
    margin: 1.5rem 0 0.5rem 0;
    color: var(--primary-color);
    font-weight: 600;
}

p {
    margin-bottom: 1.2rem;
    color: var(--text-color);
    line-height: 1.7;
}

.principle-box {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.75rem;
    margin: 2rem 0;
    border-left: 4px solid var(--primary-color);
    box-shadow: none;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.principle-box:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, var(--primary-color), transparent);
}

.principle-box:hover {
    transform: translateY(-2px);
    box-shadow: none;
    border-color: var(--primary-color);
}

.principle-title {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}

code {
    background: var(--code-bg);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.9rem;
    font-size-adjust: 0.5;
    color: var(--accent-color);
}

pre {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1.1rem 1.25rem;
    margin: 1rem 0;
    overflow-x: auto;
    font-size: 0.9rem;
    font-size-adjust: 0.5;
}

pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    color: var(--text-color);
}

ul,
ol {
    margin: 1.2rem 0;
    padding-left: 2rem;
}

li {
    margin-bottom: 0.6rem;
    line-height: 1.6;
}

/* Modern Rules Cards */
.rules-list {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin: 2rem 0;
    padding: 0;
    counter-reset: rule-counter;
}

.rules-list li {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 2rem;
    margin: 0;
    position: relative;
    list-style: none;
    counter-increment: rule-counter;
    transition: all 0.3s ease;
    box-shadow: none;
    overflow: hidden;
}

.rules-container ul li:before {
    content: counter(rule-counter);
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: var(--primary-color);
    color: var(--background);
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    box-shadow: none;
}

.rules-list li:after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
}

.rules-list li:hover {
    transform: translateY(-4px);
    box-shadow: none;
    border-color: var(--primary-color);
}

.rules-container ul li strong {
    display: block;
    font-size: 1.15rem;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    margin-right: 3rem;
    font-weight: 600;
    line-height: 1.3;
}

.rules-list li p {
    margin: 0;
    line-height: 1.6;
    color: var(--text-color);
}

/* Regular list styling for other sections */
ul li:not(.rules-list li):before {
    content: '•';
    color: var(--primary-color);
    font-weight: bold;
    position: absolute;
    margin-left: -1.2rem;
}

ul li:not(.rules-list li) {
    position: relative;
    list-style: none;
}

/* Mobile responsiveness for rule cards */
@media (max-width: 768px) {
    .rules-list li {
        padding: 1.5rem;
    }

    .rules-list li:before {
        top: 1rem;
        right: 1rem;
        width: 2rem;
        height: 2rem;
        font-size: 0.9rem;
    }

    .rules-list li strong {
        margin-right: 2.5rem;
        font-size: 1.05rem;
    }
}

.highlight {
    /* background: linear-gradient(120deg, var(--highlight-bg) 0%, var(--highlight-bg) 100%); */
    background-repeat: no-repeat;
    background-size: 100% 0.2em;
    background-position: 0 88%;
    padding: 0.1rem 0.2rem;
    color: var(--primary-color);
    font-weight: 500;
}

.example {
    background: var(--surface);
    border: 1px solid var(--accent-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin: 2rem 0;
    position: relative;
    overflow: hidden;
}

.example:before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent-color);
}

.example h4 {
    color: var(--accent-color);
    margin-bottom: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
}

blockquote {
    border-left: 4px solid var(--primary-color);
    background: var(--surface);
    padding: 1rem 1.5rem;
    margin: 1rem 0;
    border-radius: 0 0.5rem 0.5rem 0;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover:not(.quick-nav a):not(.contribute-btn) {
    text-decoration: underline;
}

strong {
    color: var(--primary-color);
}

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

footer {
    text-align: center;
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-light);
}

.github-btn {
    color: white;
    background-color: #24292e;
    border: 1px solid #24292e;
    font-weight: 500;
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    display: inline-flex;
    align-items: center;
    transition: all 0.2s ease;
}

.github-btn:hover {
    /* Keep appearance stable on hover */
    background-color: #24292e;
    border-color: #24292e;
    text-decoration: none;
}

/* Progress bar */
.scroll-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0;
    height: 3px;
    background: linear-gradient(90deg, #efa8b0, #a89cc8, #8cc9f0);
    z-index: 1000;
    transition: width 0.1s linear;
}

/* Selection */
::selection {
    background: rgba(95, 77, 147, 0.15);
}

/* Dark mode (auto), but do not apply if user chose light) */
@media (prefers-color-scheme: dark) {
    html:not([data-theme="light"]) {
        --text-color: #e5e7eb; /* slate-200 */
        --text-light: #9ca3af; /* slate-400 */
        --background: #0b0b10;
        --surface: rgba(22, 22, 28, 0.7);
        --surface-light: #101018;
        --code-bg: #0f172a; /* slate-900 */
        --border-color: #1f2937; /* slate-800 */
        /* Increased contrast for links/headlines in dark theme */
        --primary-color: #c0b5ff;
    }

    html:not([data-theme="light"]) body {
        background:
            radial-gradient(900px 500px at 80% -10%, rgba(95, 77, 147, 0.25), transparent 60%),
            radial-gradient(800px 400px at 0% 0%, rgba(227, 118, 130, 0.16), transparent 55%),
            linear-gradient(45deg, #0b0b10 0%, #0e1020 60%, #0b0b10 100%);
    }

    html:not([data-theme="light"]) .container {
        background: rgba(15, 17, 25, 0.6);
        border: 1px solid rgba(255, 255, 255, 0.06);
        box-shadow: none;
    }

    html:not([data-theme="light"]) .quick-nav a {
        background: rgba(255, 255, 255, 0.06);
        color: #e5e7eb; /* improve contrast */
        border-color: rgba(255, 255, 255, 0.16);
    }

    html:not([data-theme="light"]) .github-btn {
        box-shadow: none;
    }
}

/* Explicit theme overrides (user-chosen) */
/* Light uses base variables (no overrides) */
html[data-theme="dark"] {
    --text-color: #e5e7eb;
    --text-light: #9ca3af;
    --background: #0b0b10;
    --surface: rgba(22, 22, 28, 0.7);
    --surface-light: #101018;
    --code-bg: #0f172a;
    --border-color: #1f2937;
    /* Increased contrast for links/headlines in explicit dark theme */
    --primary-color: #c0b5ff;
}

html[data-theme="dark"] body {
    background:
        radial-gradient(900px 500px at 80% -10%, rgba(95, 77, 147, 0.25), transparent 60%),
        radial-gradient(800px 400px at 0% 0%, rgba(227, 118, 130, 0.16), transparent 55%),
        linear-gradient(45deg, #0b0b10 0%, #0e1020 60%, #0b0b10 100%);
}

/* Ensure readable nav pills when user explicitly chooses dark */
html[data-theme="dark"] .quick-nav a {
    background: rgba(255, 255, 255, 0.06);
    color: #e5e7eb;
    border-color: rgba(255, 255, 255, 0.16);
}

/* Remove code/pre backgrounds to avoid white lines in dark mode */
html[data-theme="dark"] pre,
html[data-theme="dark"] code,
html[data-theme="dark"] pre code {
    background: transparent !important;
    border-color: transparent !important;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
    h1 { font-size: 2rem; }
    h2 { font-size: 1.5rem; }

    /* Make quick nav horizontally scrollable pills on mobile */
    .quick-nav {
        gap: 0.75rem;
        padding: 0.25rem 0.5rem;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        scroll-snap-type: x mandatory;
        touch-action: pan-x;
        scrollbar-width: none;
        mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 16px), transparent 100%);
        -webkit-mask-image: linear-gradient(to right, transparent 0, black 16px, black calc(100% - 16px), transparent 100%);
    }
    .quick-nav::-webkit-scrollbar { display: none; }

    .quick-nav a {
        display: inline-flex;
        align-items: center;
        white-space: nowrap;
        padding: 0.45rem 0.75rem;
        scroll-snap-align: start;
        font-size: 0.95rem;
    }

    .container { padding: 0.6rem; max-width: 100%; }

    .content-wrapper { padding: 1.25rem; }
    header { padding: 1.5rem 0 0.75rem; margin-bottom: 1rem; }
    header h1 { letter-spacing: -0.01em; }
    .subtitle { font-size: 1rem; margin-bottom: 1.25rem; }
    .theme-toggle-icons { gap: 0.4rem; margin-bottom: 1rem; }

    .principle-box { padding: 1.1rem; margin: 1.25rem 0; }
    section { margin: 2rem 0; }

    pre { padding: 0.9rem 1rem; font-size: 0.85rem; -webkit-overflow-scrolling: touch; }
    code { font-size: 0.85rem; }

    .scroll-progress { height: 2px; }
}

/* Small phones */
@media (max-width: 480px) {
    html { font-size: 16px; }
    header h1 { font-size: 1.75rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }
    .logo-img { max-width: 140px; filter: drop-shadow(0 5px 10px rgba(0,0,0,0.06)); }
    .container { margin: 1rem auto; border-radius: 12px; }
    main h1 { font-size: 1.6rem; margin-top: 1.5rem; }
    .quick-nav { gap: 0.6rem; }
    .quick-nav a { padding: 0.4rem 0.7rem; font-size: 0.95rem; }
}

/* Accessible motion preferences */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* Inline-style replacements */
.logo-container {
    text-align: center;
    margin-bottom: 1.25rem;
}

.logo-img {
    max-width: 200px;
    height: auto;
    display: block;
    margin: 0 auto;
    filter: drop-shadow(0 6px 12px rgba(0,0,0,0.06));
}

.github-btn svg {
    vertical-align: middle;
    margin-right: 6px;
}
