/* ── Web fonts ────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Caveat+Brush&family=Space+Grotesk:wght@700&family=Syne:wght@700&family=Exo+2:wght@700&family=Orbitron:wght@700&display=swap');

/* ── Brand tokens ─────────────────────────────────────────────────────────── */
:root {
    --brand-purple:      #8D43F7;
    --brand-purple-dark: #240453;
    --brand-purple-soft: #B588F3;
    --brand-lime:        #BFFF02;
    --brand-purple-tint: rgba(141, 67, 247, 0.08);
    --brand-purple-tint2:rgba(141, 67, 247, 0.15);
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f8fafc;
    color: #1e293b;
    line-height: 1.6;
}

a { color: var(--brand-purple); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin-top: 0; line-height: 1.3; }

img { display: block; max-width: 100%; }

/* ── Site header ──────────────────────────────────────────────────────────── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--brand-purple);
    border-bottom: none;
    overflow: hidden;
}


.site-header-inner {
    position: relative;
    z-index: 1;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 40px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: 0;
    font-family: 'Caveat Brush', cursive;
    color: #ffffff;
    text-decoration: none;
    cursor: pointer;
}

.site-logo:hover {
    opacity: 0.85;
    text-decoration: none;
}

.site-logo-img {
    width: 38px;
    height: 38px;
    object-fit: contain;
    border-radius: 6px;
    flex-shrink: 0;
    transform: translateY(1px);
}

.site-header nav {
    display: inline-flex;
    align-items: center;
}

.site-header nav a,
.site-header nav .nav-btn {
    margin-left: 4px;
}

.site-header nav a:hover { color: var(--brand-lime); text-decoration: none; }

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    padding: 6px 10px;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.75);
    line-height: 1;
    transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #ffffff;
}

.nav-btn svg {
    flex-shrink: 0;
    vertical-align: middle;
}

.nav-btn--back {
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.28);
    color: #ffffff;
    font-weight: 700;
    padding: 7px 12px;
}

.nav-btn--back:hover {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 255, 255, 0.42);
}

/* ── Container ────────────────────────────────────────────────────────────── */
.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 12px 40px 64px;
}

.auth-container { max-width: 560px; }

.auth-container h1 {
    color: var(--brand-purple);
}

.auth-page .auth-container {
    position: relative;
    z-index: 3;
    margin-top: 18px;
    padding: 26px 28px 28px;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

.auth-page .auth-container .card {
    background: transparent;
    border: none;
    padding: 0;
    margin: 14px 0 12px;
}

/* ── Auth background discover preview ─────────────────────────────────────── */
.auth-page {
    position: relative;
    min-height: 100vh;
}

.auth-page .site-header,
.auth-page .container {
    position: relative;
    z-index: 2;
}

.auth-bg {
    position: fixed;
    inset: 56px 0 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.auth-bg-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 18px;
    padding: 14px 40px 40px;
    opacity: 0.8;
}

.auth-bg-card {
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    overflow: hidden;
}

.auth-bg-cover {
    aspect-ratio: 5 / 3;
    background: linear-gradient(135deg, #dbeafe 0%, #e9d5ff 55%, #ddd6fe 100%);
}

.auth-bg-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.auth-bg-card:nth-child(3n) .auth-bg-cover {
    background: linear-gradient(135deg, #dbeafe 0%, #ddd6fe 48%, #cffafe 100%);
}

.auth-bg-card:nth-child(4n) .auth-bg-cover {
    background: linear-gradient(135deg, #e0e7ff 0%, #e9d5ff 55%, #ede9fe 100%);
}

.auth-bg-body {
    padding: 12px;
}

.auth-bg-title,
.auth-bg-summary,
.auth-bg-meta {
    border-radius: 999px;
    background: #e2e8f0;
}

.auth-bg-title {
    height: 10px;
    width: 68%;
    margin-bottom: 10px;
}

.auth-bg-summary {
    height: 8px;
    width: 92%;
    margin-bottom: 8px;
}

.auth-bg-summary.short {
    width: 72%;
}

.auth-bg-meta {
    height: 8px;
    width: 44%;
}

.auth-bg-card--real {
    display: flex;
    flex-direction: column;
}

.auth-bg-real-meta {
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.82);
}

.auth-bg-real-title {
    margin: 0;
    font-size: 0.8rem;
    font-weight: 600;
    color: #334155;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.auth-bg-real-time {
    display: inline-block;
    margin-top: 4px;
    font-size: 0.72rem;
    color: #64748b;
}

.auth-bg-mask {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(to bottom, rgba(248, 250, 252, 0.35) 0%, rgba(248, 250, 252, 0.62) 100%),
        radial-gradient(circle at 50% 30%, rgba(141, 67, 247, 0.08) 0%, transparent 55%);
    backdrop-filter: blur(1px);
}

.auth-page .card {
    background: rgba(255, 255, 255, 0.93);
}

/* ── Story grid ───────────────────────────────────────────────────────────── */
.story-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 24px;
}

/* ── Story card ───────────────────────────────────────────────────────────── */
.story-card {
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    overflow: hidden;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.story-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 28px rgba(141, 67, 247, 0.15);
    border-color: var(--brand-purple-soft);
    text-decoration: none;
}

.story-card-cover {
    aspect-ratio: 5 / 3;
    overflow: hidden;
    background: #e2e8f0;
}

.story-card-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.3s ease;
}

.story-card:hover .story-card-cover img {
    transform: scale(1.03);
}

.story-card-body {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.story-card-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #0f172a;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.story-card-summary {
    margin: 0;
    font-size: 0.875rem;
    color: #64748b;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.story-card-meta {
    margin-top: auto;
    font-size: 0.78rem;
    color: var(--brand-purple-soft);
    font-weight: 500;
}

/* ── Infinite scroll sentinel ─────────────────────────────────────────────── */
.scroll-sentinel {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 24px;
    color: #94a3b8;
    font-size: 0.875rem;
}

.scroll-sentinel.loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 2px solid #e2e8f0;
    border-top-color: var(--brand-purple);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-size: 0.95rem;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s, transform 0.15s, box-shadow 0.15s;
    background: var(--brand-purple);
    color: #ffffff;
}

