:root {
    --guide-ink: #071827;
    --guide-navy: #0c2a42;
    --guide-sea: #087b91;
    --guide-teal: #35d0ba;
    --guide-sand: #ffd166;
    --guide-cream: #fff4cc;
    --guide-coral: #ff8066;
    --guide-pink: #ff6b9d;
}

html {
    scroll-behavior: smooth;
}

.rulebook-page {
    background: var(--guide-ink);
    color: #fff8e8;
}

.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 20000;
    padding: 12px 16px;
    background: var(--guide-cream);
    color: var(--guide-ink);
    font-size: 9px;
    text-decoration: none;
    transform: translateY(-150%);
}

.skip-link:focus {
    transform: translateY(0);
}

.rulebook-hero {
    position: relative;
    isolation: isolate;
    display: grid;
    min-height: 78svh;
    place-items: center;
    overflow: hidden;
    padding: 118px 20px 95px;
    border-bottom: 5px solid var(--guide-sand);
    background:
        radial-gradient(circle at 78% 19%, rgba(255, 242, 194, 0.92) 0 5rem, transparent 5.2rem),
        linear-gradient(180deg, #355f9d 0%, #da7181 40%, #ffad72 62%, #f7cf81 73%, #178ca5 73.5%, #07506c 100%);
}

.rulebook-hero::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 2;
    opacity: 0.12;
    background:
        linear-gradient(90deg, transparent 50%, rgba(255, 255, 255, 0.1) 50%),
        linear-gradient(0deg, transparent 50%, rgba(255, 255, 255, 0.07) 50%);
    background-size: 5px 5px;
    pointer-events: none;
}

.rulebook-hero .summer-scene {
    z-index: 3;
}

.rulebook-hero-content {
    position: relative;
    z-index: 5;
    width: min(920px, 92vw);
    padding: clamp(26px, 4vw, 48px);
    border: 3px solid rgba(255, 244, 204, 0.7);
    border-bottom-color: var(--guide-teal);
    background: linear-gradient(160deg, rgba(7, 24, 39, 0.76), rgba(7, 24, 39, 0.54));
    box-shadow: 10px 12px 0 rgba(7, 24, 39, 0.25), 0 34px 90px rgba(7, 24, 39, 0.28);
    text-align: center;
    backdrop-filter: blur(5px);
}

.rulebook-kicker,
.eyebrow,
.section-number,
.card-label {
    font-family: 'Press Start 2P', monospace;
    letter-spacing: 1px;
}

.rulebook-kicker {
    margin-bottom: 18px;
    color: var(--guide-teal);
    font-size: clamp(7px, 1.2vw, 11px);
}

.rulebook-hero h1 {
    margin: 0;
    background: linear-gradient(90deg, var(--guide-cream), var(--guide-sand), var(--guide-coral), var(--guide-teal), var(--guide-cream));
    background-size: 260% 100%;
    background-clip: text;
    -webkit-background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    -webkit-text-stroke: 1px var(--guide-cream);
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(36px, 8vw, 86px);
    line-height: 1.15;
    text-shadow: 4px 4px 0 #71335d, 8px 8px 0 var(--guide-ink);
    animation: guide-title-shift 7s steps(18, end) infinite, guide-title-float 3.8s ease-in-out infinite;
}

.rulebook-lead {
    max-width: 760px;
    margin: 26px auto 0;
    color: #fff8e8;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: clamp(17px, 2vw, 22px);
    line-height: 1.65;
    text-shadow: 0 2px 8px rgba(7, 24, 39, 0.8);
}

.rulebook-hero-actions,
.final-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px;
    margin-top: 28px;
}

@keyframes guide-title-shift {
    from { background-position: 0% 50%; }
    to { background-position: 260% 50%; }
}

