/* === CSS Reset === */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* === Design Tokens === */
:root {
    --felt: #1a472a;
    --felt-dark: #0e2b17;
    --felt-light: #245c38;
    --gold: #d4a843;
    --gold-bright: #f0d060;
    --gold-dark: #8b6914;
    --text-primary: #f0e6d3;
    --text-dim: #9e9a8e;
    --panel-bg: rgba(0, 0, 0, 0.35);
    --die-bg: #f5f0e8;
    --die-bg-gradient: linear-gradient(135deg, #fffef9 0%, #e8e0d0 100%);
    --die-pip: #1a1a1a;
    --die-locked-bg: #fff8e7;
    --border-gold: #b8942e;
    --btn-bg: #8b1a1a;
    --btn-hover: #a82020;
    --score-bg: rgba(0, 0, 0, 0.25);
    --score-hover: rgba(180, 140, 40, 0.3);
    --score-filled-bg: rgba(0, 0, 0, 0.15);
    --score-preview: #c0a040;
    --bonus-green: #4caf50;
    --section-gold: #d4a843;
}

html,
body {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(ellipse at 50% 0%, var(--felt-light) 0%, transparent 70%),
        linear-gradient(180deg, var(--felt-dark) 0%, var(--felt) 40%, var(--felt-dark) 100%);
    background-color: var(--felt);
    color: var(--text-primary);
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    font-size: 18px;
    line-height: 1.5;
    scrollbar-width: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
    display: none;
}

/* === Texture overlay === */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 0, 0, 0.03) 2px, rgba(0, 0, 0, 0.03) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0, 0, 0, 0.03) 2px, rgba(0, 0, 0, 0.03) 4px);
    opacity: 0.5;
}

/* === Header === */
.top-bar {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px;
    background: var(--panel-bg);
    border-bottom: 2px solid var(--border-gold);
    flex-wrap: wrap;
    gap: 12px;
}

.title {
    font-size: 2.5rem;
    font-weight: 900;
    letter-spacing: 0.15em;
    color: var(--gold-bright);
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6), 0 0 20px rgba(212, 168, 67, 0.3);
    text-transform: uppercase;
}

.high-score-block {
    font-size: 0.95rem;
    color: var(--text-dim);
    text-align: center;
    background: rgba(0, 0, 0, 0.25);
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-gold);
    width: 100%;
}

.high-score-block strong {
    color: var(--gold-bright);
    font-size: 1.1rem;
}
/* === Main Layout === */
.game-layout {
    position: relative;
    z-index: 1;
    display: flex;
    gap: 32px;
    padding: 32px;
    max-width: 1200px;
    margin: 0 auto;
    align-items: flex-start;
    flex: 1;
}

/* === Dice Panel === */
.dice-panel {
    position: sticky;
    top: 28px;
    flex: 1;
    min-width: 380px;
    background: var(--panel-bg);
    border: 1px solid var(--border-gold);
    border-radius: 16px;
    padding: 32px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.dice-tray {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    justify-content: center;
}

/* === Pip Die Styling === */
.die {
    width: 60px;
    height: 60px;
    background: var(--die-bg-gradient);
    border: 2px solid #b8b0a0;
    border-radius: 10px;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    transition: all 0.2s ease;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    position: relative;
    display: block;
    padding: 8px;
    flex-shrink: 0;
}

.die:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.die.unrolled {
    cursor: not-allowed;
    opacity: 0.8;
}

.die.unrolled:hover {
    transform: none;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.die.locked {
    border-color: var(--gold-bright);
    box-shadow: 0 0 14px var(--gold), 0 0 28px rgba(212, 168, 67, 0.4), 0 3px 8px rgba(0, 0, 0, 0.3);
    transform: translateY(-4px);
}

.die.locked::after {
    content: '🔒';
    position: absolute;
    top: -10px;
    right: -10px;
    font-size: 0.95rem;
    z-index: 2;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.die.rolling {
    animation: diceRoll 0.6s cubic-bezier(0.2, 0.9, 0.3, 1);
}

@keyframes diceRoll {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(1080deg);
    }
}

/* Pip grid (3x3) */
.pip-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    place-items: center;
}

.pip-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--die-pip);
}