button:hover {
    background: #7c35e8;
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(36, 4, 83, 0.18);
}
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
    background: transparent;
    color: var(--brand-purple);
    border: 1.5px solid var(--brand-purple);
    padding: 7px 16px;
    font-size: 0.875rem;
}

.btn-ghost:hover { background: var(--brand-purple-tint); }

/* ── Auth card ────────────────────────────────────────────────────────────── */
.card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 28px;
    margin-bottom: 20px;
}

.card h2 { font-size: 1.15rem; margin-bottom: 4px; }

label {
    display: block;
    margin: 14px 0 6px;
    font-weight: 600;
    font-size: 0.9rem;
}

input[type="email"],
input[type="password"],
input[type="text"] {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.15s;
    background: #f8fafc;
}

input:focus {
    outline: none;
    border-color: var(--brand-purple);
    background: #fff;
}

/* Extra breathing room before submit actions in auth forms */
.card button[type="submit"],
.card .btn[type="submit"] {
    margin-top: 14px;
}

/* Keep auth submit buttons visually stable across label changes */
#loginBtn,
#registerBtn {
    min-width: 220px;
}

/* ── Page header (read page) ──────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 1.6rem;
    margin: 0;
    flex: 1;
}

.page-header nav a {
    font-size: 0.9rem;
    color: #64748b;
    white-space: nowrap;
}

/* ── Reading progress in header ───────────────────────────────────────────── */
.read-progress-bar {
    position: absolute;
    bottom: 6px;
    left: 0;
    width: 0%;
    height: 3px;
    background: var(--brand-lime);
    border-radius: 0 3px 3px 0;
    transition: width 0.1s linear;
    z-index: 5;
    pointer-events: none;
}

.read-progress-inline {
    display: inline-flex;
    align-items: center;
    margin-right: 8px;
    color: var(--brand-lime);
    font-size: 0.8rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

/* ── Resume toast ─────────────────────────────────────────────────────────── */
.resume-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: var(--brand-purple);
    color: #ffffff;
    border: none;
    padding: 10px 22px;
    border-radius: 24px;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s ease;
    z-index: 200;
}

.resume-toast.toast--visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Read page ────────────────────────────────────────────────────────────── */
.read-container {
    max-width: 1440px;
}

/* Keep key unplot_lite headers near screen edges on wide displays */
.auth-page .site-header-inner,
.discover-page .site-header-inner,
.read-page .site-header-inner {
    max-width: none;
    padding: 0 20px;
}

/* Hero: cover left + meta right */
.story-hero {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 32px;
    align-items: flex-start;
    margin: 0 auto 48px;
    max-width: 960px;
}

.story-hero-cover {
    aspect-ratio: 2 / 3;
    border-radius: 12px;
    overflow: hidden;
    background: var(--brand-purple-dark);
    flex-shrink: 0;
}

.story-hero-cover--placeholder {
    background: #e2e8f0;
}

.story-hero-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.story-hero-meta {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-top: 8px;
}

.story-hero-meta h1 {
    font-size: 1.75rem;
    line-height: 1.25;
    margin: 0;
    color: #0f172a;
}

.story-abstract {
    font-size: 1rem;
    color: #475569;
    line-height: 1.7;
    margin: 0;
}

