/* ============================================================
   GeekRewind Theme — Main Stylesheet
   Design system built for Core Web Vitals + AdSense + SEO
   ============================================================ */

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
    --color-primary:      #6366f1;
    --color-primary-dark: #4f46e5;
    --color-primary-light:#ede9fe;
    --color-accent:       #06b6d4;
    --color-text:         #1e293b;
    --color-text-muted:   #64748b;
    --color-text-light:   #94a3b8;
    --color-bg:           #ffffff;
    --color-bg-soft:      #f8fafc;
    --color-bg-muted:     #f1f5f9;
    --color-border:       #e2e8f0;
    --color-border-dark:  #cbd5e1;
    --color-success:      #22c55e;
    --color-warn:         #f59e0b;
    --color-danger:       #ef4444;

    --font-sans:   system-ui,-apple-system,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
    --font-mono:   'JetBrains Mono','Fira Code','Cascadia Code',Consolas,Monaco,monospace;
    --font-size:   16px;
    --line-height: 1.75;

    --content-width:  780px;
    --sidebar-width:  300px;
    --layout-gap:     32px;
    --max-width:      1140px;

    --radius-sm:  4px;
    --radius-md:  8px;
    --radius-lg:  12px;
    --radius-xl:  16px;

    --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
    --shadow-md:  0 4px 16px rgba(0,0,0,.1);
    --shadow-lg:  0 8px 32px rgba(0,0,0,.12);

    --header-height: 64px;
    --ad-bg:         #f8fafc;
}

/* ── Reset & base ────────────────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: var(--font-size); scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: var(--line-height);
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { color: var(--color-primary-dark); text-decoration: underline; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.gr-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 20px;
}

.gr-layout {
    display: grid;
    grid-template-columns: 1fr var(--sidebar-width);
    gap: var(--layout-gap);
    align-items: start;
    padding: 32px 0;
}

.gr-main { min-width: 0; }

/* Sidebar column — stretches to match main content height */
.gr-sidebar {
    min-width: 0;
    width: var(--sidebar-width);
    /* align-self:stretch makes it as tall as the main article column
       so the sticky ad has room to travel the full scroll distance */
    align-self: stretch;
}

/* Inner wrapper — flex column, full height, no overflow clipping */
.gr-sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Sticky ad — sticks to top of viewport as user scrolls.
   Works because .gr-sidebar is stretch-height (same as article). */
.gr-sidebar-ad-sticky {
    position: -webkit-sticky;
    position: sticky;
    top: calc(var(--header-height) + 16px);
    margin-top: 20px;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.gr-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    border-bottom: 1px solid var(--color-border);
    height: var(--header-height);
    box-shadow: var(--shadow-sm);
}

.gr-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    gap: 0;
}

/* ── Logo — site name text, top left, no icon ─────────────────────────── */
.gr-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: var(--color-text);
    font-weight: 900;
    font-size: 1.35rem;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: -.03em;
    line-height: 1;
}
.gr-logo__wordmark {
    display: flex;
    align-items: baseline;
    gap: 0;
}
.gr-logo__geek {
    color: var(--color-text);
}
.gr-logo__rewind {
    color: var(--color-primary);
}
/* Hide the icon div — site name only */
.gr-logo__icon { display: none; }
.gr-logo:hover { text-decoration: none; }
.gr-logo:hover .gr-logo__geek   { color: var(--color-primary-dark); }
.gr-logo:hover .gr-logo__rewind { color: var(--color-accent); }

/* ── Right side — nav + search ────────────────────────────────────────── */
.gr-header__right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    justify-content: flex-end;
}

/* Nav links */
.gr-nav {
    display: flex;
    align-items: center;
}

.gr-nav__list {
    display: flex;
    align-items: center;
    gap: 2px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.gr-nav__list li { margin: 0; padding: 0; }

.gr-nav__list li a,
.gr-nav a {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-muted);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    text-decoration: none;
    transition: color .2s, background .2s;
    white-space: nowrap;
    display: inline-block;
}

.gr-nav__list li a:hover,
.gr-nav__list li a[aria-current="page"],
.gr-nav__list li.current-menu-item > a,
.gr-nav__list li.current_page_item > a {
    color: var(--color-primary);
    background: var(--color-primary-light);
    text-decoration: none;
}

