:root {
    --felt: #163b35;
    --felt-light: #1d4a42;
    --felt-dark: #0c2422;
    --paper: #f7f1e3;
    --ink: #1d1812;
    --accent: #d84339;
    --accent-soft: #f0c9c4;
    --peg-red: #d84339;
    --peg-orange: #e8842c;
    --peg-yellow: #eec83d;
    --peg-green: #4b9e56;
    --peg-blue: #3d6fd8;
    --peg-purple: #8a4bbf;
    --peg-pink: #e06ba8;
    --peg-teal: #2fa9a2;
    --key-red: #c2362d;
    --key-white: #f4efe6;
    --hole: rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.05), transparent 55%),
        linear-gradient(135deg, var(--felt-dark), var(--felt) 52%, var(--felt-dark));
    color: var(--ink);
    font-family: "Fredoka", "Trebuchet MS", "Segoe UI", sans-serif;
}

main {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1.25rem 4rem;
}

h1 {
    color: var(--paper);
    font-size: clamp(2.4rem, 6vw, 3.6rem);
    font-weight: 700;
    letter-spacing: 0.04em;
    margin: 0.5rem 0 0;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

h2 {
    color: var(--paper);
    font-size: clamp(1.5rem, 4vw, 2rem);
    font-weight: 700;
    letter-spacing: 0.03em;
    margin: 0;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
}

/* ---------- peg palette by colour index ---------- */

.c0 { --pegc: var(--peg-red); }
.c1 { --pegc: var(--peg-orange); }
.c2 { --pegc: var(--peg-yellow); }
.c3 { --pegc: var(--peg-green); }
.c4 { --pegc: var(--peg-blue); }
.c5 { --pegc: var(--peg-purple); }
.c6 { --pegc: var(--peg-pink); }
.c7 { --pegc: var(--peg-teal); }

.peg.blank {
    background: var(--felt-dark);
    box-shadow:
        inset 0 0 0 2px rgba(247, 241, 227, 0.55),
        inset 0 3px 6px rgba(0, 0, 0, 0.55),
        0 3px 4px rgba(0, 0, 0, 0.4);
}

.peg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--pegc, var(--felt-light));
    box-shadow:
        inset -3px -4px 6px rgba(0, 0, 0, 0.35),
        inset 3px 4px 6px rgba(255, 255, 255, 0.35),
        0 3px 4px rgba(0, 0, 0, 0.4);
}

.hidden-peg {
    background: var(--felt-dark);
    color: rgba(247, 241, 227, 0.7);
    font-weight: 700;
}

/* ---------- landing + shared ---------- */

.hero,
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    text-align: center;
    padding-top: 12vh;
}

.empty-state h1 {
    font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.empty-state p,
.tagline {
    color: rgba(247, 241, 227, 0.85);
    font-size: 1.15rem;
    margin: 0;
}

.hero-footnote {
    color: rgba(247, 241, 227, 0.55);
    font-size: 0.95rem;
    margin-top: 1.5rem;
}

.hero-actions {
    margin-top: 1rem;
}

.peg-row {
    display: flex;
    gap: 0.7rem;
}

.button {
    display: inline-block;
    border: none;
    border-radius: 999px;
    padding: 0.8rem 1.9rem;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    text-decoration: none;
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.button.primary {
    background: var(--accent);
    color: var(--paper);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

.button.primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.3);
}

.button.primary:disabled {
    background: var(--felt-light);
    color: rgba(247, 241, 227, 0.6);
    cursor: not-allowed;
    box-shadow: none;
}

.button.ghost {
    background: rgba(247, 241, 227, 0.12);
    color: var(--paper);
    border: 1px solid rgba(247, 241, 227, 0.35);
}

.button.ghost:hover:not(:disabled) {
    background: rgba(247, 241, 227, 0.22);
}

.button.ghost:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.back-link {
    color: rgba(247, 241, 227, 0.7);
    font-size: 0.95rem;
}

.error {
    color: #ffb3ab;
    font-weight: 600;
    margin: 0;
}

/* ---------- solo settings ---------- */

.settings-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.1rem;
    max-width: 460px;
    margin: 8vh auto 0;
    padding: 2rem 2.2rem;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(247, 241, 227, 0.15);
    border-radius: 18px;
    text-align: center;
}