/* Story layout: TOC + body */
.story-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 40px;
    border-top: 1px solid #e2e8f0;
    padding-top: 36px;
    align-items: start;
    max-width: 960px;
    margin: 0 auto;
}

/* TOC sidebar */
.story-toc {
    position: sticky;
    top: calc(56px + 20px);
}

.toc-heading {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #94a3b8;
    margin: 0 0 10px;
}

.toc-link {
    display: block;
    padding: 6px 10px;
    margin-bottom: 2px;
    font-size: 0.875rem;
    font-weight: 500;
    color: #64748b;
    border-left: 2px solid transparent;
    border-radius: 0 6px 6px 0;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    text-decoration: none;
}

.toc-link--title {
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e2e8f0;
}

.toc-link:hover {
    color: var(--brand-purple);
    background: var(--brand-purple-tint);
    text-decoration: none;
}

.toc-link--active {
    color: var(--brand-purple);
    border-left-color: var(--brand-purple);
    background: var(--brand-purple-tint);
    font-weight: 600;
}

/* Story body */
.story-body {
    min-width: 0;
    max-width: 720px;
}

.chapter {
    margin-bottom: 40px;
    scroll-margin-top: 80px;
}

.chapter h3 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--brand-purple);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 14px;
}

.story-body p {
    color: #1e293b;
    font-size: 1.05rem;
    line-height: 1.9;
    margin: 0;
}

/* Read page copy protection */
.read-container .story-hero-meta,
.read-container .story-body,
.read-container .chapter,
.read-container .chapter p,
.read-container .chapter h3 {
    -webkit-user-select: none;
    user-select: none;
}

/* Responsive */
@media (max-width: 700px) {
    .story-hero { grid-template-columns: 1fr; }
    .story-hero-cover { max-width: 160px; }
    .story-layout { grid-template-columns: 1fr; gap: 0; }
    .story-body { max-width: none; }
    .story-toc {
        position: fixed;
        top: calc(56px + 10px);
        left: 12px;
        right: 12px;
        z-index: 140;
        max-height: min(72vh, 460px);
        overflow-y: auto;
        display: none;
        background: rgba(255, 255, 255, 0.98);
        border: 1px solid #e2e8f0;
        border-radius: 14px;
        box-shadow: 0 16px 36px rgba(15, 23, 42, 0.18);
        padding: 10px;
    }
    .story-toc.toc-open { display: block; }
    .toc-heading {
        display: block;
        margin: 0 0 8px;
    }
    #tocNav {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }
    .toc-link {
        display: block;
        border-left: 2px solid transparent;
        border-radius: 8px;
        border-bottom: none;
        padding: 9px 10px;
        margin-bottom: 0;
        white-space: nowrap;
    }
    .toc-link--title {
        border-bottom: 1px solid #e2e8f0;
    }
    .toc-link--active {
        border-left-color: var(--brand-purple);
        background: var(--brand-purple-tint);
    }
}

/* ── Utility ──────────────────────────────────────────────────────────────── */
.message { min-height: 20px; margin: 8px 0; }
.message.error   { color: #dc2626; }
.message.success { color: #059669; }
.muted  { color: #64748b; }
.small  { font-size: 0.85em; }
.hidden { display: none; }
.required { color: #dc2626; }

/* ── Channel picker ───────────────────────────────────────────────────────── */
.channel-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.channel-btn {
    background: #f8fafc;
    color: #374151;
    border: 1.5px solid #cbd5e1;
    border-radius: 20px;
    padding: 7px 18px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.channel-btn:hover {
    background: var(--brand-purple-tint);
    border-color: var(--brand-purple-soft);
    color: var(--brand-purple);
}

.channel-btn.active {
    background: var(--brand-purple);
    border-color: var(--brand-purple);
    color: #ffffff;
}

.policy-consent {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 16px;
}

.policy-consent input[type="checkbox"] {
    margin-top: 2px;
}

.policy-consent-label {
    margin: 0;
    font-weight: 500;
    font-size: 0.86rem;
    line-height: 1.45;
    color: #334155;
}

.policy-consent-label a {
    font-weight: 600;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .site-header-inner { padding: 0 16px; }
    .auth-page .site-header-inner,
    .discover-page .site-header-inner,
    .read-page .site-header-inner {
        padding: 0 16px;
    }
    .container { padding: 20px 16px 48px; }
    .auth-container { padding: 20px 16px 48px; }
    .auth-page .auth-container {
        padding: 20px 18px 22px;
        margin-top: 12px;
    }
    .auth-bg-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
        padding: 12px 16px 28px;
    }
    .auth-bg-card:nth-child(n+9) {
        display: none;
    }
    .story-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }
    .story-card-body { padding: 12px; }
    .story-card-title { font-size: 0.95rem; }
    .story-card-summary { font-size: 0.82rem; }
    .page-header h1 { font-size: 1.2rem; }
}
