/* Matt's Lucky Draw
   Layout: a ticket kiosk on a night sky. Top bar, a paytable panel, the drawn-numbers
   area, the player's tickets, and one control dock whose contents follow the game phase
   ([data-phase] on #game-container, set by lottery.js). */

:root {
    --sky-top: #1c1440;
    --sky-bottom: #0a0620;
    --panel: rgba(255, 255, 255, 0.06);
    --booth: #241a52;
    --booth-edge: #ffd54a;
    --ink: #ffffff;
    --accent: #ffd54a;
    --win: #46e08c;
    --loss: #ff6b6b;
    --white-ball: #f4f6fb;
    --white-ball-ink: #1b1b2c;
    --red-ball: #e0392f;
    --serif: 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, 'Times New Roman', serif;
}

* {
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 12px;
    box-sizing: border-box;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: radial-gradient(ellipse at 50% -10%, #3a2a7a 0%, var(--sky-top) 45%, var(--sky-bottom) 100%);
    background-attachment: fixed;
}

/* A few static stars behind the kiosk */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    background-image:
        radial-gradient(1.5px 1.5px at 10% 20%, #fff, transparent),
        radial-gradient(1.5px 1.5px at 80% 15%, #fff, transparent),
        radial-gradient(1px 1px at 60% 70%, #fff, transparent),
        radial-gradient(1px 1px at 30% 85%, #fff, transparent),
        radial-gradient(1.5px 1.5px at 90% 60%, #fff, transparent),
        radial-gradient(1px 1px at 20% 55%, #fff, transparent);
    opacity: 0.55;
}

#game-container {
    position: relative;
    box-sizing: border-box;
    width: 100%;
    max-width: 720px;
    padding: 12px 18px 10px;
    text-align: center;
    border: 8px solid var(--booth);
    border-radius: 20px;
    background: linear-gradient(180deg, #1a1240 0%, #120c30 100%);
    box-shadow:
        0 22px 55px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(0, 0, 0, 0.5),
        inset 0 0 0 2px var(--booth-edge),
        inset 0 0 70px rgba(0, 0, 0, 0.4);
}

h1 {
    margin: 0;
    font-family: var(--serif);
    font-size: 23px;
    font-weight: 700;
    font-style: italic;
    letter-spacing: 0.02em;
    color: var(--accent);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

/* ---------- Top bar ---------- */

#other-games {
    display: flex;
    gap: 6px;
}

.other-game {
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    transition: background-color 0.15s ease, transform 0.08s ease;
}

.other-game:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: translateY(-1px);
}

.other-game:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 2px;
}

#top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px 14px;
    margin-bottom: 4px;
}

#game-info {
    display: flex;
    align-items: center;
    justify-content: center;
}

#stats-bar {
    display: flex;
    align-items: center;
    gap: 10px;
}

#balance, #jackpot {
    margin: 0;
    padding: 4px 13px;
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    color: var(--accent);
    background: rgba(0, 0, 0, 0.32);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
}

#top-buttons {
    display: flex;
    gap: 8px;
}

#mute, #toggle-paytable {
    padding: 6px 12px;
    font-size: 13px;
}

/* ---------- Message ---------- */

#message {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 42px;
    margin: 2px 0 6px;
    overflow-y: auto;
    font-size: 16px;
    font-weight: 700;
    color: #fff1c2;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

/* ---------- Paytable ---------- */

#paytable {
    margin-bottom: 8px;
    padding: 10px 12px;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
}

#paytable table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

#paytable caption {
    margin-bottom: 6px;
    font-weight: 700;
    color: var(--accent);
}

#paytable th, #paytable td {
    padding: 4px 6px;
    text-align: right;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

#paytable th:first-child, #paytable td:first-child {
    text-align: left;
}

#paytable tr.overall-row {
    font-weight: 700;
    color: var(--accent);
}

#paytable-note {
    margin: 8px 0 0;
    font-size: 11.5px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.6);
}

/* ---------- Drawn numbers ---------- */

#draw-area {
    position: relative;
    margin-bottom: 10px;
    padding: 10px;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.3);
}

.area-title {
    margin-bottom: 8px;
    font-weight: 700;
    color: var(--accent);
}

#drawn-balls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
    min-height: 64px;
}

#drawn-balls:empty::after {
    content: 'Buy tickets, then hit Draw to reveal the winning numbers.';
    max-width: 90%;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
}

