/* L. Knight book bingo (/lknight/bingo). Uses --primaryColour from lknight.css.
   A seasonal theme (see bingo-themes/) can override the --bingo-* colours below and add
   decorations to the space beside the card. */

.bingo {
    --bingo-board-from: #8d1267;
    --bingo-board-to: #670b4b;
    --bingo-board-shadow: rgba(141, 18, 103, 0.3);
    --bingo-line-glow: #ffd166;
    /* Ticker tape colours, read by bingo.js. */
    --bingo-confetti: #8d1267, #c2187a, #f4a6d7, #ffd166, #ffffff, #ae841a;
    padding: 50px 0 0;
}

/* The hearts, card and the space either side of them, where theme decorations go. */
.bingo__stage {
    position: relative;
}

.bingo-deco {
    pointer-events: none;
    user-select: none;
}

.bingo-deco svg {
    display: block;
    overflow: visible;
}

.bingo .section-header {
    margin-bottom: 24px;
}

.bingo__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 520px;
    margin: 0 auto 14px;
}

.bingo__lives {
    display: inline-flex;
    gap: 3px;
    color: var(--primaryColour);
    font-size: 17px;
    white-space: nowrap;
}

.bingo__lives.is-hit {
    animation: bingo-shake 0.4s ease;
}

/* Out of guesses: the card fades while the new one is dealt. */
.bingo__board.is-resetting {
    opacity: 0.45;
    filter: grayscale(0.7);
    transition: opacity 0.4s ease, filter 0.4s ease;
    pointer-events: none;
}

.bingo__status {
    flex: 1;
    margin: 0;
    min-height: 1.5em;
    color: var(--neutralColour);
    font-size: 15px;
}

.bingo__button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border: 2px solid var(--primaryColour);
    border-radius: 50px;
    background: var(--primaryColour);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    white-space: nowrap;
    text-decoration: none;
    transition: all 0.2s ease-in-out;
}

.bingo__button:hover,
.bingo__button:focus-visible {
    background: #fff;
    color: var(--primaryColour);
}

.bingo__button--ghost {
    background: #fff;
    color: var(--primaryColour);
}

.bingo__button--ghost:hover,
.bingo__button--ghost:focus-visible {
    background: var(--primaryColour);
    color: #fff;
}

/* ---- The card ---- */

.bingo__board {
    display: grid;
    grid-template-columns: repeat(var(--bingo-size, 3), 1fr);
    gap: 8px;
    max-width: 520px;
    margin: 0 auto 30px;
    padding: 10px;
    border-radius: 14px;
    background: linear-gradient(180deg, var(--bingo-board-from) 0%, var(--bingo-board-to) 100%);
    box-shadow: 0 18px 40px var(--bingo-board-shadow);
    user-select: none;
    -webkit-user-select: none;
}

