:root {
    --game-primary: #c90c0f;
    --game-secondary: #f4c430;
    --spm-ink: #1a120c;
    --spm-cream: #f8f0e3;
    --spm-gold: #f4c430;
}

body.spm-page {
    margin: 0;
    min-height: 100vh;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #f8f4ea;
    background:
        radial-gradient(circle at 14% 10%, rgba(244, 196, 48, 0.16), transparent 42%),
        radial-gradient(circle at 88% 8%, rgba(201, 12, 15, 0.22), transparent 46%),
        linear-gradient(180deg, #2a1810 0%, #4a2c18 46%, #1a120c 100%);
}

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

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

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

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

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

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

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

.spm-lcd {
    min-width: 6.4rem;
    padding: 0.2rem 0.45rem;
    background: #140414;
    color: #f5c518;
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: center;
    border-radius: 6px;
    box-shadow: inset 0 0 0 2px #7f1d1d, inset 0 8px 16px rgba(0, 0, 0, 0.45);
}

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

.spm-lcd.is-over {
    color: #fecaca;
}

.spm-lcd.is-exact {
    color: #86efac;
}

.spm-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
    margin: 0 auto 0.65rem;
    max-width: 560px;
}

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

.spm-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border-radius: 999px;
    border: 1px solid rgba(244, 196, 48, 0.35);
    background: rgba(26, 18, 12, 0.75);
    color: #f8fafc !important;
    font-weight: 700;
    cursor: pointer;
}

.spm-tool-btn:hover {
    border-color: #f4c430;
    color: #f4c430 !important;
    background: rgba(201, 12, 15, 0.22);
}

.spm-tool-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    color: #f8fafc;
}

.spm-status {
    text-align: center;
    margin: 0 auto 0.75rem;
    max-width: 560px;
    color: #fde68a;
    font-weight: 600;
    min-height: 1.4em;
}

.spm-status.is-warn {
    color: #fecaca;
}

.spm-status.is-ok {
    color: #86efac;
}

.spm-board-wrap {
    position: relative;
    display: flex;
    justify-content: center;
    overflow: auto;
    padding: 0.35rem;
}

.spm-board {
    --spm-n: 4;
    --spm-cell: min(78px, calc((min(92vw, 560px) - 1.2rem) / var(--spm-n)));
    display: grid;
    grid-template-columns: repeat(var(--spm-n), var(--spm-cell));
    grid-template-rows: repeat(var(--spm-n), var(--spm-cell));
    width: calc(var(--spm-n) * var(--spm-cell));
    border: 4px solid #1a120c;
    border-radius: 12px;
    overflow: hidden;
    background: #1a120c;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
    z-index: 1;
}

.spm-path-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    overflow: visible;
}

.spm-path-svg polyline {
    fill: none;
    stroke: #f4c430;
    stroke-width: 6;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 4px rgba(244, 196, 48, 0.7));
}

.spm-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(26, 18, 12, 0.35);
    background: #f8f0e3;
    color: #1a120c !important;
    cursor: pointer;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    overflow: hidden;
}

.spm-cell:hover:not(:disabled) {
    background: #fff6e8;
    color: #1a120c;
}

.spm-cell .spm-num {
    font-size: calc(var(--spm-cell) * 0.42);
    font-weight: 700;
    line-height: 1;
    color: inherit;
}

.spm-cell .spm-badge {
    position: absolute;
    top: 4px;
    left: 5px;
    font-size: 0.58rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-weight: 700;
    color: #7f1d1d;
}

.spm-cell.is-path {
    background: #c90c0f;
    color: #fff !important;
}

.spm-cell.is-path .spm-badge {
    color: #fde68a;
}

.spm-cell.is-head {
    background: #9f0712;
    color: #fff !important;
    box-shadow: inset 0 0 0 3px #f4c430;
}

.spm-cell.is-hint {
    animation: spm-hint-pulse 1s ease 2;
    box-shadow: inset 0 0 0 3px #f4c430;
}

.spm-cell.is-fresh {
    animation: spm-ink 0.32s ease;
}

.spm-cell.is-legal {
    box-shadow: inset 0 0 0 2px rgba(201, 12, 15, 0.45);
}

