:root {
    --bg-1: #0c1326;
    --bg-2: #111f3f;
    --bg-3: #060b18;
    --panel: rgba(16, 24, 42, 0.94);
    --panel-border: rgba(255, 255, 255, 0.14);
    --accent: #ffbe32;
    --accent-2: #ffd766;
    --danger: #ff5252;
    --text-dim: rgba(255, 255, 255, 0.75);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
}

body {
    font-family: "Inter", "Segoe UI", sans-serif;
    color: #fff;
    background:
        radial-gradient(circle at 20% 16%, rgba(255, 207, 69, 0.2), transparent 24%),
        radial-gradient(circle at 82% 18%, rgba(86, 194, 255, 0.16), transparent 20%),
        radial-gradient(circle at 52% 78%, rgba(255, 100, 100, 0.2), transparent 22%),
        linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 46%, var(--bg-3) 100%);
}

.spark-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
}

.spark {
    position: absolute;
    width: 180px;
    height: 2px;
    opacity: 0.22;
    background: linear-gradient(90deg, transparent, rgba(255, 224, 137, 0.95), transparent);
    transform: rotate(-26deg);
    animation: spark-float linear infinite;
}

.spark-a { top: 8%; left: 8%; animation-duration: 9s; }
.spark-b { top: 20%; right: 12%; animation-duration: 11s; }
.spark-c { top: 66%; right: 20%; animation-duration: 8s; }
.spark-d { top: 76%; left: 20%; animation-duration: 12s; }

@keyframes spark-float {
    from { transform: translate3d(0, 0, 0) rotate(-26deg); }
    to { transform: translate3d(-220px, 240px, 0) rotate(-26deg); }
}

.game-shell {
    position: relative;
    z-index: 1;
    width: min(1180px, calc(100vw - 14px));
    max-width: 1180px;
    height: calc(100vh - 14px);
    margin: 7px auto;
    border-radius: 24px;
    padding: 14px;
    background: linear-gradient(180deg, rgba(20, 31, 56, 0.95), rgba(8, 12, 24, 0.95));
    border: 1px solid var(--panel-border);
    box-shadow:
        0 24px 60px rgba(0, 0, 0, 0.42),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
    display: grid;
    grid-template-rows: auto auto 1fr;
    gap: 12px;
    overflow: hidden;
}

html:fullscreen .game-shell,
html:-webkit-full-screen .game-shell {
    width: 100vw;
    max-width: none;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    border: 0;
    padding: 14px;
}

html:fullscreen .side-menu,
html:-webkit-full-screen .side-menu {
    top: 0;
    right: 0;
    height: 100vh;
    border-radius: 0;
}

.start-screen {
    position: absolute;
    inset: 0;
    z-index: 35;
    padding: 18px;
    background: linear-gradient(180deg, rgba(8, 12, 23, 0.95), rgba(8, 13, 26, 0.9));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 20px;
    transition: opacity 0.2s ease;
}

.start-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.logo-wrap {
    text-align: center;
}

.logo-badge {
    width: 72px;
    height: 72px;
    margin: 0 auto 10px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 2rem;
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
    color: #412000;
    box-shadow: 0 12px 26px rgba(255, 190, 50, 0.35);
}

.logo-title {
    margin: 0;
    font-family: "Russo One", "Inter", sans-serif;
    font-size: clamp(2rem, 6vw, 3.4rem);
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #fff5cb;
    text-shadow: 0 8px 20px rgba(255, 186, 59, 0.28);
}

.logo-subtitle {
    margin: 8px 0 0;
    color: var(--text-dim);
    font-weight: 600;
}

.start-panel {
    width: min(600px, 100%);
    padding: 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.14);
}

.panel-title {
    margin: 0 0 12px;
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.88);
}

.difficulty-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.diff-btn {
    min-height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06));
    color: #fff;
    font-size: 0.84rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, filter 0.15s ease;
}

.diff-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
}

