/* ============================================================
   BBATTL.com — Translucent Frost Theme
   A scholarly debate platform with grainy frosted glass aesthetic
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    --bg-base: #0f1118;
    --surface-frost: rgba(255, 255, 255, 0.06);
    --surface-frost-hover: rgba(255, 255, 255, 0.12);
    --text-primary: #e8e0d4;
    --text-secondary: #9b9285;
    --accent-warm: #c4a265;
    --accent-cool: #6b8cae;
    --border-frost: rgba(255, 255, 255, 0.08);
    --highlight-amber: #d4a843;
    --danger-crimson: #a34a4a;
    --victory-green: #5a8a6a;
    --grain-overlay: rgba(255, 255, 255, 0.03);

    --font-heading: 'EB Garamond', Georgia, serif;
    --font-body: 'Source Sans 3', 'Source Sans Pro', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --grid-gap: 24px;
    --card-padding: 32px;
    --radius: 6px;
    --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    background: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 1.125rem;
    line-height: 1.75;
    overflow-x: hidden;
    display: grid;
    grid-template-columns: 18% 58% 24%;
    min-height: 100vh;
}

/* --- Grain Overlay --- */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    filter: url(#grain-filter);
    background: transparent;
}

/* --- SVG Filters (hidden) --- */
.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --- Custom Quill Cursor --- */
@media (pointer: fine) {
    a, button, .book-spine, .rail-link, .clickable {
        cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M21 2C17 3 13 6 10 10L9 13L11 14C15 11 18 7 21 2Z' fill='%23c4a265' stroke='%23e8e0d4' stroke-width='0.5'/%3E%3Cpath d='M9 13L6 20L8 21L11 14' fill='%23e8e0d4' stroke='%239b9285' stroke-width='0.5'/%3E%3Cpath d='M6 20L3 22L5 21L6 20Z' fill='%239b9285'/%3E%3C/svg%3E") 3 22, pointer;
    }
}

/* --- Index Rail (Left Navigation) --- */
#index-rail {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 0;
    background: rgba(15, 17, 24, 0.6);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border-frost);
    z-index: 100;
}

.rail-brand {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: 0.15em;
    color: var(--accent-warm);
    margin-bottom: 48px;
    text-transform: uppercase;
}

.rail-nav {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
    justify-content: center;
}

.rail-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: var(--surface-frost);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-frost);
    text-decoration: none;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.rail-link:hover,
.rail-link.active {
    background: var(--surface-frost-hover);
    color: var(--accent-warm);
    border-color: rgba(196, 162, 101, 0.3);
    box-shadow: 0 0 20px rgba(196, 162, 101, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.numeral {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0;
}

.rail-footer {
    margin-top: auto;
}

.rail-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
    opacity: 0.5;
    writing-mode: vertical-lr;
    text-orientation: mixed;
    letter-spacing: 0.1em;
}

/* --- Main Content Column --- */
#main-content {
    min-height: 100vh;
    overflow: hidden;
}

/* --- Frost Panel Mixin-like Class --- */
.frost-panel {
    background: var(--surface-frost);
    backdrop-filter: blur(16px) saturate(120%);
    border: 1px solid var(--border-frost);
    border-radius: var(--radius);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
    position: relative;
}

/* Fallback for no backdrop-filter support */
@supports not (backdrop-filter: blur(16px)) {
    .frost-panel {
        background: rgba(15, 17, 24, 0.92);
    }
}

/* Dog-ear fold on panels */
.frost-panel::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: linear-gradient(225deg, var(--bg-base) 50%, rgba(255, 255, 255, 0.06) 50%);
    border-radius: 0 var(--radius) 0 0;
    z-index: 1;
}

/* --- Section I: Debate Stage (Hero) --- */
#debate-stage {
    height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(ellipse at 50% 40%, rgba(196, 162, 101, 0.08) 0%, transparent 70%),
        var(--bg-base);
    position: relative;
    padding: var(--card-padding);
    text-align: center;
}

.debate-stage-inner {
    display: flex;
    align-items: center;
    gap: 60px;
    margin-bottom: 48px;
}

.debate-contestant {
    text-align: center;
}

.contestant-label {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    display: block;
    margin-bottom: 12px;
}

.contestant-name {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 3.2rem;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1.1;
}

.contestant-school {
    font-family: var(--font-heading);
    font-style: italic;
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--accent-warm);
    display: block;
    margin-top: 8px;
}

/* VS Monogram */
.vs-monogram {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.vs-glow {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 2rem;
    color: var(--highlight-amber);
    text-shadow:
        0 0 30px rgba(212, 168, 67, 0.4),
        0 0 60px rgba(212, 168, 67, 0.2);
    z-index: 2;
    position: relative;
}

.vs-ring {
    position: absolute;
    width: 80px;
    height: 80px;
    border: 2px solid rgba(212, 168, 67, 0.3);
    border-radius: 50%;
    animation: vs-pulse 3s ease-in-out infinite;
}

@keyframes vs-pulse {
    0%, 100% { transform: scale(1); opacity: 0.3; }
    50% { transform: scale(1.15); opacity: 0.6; }
}

/* Debate Topic */
.debate-topic {
    max-width: 600px;
    margin: 0 auto;
}

.topic-label {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--accent-warm);
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: 16px;
}