.settings-intro {
    color: rgba(247, 241, 227, 0.85);
    margin: 0;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.9rem 1.4rem;
    width: 100%;
}

.settings-grid label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    color: var(--paper);
    font-weight: 600;
    font-size: 0.95rem;
    text-align: left;
}

.settings-grid label.check {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
}

.settings-grid select {
    font-family: inherit;
    font-size: 1rem;
    padding: 0.45rem 0.6rem;
    border-radius: 10px;
    border: none;
    background: var(--paper);
    color: var(--ink);
}

.settings-grid input[type="checkbox"] {
    width: 1.15rem;
    height: 1.15rem;
    accent-color: var(--accent);
}

/* ---------- game board ---------- */

.game {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.game-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.8rem 1.4rem;
}

.game-status {
    color: rgba(247, 241, 227, 0.85);
    font-weight: 600;
}

.game-actions {
    display: flex;
    gap: 0.5rem;
}

.game-actions .button {
    padding: 0.5rem 1.15rem;
    font-size: 0.95rem;
}

.shield {
    display: flex;
    gap: 0.55rem;
    padding: 0.8rem 1.4rem;
    background: var(--felt-dark);
    border: 2px solid rgba(247, 241, 227, 0.2);
    border-radius: 14px;
    box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.45);
}

.play-area {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 1.4rem;
}

.board-cluster {
    /* Room for the Reveal lane that hangs to the right of the felt board. */
    padding-right: 7.2rem;
}

.board {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 1rem 1.2rem;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 16px;
    overflow: visible;
}

.board-row {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

/* Zero-width lane at the end of the row; the button hangs just past the
   board's right edge so it never covers the pip grid. */
.row-action {
    position: relative;
    flex: 0 0 0;
    width: 0;
    align-self: stretch;
}

.reveal-inline {
    position: absolute;
    left: 2.6rem;
    top: 50%;
    translate: 0 -50%;
    padding: 0.45rem 1.1rem;
    font-size: 0.9rem;
    white-space: nowrap;
}

.reveal-inline:hover:not(:disabled) {
    transform: none;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3);
}

.board-row.future {
    opacity: 0.45;
}

.board-row.active-row .slots {
    outline: 2px solid rgba(238, 200, 61, 0.7);
    outline-offset: 4px;
    border-radius: 999px;
}

.row-num {
    width: 1.4rem;
    color: rgba(247, 241, 227, 0.5);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: right;
}

.slots {
    display: flex;
    gap: 0.5rem;
}

.slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--hole);
    box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.5);
}

button.slot {
    cursor: pointer;
    transition: transform 100ms ease;
}

button.slot:hover {
    transform: scale(1.08);
}

.slot .peg {
    width: 2rem;
    height: 2rem;
}

/* ---------- feedback pips (die face) ---------- */

.pips {
    display: grid;
    gap: 0.28rem;
    padding: 0.35rem;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 8px;
}

.pips-2 {
    grid-template-columns: repeat(2, auto);
}

.pips-3 {
    grid-template-columns: repeat(3, auto);
}

.pip {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
    box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.45);
    background: var(--hole);
}

.pip.exact {
    background: var(--key-red);
    box-shadow:
        inset -1px -2px 3px rgba(0, 0, 0, 0.4),
        inset 1px 2px 3px rgba(255, 255, 255, 0.3);
}

.pip.colour {
    background: var(--key-white);
    box-shadow:
        inset -1px -2px 3px rgba(0, 0, 0, 0.25),
        inset 1px 2px 3px rgba(255, 255, 255, 0.5);
}

/* ---------- colour tray ---------- */

.tray {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.8rem 1.2rem;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 999px;
}

/* Desktop: the tray rides along the left of the board while scrolling. */
.tray-side {
    flex-direction: column;
    flex-wrap: nowrap;
    padding: 0.9rem 0.6rem;
    position: sticky;
    top: 22vh;
    align-self: flex-start;
}

.tray-peg {
    padding: 0.3rem;
    border: 2px solid transparent;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
    transition: transform 100ms ease, border-color 100ms ease;
}

.tray-peg:hover {
    transform: translateY(-3px);
}

.tray-peg.selected {
    border-color: var(--paper);
    transform: translateY(-3px);
}