.diff-btn.is-active {
    color: #3d1f00;
    border-color: rgba(255, 255, 255, 0.48);
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

.start-btn {
    width: 100%;
    min-height: 44px;
    margin-top: 12px;
    border: 0;
    border-radius: 999px;
    font-size: 1rem;
    font-weight: 800;
    color: #3d1f00;
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
    cursor: pointer;
}

.top-controls {
    position: relative;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.top-controls__right {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-only {
    display: none;
}

body.touch-ui .mobile-only {
    display: inline-flex;
}

.menu-toggle,
.small-btn,
.input-mode-btn {
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 700;
    min-height: 36px;
    padding: 0 12px;
}

.small-btn.strong {
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
    color: #3f2100;
    border-color: rgba(255, 255, 255, 0.4);
}

.input-mode-btn[data-mode="flag"] {
    color: #3d1f00;
    border-color: rgba(255, 255, 255, 0.48);
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

.top-actions {
    display: flex;
    gap: 8px;
}

.mode-pill {
    font-size: 0.84rem;
    font-weight: 700;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.08);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-bar {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: linear-gradient(180deg, #1d273a 0%, #121927 100%);
}

.digit-box {
    width: 132px;
    padding: 8px 10px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(180deg, #2a1212, #140909);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.stats-bar .digit-box:first-child { justify-self: start; }
.stats-bar .digit-box:last-child { justify-self: end; }

.stat-svg {
    width: 18px;
    height: 18px;
    color: #ffd36f;
    flex-shrink: 0;
}

.stat-value {
    font-family: "Orbitron", "Courier New", monospace;
    font-size: 1.7rem;
    font-weight: 900;
    letter-spacing: 2px;
    font-variant-numeric: tabular-nums;
    color: var(--danger);
    line-height: 1;
    width: 66px;
    text-align: right;
}

.reset-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 0;
    cursor: pointer;
    font-size: 1.75rem;
    background: linear-gradient(180deg, var(--accent-2), var(--accent));
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.6),
        inset 0 -3px 0 rgba(139, 83, 0, 0.55);
}

.board-stage {
    position: relative;
    min-height: 180px;
    border-radius: 18px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.board {
    --cell-size: 32px;
    --cell-gap: 3px;
    display: grid;
    gap: var(--cell-gap);
    justify-content: center;
    align-content: center;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: max(4px, calc(var(--cell-size) * 0.2));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: max(10px, calc(var(--cell-size) * 0.46));
    font-weight: 800;
    user-select: none;
    position: relative;
    cursor: pointer;
    transition: transform 0.12s ease, filter 0.12s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.cell.hidden {
    background: linear-gradient(180deg, #dfe6ed, #aab4c0);
    border: 1px solid rgba(255, 255, 255, 0.66);
    box-shadow:
        inset 0 2px 0 rgba(255, 255, 255, 0.94),
        inset 0 -2px 0 rgba(77, 92, 112, 0.6);
}

.cell.hidden:hover { transform: translateY(-1px); filter: brightness(1.04); }
.cell.pop { transform: scale(0.92); }

.cell.revealed {
    background: linear-gradient(180deg, #f4f7fa, #dfe7ef);
    border: 1px solid #aebdca;
    cursor: default;
}

.cell.empty { background: linear-gradient(180deg, #eef3f8, #dde6ef); }

.cell.flagged::after {
    content: "⚑";
    color: #c5162f;
    font-weight: 900;
    font-size: max(11px, calc(var(--cell-size) * 0.52));
}

.cell.question::after {
    content: "?";
    color: #222;
    font-weight: 900;
}

.cell.mine {
    background: radial-gradient(circle at 50% 45%, #ff9696 0%, #ff5151 35%, #7a1010 100%);
    border: 1px solid rgba(255, 255, 255, 0.36);
    animation: explode 0.45s ease;
}

.cell.mine::after,
.cell.mine-revealed::after {
    content: "✹";
    color: #2b0909;
    font-weight: 900;
}

.cell.mine-revealed {
    background: linear-gradient(180deg, #ffdede, #ffbbbb);
    border: 1px solid #ef9292;
}

.cell.mine-correct-flag {
    background: linear-gradient(180deg, #e9f8ee, #c9e8d3);
    border: 1px solid #8fc39f;
    cursor: default;
}

.cell.mine-correct-flag::after {
    content: "\2713";
    color: #1b7c3a;
    font-weight: 900;
    font-size: max(11px, calc(var(--cell-size) * 0.52));
}

.cell.wrong-flag {
    background: linear-gradient(180deg, #f7eaea, #ebcaca);
    border: 1px solid #d39b9b;
    color: #7e0a0a;
}

.cell.win-mine {
    animation: pulse 0.8s ease infinite;
}

@keyframes explode {
    0% { transform: scale(1); }
    45% { transform: scale(1.28); }
    100% { transform: scale(1); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

.cell[data-number="1"] { color: #1e56dc; }
.cell[data-number="2"] { color: #0f8c43; }
.cell[data-number="3"] { color: #d62020; }
.cell[data-number="4"] { color: #4a28cf; }
.cell[data-number="5"] { color: #9d3a19; }
.cell[data-number="6"] { color: #14859f; }
.cell[data-number="7"] { color: #1f2937; }
.cell[data-number="8"] { color: #5f6d7b; }

.side-menu {
    position: fixed;
    top: max(7px, env(safe-area-inset-top, 0px));
    right: max(7px, env(safe-area-inset-right, 0px));
    height: calc(100dvh - (max(7px, env(safe-area-inset-top, 0px)) + max(7px, env(safe-area-inset-bottom, 0px))));
    width: min(380px, calc(100vw - 24px));
    z-index: 42;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: linear-gradient(180deg, rgba(19, 28, 47, 0.98), rgba(9, 13, 24, 0.98));
    box-shadow: 0 24px 50px rgba(0, 0, 0, 0.45);
    transform: translateX(106%);
    transition: transform 0.2s ease;
    display: flex;
    flex-direction: column;
    padding: 14px;
    gap: 12px;
}

.side-menu.open { transform: translateX(0); }

.side-menu__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.side-menu__head h3 {
    margin: 0;
    font-family: "Russo One", "Inter", sans-serif;
}

.menu-close {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 0;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
}

.side-menu__section {
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-top: 10px;
}

.menu-caption {
    margin: 0 0 8px;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(255, 255, 255, 0.7);
}

.menu-text {
    margin: 6px 0;
    color: rgba(255, 255, 255, 0.88);
    font-size: 0.9rem;
}

.menu-text strong { color: #ffe08d; }

.menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.menu-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

.rotate-notice {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    transform: translateX(-50%) translateY(8px);
    width: min(calc(100vw - 20px), 440px);
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(6, 10, 19, 0.86);
    backdrop-filter: blur(6px);
    color: rgba(255, 255, 255, 0.95);
    font-size: 0.82rem;
    text-align: center;
    z-index: 46;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.rotate-notice.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.overlay {
    position: fixed;
    inset: 12px 12px auto 12px;
    z-index: 50;
    background: transparent;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    pointer-events: none;
}

.overlay.hidden { display: none; }

.overlay-card {
    width: min(560px, 100%);
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: linear-gradient(180deg, rgba(25, 35, 58, 0.96), rgba(10, 14, 25, 0.96));
    text-align: center;
    pointer-events: auto;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

.overlay-card h2 {
    margin: 0 0 10px;
    font-size: clamp(1.2rem, 3.4vw, 1.8rem);
}

.overlay-card h2.win {
    color: #ffd86f;
    text-shadow: 0 10px 24px rgba(255, 189, 62, 0.34);
}

.overlay-card h2.lose {
    color: #ff8f8f;
    text-shadow: 0 10px 24px rgba(255, 98, 98, 0.28);
}

.overlay-card p {
    margin: 0;
    color: var(--text-dim);
}

.overlay-card .start-btn {
    width: auto;
    min-width: 170px;
    margin-top: 10px;
    padding: 0 18px;
}

.w-full { width: 100%; }

@media (max-width: 860px) {
    .difficulty-grid { grid-template-columns: 1fr; }
    .top-controls { flex-wrap: wrap; }
    .stats-bar {
        grid-template-columns: 1fr auto 1fr;
        gap: 10px;
    }
    .digit-box { width: 112px; }
    .stat-value { font-size: 1.35rem; }
    .reset-btn { width: 56px; height: 56px; font-size: 1.45rem; }
}

@media (max-width: 680px) {
    .game-shell {
        width: 100vw;
        max-width: none;
        height: 100dvh;
        margin: 0;
        border-radius: 0;
        border: 0;
        padding-top: max(8px, env(safe-area-inset-top, 0px));
        padding-right: max(8px, env(safe-area-inset-right, 0px));
        padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
        padding-left: max(8px, env(safe-area-inset-left, 0px));
        gap: 8px;
    }

    .spark {
        opacity: 0.15;
    }

    .top-controls {
        gap: 8px;
        flex-wrap: nowrap;
    }

    .top-controls__right {
        flex: 1;
        justify-content: flex-end;
    }

    .menu-toggle,
    .small-btn,
    .input-mode-btn {
        min-height: 40px;
        font-size: 0.78rem;
        padding: 0 10px;
    }

    .mode-pill {
        max-width: 46vw;
        font-size: 0.74rem;
        padding: 7px 10px;
    }

    .stats-bar {
        gap: 8px;
        padding: 8px;
        border-radius: 14px;
    }

    .digit-box {
        width: auto;
        min-width: 94px;
        padding: 6px 8px;
        border-radius: 10px;
    }

    .stat-value {
        width: 54px;
        letter-spacing: 1.4px;
        font-size: 1.15rem;
    }

    .reset-btn {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }

    .board-stage {
        padding: 6px;
        border-radius: 14px;
    }
}

@media (max-width: 420px) {
    .digit-box {
        min-width: 82px;
    }

    .stat-value {
        width: 48px;
    }

    .mode-pill {
        max-width: 42vw;
    }
}
