:root {
    --bg: #f5f0e4;
    --bg-paper: #faf7ef;
    --ink: #2c2418;
    --ink-light: #6b5f50;
    --ink-muted: #9a8e7e;
    --vermillion: #c41e3a;
    --vermillion-bg: rgba(196,30,58,0.06);
    --gold: #8a6d2b;
    --gold-dim: #7a6030;
    --gold-bg: rgba(138,109,43,0.06);
    --border: #d4c9a8;
    --border-light: #e5ddd0;
    --font-title: 'Ma Shan Zheng', cursive;
    --font-body: 'Noto Serif SC', serif;
    --paper-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
}

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: 24px;
}

body {
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.8;
    color: var(--ink);
    background: var(--bg);
    display: flex;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        var(--paper-noise),
        radial-gradient(ellipse at 10% 20%, rgba(120,100,60,0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 90% 80%, rgba(100,80,50,0.05) 0%, transparent 45%);
}

.toc {
    position: fixed;
    left: 0;
    top: 0;
    width: 220px;
    height: 100vh;
    background: var(--bg-paper);
    background-image: var(--paper-noise);
    border-right: 1px solid var(--border-light);
    padding: 32px 16px 32px 20px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 2px 0 12px rgba(0,0,0,0.03);
}

.toc-title {
    font-family: var(--font-title);
    font-size: 1.2rem;
    color: var(--vermillion);
    letter-spacing: 3px;
}

.toc-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--vermillion);
}

.toc-close {
    display: none;
}

.toc-list {
    list-style: none;
}

.toc-item {
    margin-bottom: 2px;
    border-bottom: 1px solid rgba(0,0,0,0.03);
}

.toc-item:last-child {
    border-bottom: none;
}

.toc-link {
    display: block;
    padding: 4px 8px;
    font-size: 0.8rem;
    color: var(--ink-muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all 0.25s ease;
    line-height: 1.5;
}

.toc-link:hover {
    color: var(--ink);
    border-left-color: var(--border);
    background: rgba(0,0,0,0.02);
}

.toc-link.active {
    color: var(--vermillion);
    border-left: 3px solid var(--vermillion);
    background: var(--vermillion-bg);
    font-weight: 600;
    padding-left: 7px;
}

.toc-link::before {
    content: '';
    display: inline-block;
    width: 0;
    transition: width 0.3s ease;
}

.toc-link.active::before {
    width: 0;
}

.rulebook {
    margin-left: 220px;
    flex: 1;
    max-width: 820px;
    padding: 60px 40px 120px;
    position: relative;
    background-image: var(--paper-noise);
}

.rulebook::before,
.rulebook::after {
    content: '';
    position: absolute;
    top: 40px;
    bottom: 40px;
    width: 1px;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        var(--border-light) 8%,
        var(--border-light) 92%,
        transparent 100%
    );
    pointer-events: none;
}

.rulebook::before {
    left: 16px;
}

.rulebook::after {
    right: 16px;
}

.rulebook h1 {
    font-family: var(--font-title);
    font-size: 2.6rem;
    color: var(--ink);
    letter-spacing: 6px;
    text-align: center;
    margin-bottom: 8px;
}

.rulebook h1 + hr {
    border: none;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--vermillion), var(--gold), var(--vermillion), transparent);
    margin-bottom: 48px;
}

.rulebook h2 {
    font-family: var(--font-title);
    font-size: 1.7rem;
    color: var(--ink);
    letter-spacing: 3px;
    margin-top: 52px;
    margin-bottom: 20px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.rulebook h2::before {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 80px;
    height: 2px;
    background: var(--vermillion);
}

.rulebook h3 {
    font-family: var(--font-title);
    font-size: 1.25rem;
    color: var(--ink-light);
    letter-spacing: 2px;
    margin-top: 28px;
    margin-bottom: 12px;
}

.rulebook p {
    margin-bottom: 14px;
}

.rulebook strong {
    color: var(--vermillion);
    font-weight: 700;
}

.rulebook em {
    font-style: italic;
    color: var(--ink-light);
}

.rulebook hr {
    border: none;
    height: 1px;
    background: var(--border-light);
    margin: 36px 0;
}

.rulebook ul,
.rulebook ol {
    padding-left: 24px;
    margin-bottom: 14px;
}

.rulebook li {
    margin-bottom: 6px;
}

.rulebook blockquote {
    margin: 16px 0;
    padding: 16px 20px 16px 28px;
    background: var(--gold-bg);
    border-left: 3px solid var(--gold-dim);
    border-radius: 0 4px 4px 0;
    color: var(--ink-light);
    font-size: 0.92rem;
    line-height: 1.9;
    position: relative;
}

.rulebook blockquote::before {
    content: '\201C';
    position: absolute;
    top: 4px;
    left: 8px;
    font-family: var(--font-title);
    font-size: 2rem;
    color: var(--gold);
    opacity: 0.35;
    line-height: 1;
    pointer-events: none;
}

.rulebook blockquote strong {
    color: var(--gold-dim);
}

.rulebook code {
    background: var(--vermillion-bg);
    color: var(--vermillion);
    padding: 1px 6px;
    border-radius: 2px;
    font-family: var(--font-body);
    font-size: 0.92em;
    border: 1px solid rgba(196,30,58,0.1);
}

.rulebook table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 0.92rem;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.rulebook thead th {
    background: var(--ink);
    color: var(--bg);
    font-weight: 600;
    padding: 10px 14px;
    text-align: left;
    letter-spacing: 1px;
    font-size: 0.85rem;
}

.rulebook thead th:first-child { border-radius: 3px 0 0 0; }
.rulebook thead th:last-child { border-radius: 0 3px 0 0; }

.rulebook tbody td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.2s ease;
}