/* Search icon sits flush after last nav link */
.sal-search-menu-item {
    display: flex;
    align-items: center;
    list-style: none;
    margin-left: 4px;
}
.sal-search-trigger {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 6px 10px;
    cursor: pointer;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 600;
    transition: all .2s;
    white-space: nowrap;
}
.sal-search-trigger:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
    background: var(--color-primary-light);
}
.sal-search-trigger kbd {
    font-size: 10px;
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border-dark);
    border-radius: 3px;
    padding: 0 4px;
    font-family: var(--font-mono);
    color: var(--color-text-light);
    line-height: 1.6;
}

/* Mobile menu toggle */
.gr-menu-toggle {
    display: none;
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 6px 10px;
    cursor: pointer;
    color: var(--color-text);
    font-size: 20px;
    line-height: 1;
    margin-left: 8px;
}

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */
.gr-breadcrumb {
    background: var(--color-bg-soft);
    border-bottom: 1px solid var(--color-border);
    padding: 10px 0;
    font-size: 12px;
    color: var(--color-text-muted);
}
.gr-breadcrumb a { color: var(--color-text-muted); }
.gr-breadcrumb a:hover { color: var(--color-primary); }
.gr-breadcrumb span { margin: 0 6px; color: var(--color-text-light); }

/* ── Hero / Post header ──────────────────────────────────────────────────── */
.gr-post-header { margin-bottom: 28px; }

.gr-post-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}
.gr-cat-badge {
    display: inline-block;
    background: var(--color-primary-light);
    color: var(--color-primary-dark);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 3px 10px;
    border-radius: 99px;
    text-decoration: none;
}
.gr-cat-badge:hover { background: var(--color-primary); color: #fff; text-decoration: none; }

.gr-post-title {
    font-size: clamp(1.6rem, 3vw, 2.2rem);
    font-weight: 800;
    line-height: 1.2;
    color: var(--color-text);
    margin-bottom: 16px;
    letter-spacing: -.02em;
}

/* Featured image */
.gr-featured-image {
    margin: 24px 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
    aspect-ratio: 16/9;
    background: var(--color-bg-muted);
}
.gr-featured-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ── Ad slots ────────────────────────────────────────────────────────────── */
.gr-ad {
    text-align: center;
    overflow: hidden;
    position: relative;
}
/* No ::before — "Advertisement" label removed */

/* Below title — leaderboard */
.gr-ad--leaderboard {
    min-height: 90px;
    margin: 20px 0 28px;
}
/* Mid-content — rectangle */
.gr-ad--rectangle {
    min-height: 250px;
    margin: 32px auto;
    max-width: 336px;
}
/* Sidebar half-page 300x600 */
.gr-ad--halfpage {
    width: 300px;
    min-height: 600px;
    display: block;
}
.gr-ad--halfpage ins.adsbygoogle {
    display: inline-block !important;
    width: 300px;
    height: 600px;
}
/* Sidebar 300x250 */
.gr-ad--sidebar {
    width: 300px;
    min-height: 250px;
}

/* After content */
.gr-ad--footer {
    min-height: 90px;
    margin: 32px 0;
}

/* ── Post content typography ─────────────────────────────────────────────── */
.gr-content {
    font-size: 1.0625rem;
    line-height: 1.8;
    color: var(--color-text);
}

.gr-content h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--color-text);
    margin: 2.2em 0 .75em;
    padding-bottom: .4em;
    border-bottom: 2px solid var(--color-border);
    letter-spacing: -.01em;
    scroll-margin-top: calc(var(--header-height) + 16px);
}

.gr-content h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 1.8em 0 .6em;
    scroll-margin-top: calc(var(--header-height) + 16px);
}

.gr-content h4 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 1.4em 0 .5em;
}

.gr-content p { margin-bottom: 1.2em; }

.gr-content ul,
.gr-content ol {
    margin: 0 0 1.2em 1.5em;
    padding: 0;
}
.gr-content li { margin-bottom: .4em; }

.gr-content strong { font-weight: 700; color: var(--color-text); }
.gr-content em { font-style: italic; }

.gr-content blockquote {
    border-left: 4px solid var(--color-primary);
    background: var(--color-primary-light);
    padding: 16px 20px;
    margin: 1.5em 0;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    font-style: italic;
    color: var(--color-text-muted);
}