.pip-dot.hidden {
    visibility: hidden;
}


/* === Roll Area (rolls-left + button together) === */
.roll-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.rolls-badge {
    font-size: 1rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--border-gold);
}

.rolls-badge strong {
    color: var(--gold-bright);
    font-size: 1.2rem;
}

.roll-button {
    padding: 16px 48px;
    font-size: 1.25rem;
    font-weight: 700;
    font-family: inherit;
    background: linear-gradient(180deg, #a82020 0%, #7a1010 100%);
    color: #fff;
    border: 2px solid var(--border-gold);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
    box-shadow: 0 4px 0 #4a0808;
    letter-spacing: 0.03em;
}

.roll-button:hover:not(:disabled) {
    background: linear-gradient(180deg, #c42828 0%, #901818 100%);
}

.roll-button:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #4a0808;
}

.roll-button:disabled {
    background: #4a3030;
    border-color: #5a4a3a;
    box-shadow: none;
    cursor: not-allowed;
    color: #8a7a7a;
}

.hint {
    font-size: 0.85rem;
    color: var(--text-dim);
    text-align: center;
}

/* === Scorecard Panel === */
.scorecard-panel {
    flex: 2;
    min-width: 360px;
}

.scorecard {
    background: var(--panel-bg);
    border: 1px solid var(--border-gold);
    border-radius: 16px;
    padding: 24px;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    display: flex;
    gap: 40px;
}

.scorecard-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 280px;
}

.section-title {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--section-gold);
    margin: 18px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-gold);
}

.section-title:first-child {
    margin-top: 0;
}

/* === Score Row as Button === */
.score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 11px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    border: 1px solid transparent;
    margin-bottom: 3px;
}

.score-row.empty {
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
}

.score-row.empty:hover {
    background: var(--score-hover);
    border-color: var(--border-gold);
    transform: scale(1.015);
}

.score-row.empty.disabled {
    cursor: not-allowed;
    opacity: 0.4;
    pointer-events: none;
}

.score-row.empty.disabled:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.08);
    transform: none;
}

.score-row.filled {
    cursor: default;
    background: rgba(180, 140, 40, 0.15);
    border-color: var(--border-gold);
    opacity: 1;
}

.score-row .category-name {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 600;
}

.score-row.filled .category-name {
    color: var(--gold-bright);
    font-weight: 700;
    text-decoration: none;
}

.score-row .category-score {
    font-size: 1.1rem;
    font-weight: 700;
    min-width: 48px;
    text-align: right;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.2);
}

.score-row.empty .category-score {
    background: rgba(255, 255, 255, 0.05);
}

.score-row.filled .category-score {
    color: var(--gold-bright);
    background: rgba(180, 140, 40, 0.2);
    border: 1px solid var(--border-gold);
}

.score-row .preview-score {
    color: var(--score-preview);
    background: rgba(192, 160, 64, 0.15);
    border: 1px dashed rgba(192, 160, 64, 0.3);
}

.score-row .empty-score {
    color: var(--text-dim);
    opacity: 0.4;
}

/* === Summary Rows === */
.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px;
    font-size: 0.95rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 4px;
}

.summary-row span {
    color: var(--text-dim);
}

.summary-row strong {
    color: var(--text-primary);
    font-size: 1.05rem;
}

.summary-row.grand {
    font-size: 1.1rem;
    padding: 12px 14px;
    margin-top: 8px;
    border-top: 2px solid var(--border-gold);
}

.summary-row.grand span {
    color: var(--gold-bright);
    font-weight: 700;
    font-size: 1.1rem;
}

.summary-row.grand strong {
    color: var(--gold-bright);
    font-size: 1.35rem;
}

#upper-bonus {
    color: var(--bonus-green);
}

/* === Upper Bonus Tracker === */
.bonus-tracker {
    text-align: right;
    padding: 4px 14px;
    font-size: 0.85rem;
    min-height: 1.5em;
    font-style: italic;
}