.spm-cell.is-error {
    animation: spm-shake 0.32s ease;
    background: #fecaca;
    color: #7f1d1d !important;
}

.spm-cell.is-win {
    background: #15803d;
    color: #fff !important;
}

@keyframes spm-ink {
    from { transform: scale(0.82); }
    to { transform: scale(1); }
}

@keyframes spm-hint-pulse {
    0%, 100% { background: #f8f0e3; }
    50% { background: #f4c430; color: #1a120c; }
}

@keyframes spm-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.spm-fail {
    max-width: 560px;
    margin: 0.9rem auto 0;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    background: #fff;
    color: #1a120c;
    border: 3px solid #c90c0f;
    text-align: center;
}

.spm-fail[hidden] {
    display: none;
}

.spm-fail strong {
    display: block;
    color: #c90c0f;
    font-size: 1.15rem;
    margin-bottom: 0.35rem;
}

.spm-fail p {
    margin: 0 0 0.75rem;
}

.spm-fail-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.spm-hint {
    text-align: center;
    color: #fde68a;
    margin: 0.85rem auto 0;
    max-width: 560px;
}

.spm-settings-panel {
    margin: 0.4rem 0 0.2rem;
    padding: 0.9rem 1rem;
    border: 1px solid rgba(244, 196, 48, 0.22);
    border-radius: 12px;
    background: rgba(26, 18, 12, 0.35);
}

.spm-settings-panel__title {
    font-weight: 700;
    margin-bottom: 0.55rem;
    color: #f5c518;
}

.spm-settings-panel__label {
    margin: 0 0 0.45rem;
    color: #e2e8f0;
    font-weight: 600;
}

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

.spm-page .difficulty-pill {
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    background: rgba(255, 255, 255, 0.05);
    color: #f8fafc !important;
    font-weight: 600;
    cursor: pointer;
}

.spm-page .difficulty-pill:hover {
    border-color: #f4c430;
    color: #fde68a !important;
    background: rgba(201, 12, 15, 0.22);
}

.spm-page .difficulty-pill.is-selected {
    background: #f4c430;
    color: #1a120c !important;
    border-color: #f4c430;
}

.spm-settings-panel__note,
#settingsModal .spm-settings-panel__note {
    margin: 0.35rem 0 0;
    color: #fde68a;
    font-size: 0.9rem;
}

.spm-page .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;
}

.spm-page .modal.active {
    display: flex;
}

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

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

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

.spm-page .modal-header { border-bottom: 2px solid #eee; }
.spm-page .modal-header h2 { margin: 0; color: #c90c0f; font-size: 1.35rem; }

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

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

.spm-page .modal-body { padding: 1.2rem 1.4rem; }
.spm-page .modal-footer { border-top: 2px solid #eee; justify-content: flex-end; }

.spm-page .help-section { margin-bottom: 1.1rem; }
.spm-page .help-section h3 { color: #c90c0f; margin: 0 0 0.4rem; }
.spm-page .help-section ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }

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

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

.spm-page .stat-value { font-size: 1.6rem; color: #c90c0f; font-weight: 700; }
.spm-page .stat-label { color: #64748b; font-size: 0.85rem; }

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

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

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

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

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

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

.spm-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;
}

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

.spm-page .btn-primary:hover {
    background: #a00a0c;
    color: #fff;
}

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

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

.spm-page .spm-fail .btn-secondary {
    background: #fff;
    color: #c90c0f !important;
    border: 2px solid #c90c0f;
}

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

#settingsModal .spm-settings-panel__label {
    color: #1a120c;
}

#settingsModal .spm-settings-panel__note {
    color: #7f1d1d;
}

#settingsModal .difficulty-pill {
    background: #fff7ed;
    color: #1a120c !important;
    border-color: #fdba74;
}

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

@media (max-width: 640px) {
    .spm-lcd {
        min-width: 4.6rem;
        font-size: 1.05rem;
    }

    .spm-tool-btn span {
        display: none;
    }

    .spm-cell .spm-badge {
        font-size: 0.5rem;
        top: 2px;
        left: 3px;
    }
}