.ball {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 52px;
    height: 52px;
    flex: 0 0 auto;
    font-weight: 800;
    font-size: 18px;
    border-radius: 50%;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.45), inset 0 -4px 6px rgba(0, 0, 0, 0.18), inset 0 3px 4px rgba(255, 255, 255, 0.6);
    animation: ballPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.ball.white {
    color: var(--white-ball-ink);
    background: radial-gradient(circle at 35% 30%, #ffffff, var(--white-ball) 70%);
}

.ball.red {
    color: #ffffff;
    background: radial-gradient(circle at 35% 30%, #ff6a5a, var(--red-ball) 70%);
}

@keyframes ballPop {
    0% { opacity: 0; transform: scale(0.3) translateY(-14px); }
    100% { opacity: 1; transform: none; }
}

/* ---------- Tickets ---------- */

#tickets-area {
    margin-bottom: 10px;
    padding: 8px 10px;
    background: var(--panel);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
}

#tickets-summary {
    min-height: 20px;
    font-weight: 600;
}

#ticket-details {
    margin-top: 6px;
    text-align: left;
}

#ticket-details summary {
    cursor: pointer;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.75);
    outline: none;
}

#ticket-list {
    max-height: 220px;
    margin-top: 6px;
    overflow-y: auto;
    border-radius: 8px;
}

#ticket-list-note {
    margin-top: 6px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
}

.ticket-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    font-size: 12px;
}

.ticket-row:nth-child(odd) {
    background: rgba(255, 255, 255, 0.04);
}

.ticket-label {
    flex: 0 0 32px;
    color: rgba(255, 255, 255, 0.6);
}

.ticket-balls {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.mini-ball {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    font-size: 10px;
    font-weight: 700;
    border-radius: 50%;
    color: var(--white-ball-ink);
    background: var(--white-ball);
}

.mini-ball.red {
    color: #fff;
    background: var(--red-ball);
}

.mini-ball.hit {
    box-shadow: 0 0 0 2px var(--accent);
}

#winners-list {
    margin-top: 8px;
    text-align: left;
}

.winner-rows {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.winner-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    font-size: 13px;
    background: rgba(70, 224, 140, 0.12);
    border: 1px solid rgba(70, 224, 140, 0.4);
    border-radius: 8px;
}

.winner-tier {
    flex: 1;
    text-align: center;
    color: rgba(255, 255, 255, 0.85);
}

.winner-prize {
    font-weight: 800;
    color: var(--win);
}

.no-winners {
    margin: 6px 0 0;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.55);
}

/* ---------- Chips (ticket quantities) ---------- */

.chip {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    cursor: pointer;
    user-select: none;
    color: #ffffff;
    background: radial-gradient(circle at 35% 30%, #6a5acd, #3d2f8f 75%);
    box-shadow:
        0 4px 7px rgba(0, 0, 0, 0.45),
        inset 0 -3px 4px rgba(0, 0, 0, 0.28),
        inset 0 3px 3px rgba(255, 255, 255, 0.25);
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
}

.chip::before {
    content: '';
    position: absolute;
    inset: 8px;
    border-radius: 50%;
    border: 2px dashed rgba(255, 255, 255, 0.6);
}

.chip.qty-max {
    background: radial-gradient(circle at 35% 30%, #ffe57a, #d8a10f 75%);
    color: #3a2a00;
}

.chip-value {
    position: relative;
    z-index: 1;
    font-size: 15px;
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.chip:hover {
    transform: translateY(-4px);
}

.chip:active {
    transform: translateY(0);
}

.chip.locked {
    pointer-events: none;
    opacity: 0.4;
    filter: grayscale(0.5);
}

/* ---------- Buttons ---------- */

button {
    padding: 10px 18px;
    font: inherit;
    font-size: 15px;
    font-weight: 700;
    color: #1d1a10;
    cursor: pointer;
    background: linear-gradient(#ffe57a, #f2bf10);
    border: none;
    border-radius: 9px;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.38), 0 6px 12px rgba(0, 0, 0, 0.25);
    transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}

button:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

button:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.38);
}

#draw-button, #next-round {
    color: #ffffff;
    background: linear-gradient(#4fc46a, #2d9448);
}

#clear-tickets, #restart {
    color: #ffffff;
    background: linear-gradient(#ff6a4d, #d8391c);
}

#draw-button {
    padding: 10px 30px;
    font-size: 17px;
}

button:disabled {
    color: rgba(255, 255, 255, 0.6);
    cursor: not-allowed;
    background: linear-gradient(#8b9892, #6f7c76);
    box-shadow: none;
    filter: none;
    transform: none;
}

button:focus-visible, .chip:focus-visible, #quantity-amount:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 2px;
}

#quantity-amount {
    width: 90px;
    padding: 10px;
    box-sizing: border-box;
    font: inherit;
    font-size: 15px;
    color: #1d1a10;
    background: #ffffff;
    border: none;
    border-radius: 9px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

#quantity-amount:disabled {
    cursor: not-allowed;
    background: #b8c1bd;
}

/* ---------- Control dock ---------- */

#dock {
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    min-height: 128px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    box-shadow: inset 0 3px 12px rgba(0, 0, 0, 0.35);
}

