:root {
    --game-primary: #c90c0f;
    --game-secondary: #f4c430;
    --gc-ink: #07141d;
    --gc-navy: #0f2430;
    --gc-panel: #163445;
    --gc-gold: #f4c430;
    --gc-cyan: #4cc9f0;
}

body.gc-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(76, 201, 240, 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.gc-page.game-menu-active {
    overflow-y: auto;
    overflow-x: hidden;
}

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

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

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

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

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

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

.gc-lcd {
    min-width: 5.2rem;
    padding: 0.2rem 0.45rem;
    background: #041016;
    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);
}

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

.gc-lcd.is-target {
    color: #7dffb3;
    box-shadow: inset 0 0 0 2px #1b7a4a, inset 0 8px 16px rgba(0, 0, 0, 0.45);
}

.gc-lcd.is-sum.is-match {
    color: #7dffb3;
}

.gc-lcd.is-sum.is-hot {
    color: #ff8a7a;
}

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

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

.gc-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;
    font-weight: 700;
    cursor: pointer;
}

.gc-tool-btn:hover {
    border-color: #f5c518;
    color: #f5c518;
}

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

.gc-equation {
    text-align: center;
    min-height: 1.4rem;
    margin: 0 auto 0.65rem;
    color: #fde68a;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.gc-board-wrap {
    display: flex;
    justify-content: center;
    padding: 0.25rem;
}

.gc-board {
    --gc-cols: 6;
    --gc-rows: 8;
    --gc-gap: 6px;
    --gc-cell: min(64px, calc((min(100vw, 420px) - 2.6rem - (var(--gc-cols) + 1) * var(--gc-gap)) / var(--gc-cols)));
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--gc-cols), var(--gc-cell));
    grid-template-rows: repeat(var(--gc-rows), var(--gc-cell));
    gap: var(--gc-gap);
    padding: var(--gc-gap);
    background: #102834;
    border: 4px solid #07141d;
    border-radius: 14px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
    box-sizing: border-box;
}

.gc-board::before {
    content: "";
    position: absolute;
    left: var(--gc-gap);
    right: var(--gc-gap);
    top: var(--gc-gap);
    height: var(--gc-cell);
    border-radius: 8px;
    border: 1px dashed rgba(201, 12, 15, 0.45);
    pointer-events: none;
}

.gc-cell {
    width: var(--gc-cell);
    height: var(--gc-cell);
    border: 0;
    padding: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    color: inherit;
    cursor: pointer;
    position: relative;
}

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

.gc-cell.is-danger {
    box-shadow: inset 0 0 0 2px rgba(201, 12, 15, 0.55);
}

.gc-cell.is-cursor:focus,
.gc-cell.is-cursor {
    outline: 2px dashed rgba(76, 201, 240, 0.75);
    outline-offset: -2px;
}

.gc-block {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-weight: 800;
    font-size: calc(var(--gc-cell) * 0.46);
    line-height: 1;
    user-select: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 0 rgba(0, 0, 0, 0.18);
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.gc-cell.is-selected .gc-block {
    transform: scale(1.06);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        0 0 0 3px #f4c430,
        0 6px 0 rgba(0, 0, 0, 0.2);
}

.gc-cell.is-hint .gc-block {
    animation: gc-hint 0.7s ease-in-out infinite;
}

.gc-cell.is-overflow .gc-block {
    animation: gc-shake 0.28s ease;
}

.gc-cell.is-clearing .gc-block {
    animation: gc-pop 0.28s ease forwards;
}

.gc-cell.is-new .gc-block {
    animation: gc-fall 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.gc-block.v-1 { background: #f8f0e3; color: #3b3228; }
.gc-block.v-2 { background: #4cc9f0; color: #083344; }
.gc-block.v-3 { background: #2a9d8f; color: #fff; }
.gc-block.v-4 { background: #f4c430; color: #1a120c; }
.gc-block.v-5 { background: #f4a261; color: #1a120c; }
.gc-block.v-6 { background: #e76f51; color: #fff; }
.gc-block.v-7 { background: #c90c0f; color: #fff; }
.gc-block.v-8 { background: #7b2cbf; color: #fff; }
.gc-block.v-9 { background: #3a0ca3; color: #fff; }

@keyframes gc-fall {
    from { transform: translateY(calc(var(--gc-drop, 4) * -100%)); opacity: 0.15; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes gc-pop {
    0% { transform: scale(1); opacity: 1; }
    55% { transform: scale(1.18); opacity: 1; }
    100% { transform: scale(0.2); opacity: 0; }
}

@keyframes gc-hint {
    0%, 100% { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 0 0 0 rgba(244, 196, 48, 0.1); }
    50% { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 0 0 3px #f4c430; }
}

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

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

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

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

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

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

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

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

.help-powers {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.help-power {
    width: 2.6rem;
    height: 2.6rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-weight: 800;
}

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

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

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

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

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

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

    .gc-hud {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 0.35rem;
        max-width: 100%;
        padding: 0.4rem 0.4rem;
    }

    .gc-lcd {
        min-width: 0;
        font-size: 1.05rem;
        padding: 0.15rem 0.2rem;
    }

    .gc-lcd span {
        font-size: 0.52rem;
        letter-spacing: 0.08em;
    }

    .gc-equation {
        font-size: 0.88rem;
        padding: 0 0.15rem;
    }

    .gc-board {
        --gc-gap: 5px;
        --gc-cell: min(52px, calc((100vw - 2.4rem - (var(--gc-cols) + 1) * var(--gc-gap)) / var(--gc-cols)));
    }

    .gc-board-wrap {
        overflow-x: hidden;
        padding: 0.15rem;
    }

    .gc-tool-btn {
        min-height: 44px;
        color: #f4f7fb;
        background: rgba(7, 20, 29, 0.85);
    }

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

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