:root {
    --game-primary: #c90c0f;
    --game-secondary: #f4c430;
}

body.fk-page {
    margin: 0;
    min-height: 100vh;
    display: block;
    align-items: stretch;
    justify-content: stretch;
    perspective: none;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #f4f7fb;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 18% 12%, rgba(46, 120, 62, 0.28), transparent 44%),
        radial-gradient(circle at 86% 8%, rgba(201, 12, 15, 0.16), transparent 46%),
        linear-gradient(180deg, #121212 0%, #1c1c1c 48%, #0a0a0a 100%);
}

body.fk-page.game-menu-active {
    overflow-y: auto;
    overflow-x: hidden;
}

body.fk-page.game-menu-active #game-header {
    display: none !important;
}

.fk-page .game-screen {
    display: none;
    min-height: 100vh;
}

.fk-page .game-screen.active {
    display: block;
}

body.fk-page.with-game-header .fk-shell {
    padding-top: 5.5rem;
}

.fk-shell {
    max-width: min(820px, 96vw);
    margin: 0 auto;
    padding: 1.1rem 0.75rem 2.5rem;
}

.fk-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 640px;
    margin: 0 auto 0.85rem;
    padding: 0.55rem 0.7rem;
    background: linear-gradient(180deg, #2a2a2a, #161616);
    border: 3px solid #0a0a0a;
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 10px 24px rgba(0, 0, 0, 0.35);
}

.fk-lcd {
    min-width: 4.6rem;
    padding: 0.2rem 0.45rem;
    background: #041016;
    color: #f5c518;
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.15rem;
    font-weight: 700;
    text-align: center;
    border-radius: 6px;
    box-shadow: inset 0 0 0 2px #7f1d1d, inset 0 8px 16px rgba(0, 0, 0, 0.45);
}

.fk-lcd span {
    display: block;
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #4cc9f0;
}

.fk-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
    margin: 0 auto 0.85rem;
    max-width: 640px;
}

.fk-chip {
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fde68a;
    font-weight: 700;
}

.fk-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    min-height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(244, 196, 48, 0.28);
    background: rgba(10, 10, 10, 0.7);
    color: #f4f7fb;
    font-weight: 700;
    cursor: pointer;
}

.fk-tool-btn:hover:not(:disabled) {
    border-color: #f5c518;
    color: #f5c518;
}

.fk-tool-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.fk-tool-btn.is-primary {
    background: #c90c0f;
    border-color: #c90c0f;
    color: #fff;
}

.fk-tool-btn.is-primary:hover:not(:disabled) {
    background: #a50a0c;
    color: #fff;
    border-color: #a50a0c;
}

.fk-status {
    text-align: center;
    min-height: 1.4rem;
    margin: 0 auto 0.75rem;
    color: #fde68a;
    font-weight: 700;
}

.fk-table-wrap {
    max-width: 640px;
    margin: 0 auto;
    padding: 0.85rem 0.85rem 1.1rem;
    border-radius: 18px;
    background:
        radial-gradient(circle at 50% 40%, #2f7a45 0%, #1c4d2c 58%, #123220 100%);
    box-shadow:
        inset 0 0 0 10px #6b3e22,
        inset 0 0 0 14px #3d2416,
        0 18px 40px rgba(0, 0, 0, 0.45);
}

.fk-kept-block {
    margin-bottom: 0.7rem;
}

.fk-kept {
    --fk-cube: 48px;
    min-height: 3.4rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.35rem;
    margin: 0;
}

.fk-kept-label {
    width: 100%;
    text-align: center;
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #d7f5dc;
    opacity: 0.8;
}

.fk-live {
    --fk-cube: 80px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.85rem;
    min-height: 7.2rem;
    padding: 0.6rem 0.2rem 1.1rem;
    margin: 0;
}

.fk-page .fk-table-wrap .dice-container {
    width: var(--fk-cube);
    height: var(--fk-cube);
    margin: 0;
    perspective: 640px;
    transform-style: preserve-3d;
}

.fk-page .fk-table-wrap .dice,
.fk-page .fk-table-wrap .dice .face {
    width: var(--fk-cube);
    height: var(--fk-cube);
}

.fk-page .fk-table-wrap .dice {
    transform-style: preserve-3d;
    will-change: transform;
}

.fk-page .fk-table-wrap .dice .face {
    backface-visibility: hidden;
    border-radius: calc(var(--fk-cube) * 0.075);
}

.fk-page .fk-table-wrap .dice .front { transform: translateZ(calc(var(--fk-cube) / 2)); }
.fk-page .fk-table-wrap .dice .right { transform: rotateY(90deg) translateZ(calc(var(--fk-cube) / 2)); }
.fk-page .fk-table-wrap .dice .top { transform: rotateX(90deg) translateZ(calc(var(--fk-cube) / 2)); }
.fk-page .fk-table-wrap .dice .bottom { transform: rotateX(-90deg) translateZ(calc(var(--fk-cube) / 2)); }
.fk-page .fk-table-wrap .dice .left { transform: rotateY(-90deg) translateZ(calc(var(--fk-cube) / 2)); }
.fk-page .fk-table-wrap .dice .back { transform: translateZ(calc(var(--fk-cube) / -2)) rotateY(180deg); }

.fk-page .fk-table-wrap .dice .dot {
    width: calc(var(--fk-cube) * 0.15);
    height: calc(var(--fk-cube) * 0.15);
}

.fk-page .fk-table-wrap .dice .right,
.fk-page .fk-table-wrap .dice .bottom {
    gap: calc(var(--fk-cube) * 0.1);
    padding: calc(var(--fk-cube) * 0.15);
}

.fk-page .fk-table-wrap .dice .top,
.fk-page .fk-table-wrap .dice .left {
    gap: calc(var(--fk-cube) * 0.075);
    padding: calc(var(--fk-cube) * 0.125);
}

.fk-page .fk-table-wrap .dice .back {
    gap: calc(var(--fk-cube) * 0.1);
    padding: calc(var(--fk-cube) * 0.15);
}

.fk-live .dice-container {
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.18s ease, filter 0.18s ease;
}

.fk-live .dice-container:hover {
    transform: translateY(-4px);
}

.fk-live .dice-container.is-scoring {
    filter: drop-shadow(0 0 10px rgba(250, 204, 21, 0.9));
}

.fk-live .dice-container.is-selected {
    transform: translateY(-12px);
    filter: drop-shadow(0 0 8px rgba(245, 197, 24, 0.95));
}

.fk-live .dice-container.is-selected:hover {
    transform: translateY(-12px);
}

.fk-live .dice-container.is-bust {
    animation: fk-bust 0.45s ease;
}

.fk-kept .dice-container {
    pointer-events: none;
}

.fk-selection {
    text-align: center;
    margin: 0.65rem auto 0;
    color: #ecfdf3;
    font-weight: 700;
    min-height: 1.3rem;
}

.fk-hint {
    text-align: center;
    color: #d7f5dc;
    font-size: 0.92rem;
    margin: 0.85rem 0 0;
}

.fk-banner {
    display: none;
    text-align: center;
    margin: 0.6rem auto 0;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    max-width: 320px;
}

.fk-banner.is-farkle {
    display: block;
    background: #c90c0f;
    color: #fff;
}

.fk-banner.is-hot {
    display: block;
    background: #f5c518;
    color: #1a120c;
}

.fk-settings-panel__label {
    margin: 0 0 0.45rem;
    color: #1a120c;
    font-weight: 600;
}

.fk-settings-panel__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.85rem;
}