.dock-panel {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
}

#results-dock {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
}

#game-container[data-phase="buying"] #buy-dock,
#game-container[data-phase="checking"] #checking-dock,
#game-container[data-phase="results"] #results-dock {
    display: flex;
}

/* While fast-forwarding, only its own dock shows, regardless of the underlying phase -
   the player isn't meant to interact with individual rounds during a simulated run. */
#game-container[data-fastforward="true"] #buy-dock,
#game-container[data-fastforward="true"] #checking-dock,
#game-container[data-fastforward="true"] #results-dock {
    display: none !important;
}

#game-container[data-fastforward="true"] #fastforward-dock {
    display: flex;
}

#fastforward-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding-top: 10px;
    margin-top: 2px;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.75);
    border-top: 1px dashed rgba(255, 255, 255, 0.15);
}

#fastforward-controls input {
    width: 70px;
    padding: 6px 8px;
    box-sizing: border-box;
    font: inherit;
    font-size: 14px;
    color: #1d1a10;
    background: #ffffff;
    border: none;
    border-radius: 8px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

#fast-forward-button {
    padding: 8px 16px;
    font-size: 14px;
}

#ff-progress-label {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
}

#ff-stop-button {
    color: #ffffff;
    background: linear-gradient(#ff6a4d, #d8391c);
}

#fastforward-summary {
    margin-top: 8px;
    padding: 10px 12px;
    text-align: left;
    font-size: 13px;
    line-height: 1.6;
    background: rgba(255, 213, 74, 0.08);
    border: 1px solid rgba(255, 213, 74, 0.4);
    border-radius: 10px;
}

#fastforward-summary h3 {
    margin: 0 0 6px;
    font-size: 14px;
    color: var(--accent);
}

.progress-bar, #check-progress, #ff-progress {
    width: 100%;
    max-width: 420px;
    height: 18px;
    box-sizing: border-box;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35);
}

.progress-fill, #check-progress-fill, #ff-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ffe57a, #f2bf10);
    border-radius: 999px;
    transition: width 0.15s ease-out;
}

#check-progress-label {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.8);
}

#check-tickets-button:disabled {
    color: rgba(255, 255, 255, 0.6);
    background: linear-gradient(#8b9892, #6f7c76);
    box-shadow: none;
}

#bankroll-controls, #quantity-container, #buy-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

#bankroll-controls {
    padding-bottom: 10px;
    margin-bottom: 2px;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.15);
}

#bankroll-controls label {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.75);
}

#bankroll-amount {
    width: 90px;
    padding: 8px 10px;
    box-sizing: border-box;
    font: inherit;
    font-size: 14px;
    color: #1d1a10;
    background: #ffffff;
    border: none;
    border-radius: 9px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

#bankroll-amount:disabled {
    cursor: not-allowed;
    background: #b8c1bd;
}

#set-bankroll {
    padding: 8px 16px;
    font-size: 14px;
}

#stats {
    margin-top: 8px;
    font-size: 11.5px;
    color: rgba(255, 255, 255, 0.65);
}

/* ---------- Jackpot celebration ---------- */

@keyframes jackpotPop {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    70% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes jackpotGlow {
    0%, 100% { box-shadow: 0 0 20px #ffd700; }
    50% { box-shadow: 0 0 45px #ffd700, 0 0 70px #ff6347; }
}

.jackpot-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 1000;
    padding: 26px 44px;
    font-family: var(--serif);
    font-size: 40px;
    font-weight: 800;
    line-height: 1.3;
    text-align: center;
    color: #ffffff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    background: linear-gradient(45deg, #b8860b, #daa520);
    border-radius: 15px;
    animation: jackpotPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275), jackpotGlow 2s infinite;
}

/* ---------- Phones ---------- */

@media (max-width: 600px) {
    body {
        padding: 8px;
    }

    #game-container {
        padding: 10px 10px 8px;
        border-width: 6px;
        border-radius: 16px;
    }

    h1 {
        font-size: 19px;
    }

    #balance, #jackpot {
        padding: 3px 10px;
        font-size: 13px;
    }

    #mute, #toggle-paytable {
        padding: 5px 8px;
        font-size: 11.5px;
    }

    .ball {
        width: 42px;
        height: 42px;
        font-size: 15px;
    }

    .chip {
        width: 46px;
        height: 46px;
    }

    .chip-value {
        font-size: 13px;
    }

    #dock {
        min-height: 112px;
        padding: 8px 6px;
    }

    button {
        padding: 8px 12px;
        font-size: 13px;
    }

    #draw-button {
        padding: 8px 22px;
        font-size: 15px;
    }

    #quantity-amount {
        width: 76px;
        padding: 8px;
        font-size: 14px;
    }

    .jackpot-popup {
        padding: 20px 26px;
        font-size: 26px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
