:root {
    --bg: #f4f7f2;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #667085;
    --line: #d9e4d2;
    --accent: #166534;
    --accent-dark: #14532d;
    --gold: #d99a1b;
    --red: #dc2626;
    --blue: #1d4ed8;
    --shadow: 0 16px 42px rgba(23, 32, 51, 0.14);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--bg);
}

body {
    margin: 0;
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    line-height: 1.5;
    letter-spacing: 0;
}

a {
    color: inherit;
}

button {
    font: inherit;
}

.site-header {
    height: 54px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
    background: #172033;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 80;
}

.brand {
    font-size: 20px;
    font-weight: 900;
    text-decoration: none;
    white-space: nowrap;
}

.desktop-nav {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
}

.desktop-nav a {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.84);
    font-weight: 800;
    text-decoration: none;
}

.desktop-nav a:hover,
.desktop-nav a:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

.header-download,
.mobile-menu {
    display: none;
}

main {
    padding: 14px 12px 0;
}

.game-shell {
    width: min(900px, 100%);
    margin: 0 auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.game-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 14px;
    align-items: center;
    margin-bottom: 8px;
}

.game-head h1 {
    margin: 0 0 4px;
    font-size: 28px;
    line-height: 1.15;
}

.game-head p {
    margin: 0;
    color: var(--muted);
    font-weight: 800;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.actions button,
.actions a,
.level-btn,
.dir-btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    font-weight: 900;
    text-decoration: none;
}

.actions button,
.actions a,
.level-btn {
    padding: 0 11px;
}

.actions button:first-child,
.level-btn.active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.download-strip {
    min-height: 36px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 5px 8px;
    border: 1px solid #f1d39b;
    border-radius: 7px;
    background: #fff7e6;
    color: #68430d;
}

.download-strip span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    font-weight: 900;
    white-space: nowrap;
}

.download-strip a {
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 12px;
    border-radius: 6px;
    background: var(--gold);
    color: #fff;
    font-size: 13px;
    font-weight: 900;
    text-decoration: none;
    white-space: nowrap;
}

.play-layout {
    display: grid;
    grid-template-columns: minmax(280px, 520px) 220px;
    justify-content: center;
    gap: 12px;
    align-items: start;
}

.board-wrap {
    position: relative;
    display: grid;
    place-items: center;
    padding: 8px;
    border-radius: 8px;
    background:
        linear-gradient(90deg, rgba(22, 101, 52, 0.08) 1px, transparent 1px),
        linear-gradient(rgba(22, 101, 52, 0.08) 1px, transparent 1px),
        #eef7e8;
    background-size: 18px 18px;
    overflow: hidden;
}

#gameCanvas {
    width: min(520px, 100%);
    aspect-ratio: 1;
    display: block;
    border-radius: 8px;
    background: #173b28;
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
    touch-action: none;
}

.board-badge {
    position: absolute;
    left: 14px;
    top: 14px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    padding: 0 10px;
    border-radius: 6px;
    background: rgba(23, 32, 51, 0.82);
    color: #fff;
    font-size: 13px;
    font-weight: 900;
    pointer-events: none;
}

.side-panel {
    display: grid;
    gap: 8px;
}

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

.stat-card {
    min-height: 56px;
    display: grid;
    align-content: center;
    gap: 3px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.stat-card span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 900;
}

.stat-card strong {
    font-size: 20px;
    line-height: 1.1;
}

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

.level-btn {
    min-width: 0;
}