.hint {
    max-width: 34rem;
    color: rgba(247, 241, 227, 0.6);
    font-size: 0.9rem;
    text-align: center;
    margin: 0;
}

/* ---------- banners + confetti ---------- */

.banner {
    padding: 0.8rem 1.6rem;
    border-radius: 14px;
    font-size: 1.15rem;
    font-weight: 700;
    animation: jumpIn 350ms ease;
}

.banner.win {
    background: var(--paper);
    color: var(--ink);
}

.banner.lose {
    background: rgba(0, 0, 0, 0.4);
    color: var(--accent-soft);
    border: 1px solid rgba(216, 67, 57, 0.5);
}

@keyframes jumpIn {
    0% { transform: scale(0.6); opacity: 0; }
    70% { transform: scale(1.06); }
    100% { transform: scale(1); opacity: 1; }
}

.confetti {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 50;
}

.confetti-piece {
    position: absolute;
    top: -5vh;
    width: 0.6rem;
    height: 0.9rem;
    border-radius: 2px;
    background: var(--pegc, var(--paper));
    animation: confettiFall 2.6s ease-in forwards;
}

@keyframes confettiFall {
    0% {
        transform: translate(0, 0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translate(var(--drift, 0px), 115vh) rotate(680deg);
        opacity: 0.85;
    }
}

/* ---------- help modal ---------- */

/* Beat `.game-actions .button` padding so the glyph actually centres. */
.game-actions .button.help-btn,
.help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1;
    border-radius: 50%;
}

.help-glyph {
    display: block;
    line-height: 1;
    /* Fredoka's "?" sits optically high/left in a circle; nudge it true-centre. */
    transform: translate(0.02em, 0.08em);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.55);
    z-index: 100;
}

.modal-panel {
    position: relative;
    max-width: 430px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 1.6rem 1.9rem;
    background: var(--paper);
    color: var(--ink);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    animation: jumpIn 250ms ease;
}

.modal-panel h3 {
    margin: 0 0 0.6rem;
}

.modal-panel h4 {
    margin: 1rem 0 0.4rem;
}

.modal-panel p {
    margin: 0 0 0.6rem;
    line-height: 1.45;
}

.modal-close {
    position: absolute;
    top: 0.6rem;
    right: 0.8rem;
    border: none;
    background: transparent;
    font-size: 1.6rem;
    line-height: 1;
    color: var(--ink);
    cursor: pointer;
}

.legend {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin: 0.4rem 0;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.legend-row .pip {
    flex-shrink: 0;
    width: 0.9rem;
    height: 0.9rem;
}

.help-list {
    margin: 0;
    padding-left: 1.2rem;
    line-height: 1.5;
}

.help-list li {
    margin-bottom: 0.35rem;
}

/* ---------- mobile layout ---------- */

@media (max-width: 720px) {
    .play-area {
        flex-direction: column;
        align-items: center;
        gap: 0.8rem;
    }

    /* Tray drops to the bottom and sticks there while scrolling. */
    .tray-side {
        order: 2;
        flex-direction: row;
        flex-wrap: wrap;
        position: sticky;
        top: auto;
        bottom: 0.5rem;
        align-self: center;
        z-index: 55;
        box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
        backdrop-filter: blur(4px);
    }

    /* The help button becomes a floating bubble clear of the sticky tray. */
    .game-actions .button.help-btn,
    .help-btn {
        position: fixed;
        right: 0.9rem;
        bottom: 6.2rem;
        width: 2.7rem;
        height: 2.7rem;
        padding: 0;
        z-index: 60;
        background: var(--accent);
        border: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
    }
}

@media (max-width: 480px) {
    .slot {
        width: 2rem;
        height: 2rem;
    }

    .slot .peg,
    .peg {
        width: 1.65rem;
        height: 1.65rem;
    }

    .board-cluster {
        padding-right: 0;
    }

    .row-action {
        flex: 0 0 auto;
        width: auto;
        align-self: center;
    }

    .reveal-inline {
        position: static;
        translate: none;
        padding: 0.4rem 0.8rem;
    }

    .board {
        padding: 0.8rem 0.7rem;
    }

    .board-row {
        gap: 0.5rem;
    }
}