.topic-text {
    font-family: var(--font-heading);
    font-style: italic;
    font-weight: 500;
    font-size: 1.5rem;
    color: var(--text-primary);
    line-height: 1.6;
    opacity: 0.9;
}

/* Scroll Indicator */
.scroll-indicator {
    position: absolute;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    animation: float-down 2s ease-in-out infinite;
}

@keyframes float-down {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(8px); }
}

.scroll-text {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    display: block;
    margin-bottom: 8px;
}

.scroll-arrow {
    font-size: 1.2rem;
    color: var(--accent-warm);
    opacity: 0.6;
}

/* --- Dashboard Sections --- */
.dashboard-section {
    padding: 80px var(--card-padding) 40px;
}

.section-header {
    margin-bottom: 40px;
}

.section-header h2 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 2.4rem;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.section-subtitle {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--accent-warm);
    letter-spacing: 0.05em;
}

/* --- Section II: Library Wall --- */
.book-shelf {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--grid-gap);
}

.book-spine {
    perspective: 800px;
    height: 220px;
}

.book-spine .spine-front,
.book-spine .spine-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: var(--radius);
    padding: var(--card-padding);
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: var(--surface-frost);
    backdrop-filter: blur(16px) saturate(120%);
    border: 1px solid var(--border-frost);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
    transition: transform 0.6s ease;
}

.book-spine .spine-back {
    transform: rotateY(180deg);
    background: rgba(15, 17, 24, 0.95);
}

.book-spine:hover .spine-front {
    transform: rotateY(-180deg);
}

.book-spine:hover .spine-back {
    transform: rotateY(0deg);
}

.book-spine .spine-front,
.book-spine .spine-back {
    position: absolute;
    inset: 0;
}

.book-spine {
    position: relative;
    cursor: pointer;
}

.spine-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}

.spine-authors {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.spine-ribbon {
    position: absolute;
    top: 0;
    right: 16px;
    width: 14px;
    height: 36px;
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 80%, 0 100%);
}

.spine-ribbon.victory {
    background: var(--victory-green);
}

.spine-ribbon.defeat {
    background: var(--danger-crimson);
}

.spine-ribbon.draw {
    background: var(--highlight-amber);
}

.spine-summary {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 12px;
}

.spine-date {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent-warm);
    letter-spacing: 0.05em;
}

/* Dog-ear on spine front */
.book-spine .spine-front::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 16px;
    height: 16px;
    background: linear-gradient(225deg, var(--bg-base) 50%, rgba(255, 255, 255, 0.06) 50%);
    border-radius: 0 var(--radius) 0 0;
    z-index: 1;
}

/* --- Book Divider --- */
.book-divider {
    display: flex;
    justify-content: center;
    padding: 48px 0 0;
    opacity: 0.6;
}

.divider-svg {
    width: 120px;
    height: 30px;
}

/* --- Section IV: Scoreboard Codex --- */
.codex-table-wrap {
    padding: var(--card-padding);
    overflow-x: auto;
}

.codex-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.codex-table thead th {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent-warm);
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-frost);
    letter-spacing: 0.02em;
}

.codex-table tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}

.codex-table tbody tr:hover {
    background: var(--surface-frost-hover);
}

.scholar-name {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary) !important;
}

.score-gold {
    color: var(--highlight-amber) !important;
    font-weight: 700;
}

.counter {
    font-variant-numeric: tabular-nums;
}

/* --- Pull Quote --- */
.pull-quote {
    margin: 48px 0 0;
    padding: 32px;
    border-left: 3px solid var(--accent-warm);
    background: var(--surface-frost);
    border-radius: 0 var(--radius) var(--radius) 0;
}

.pull-quote p {
    font-family: var(--font-heading);
    font-style: italic;
    font-weight: 500;
    font-size: 1.5rem;
    color: var(--text-primary);
    line-height: 1.6;
    margin-bottom: 12px;
}

.pull-quote cite {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-style: normal;
}

/* --- Marginalia Stream (Sidebar) --- */
#marginalia-stream {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 40px 20px;
    border-left: 1px solid var(--border-frost);
    background: rgba(15, 17, 24, 0.4);
    backdrop-filter: blur(8px);
}

#marginalia-stream::-webkit-scrollbar {
    width: 4px;
}

#marginalia-stream::-webkit-scrollbar-track {
    background: transparent;
}

#marginalia-stream::-webkit-scrollbar-thumb {
    background: var(--border-frost);
    border-radius: 2px;
}