.bingo-square {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 3 / 4; /* book-shaped, so a cover fills it */
    overflow: hidden;
    padding: 10px;
    border: 0;
    border-radius: 8px;
    background: #fff;
    color: #2b1a26;
    text-align: center;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.bingo-square__line {
    font-family: "Raleway", sans-serif;
    font-size: clamp(13px, 3.8vw, 19px);
    font-style: italic;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

/* While a cover is picked up, hint at where it can go. */
.bingo__board.is-choosing .bingo-square:not(.is-matched) {
    box-shadow: inset 0 0 0 2px rgba(141, 18, 103, 0.25);
    cursor: pointer;
}

.bingo__board .bingo-square.is-target,
.bingo__board.is-choosing .bingo-square:not(.is-matched):hover {
    background: #fbe3f2;
    box-shadow: inset 0 0 0 3px var(--primaryColour);
    transform: scale(1.04);
}

.bingo-square.is-wrong {
    animation: bingo-shake 0.4s ease;
    background: #ffe1e1;
}

@keyframes bingo-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

.bingo-square__cover {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    animation: bingo-stick 0.3s ease;
}

@keyframes bingo-stick {
    from { transform: scale(1.15); }
    to { transform: scale(1); }
}

.bingo-square.is-matched .bingo-square__line {
    visibility: hidden;
}

/* Squares in a completed row, column or diagonal. */
.bingo-square.is-line {
    box-shadow: 0 0 0 3px var(--bingo-line-glow), 0 0 16px var(--bingo-line-glow);
    z-index: 1;
}

/* ---- The covers along the bottom ---- */

.bingo__tray-wrap {
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding: 10px 0 12px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.12);
}

.bingo__tray {
    display: flex;
    justify-content: center;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 4px 2px;
    user-select: none;
    -webkit-user-select: none;
}

.bingo-cover {
    position: relative;
    flex: 0 0 auto;
    width: 90px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: none;
    cursor: grab;
    touch-action: pan-x; /* sideways swipes scroll the tray; anything else drags the cover */
    transition: transform 0.15s ease, opacity 0.2s ease;
}

.bingo-cover img {
    display: block;
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 4px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

.bingo-cover:hover:not(:disabled),
.bingo-cover:focus-visible {
    transform: translateY(-4px);
}

.bingo-cover.is-selected {
    transform: translateY(-6px);
}

.bingo-cover.is-selected img {
    box-shadow: 0 0 0 3px var(--primaryColour), 0 8px 16px rgba(141, 18, 103, 0.4);
}

.bingo-cover.is-done {
    opacity: 0.25;
    cursor: default;
}

.bingo-cover__count {
    position: absolute;
    top: -7px;
    right: -7px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: var(--primaryColour);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 22px;
}

.bingo-ghost {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1500;
    object-fit: cover;
    border-radius: 4px;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    transform-origin: 0 0;
}

.bingo-ghost.is-settling {
    transition: transform 0.25s ease, opacity 0.25s ease;
}

/* ---- Celebrations ---- */

.bingo-confetti {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 2100;
    pointer-events: none;
}

.bingo__toast {
    position: fixed;
    top: 40%; /* over the card, where the player is looking */
    left: 50%;
    z-index: 2000;
    padding: 12px 26px;
    border-radius: 50px;
    background: var(--primaryColour);
    color: #fff;
    font-family: "Raleway", sans-serif;
    font-size: 20px;
    font-weight: 800;
    box-shadow: 0 10px 30px rgba(141, 18, 103, 0.45);
    transform: translateX(-50%);
    animation: bingo-pop 0.35s ease;
    text-align: center;
    width: max-content;
    max-width: calc(100% - 32px);
}

.bingo__toast[hidden],
.bingo__win[hidden] {
    display: none;
}

@keyframes bingo-pop {
    from { transform: translateX(-50%) scale(0.6); opacity: 0; }
    to { transform: translateX(-50%) scale(1); opacity: 1; }
}

.bingo__win {
    position: fixed;
    inset: 0;
    z-index: 2050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(6, 12, 34, 0.7);
}

.bingo__win-card {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: 100%;
    overflow-y: auto;
    padding: 34px 28px 28px;
    border-radius: 16px;
    background: #fff;
    text-align: center;
    animation: bingo-rise 0.4s ease;
}

.bingo__win-card h2 {
    color: var(--primaryColour);
    font-family: "Raleway", sans-serif;
    font-size: 34px;
    font-weight: 800;
}

.bingo__win-close {
    position: absolute;
    top: 14px;
    right: 14px;
}

/* ---- Prize draw ---- */

.section-header .bingo__prize-note {
    margin-top: 10px;
    color: var(--primaryColour);
    font-weight: 600;
}

.bingo__prize {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 18px 0 16px;
    padding: 14px;
    border-radius: 12px;
    background: #fbe3f2;
    text-align: left;
}

.bingo__prize-cover {
    flex: 0 0 auto;
    width: 84px;
    border-radius: 4px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
}

.bingo__prize-text h3 {
    margin: 0 0 4px;
    color: var(--primaryColour);
    font-family: "Raleway", sans-serif;
    font-size: 18px;
    font-weight: 800;
}

.bingo__prize-text p {
    margin: 0;
    font-size: 14px;
}

.bingo__entry {
    display: grid;
    gap: 10px;
    text-align: left;
}

.bingo__entry .form-check-label {
    font-size: 13px;
}

.bingo__entry .bingo__button {
    justify-self: center;
}

.bingo__entry-error {
    margin: 0;
    color: #b00020;
    font-size: 14px;
}

.bingo__entry[hidden],
.bingo__entry-error[hidden],
.bingo__entered[hidden] {
    display: none;
}

.bingo__entered {
    margin: 0;
    color: var(--primaryColour);
    font-size: 18px;
    font-weight: 700;
}

.bingo__win-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

@keyframes bingo-rise {
    from { transform: translateY(30px) scale(0.9); opacity: 0; }
    to { transform: none; opacity: 1; }
}

/* On bigger screens keep the whole card in view above the tray. */
@media (min-width: 576px) {
    .bingo__board,
    .bingo__bar {
        max-width: min(520px, calc((100vh - 290px) * 0.75));
    }
}

@media (max-width: 575px) {
    .bingo {
        padding-top: 30px;
    }

    .bingo__board {
        gap: 4px;
        padding: 5px;
        border-radius: 10px;
    }

    .bingo-square {
        padding: 6px;
        border-radius: 6px;
    }

    .bingo-cover {
        width: 72px;
    }

    /* Hearts and "New card" on one row, the message underneath. */
    .bingo__bar {
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .bingo__status {
        flex-basis: 100%;
        order: 3;
        font-size: 13px;
    }

    .bingo__toast {
        font-size: 17px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bingo-square,
    .bingo-cover,
    .bingo-square__cover,
    .bingo__toast,
    .bingo__win-card {
        animation: none !important;
        transition: none !important;
    }
}