.pad {
    display: grid;
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(3, 40px);
    justify-content: center;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.dir-btn {
    padding: 0;
    background: #172033;
    color: #fff;
    border-color: #172033;
    font-size: 20px;
    line-height: 1;
}

.dir-up {
    grid-column: 2;
}

.dir-left {
    grid-column: 1;
    grid-row: 2;
}

.dir-right {
    grid-column: 3;
    grid-row: 2;
}

.dir-down {
    grid-column: 2;
    grid-row: 3;
}

.mini-links {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

.mini-links a {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--accent-dark);
    font-weight: 900;
    text-decoration: none;
}

.content-page {
    width: min(900px, 100%);
    margin: 0 auto;
    padding: 14px 12px 0;
}

.content-panel {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.content-panel h1 {
    margin: 0 0 14px;
    font-size: 28px;
    line-height: 1.2;
}

.content-panel p,
.content-panel li {
    color: var(--muted);
    font-weight: 700;
}

.content-panel a {
    color: var(--accent-dark);
    font-weight: 900;
}

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

.game-card {
    min-height: 56px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    color: var(--ink);
    text-decoration: none;
}

.game-card:hover,
.game-card:focus-visible {
    border-color: var(--accent);
    outline: none;
}

.game-card-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 7px;
    background: var(--accent);
    color: #fff;
    font-size: 13px;
    font-weight: 900;
}

.game-card strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.site-footer {
    margin-top: 18px;
    padding: 16px 12px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    text-align: center;
}

.site-footer p {
    margin: 0;
}

.site-footer a {
    color: var(--accent-dark);
    font-weight: 900;
    text-decoration: none;
}

@media (max-width: 820px) {
    .game-head,
    .play-layout {
        grid-template-columns: 1fr;
    }

    .side-panel {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 700px) {
    .site-header {
        height: 48px;
        grid-template-columns: minmax(0, 1fr) auto 40px;
        gap: 6px;
        padding: 0 8px;
    }

    .brand {
        font-size: 17px;
    }

    .desktop-nav {
        display: none;
    }

    .header-download {
        min-height: 34px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0 10px;
        border-radius: 6px;
        background: #fff7e6;
        color: #68430d;
        border: 1px solid #e5c16b;
        font-size: 13px;
        font-weight: 900;
        text-decoration: none;
        white-space: nowrap;
    }

    .mobile-menu {
        display: block;
        position: relative;
    }

    .mobile-menu summary {
        width: 40px;
        height: 40px;
        display: grid;
        place-items: center;
        gap: 4px;
        padding: 10px;
        border-radius: 6px;
        background: rgba(255, 255, 255, 0.1);
        cursor: pointer;
        list-style: none;
    }

    .mobile-menu summary::-webkit-details-marker {
        display: none;
    }

    .mobile-menu span {
        width: 18px;
        height: 2px;
        display: block;
        border-radius: 2px;
        background: #fff;
    }

    .mobile-menu nav {
        position: fixed;
        top: 48px;
        right: 8px;
        z-index: 90;
        width: min(220px, calc(100vw - 16px));
        display: grid;
        gap: 4px;
        padding: 10px;
        border-radius: 8px;
        background: #172033;
        box-shadow: var(--shadow);
    }

    .mobile-menu:not([open]) nav {
        display: none;
    }

    .mobile-menu nav a {
        min-height: 42px;
        display: flex;
        align-items: center;
        padding: 0 12px;
        border-radius: 6px;
        color: #fff;
        font-weight: 800;
        text-decoration: none;
    }

    main {
        padding: 8px 8px 0;
    }

    .content-page {
        padding: 8px 8px 0;
    }

    .game-shell {
        padding: 8px;
    }

    .game-head {
        gap: 8px;
        margin-bottom: 8px;
    }

    .game-head h1 {
        font-size: 22px;
    }

    .game-head p {
        min-height: 22px;
        font-size: 13px;
        line-height: 1.4;
    }

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

    .actions button,
    .actions a,
    .level-btn {
        min-height: 34px;
        padding: 0 8px;
        font-size: 13px;
    }

    .download-strip {
        min-height: 34px;
        gap: 6px;
        margin-bottom: 8px;
        padding: 5px 6px;
    }

    .download-strip span,
    .download-strip a {
        font-size: 12px;
    }

    .download-strip a {
        min-height: 28px;
        padding: 0 9px;
    }

    .board-wrap {
        padding: 6px;
        border-radius: 7px;
    }

    #gameCanvas {
        width: 100%;
    }

    .board-badge {
        left: 10px;
        top: 10px;
        min-height: 26px;
        font-size: 12px;
    }

    .stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px;
    }

    .stat-card {
        min-height: 48px;
        padding: 7px;
        border-radius: 7px;
    }

    .stat-card span {
        font-size: 11px;
    }

    .stat-card strong {
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 16px;
        white-space: nowrap;
    }

    .level-row {
        gap: 6px;
    }

    .pad {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-rows: repeat(3, 38px);
        gap: 5px;
        padding: 6px;
    }

    .mini-links {
        display: none;
    }

    .content-panel {
        padding: 14px;
    }

    .content-panel h1 {
        font-size: 24px;
    }

    .game-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .game-card {
        min-height: 52px;
        padding: 8px;
    }

    .game-card strong {
        font-size: 15px;
    }

    .site-footer {
        margin-top: 18px;
        padding: 16px 10px;
        font-size: 13px;
    }
}