.rulebook tbody tr:nth-child(even) {
    background: rgba(0,0,0,0.015);
}

.rulebook tbody tr {
    transition: background 0.25s ease, box-shadow 0.25s ease;
}

.rulebook tbody tr:hover {
    background: rgba(196,30,58,0.04);
    box-shadow: inset 2px 0 0 var(--vermillion);
}

.rulebook tbody tr:last-child td:first-child { border-radius: 0 0 0 3px; }
.rulebook tbody tr:last-child td:last-child { border-radius: 0 0 3px 0; }

.back-top {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 40px;
    height: 40px;
    background: var(--bg-paper);
    border: 1px solid var(--border);
    border-radius: 50%;
    font-size: 1.1rem;
    color: var(--ink-muted);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
}

.back-top.show {
    opacity: 1;
    pointer-events: auto;
}

.back-top:hover {
    border-color: var(--vermillion);
    color: var(--vermillion);
    box-shadow: 0 4px 16px rgba(196,30,58,0.15);
    transform: translateY(-2px);
}

.rules-header {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 150;
    display: flex;
    gap: 8px;
    padding: 10px 16px;
}

.rules-back {
    font-family: var(--font-body);
    font-size: 0.85rem;
    color: var(--ink-muted);
    text-decoration: none;
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg-paper);
    transition: all 0.2s;
}

.rules-back:hover {
    color: var(--vermillion);
    border-color: var(--vermillion);
}

.toc-toggle {
    display: none;
    font-family: var(--font-body);
    font-size: 0.85rem;
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg-paper);
    color: var(--ink-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.toc-toggle:hover {
    color: var(--vermillion);
    border-color: var(--vermillion);
}

.toc-overlay {
    display: none;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.2); }

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

    .rules-header {
        position: sticky;
        top: 0;
        left: 0;
        right: 0;
        background: var(--bg);
        border-bottom: 1px solid var(--border-light);
        padding: 8px 16px;
        z-index: 200;
        justify-content: space-between;
    }

    .toc-toggle {
        display: block;
    }

    .toc {
        position: fixed;
        left: -280px;
        top: 0;
        width: 260px;
        height: 100vh;
        background: var(--bg-paper);
        background-image: var(--paper-noise);
        border-right: 1px solid var(--border-light);
        padding: 20px 16px;
        overflow-y: auto;
        z-index: 300;
        box-shadow: 4px 0 16px rgba(0,0,0,0.08);
        transition: left 0.3s ease;
    }

    .toc.open {
        left: 0;
    }

    .toc-close {
        display: block;
        position: absolute;
        top: 12px;
        right: 12px;
        background: none;
        border: none;
        font-size: 1.3rem;
        color: var(--ink-muted);
        cursor: pointer;
    }

    .toc-close:hover {
        color: var(--vermillion);
    }

    .toc-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.3);
        z-index: 250;
    }

    .toc-overlay.show {
        display: block;
    }

    .rulebook {
        margin-left: 0;
        padding: 20px 16px 80px;
    }

    .rulebook::before,
    .rulebook::after {
        display: none;
    }

    .rulebook h1 {
        font-size: 2rem;
        letter-spacing: 4px;
    }

    .rulebook h2 {
        font-size: 1.4rem;
        margin-top: 36px;
        margin-bottom: 14px;
    }

    .rulebook table {
        font-size: 0.85rem;
    }

    .rulebook thead th,
    .rulebook tbody td {
        padding: 6px 10px;
    }

    .back-top {
        bottom: 20px;
        right: 16px;
        width: 36px;
        height: 36px;
    }
}

.global-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 900;
    display: flex;
    justify-content: center;
    gap: 0;
    background: rgba(245,240,228,0.88);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(212,201,168,0.5);
    background-image: linear-gradient(
        to right,
        transparent,
        rgba(196,30,58,0.15),
        rgba(138,109,43,0.15),
        rgba(196,30,58,0.15),
        transparent
    );
    background-size: 100% 2px;
    background-repeat: no-repeat;
    background-position: top;
}

.global-nav-item {
    flex: 1;
    max-width: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 12px 10px;
    text-decoration: none;
    background: none;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-body);
    position: relative;
}

.global-nav-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 2px;
    background: var(--vermillion);
    border-radius: 0 0 2px 2px;
    transition: width 0.3s ease;
}

.global-nav-item:hover {
    background: rgba(0,0,0,0.03);
}

.global-nav-item.active {
    background: rgba(196,30,58,0.04);
}

.global-nav-item.active::before {
    width: 32px;
}

.global-nav-icon {
    font-family: var(--font-title);
    font-size: 1.3rem;
    color: var(--ink-light);
    line-height: 1;
    transition: color 0.2s;
}

.global-nav-item.active .global-nav-icon {
    color: var(--vermillion);
}

.global-nav-label {
    font-size: 0.68rem;
    color: var(--ink-light);
    letter-spacing: 1px;
    transition: color 0.2s;
}

.global-nav-item.active .global-nav-label {
    color: var(--vermillion);
    font-weight: 600;
}

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