/* Inline code */
.gr-content :not(pre) > code {
    font-family: var(--font-mono);
    font-size: .875em;
    background: var(--color-bg-muted);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    color: var(--color-primary-dark);
    white-space: nowrap;
}

/* Tables */
.gr-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5em 0;
    font-size: .9375rem;
}
.gr-content th {
    background: var(--color-bg-soft);
    font-weight: 700;
    text-align: left;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    color: var(--color-text);
}
.gr-content td {
    padding: 9px 14px;
    border: 1px solid var(--color-border);
    vertical-align: top;
}
.gr-content tr:nth-child(even) td { background: var(--color-bg-soft); }

/* Images in content */
.gr-content figure {
    margin: 1.5em 0;
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.gr-content figure img { border-radius: var(--radius-lg); }
.gr-content figcaption {
    font-size: .8125rem;
    color: var(--color-text-muted);
    text-align: center;
    padding: 8px 12px;
    background: var(--color-bg-soft);
}

/* ── Steps ───────────────────────────────────────────────────────────────── */
.gr-steps { counter-reset: gr-step; margin: 1.5em 0; }
.gr-step {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    align-items: flex-start;
}
.gr-step__number {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    background: var(--color-primary);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: .875rem;
    counter-increment: gr-step;
    margin-top: 2px;
}
.gr-step__number::after { content: counter(gr-step); }
.gr-step__body { flex: 1; min-width: 0; }
.gr-step__body h3 { margin-top: 0; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.gr-sidebar-widget {
    background: var(--color-bg-soft);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 24px;
}
.gr-sidebar-widget__title {
    font-size: .875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--color-text-muted);
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
}

/* Sidebar widget scrollbar styling */
.gr-sidebar-widget::-webkit-scrollbar { width: 4px; }
.gr-sidebar-widget::-webkit-scrollbar-thumb { background: var(--color-border-dark); border-radius: 4px; }

/* ── Archive / home cards ────────────────────────────────────────────────── */
.gr-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 24px;
}

.gr-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    transition: box-shadow .2s, transform .2s;
    display: flex;
    flex-direction: column;
}
.gr-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.gr-card__thumb {
    aspect-ratio: 16/9;
    overflow: hidden;
    background: var(--color-bg-muted);
}
.gr-card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .3s;
}
.gr-card:hover .gr-card__thumb img { transform: scale(1.03); }

.gr-card__thumb--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 40px;
    background: linear-gradient(135deg, var(--color-primary-light), #e0f2fe);
}

.gr-card__body { padding: 20px; flex: 1; display: flex; flex-direction: column; }
.gr-card__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.gr-card__time { font-size: 11px; color: var(--color-text-light); }
.gr-card__title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.35;
    margin-bottom: 8px;
    text-decoration: none;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.gr-card__title:hover { color: var(--color-primary); text-decoration: none; }
.gr-card__excerpt {
    font-size: .875rem;
    color: var(--color-text-muted);
    line-height: 1.6;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.gr-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--color-border);
    font-size: 12px;
    color: var(--color-text-light);
}
.gr-card__read-more {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}
.gr-card__read-more:hover { text-decoration: underline; }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.gr-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 32px 0;
    flex-wrap: wrap;
}
.gr-pagination a,
.gr-pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    color: var(--color-text-muted);
    transition: all .2s;
}
.gr-pagination a:hover { background: var(--color-primary-light); color: var(--color-primary); border-color: var(--color-primary); text-decoration: none; }
.gr-pagination .current { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.gr-footer {
    background: #0f172a;
    color: #94a3b8;
    padding: 48px 0 24px;
    margin-top: 64px;
}
.gr-footer__grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 40px;
    margin-bottom: 40px;
}
.gr-footer__brand { }
.gr-footer__logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.125rem;
    color: #fff;
    text-decoration: none;
    margin-bottom: 12px;
}
.gr-footer__logo:hover { text-decoration: none; color: var(--color-primary-light); }
.gr-footer__desc { font-size: .875rem; line-height: 1.7; max-width: 280px; }