.marginalia-header {
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-frost);
}

.marginalia-header h3 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.3rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.marginalia-subtitle {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent-warm);
}

.marginalia-item {
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    animation: marginalia-fade-in 0.3s ease-in;
}

@keyframes marginalia-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.marginalia-glyph {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--accent-warm);
    display: block;
    margin-bottom: 6px;
}

.marginalia-text {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 6px;
}

.marginalia-time {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: rgba(155, 146, 133, 0.6);
    letter-spacing: 0.05em;
}

/* --- Mobile Marginalia (hidden on desktop) --- */
.mobile-only {
    display: none;
}

/* --- Footer --- */
#site-footer {
    padding: 80px var(--card-padding) 40px;
    text-align: center;
    border-top: 1px solid var(--border-frost);
}

.footer-brand {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.8rem;
    color: var(--accent-warm);
    letter-spacing: 0.1em;
    margin-bottom: 8px;
}

.footer-tagline {
    font-family: var(--font-heading);
    font-style: italic;
    font-weight: 500;
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.footer-divider {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
    opacity: 0.5;
}

.footer-copy {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: rgba(155, 146, 133, 0.5);
    letter-spacing: 0.05em;
}

/* --- Bounce Enter Animation --- */
.bounce-enter {
    opacity: 0;
    transform: scale(0.85);
}

.bounce-enter.visible {
    opacity: 1;
    transform: scale(1);
    animation: bounce-in 600ms var(--bounce) forwards;
}

@keyframes bounce-in {
    0% { opacity: 0; transform: scale(0.85); }
    60% { opacity: 1; transform: scale(1.02); }
    100% { opacity: 1; transform: scale(1); }
}

/* Hover tilt for frost panels */
.book-spine .spine-front {
    transition: transform 0.6s ease, background 0.3s ease;
}

.book-spine .spine-back {
    transition: transform 0.6s ease;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    body {
        grid-template-columns: 60px 1fr 220px;
    }

    .contestant-name {
        font-size: 2.4rem;
    }

    .debate-stage-inner {
        gap: 30px;
    }

    .book-shelf {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    body {
        display: flex;
        flex-direction: column;
    }

    #index-rail {
        position: sticky;
        top: 0;
        height: auto;
        flex-direction: row;
        padding: 12px 20px;
        z-index: 200;
        width: 100%;
        gap: 8px;
    }

    .rail-brand {
        margin-bottom: 0;
        margin-right: 16px;
        font-size: 1rem;
    }

    .rail-nav {
        flex-direction: row;
        gap: 8px;
        flex: 1;
        justify-content: center;
    }

    .rail-link {
        width: 38px;
        height: 38px;
    }

    .numeral {
        font-size: 0.85rem;
    }

    .rail-footer {
        display: none;
    }

    #marginalia-stream {
        display: none;
    }

    .mobile-only {
        display: block;
    }

    .debate-stage-inner {
        flex-direction: column;
        gap: 24px;
    }

    .contestant-name {
        font-size: 2.2rem;
    }

    .section-header h2 {
        font-size: 1.8rem;
    }

    .book-shelf {
        grid-template-columns: 1fr;
    }

    .topic-text {
        font-size: 1.2rem;
    }

    .codex-table-wrap {
        padding: 16px;
    }

    .codex-table {
        font-size: 0.75rem;
    }

    .codex-table thead th,
    .codex-table tbody td {
        padding: 8px 10px;
    }

    .pull-quote p {
        font-size: 1.2rem;
    }

    .dashboard-section {
        padding: 60px 20px 30px;
    }
}

@media (max-width: 480px) {
    .contestant-name {
        font-size: 1.8rem;
    }

    .vs-glow {
        font-size: 1.4rem;
    }

    .vs-ring {
        width: 60px;
        height: 60px;
    }

    .debate-stage-inner {
        gap: 16px;
    }

    .section-header h2 {
        font-size: 1.5rem;
    }
}

/* --- Desktop Sidebar visibility --- */
@media (min-width: 769px) {
    .desktop-only {
        display: block;
    }
}

/* --- Selection Styling --- */
::selection {
    background: rgba(196, 162, 101, 0.3);
    color: var(--text-primary);
}

/* --- Additional grain on frost panels --- */
.frost-panel::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    opacity: 0.05;
    filter: url(#grain-filter);
    pointer-events: none;
    z-index: 0;
}

/* Marginalia mobile list styling */
#marginalia-list-mobile .marginalia-item {
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

#marginalia-list-mobile .marginalia-glyph {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--accent-warm);
    display: block;
    margin-bottom: 6px;
}

#marginalia-list-mobile .marginalia-text {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 6px;
}

#marginalia-list-mobile .marginalia-time {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: rgba(155, 146, 133, 0.6);
    letter-spacing: 0.05em;
}