@keyframes guide-title-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.rulebook-toc {
    position: sticky;
    top: 84px;
    z-index: 100;
    display: flex;
    justify-content: center;
    gap: 5px;
    overflow-x: auto;
    padding: 10px 14px;
    border-bottom: 3px solid #07506c;
    background: linear-gradient(90deg, var(--guide-sand), #ffbf69 50%, var(--guide-sand));
    box-shadow: 0 8px 0 rgba(4, 20, 32, 0.2);
    scrollbar-width: thin;
}

.rulebook-toc a {
    flex: 0 0 auto;
    padding: 11px 13px;
    border: 1px solid rgba(18, 52, 74, 0.24);
    color: #12344a;
    font-size: 7px;
    line-height: 1;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.rulebook-toc a:hover,
.rulebook-toc a:focus-visible {
    background: #12344a;
    color: var(--guide-cream);
    outline: none;
    transform: translateY(-2px);
}

.rulebook-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 72px 0 90px;
}

.guide-intro,
.rulebook-section,
.final-checklist {
    scroll-margin-top: 160px;
}

.guide-intro {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
    gap: clamp(28px, 5vw, 70px);
    align-items: center;
    margin-bottom: 48px;
    padding: clamp(28px, 5vw, 54px);
    border: 4px solid var(--guide-coral);
    background: linear-gradient(145deg, var(--guide-cream), #f5d175);
    color: #173c4d;
    box-shadow: 9px 9px 0 #07506c;
}

.guide-intro h2,
.rulebook-section h2,
.final-checklist h2 {
    margin: 8px 0 18px;
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(19px, 3vw, 31px);
    line-height: 1.45;
}

.guide-intro p,
.rulebook-section p,
.rulebook-section li,
.final-checklist li,
.command-table td {
    font-family: 'Segoe UI', Arial, sans-serif;
}

.guide-intro > div > p:last-child {
    font-size: 18px;
    line-height: 1.75;
}

.section-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 36px;
    padding: 8px 10px;
    background: #173c4d;
    color: var(--guide-sand);
    font-size: 10px;
}

.fact-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.fact-card {
    display: grid;
    min-height: 118px;
    place-items: center;
    align-content: center;
    padding: 16px;
    border: 3px solid #173c4d;
    background: rgba(255, 250, 240, 0.65);
    text-align: center;
}

.fact-card strong {
    color: #b6375d;
    font-family: 'Press Start 2P', monospace;
    font-size: clamp(21px, 3vw, 34px);
}

.fact-card span {
    margin-top: 10px;
    color: #173c4d;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 14px;
    font-weight: 700;
}

.rulebook-section {
    position: relative;
    margin-top: 32px;
    padding: clamp(28px, 5vw, 58px);
    border: 3px solid rgba(53, 208, 186, 0.56);
    background:
        radial-gradient(circle at 92% 8%, rgba(255, 209, 102, 0.08), transparent 20rem),
        linear-gradient(155deg, rgba(12, 42, 66, 0.98), rgba(7, 24, 39, 0.98));
    box-shadow: 8px 8px 0 rgba(4, 20, 32, 0.7), 0 20px 50px rgba(4, 20, 32, 0.2);
}

.rulebook-section:nth-of-type(even) {
    border-color: rgba(255, 128, 102, 0.65);
}

.section-heading {
    display: flex;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 34px;
}

.section-heading .section-number {
    flex: 0 0 auto;
    background: var(--guide-sand);
    color: var(--guide-ink);
    box-shadow: 4px 4px 0 #71335d;
}

.section-heading h2 {
    margin-bottom: 0;
    color: var(--guide-cream);
}

.eyebrow {
    margin: 0;
    color: var(--guide-teal);
    font-size: 8px;
    line-height: 1.6;
}

.step-list {
    display: grid;
    gap: 14px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.step-list li {
    display: grid;
    grid-template-columns: 54px 1fr;
    gap: 18px;
    align-items: start;
    padding: 20px;
    border-left: 4px solid var(--guide-teal);
    background: rgba(255, 248, 232, 0.06);
    transition: transform 0.2s ease, background 0.2s ease;
}

.step-list li:hover {
    background: rgba(53, 208, 186, 0.1);
    transform: translateX(5px);
}

.step-index {
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    background: var(--guide-coral);
    color: var(--guide-ink);
    font-family: 'Press Start 2P', monospace;
    font-size: 13px;
    box-shadow: 4px 4px 0 #71335d;
}

.step-list h3,
.guide-card h3,
.currency-card h3,
.modifier-flow h3 {
    margin: 0 0 9px;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    line-height: 1.65;
}

.step-list p,
.guide-card p,
.currency-card p,
.modifier-flow p {
    margin: 0;
    font-size: 16px;
    line-height: 1.65;
}

code {
    padding: 3px 6px;
    border: 1px solid rgba(53, 208, 186, 0.38);
    background: #06131e;
    color: var(--guide-sand);
    font-family: Consolas, 'Courier New', monospace;
    font-size: 0.92em;
}

.guide-callout {
    margin-top: 24px;
    padding: 20px 22px;
    border: 3px solid var(--guide-coral);
    background: rgba(255, 128, 102, 0.12);
    color: #fff8e8;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 16px;
    line-height: 1.65;
}

.guide-callout.coral strong {
    color: var(--guide-coral);
}

.guide-callout.warning {
    border-color: var(--guide-sand);
    background: rgba(255, 209, 102, 0.1);
}

.guide-callout.warning strong {
    color: var(--guide-sand);
}

.guide-grid.two-columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.guide-card {
    min-width: 0;
    padding: 26px;
    color: #173c4d;
    box-shadow: 6px 6px 0 #07506c;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.guide-card:hover {
    transform: translateY(-5px);
    box-shadow: 8px 10px 0 #07506c;
}

.sand-card {
    border: 4px solid var(--guide-coral);
    background: linear-gradient(150deg, var(--guide-cream), #f5d175);
}

.sea-card {
    border: 4px solid var(--guide-teal);
    background: linear-gradient(150deg, #d9fff7, #86d8cc);
}

.guide-card code {
    color: var(--guide-sand);
}

.card-label {
    display: inline-block;
    margin-bottom: 16px;
    padding: 7px 9px;
    background: #173c4d;
    color: var(--guide-cream);
    font-size: 7px;
}

.guide-card pre {
    max-width: 100%;
    margin: 18px 0 0;
    overflow-x: auto;
    white-space: pre-wrap;
}

.guide-card pre code {
    display: block;
    padding: 13px;
    line-height: 1.6;
}

.mini-note {
    margin-top: 16px !important;
    font-weight: 700;
}

.currency-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.currency-card {
    padding: 26px 22px;
    border: 3px solid;
    color: #173c4d;
    box-shadow: 5px 5px 0 rgba(4, 20, 32, 0.45);
}

.currency-icon {
    display: block;
    margin-bottom: 13px;
    font-size: 36px;
}

.zijani-card {
    border-color: var(--guide-coral);
    background: #ffd6a6;
}

.dubari-card {
    border-color: #d79b21;
    background: var(--guide-sand);
}

.darzhanti-card {
    border-color: var(--guide-teal);
    background: #a7ecdf;
}

.score-equation {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto 1.25fr;
    gap: 12px;
    align-items: stretch;
    margin-top: 24px;
}

.score-equation span,
.score-equation strong,
.score-equation b {
    display: grid;
    place-items: center;
    min-height: 82px;
    padding: 16px;
    text-align: center;
}

.score-equation span {
    border: 2px solid var(--guide-teal);
    background: rgba(53, 208, 186, 0.1);
    color: var(--guide-cream);
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    line-height: 1.6;
}

.score-equation b {
    padding: 0;
    color: var(--guide-sand);
    font-family: 'Press Start 2P', monospace;
    font-size: 24px;
}

.score-equation strong {
    border: 3px solid var(--guide-coral);
    background: var(--guide-cream);
    color: #173c4d;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    line-height: 1.7;
}

.rules-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 24px;
}

.rules-list > div {
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 14px;
    padding: 18px;
    border-left: 4px solid var(--guide-sand);
    background: rgba(255, 248, 232, 0.05);
}

.rules-list > div > span {
    color: var(--guide-coral);
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
}

.rules-list p {
    margin: 0;
    font-size: 15px;
    line-height: 1.65;
}

.ranking-note {
    margin: 24px 0 0;
    padding: 18px 20px;
    border: 2px dashed var(--guide-teal);
    font-size: 16px;
    line-height: 1.7;
}

.rulebook-section a {
    color: var(--guide-sand);
    text-underline-offset: 3px;
}

.modifier-flow {
    display: grid;
    grid-template-columns: repeat(7, auto);
    gap: 10px;
    align-items: center;
}

.modifier-flow article {
    height: 100%;
    padding: 20px;
    border: 3px solid var(--guide-teal);
    background: rgba(53, 208, 186, 0.08);
}

.modifier-flow article > span {
    display: grid;
    width: 38px;
    height: 38px;
    margin-bottom: 15px;
    place-items: center;
    background: var(--guide-coral);
    color: var(--guide-ink);
    font-family: 'Press Start 2P', monospace;
    box-shadow: 3px 3px 0 #71335d;
}

.modifier-flow i {
    color: var(--guide-sand);
    font-family: 'Press Start 2P', monospace;
    font-size: 18px;
    font-style: normal;
}

.modifier-flow p {
    font-size: 14px;
}

.sun-list {
    display: grid;
    gap: 10px;
    margin: 24px 0 0;
    padding: 0;
    list-style: none;
}

.sun-list li {
    position: relative;
    padding: 14px 16px 14px 48px;
    background: rgba(255, 209, 102, 0.07);
    font-size: 16px;
    line-height: 1.6;
}

.sun-list li::before {
    content: '☀';
    position: absolute;
    top: 13px;
    left: 16px;
    color: var(--guide-sand);
    font-size: 20px;
}

.fair-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.fair-grid article {
    display: grid;
    grid-template-columns: 38px 1fr;
    gap: 14px;
    align-items: start;
    padding: 20px;
    border: 2px solid rgba(255, 244, 204, 0.16);
    background: rgba(255, 248, 232, 0.05);
}

.fair-grid article > span {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    background: var(--guide-teal);
    color: var(--guide-ink);
    font-weight: 900;
}

.fair-grid p {
    margin: 0;
    font-size: 15px;
    line-height: 1.65;
}

.command-table-wrap {
    overflow-x: auto;
    border: 3px solid var(--guide-teal);
    box-shadow: 6px 6px 0 rgba(4, 20, 32, 0.55);
}

.command-table {
    width: 100%;
    min-width: 680px;
    border-collapse: collapse;
    background: #fff4cc;
    color: #173c4d;
}

.command-table th,
.command-table td {
    padding: 17px 20px;
    border-bottom: 2px solid rgba(23, 60, 77, 0.16);
    text-align: left;
}

.command-table th {
    background: var(--guide-teal);
    color: var(--guide-ink);
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
}

.command-table td:first-child {
    width: 38%;
}

.command-table tr:last-child td {
    border-bottom: 0;
}

.command-table tbody tr {
    transition: background 0.18s ease;
}

.command-table tbody tr:hover {
    background: #a7ecdf;
}

.command-table code {
    white-space: nowrap;
}

.final-checklist {
    display: grid;
    grid-template-columns: 0.8fr 1.2fr;
    gap: 30px 50px;
    align-items: center;
    margin-top: 32px;
    padding: clamp(30px, 5vw, 58px);
    border: 4px solid var(--guide-coral);
    background: linear-gradient(145deg, var(--guide-cream), #f5d175);
    color: #173c4d;
    box-shadow: 9px 9px 0 #07506c;
}

.final-checklist .eyebrow {
    color: #a82f56;
}

.final-checklist ul {
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.final-checklist li {
    position: relative;
    padding-left: 30px;
    font-size: 16px;
    line-height: 1.55;
}

.final-checklist li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: #087b72;
    font-weight: 900;
}

.final-actions {
    grid-column: 1 / -1;
    margin-top: 0;
}

.rulebook-page footer {
    border-top-color: var(--guide-sand);
}

.rulebook-page a:focus-visible,
.rulebook-page button:focus-visible,
.rulebook-page summary:focus-visible {
    outline: 3px solid var(--guide-sand);
    outline-offset: 4px;
}

.step-list li,
.guide-card,
.currency-card,
.modifier-flow article,
.fair-grid article,
.command-table tbody tr {
    cursor: pointer;
}

@media (max-width: 980px) {
    .guide-intro,
    .final-checklist {
        grid-template-columns: 1fr;
    }

    .currency-grid {
        grid-template-columns: 1fr;
    }

    .modifier-flow {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .modifier-flow i {
        display: none;
    }
}

@media (max-width: 760px) {
    .rulebook-hero {
        min-height: 88svh;
        padding: 94px 10px 72px;
    }

    .rulebook-hero-content {
        padding: 24px 14px;
        backdrop-filter: blur(3px);
    }

    .rulebook-hero h1 {
        font-size: clamp(30px, 12vw, 58px);
        text-shadow: 3px 3px 0 #71335d, 6px 6px 0 var(--guide-ink);
    }

    .rulebook-toc {
        top: 68px;
        justify-content: flex-start;
    }

    .rulebook-shell {
        width: min(100% - 20px, 1180px);
        padding-top: 46px;
    }

    .guide-intro,
    .rulebook-section,
    .final-checklist {
        padding: 25px 18px;
    }

    .guide-grid.two-columns,
    .rules-list,
    .fair-grid {
        grid-template-columns: 1fr;
    }

    .score-equation {
        grid-template-columns: 1fr;
    }

    .score-equation b {
        min-height: 34px;
    }

    .section-heading {
        gap: 12px;
    }

    .modifier-flow {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .rulebook-page .summer-nav a:nth-child(3),
    .rulebook-page .summer-nav a:nth-child(4) {
        display: none;
    }

    .fact-grid {
        grid-template-columns: 1fr;
    }

    .step-list li {
        grid-template-columns: 42px 1fr;
        gap: 12px;
        padding: 16px 12px;
    }

    .step-index {
        width: 38px;
        height: 38px;
        font-size: 10px;
    }

    .rulebook-hero-actions,
    .final-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .rulebook-hero-actions .pixel-btn,
    .final-actions .pixel-btn {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    .rulebook-hero h1,
    .rulebook-hero .pixel-sea-game,
    .rulebook-hero .pirate-ship {
        animation: none !important;
    }
}