.gr-footer__col-title {
    font-size: .8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #fff;
    margin-bottom: 14px;
}
.gr-footer__links { list-style: none; }
.gr-footer__links li { margin-bottom: 8px; }
.gr-footer__links a {
    font-size: .875rem;
    color: #64748b;
    text-decoration: none;
    transition: color .2s;
}
.gr-footer__links a:hover { color: var(--color-primary-light); text-decoration: none; }

.gr-footer__bottom {
    border-top: 1px solid #1e293b;
    padding-top: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .8125rem;
    flex-wrap: wrap;
    gap: 12px;
}
.gr-footer__bottom a { color: #64748b; }
.gr-footer__bottom a:hover { color: var(--color-primary-light); }

/* ── Search results page ─────────────────────────────────────────────────── */
.gr-search-header {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: #fff;
    padding: 48px 0;
    margin-bottom: 40px;
    text-align: center;
}
.gr-search-form {
    display: flex;
    max-width: 560px;
    margin: 20px auto 0;
    background: #fff;
    border-radius: 999px;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}
.gr-search-form input {
    flex: 1;
    border: none;
    padding: 14px 20px;
    font-size: 16px;
    outline: none;
    color: var(--color-text);
}
.gr-search-form button {
    background: var(--color-primary);
    border: none;
    padding: 14px 24px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s;
}
.gr-search-form button:hover { background: var(--color-primary-dark); }

/* ── 404 page ────────────────────────────────────────────────────────────── */
.gr-404 {
    text-align: center;
    padding: 80px 20px;
}
.gr-404__code {
    font-size: clamp(5rem, 15vw, 9rem);
    font-weight: 900;
    color: var(--color-primary-light);
    line-height: 1;
    margin-bottom: 8px;
}
.gr-404__title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 12px;
}
.gr-404__text { color: var(--color-text-muted); margin-bottom: 28px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.gr-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--color-primary);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background .2s, transform .1s;
}
.gr-btn:hover { background: var(--color-primary-dark); color: #fff; text-decoration: none; transform: translateY(-1px); }
.gr-btn--outline {
    background: transparent;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
}
.gr-btn--outline:hover { background: var(--color-primary); color: #fff; }

/* ── Tag / category archive ──────────────────────────────────────────────── */
.gr-archive-header {
    background: linear-gradient(135deg, var(--color-primary-light), #e0f2fe);
    border-radius: var(--radius-xl);
    padding: 40px;
    margin-bottom: 32px;
}
.gr-archive-header h1 { font-size: 2rem; font-weight: 800; margin-bottom: 8px; }
.gr-archive-header p { color: var(--color-text-muted); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .gr-layout { grid-template-columns: 1fr; }
    .gr-sidebar { display: none; }
    .gr-footer__grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    :root { --header-height: 56px; }
    .gr-nav { display: none; }
    .gr-nav.open {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        position: fixed;
        inset: var(--header-height) 0 0 0;
        background: #fff;
        padding: 12px 16px;
        z-index: 99;
        border-top: 1px solid var(--color-border);
        overflow-y: auto;
    }
    .gr-nav.open .gr-nav__list {
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        width: 100%;
    }
    .gr-nav.open .gr-nav__list li a {
        padding: 12px 16px;
        font-size: 16px;
        border-radius: var(--radius-md);
        display: block;
    }
    /* Hide search trigger text label on mobile */
    .sal-search-trigger kbd { display: none; }
    .gr-menu-toggle { display: flex; align-items: center; }
    .gr-cards { grid-template-columns: 1fr; }
    .gr-footer__grid { grid-template-columns: 1fr; gap: 24px; }
    .gr-footer__bottom { flex-direction: column; text-align: center; }
    .gr-post-title { font-size: 1.5rem; }
    .gr-ad--rectangle { max-width: 100%; }
}

@media (max-width: 480px) {
    .gr-container { padding: 0 14px; }
    .gr-card__body { padding: 14px; }
    .gr-archive-header { padding: 24px; }
    .gr-archive-header h1 { font-size: 1.5rem; }
}

/* ── Print ───────────────────────────────────────────────────────────────── */
@media print {
    .gr-header, .gr-footer, .gr-sidebar, .gr-ad, .sal-search-overlay { display: none !important; }
    .gr-layout { display: block; }
    .gr-content { font-size: 12pt; }
}
