:root {
    --game-primary: #c90c0f;
    --game-secondary: #f4c430;
    --lo-ink: #07141d;
    --lo-navy: #0f2430;
    --lo-gold: #f4c430;
    --lo-on: #f5c518;
}

body.lo-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.16), 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.lo-page.game-menu-active {
    overflow-y: auto;
    overflow-x: hidden;
}

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

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

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

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

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

.lo-hud {
    display: flex;
    flex-wrap: wrap;
    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, #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);
}

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

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

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

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

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

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

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

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

.lo-hint {
    text-align: center;
    max-width: 36rem;
    margin: 0.75rem auto 0;
    color: #c5d4de;
    font-size: 0.92rem;
}

.lo-board-wrap {
    display: flex;
    justify-content: center;
    overflow: visible;
    max-width: 100%;
    padding: 0.35rem;
}

.lo-board {
    --lo-cell: min(72px, calc((min(94vw, 520px) - 1.2rem) / var(--lo-size, 5)));
    display: grid;
    grid-template-columns: repeat(var(--lo-size), var(--lo-cell));
    grid-template-rows: repeat(var(--lo-size), var(--lo-cell));
    gap: 0.28rem;
    background: #102834;
    border: 4px solid #07141d;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
    padding: 0.55rem;
    user-select: none;
    touch-action: manipulation;
}

.lo-cell {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-height: 44px;
    border-radius: 14px;
    border: 2px solid #041016;
    background:
        radial-gradient(circle at 35% 28%, rgba(80, 96, 108, 0.55), transparent 46%),
        linear-gradient(180deg, #2a3c48, #121c24);
    color: transparent;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 4px 0 #041016;
    transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.12s ease;
}

.lo-cell.is-on {
    background:
        radial-gradient(circle at 35% 30%, #fff6c2 0%, #f5c518 38%, #d97706 100%);
    border-color: #fde68a;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.55),
        0 0 16px rgba(245, 197, 24, 0.55),
        0 4px 0 #7c2d12;
}

.lo-cell.is-cursor:not(:disabled) {
    outline: 2px solid #4cc9f0;
    outline-offset: 2px;
}

.lo-cell.is-hint {
    box-shadow: 0 0 0 3px #4cc9f0, 0 0 18px rgba(76, 201, 240, 0.65);
}

.lo-cell.is-chase {
    box-shadow: 0 0 0 3px #f97316, 0 0 14px rgba(249, 115, 22, 0.55);
}

.lo-cell.is-flash {
    transform: scale(0.94);
}

.lo-cell:disabled {
    cursor: default;
}

.lo-board.is-won .lo-cell {
    background: linear-gradient(180deg, #1c4558, #102834);
    border-color: #07141d;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

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

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

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

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

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

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

.lo-settings-panel__label {
    margin: 0.85rem 0 0.45rem;
    font-weight: 700;
    color: #1a120c;
}

.lo-settings-panel__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

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

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

.lo-settings-panel__note,
#settingsModal .lo-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;
}

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

.lo-help-cell {
    width: 2.4rem;
    height: 2.4rem;
    border-radius: 10px;
    border: 2px solid #1a120c;
    background: #1f2933;
}

.lo-help-cell.is-on {
    background: radial-gradient(circle at 35% 30%, #fff6c2, #f5c518);
    border-color: #d97706;
}

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

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

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

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

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

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

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

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

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

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

    .lo-board {
        --lo-cell: min(56px, calc((100vw - 2.4rem) / var(--lo-size, 5)));
        gap: 0.2rem;
        padding: 0.4rem;
    }

    .lo-cell {
        border-radius: 10px;
        min-height: 0;
    }

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

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

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

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

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