#settingsModal .difficulty-pill {
    border: 1px solid #fed7aa;
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    background: #fff7ed;
    color: #1a120c !important;
    font-weight: 600;
    cursor: pointer;
}

#settingsModal .difficulty-pill.is-selected {
    background: #c90c0f;
    color: #fff !important;
    border-color: #c90c0f;
}

#settingsModal .fk-settings-panel__note {
    margin: 0.75rem 0 0;
    color: #7f1d1d;
    font-size: 0.9rem;
}

.fk-score-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.4rem 0 0;
}

.fk-score-table th,
.fk-score-table td {
    text-align: left;
    padding: 0.35rem 0.4rem;
    border-bottom: 1px solid #eee;
}

.fk-score-table th {
    color: #c90c0f;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 12000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: #fff;
    color: #1a1a1a;
    border-radius: 1rem;
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 760px;
}

.modal-header,
.modal-footer {
    padding: 1.1rem 1.4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.modal-header {
    border-bottom: 2px solid #eee;
}

.modal-header h2 {
    margin: 0;
    color: #c90c0f;
    font-size: 1.35rem;
}

.modal-close {
    background: #fff !important;
    border: 2px solid #c90c0f;
    color: #c90c0f !important;
    border-radius: 8px;
    cursor: pointer;
    padding: 0.35rem 0.55rem;
}

.modal-close:hover {
    background: #c90c0f !important;
    color: #fff !important;
}

.modal-body {
    padding: 1.2rem 1.4rem;
}

.modal-footer {
    border-top: 2px solid #eee;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.help-section {
    margin-bottom: 1.1rem;
}

.help-section h3 {
    color: #c90c0f;
    margin: 0 0 0.4rem;
}

.help-section ul {
    margin: 0.3rem 0 0;
    padding-left: 1.2rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: #f8fafc;
    border-radius: 12px;
    padding: 0.85rem;
    text-align: center;
}

.stat-value {
    font-size: 1.6rem;
    color: #c90c0f;
    font-weight: 700;
}

.stat-label {
    color: #64748b;
    font-size: 0.85rem;
}

.difficulty-stats {
    display: grid;
    gap: 0.45rem;
}

.difficulty-stats div {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0.55rem;
    background: #f8fafc;
    border-radius: 8px;
}

.result-message {
    font-size: 1.05rem;
    margin: 0 0 1rem;
}

.win-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    text-align: center;
}

.win-stat strong {
    display: block;
    font-size: 1.35rem;
    color: #c90c0f;
}

.win-stat span {
    color: #64748b;
    font-size: 0.82rem;
}

.fk-page .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.1rem;
    border-radius: 0.55rem;
    border: 2px solid transparent;
    font-weight: 700;
    cursor: pointer;
}

.fk-page .btn-primary {
    background: #c90c0f !important;
    color: #fff !important;
    border-color: #c90c0f;
}

.fk-page .btn-secondary {
    background: #fff !important;
    color: #c90c0f !important;
    border-color: #c90c0f;
}

.fk-page .btn-secondary:hover {
    background: #c90c0f !important;
    color: #fff !important;
}

@keyframes fk-bust {
    0%, 100% { transform: none; }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

@media (max-width: 640px) {
    body.fk-page.with-game-header .fk-shell {
        padding-top: 0.75rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .fk-hud {
        max-width: 100%;
    }

    .fk-lcd {
        min-width: 0;
        flex: 1 1 0;
    }

    .fk-live {
        --fk-cube: 64px;
        gap: 0.55rem;
    }

    .fk-kept {
        --fk-cube: 40px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .fk-live .dice-container.is-bust {
        animation: none;
    }
}
