:root {
    --game-primary: #c90c0f;
    --game-secondary: #f4c430;
    --nn-ink: #07141d;
    --nn-navy: #0f2430;
    --nn-panel: #163445;
    --nn-gold: #f4c430;
    --nn-paper: #f4efe4;
    --nn-fill: #1a120c;
}

body.nn-page {
    margin: 0;
    min-height: 100vh;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #f4f7fb;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 12% 8%, rgba(244, 196, 48, 0.14), transparent 42%),
        radial-gradient(circle at 88% 6%, rgba(201, 12, 15, 0.2), transparent 46%),
        linear-gradient(180deg, #07141d 0%, #123040 48%, #07141d 100%);
}

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

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

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

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

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

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

.nn-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, #1c4558, #102834);
    border: 3px solid #07141d;
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 10px 24px rgba(0, 0, 0, 0.35);
}

.nn-lcd {
    min-width: 5.2rem;
    padding: 0.2rem 0.45rem;
    background: #041016;
    color: #f5c518;
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.15rem;
    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);
}

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

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

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

.nn-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border-radius: 999px;
    border: 1px solid rgba(76, 201, 240, 0.28);
    background: rgba(7, 20, 29, 0.7);
    color: #f4f7fb !important;
    font-weight: 700;
    cursor: pointer;
}

.nn-tool-btn:hover {
    border-color: #f5c518;
    color: #f5c518 !important;
}

.nn-tool-btn.is-selected {
    background: #c90c0f;
    border-color: #c90c0f;
    color: #fff !important;
}

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

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

.nn-board-wrap {
    display: flex;
    justify-content: center;
    overflow-x: auto;
    overflow-y: visible;
    max-width: 100%;
    padding: 0.35rem;
    -webkit-overflow-scrolling: touch;
}

.nn-board {
    --nn-clue: min(3.4rem, 22vw);
    --nn-cell: min(42px, calc((min(94vw, 640px) - var(--nn-clue) - 0.9rem) / var(--nn-size, 10)));
    display: grid;
    grid-template-columns: auto repeat(var(--nn-size), var(--nn-cell));
    grid-template-rows: auto repeat(var(--nn-size), var(--nn-cell));
    background: #102834;
    border: 4px solid #07141d;
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
    padding: 0.35rem;
    gap: 0;
    user-select: none;
    touch-action: none;
}

.nn-corner {
    min-width: var(--nn-clue, 3.4rem);
}

.nn-col-clues,
.nn-row-clues,
.nn-cell {
    box-sizing: border-box;
}

.nn-col-clues {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 0.05rem;
    padding: 0.2rem 0 0.15rem;
    color: #fde68a;
    font-size: calc(var(--nn-cell) * 0.32);
    font-weight: 700;
    min-height: 2.6rem;
    border-bottom: 2px solid rgba(244, 196, 48, 0.35);
}

.nn-row-clues {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.28rem;
    padding: 0 0.4rem 0 0.2rem;
    color: #fde68a;
    font-size: calc(var(--nn-cell) * 0.32);
    font-weight: 700;
    min-width: var(--nn-clue, 3.4rem);
    border-right: 2px solid rgba(244, 196, 48, 0.35);
}

.nn-col-clues.is-complete,
.nn-row-clues.is-complete {
    color: #7dffb3;
    opacity: 0.7;
}

.nn-cell {
    width: var(--nn-cell);
    height: var(--nn-cell);
    border: 1px solid #c5b8a2;
    background: var(--nn-paper);
    color: #1a120c;
    cursor: pointer;
    padding: 0;
    position: relative;
}

.nn-cell:nth-child(5n + 1) {
    border-left-width: 2px;
    border-left-color: #8a7b66;
}

.nn-cell.is-fill {
    background: var(--nn-fill);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.nn-cell.is-fill.is-painted {
    background: var(--cell-color, var(--nn-fill));
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.28),
        inset 0 -2px 0 rgba(0, 0, 0, 0.12);
    animation: nn-paint-in 0.38s ease both;
    animation-delay: var(--paint-delay, 0s);
}

.nn-board.is-revealed .nn-cell {
    cursor: default;
}

.nn-board.is-revealed .nn-cell:hover {
    filter: none;
}

.nn-board.is-revealed .nn-cell.is-mark::after {
    display: none;
}