.bonus-tracker .bonus-progress {
    color: var(--score-preview);
}

.bonus-tracker .bonus-secured {
    color: var(--bonus-green);
    font-weight: 700;
    font-style: normal;
}

.bonus-tracker .bonus-missed {
    color: #c0392b;
    text-decoration: line-through;
    font-style: normal;
}

/* === Game Over Overlay === */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.overlay.hidden {
    display: none;
}

.overlay-card {
    background: var(--felt-dark);
    border: 2px solid var(--border-gold);
    border-radius: 20px;
    padding: 48px 56px;
    text-align: center;
    max-width: 460px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.overlay-card h2 {
    font-size: 2.4rem;
    color: var(--gold-bright);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.final-score-label {
    font-size: 1rem;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.final-score {
    font-size: 4rem;
    font-weight: 900;
    color: var(--gold-bright);
    text-shadow: 0 2px 10px rgba(212, 168, 67, 0.4);
    margin-bottom: 8px;
}

.high-score-line {
    font-size: 1.05rem;
    color: var(--text-dim);
    margin-bottom: 12px;
}

.high-score-line strong {
    color: var(--gold);
    font-weight: 700;
}

.high-score-line.new-record {
    color: var(--bonus-green);
    animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
    0% {
        opacity: 0.7;
    }

    100% {
        opacity: 1;
    }
}

.score-breakdown {
    font-size: 0.95rem;
    color: var(--text-dim);
    margin-bottom: 24px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 20px;
}

.play-again-btn {
    padding: 16px 44px;
    font-size: 1.25rem;
    font-weight: 700;
    font-family: inherit;
    background: linear-gradient(180deg, var(--btn-hover) 0%, var(--btn-bg) 100%);
    color: #fff;
    border: 2px solid var(--border-gold);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
    box-shadow: 0 4px 0 #4a0808;
}

.play-again-btn:hover {
    background: linear-gradient(180deg, #d43030 0%, #a01818 100%);
}

/* === Tablet & Mobile Layout === */
@media (max-width: 950px) {
    .game-layout {
        flex-direction: column;
        align-items: center;
        padding: 20px;
    }

    .dice-panel {
        position: static;
        width: 100%;
        max-width: 560px;
    }

    .scorecard-panel {
        width: 100%;
        max-width: 800px;
    }
}

@media (max-width: 640px) {
    .scorecard {
        flex-direction: column;
        gap: 20px;
    }

    .scorecard-col {
        min-width: unset;
    }

    .die {
        width: 56px;
        height: 56px;
        padding: 8px;
        border-radius: 8px;
    }

    .pip-dot {
        width: 9px;
        height: 9px;
    }

    .dice-tray {
        gap: 8px;
    }

    .title {
        font-size: 1.6rem;
    }
}

/* === Yahtzee Banner === */
.yahtzee-banner {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    animation: yahtzeeBannerFade 3s ease-in-out forwards;
}

.yahtzee-banner.hidden {
    display: none !important;
}

.yahtzee-banner-content {
    background: linear-gradient(135deg, #d4982a 0%, #fbbf24 50%, #d4982a 100%);
    border: 4px solid var(--gold-bright);
    border-radius: 24px;
    padding: 30px 60px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 40px rgba(251, 191, 36, 0.4);
    transform: scale(0.5);
    animation: yahtzeeBannerScale 3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.yahtzee-banner-title {
    font-family: 'DM Sans', Arial, sans-serif;
    font-size: 5rem;
    font-weight: 900;
    color: #ffffff;
    margin: 0;
    text-shadow: 0 4px 8px rgba(0, 0, 0, 0.4), 0 0 20px rgba(255, 255, 255, 0.6);
    letter-spacing: 0.05em;
}

@keyframes yahtzeeBannerFade {
    0% { opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes yahtzeeBannerScale {
    0% { transform: scale(0.3) rotate(-5deg); }
    12% { transform: scale(1.1) rotate(2deg); }
    16% { transform: scale(1) rotate(0deg); }
    88% { transform: scale(1) rotate(0deg); }
    100% { transform: scale(0.5) translateY(100px) opacity: 0; }
}

/* === Confetti === */
.confetti-container {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.confetti-piece {
    position: absolute;
    top: -50px;
    width: 10px;
    height: 20px;
    opacity: 0.9;
    animation: confettiFall 3s linear backwards;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-50px) rotate(0deg) translateX(0);
    }
    50% {
        transform: translateY(50vh) rotate(360deg) translateX(30px);
    }
    100% {
        transform: translateY(110vh) rotate(720deg) translateX(-30px);
    }
}

/* ============================================================
   VERSUS MODE
   ============================================================ */

/* --- Mode Toggle Button --- */
.mode-toggle {
    padding: 8px 20px;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold-bright);
    background: transparent;
    border: 1px solid var(--border-gold);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.mode-toggle:hover {
    background: rgba(212, 168, 67, 0.12);
    border-color: var(--gold-bright);
}

/* --- Turn Label --- */
.turn-label {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--gold-bright);
    text-transform: uppercase;
    text-align: center;
    padding: 10px 20px;
    margin-top: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-gold);
    border-radius: 8px;
}

.turn-label.hidden {
    display: none;
}

/* --- Hidden Utility (scoped, avoids conflict with .pip-dot.hidden) --- */
.vs-hidden,
#bot-scorecard.hidden,
#turn-label.hidden {
    display: none !important;
}

/* --- VS Layout: 3-column --- */
.game-layout.vs-mode {
    display: flex;
    flex-direction: row;
    gap: 16px;
    justify-content: center;
    align-items: flex-start;
    max-width: 100%;
    padding: 16px;
}

.dice-area-wrapper {
    order: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 0 0 auto;
}

.game-layout.vs-mode .dice-panel {
    position: sticky;
    top: 20px;
    min-width: 340px;
}

.game-layout.vs-mode #player-scorecard {
    order: 1;
    flex: 1 1 340px;
    max-width: 500px;
}

.game-layout.vs-mode #bot-scorecard {
    order: 3;
    flex: 1 1 340px;
    max-width: 500px;
}

/* Stack scorecard columns vertically in vs-mode for space */
.game-layout.vs-mode .scorecard {
    flex-direction: column;
    gap: 16px;
}

.game-layout.vs-mode .scorecard-col {
    min-width: unset;
}

/* --- Bot Scorecard Label --- */

/* --- VS Game Over Breakdown --- */
.score-breakdown {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 16px 24px;
}

.breakdown-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 150px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
}

.breakdown-col strong {
    color: var(--gold-bright);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
}

.breakdown-col span {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.breakdown-total {
    color: var(--gold-bright) !important;
    font-weight: 700;
    font-size: 1rem !important;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-gold);
}

.breakdown-result {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 12px 20px;
    border-radius: 8px;
    min-width: 140px;
}

.breakdown-result.win {
    color: var(--bonus-green);
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.breakdown-result.lose {
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.breakdown-result.tie {
    color: var(--gold-bright);
    background: rgba(212, 168, 67, 0.1);
    border: 1px solid rgba(212, 168, 67, 0.3);
}

/* --- VS Mobile --- */
@media (max-width: 1200px) {
    .game-layout.vs-mode {
        flex-direction: column;
        align-items: center;
    }

    .game-layout.vs-mode #player-scorecard,
    .game-layout.vs-mode #bot-scorecard {
        order: unset;
        flex: unset;
        max-width: 600px;
        width: 100%;
    }

    .game-layout.vs-mode .dice-panel {
        order: unset;
        position: static;
    }
}

@media (max-width: 950px) {
    .game-layout.vs-mode {
        padding: 16px;
        gap: 16px;
    }
}

.site-footer {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 16px 32px;
    font-size: 0.85rem;
    color: var(--text-dim);
    border-top: 1px solid var(--border-gold);
    background: var(--panel-bg);
    margin-top: auto;
}

.site-footer a {
    color: var(--gold-bright);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.site-footer a:hover {
    color: var(--gold);
    text-decoration: underline;
}