:root {
    --game-primary: #C90C0F;
    --game-secondary: #FAB719;
    --ms-panel: #1c2736;
    --ms-panel-dark: #121a26;
    --ms-cell: 32px;
    --ms-raised: #3d4d63;
    --ms-sunken: #0f1724;
}

body.ms-page {
    margin: 0;
    min-height: 100vh;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #f8fafc;
    background:
        radial-gradient(circle at 12% 8%, rgba(201, 12, 15, 0.22), transparent 42%),
        radial-gradient(circle at 88% 18%, rgba(250, 183, 25, 0.16), transparent 48%),
        linear-gradient(180deg, #0b1220 0%, #121a26 55%, #0a1018 100%);
}

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

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

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

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

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

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

.ms-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 420px;
    margin: 0 auto 0.75rem;
    padding: 0.55rem 0.7rem;
    background: linear-gradient(180deg, #2a3546, #151c28);
    border: 3px solid #0b1018;
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 24px rgba(0, 0, 0, 0.35);
}

.ms-lcd {
    min-width: 4.4rem;
    padding: 0.2rem 0.45rem;
    background: #140404;
    color: #ff3a3a;
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-align: center;
    border-radius: 6px;
    box-shadow: inset 0 0 0 2px #5b1212, inset 0 8px 16px rgba(0, 0, 0, 0.45);
    text-shadow: 0 0 8px rgba(255, 58, 58, 0.45);
}

.ms-face {
    width: 3rem;
    height: 3rem;
    border-radius: 10px;
    border: 2px solid #0b1018;
    background: linear-gradient(180deg, #f8e38a, #e0b122);
    color: #1a1a1a;
    font-size: 1.55rem;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.ms-face:hover {
    filter: brightness(1.05);
}

.ms-face:active {
    transform: translateY(1px);
}

.ms-face.is-won {
    background: linear-gradient(180deg, #bbf7d0, #34d399);
}

.ms-face.is-lost {
    background: linear-gradient(180deg, #fecaca, #f87171);
}

.ms-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    margin-bottom: 0.85rem;
}

.ms-chip,
.ms-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border-radius: 999px;
    padding: 0.38rem 0.85rem;
    font-size: 0.92rem;
    font-weight: 600;
    border: 1px solid rgba(250, 183, 25, 0.35);
    background: rgba(15, 23, 42, 0.72);
    color: #f8fafc;
}

.ms-tool-btn {
    cursor: pointer;
}

.ms-tool-btn[aria-pressed="true"] {
    background: rgba(201, 12, 15, 0.88);
    border-color: #FAB719;
}

.ms-board-wrap {
    overflow: auto;
    max-width: 100%;
    padding: 0.4rem;
    display: flex;
    justify-content: center;
}

.ms-board {
    display: grid;
    grid-template-columns: repeat(var(--ms-cols, 9), var(--ms-cell));
    grid-template-rows: repeat(var(--ms-rows, 9), var(--ms-cell));
    gap: 0;
    background: #0b1018;
    border: 4px solid #0b1018;
    box-shadow:
        inset 2px 2px 0 #64748b,
        inset -2px -2px 0 #020617,
        0 18px 40px rgba(0, 0, 0, 0.4);
    user-select: none;
    touch-action: manipulation;
}

.ms-cell {
    width: var(--ms-cell);
    height: var(--ms-cell);
    margin: 0;
    padding: 0;
    border: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
    font-weight: 800;
    font-size: calc(var(--ms-cell) * 0.58);
    line-height: 1;
    cursor: pointer;
    color: transparent;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 42%),
        var(--ms-raised);
    box-shadow:
        inset 2px 2px 0 rgba(255, 255, 255, 0.28),
        inset -2px -2px 0 rgba(0, 0, 0, 0.45);
}

.ms-cell:hover:not(.is-open):not(:disabled) {
    filter: brightness(1.08);
}

.ms-cell:focus-visible {
    outline: 2px solid #FAB719;
    outline-offset: -2px;
    z-index: 1;
}

.ms-cell.is-open {
    background: var(--ms-sunken);
    box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.55);
    cursor: default;
}

.ms-cell.is-open.n0 { color: transparent; }
.ms-cell.is-open.n1 { color: #60a5fa; }
.ms-cell.is-open.n2 { color: #34d399; }
.ms-cell.is-open.n3 { color: #f87171; }
.ms-cell.is-open.n4 { color: #818cf8; }
.ms-cell.is-open.n5 { color: #f59e0b; }
.ms-cell.is-open.n6 { color: #22d3ee; }
.ms-cell.is-open.n7 { color: #e5e7eb; }
.ms-cell.is-open.n8 { color: #94a3b8; }

.ms-cell.is-flagged::after,
.ms-cell.is-question::after,
.ms-cell.is-mine::after,
.ms-cell.is-wrong::after {
    display: block;
    width: 70%;
    height: 70%;
}

.ms-cell.is-flagged::after {
    content: "";
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23C90C0F' d='M6 3h2v18H6z'/%3E%3Cpath fill='%23FAB719' d='M8 4l12 5-12 5z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.ms-cell.is-question {
    color: #FAB719;
}

.ms-cell.is-question::after {
    content: "?";
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--ms-cell) * 0.55);
    width: 100%;
    height: 100%;
}

.ms-cell.is-mine.is-open {
    background: #7f1d1d;
}

.ms-cell.is-mine.is-open::after {
    content: "";
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='13' r='6' fill='%23111'/%3E%3Crect x='11' y='4' width='2' height='5' fill='%23111'/%3E%3Crect x='13' y='3' width='6' height='2' fill='%23FAB719'/%3E%3C/svg%3E") center / 78% no-repeat;
}

.ms-cell.is-exploded {
    background: #dc2626 !important;
}

.ms-cell.is-wrong::after {
    content: "";
    background:
        linear-gradient(45deg, transparent 46%, #fecaca 46%, #fecaca 54%, transparent 54%),
        linear-gradient(-45deg, transparent 46%, #fecaca 46%, #fecaca 54%, transparent 54%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='13' r='6' fill='%23111'/%3E%3C/svg%3E") center / 70% no-repeat;
}

.ms-cell.is-pressed:not(.is-open) {
    background: var(--ms-sunken);
    box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.5);
}

.ms-hint {
    text-align: center;
    color: #94a3b8;
    font-size: 0.92rem;
    margin: 0.85rem 0 0;
}

.landscape-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 20000;
    background: rgba(7, 12, 20, 0.96);
    color: #fff;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.landscape-overlay.show {
    display: flex;
}

.landscape-icon {
    font-size: 3rem;
    color: #FAB719;
    margin-bottom: 1rem;
}

.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;
    border: 2px solid #C90C0F;
    color: #C90C0F;
    border-radius: 8px;
    cursor: pointer;
    padding: 0.35rem 0.55rem;
}

.modal-close:hover {
    background: #C90C0F;
    color: #fff;
}

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

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

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

.custom-grid {
    display: grid;
    gap: 0.75rem;
}

.custom-grid label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    font-weight: 600;
}

.custom-grid input {
    width: 6rem;
    padding: 0.4rem 0.5rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
}

.custom-hint {
    margin: 0.85rem 0 0;
    color: #475569;
}

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

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

.btn-primary {
    background: #C90C0F;
    color: #fff;
}

.btn-secondary {
    background: #fff;
    color: #C90C0F;
    border-color: #C90C0F;
}

.ms-settings-panel {
    margin: 0 0 1.1rem;
    padding: 1rem 1.1rem 1.15rem;
    border-radius: 16px;
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(250, 183, 25, 0.28);
    transition: box-shadow 0.25s ease, border-color 0.25s ease;
}

.ms-settings-panel.is-highlighted {
    border-color: #FAB719;
    box-shadow: 0 0 0 3px rgba(250, 183, 25, 0.35);
}

.ms-settings-panel__title {
    margin: 0 0 0.75rem;
    color: #FAB719;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.92rem;
}

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

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

.ms-settings-panel__buttons .difficulty-pill,
#settingsModal .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;
    font-weight: 600;
    cursor: pointer;
}

.ms-settings-panel__buttons .difficulty-pill.is-selected,
#settingsModal .difficulty-pill.is-selected {
    background: rgba(201, 12, 15, 0.92);
    border-color: #FAB719;
    color: #fff;
}

#settingsModal .ms-settings-panel__label,
#settingsModal .ms-settings-panel__note {
    color: #1e293b;
}

#settingsModal .difficulty-pill {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #cbd5e1;
}

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

.ms-settings-toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: #e2e8f0;
    font-size: 0.95rem;
    cursor: pointer;
}

#settingsModal .ms-settings-toggle {
    color: #1e293b;
    margin: 0.35rem 0 0.75rem;
}

.ms-settings-panel__note {
    margin: 0.75rem 0 0;
    color: #94a3b8;
    font-size: 0.86rem;
}

@media (max-width: 720px) {
    .ms-lcd {
        font-size: 1.45rem;
        min-width: 3.6rem;
    }

    .ms-hint {
        font-size: 0.82rem;
    }
}