.nn-board-wrap.is-revealed {
    box-shadow: 0 0 0 3px rgba(244, 196, 48, 0.35);
    border-radius: 16px;
}

@keyframes nn-paint-in {
    from {
        transform: scale(0.72);
        filter: saturate(0.2) brightness(1.25);
    }
    to {
        transform: scale(1);
        filter: none;
    }
}

.nn-result-sheet {
    display: none;
    width: min(640px, calc(100% - 1.5rem));
    margin: 0.85rem auto 0;
    background: #fff;
    color: #1a1a1a;
    border-radius: 1rem;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
    z-index: 40;
}

.nn-result-sheet.active {
    display: block;
    animation: nn-sheet-in 0.4s ease;
}

.nn-result-sheet__inner {
    padding: 1rem 1.15rem 1.1rem;
}

.nn-result-sheet__header h2 {
    margin: 0 0 0.35rem;
    color: #c90c0f;
    font-size: 1.35rem;
}

.nn-result-sheet__actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.85rem;
}

@keyframes nn-sheet-in {
    from {
        opacity: 0;
        transform: translateY(1.1rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 640px) {
    .nn-result-sheet.active {
        position: sticky;
        bottom: 0.35rem;
        max-height: 28vh;
        overflow-y: auto;
        width: min(100%, calc(100vw - 1rem));
        margin-top: 0.55rem;
        z-index: 30;
    }

    .nn-result-sheet__inner {
        padding: 0.7rem 0.85rem 0.8rem;
    }

    .nn-result-sheet__header h2 {
        font-size: 1.12rem;
    }

    .nn-page.nn-has-result .nn-hint {
        display: none;
    }
}

.nn-cell.is-mark {
    background: #efe6d6;
}

.nn-cell.is-mark::after {
    content: "×";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #c90c0f;
    font-size: calc(var(--nn-cell) * 0.62);
    font-weight: 800;
    line-height: 1;
}

.nn-cell.is-cursor {
    outline: 2px dashed #4cc9f0;
    outline-offset: -2px;
}

.nn-cell.is-hint {
    box-shadow: inset 0 0 0 3px #f4c430;
}

.nn-cell.is-mistake {
    animation: nn-shake 0.28s ease;
}

.nn-cell:hover {
    filter: brightness(1.06);
}

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

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

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

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

.nn-settings-panel__buttons .difficulty-pill,
#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;
}

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

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

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

.nn-help-cells {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.6rem;
}

.nn-help-cell {
    width: 2.4rem;
    height: 2.4rem;
    border: 2px solid #c5b8a2;
    background: #f4efe4;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #1a120c;
}

.nn-help-cell.is-fill {
    background: #1a120c;
    color: #fff;
}

.nn-help-cell.is-mark::after {
    content: "×";
    color: #c90c0f;
    font-size: 1.4rem;
}

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

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

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

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

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

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

    .nn-hud {
        max-width: 100%;
        gap: 0.4rem;
        padding: 0.4rem 0.45rem;
    }

    .nn-lcd {
        min-width: 0;
        flex: 1 1 0;
        font-size: 1rem;
    }

    .nn-toolbar {
        max-width: 100%;
        gap: 0.35rem;
    }

    .nn-tool-btn {
        min-height: 44px;
        padding: 0.45rem 0.6rem;
        color: #f4f7fb !important;
        background: rgba(7, 20, 29, 0.85);
    }

    .nn-tool-btn.is-selected {
        background: #c90c0f;
        color: #fff !important;
    }

    .nn-board {
        --nn-clue: min(2.55rem, 19vw);
        --nn-cell: min(28px, calc((100vw - 1.15rem - var(--nn-clue) - 12px) / var(--nn-size, 10)));
    }

    .nn-col-clues {
        min-height: 0;
        font-size: max(9px, calc(var(--nn-cell) * 0.38));
        padding: 0.1rem 0 0.1rem;
    }

    .nn-row-clues {
        font-size: max(9px, calc(var(--nn-cell) * 0.38));
        gap: 0.12rem;
        padding: 0 0.18rem 0 0.08rem;
    }

    .nn-status {
        font-size: 0.88rem;
        padding: 0 0.15rem;
    }

    .modal {
        padding: 0.65rem;
        align-items: flex-end;
    }

    .modal-content {
        max-height: 88vh;
    }

    .win-stats {
        gap: 0.35rem;
    }
}
