/* SnakeFun – self-hosted snake game */
.sg {
    --sg-bar: #3f6a25;
    --sg-bar-2: #4f8130;
    --sg-border: #4f8130;
    --sg-accent: #4e7cf6;
    --sg-accent-dark: #2f5fd6;
    --sg-ink: #1d2817;
    --sg-muted: #66735e;
    position: relative;
    direction: ltr;
    width: 100%;
    max-width: 680px;
    margin: 18px auto;
    border-radius: 20px;
    overflow: hidden;
    background: var(--sg-border);
    box-shadow: 0 2px 4px rgba(29, 40, 23, 0.08), 0 16px 40px rgba(29, 40, 23, 0.16);
    font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

/* ---------- top bar ---------- */
.sg-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 56px;
    padding: 0 12px;
    background: linear-gradient(180deg, var(--sg-bar-2), var(--sg-bar));
    color: #fff;
    font-size: 19px;
    font-weight: 800;
}

.sg-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 64px;
    height: 36px;
    padding: 0 12px 0 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.18);
    font-variant-numeric: tabular-nums;
}

.sg-stat svg {
    width: 24px;
    height: 24px;
    flex: none;
}

.sg-spacer {
    flex: 1;
}

.sg-mode {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.sg-icon-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s;
}

.sg-icon-btn:hover {
    background: rgba(255, 255, 255, 0.26);
}

.sg-icon-btn:focus-visible,
.sg-chip:focus-visible,
.sg-play:focus-visible,
.sg-link:focus-visible,
.sg-save:focus-visible {
    outline: 3px solid #ffd54f;
    outline-offset: 2px;
}

.sg-icon-btn svg {
    width: 20px;
    height: 20px;
}

/* ---------- board ---------- */
.sg-stage {
    display: flex;
    justify-content: center;
    padding: 10px;
}

.sg-board {
    position: relative;
    line-height: 0;
    touch-action: none;
}

.sg-board canvas {
    display: block;
    border-radius: 8px;
}

.sg-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(24, 44, 14, 0.42);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    border-radius: 8px;
    line-height: 1.35;
    padding: 10px;
}

.sg-overlay[hidden] {
    display: none;
}

/* ---------- cards (menu / pause / game over) ---------- */
.sg-card {
    width: 100%;
    max-width: 390px;
    max-height: 100%;
    overflow-y: auto;
    background: #fff;
    color: var(--sg-ink);
    border-radius: 18px;
    padding: 18px 18px 16px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
    text-align: center;
    animation: sg-pop 0.18s ease-out;
}

@keyframes sg-pop {
    from {
        transform: scale(0.96);
        opacity: 0;
    }
}

.sg-card h2 {
    margin: 0 0 8px;
    font-size: 22px;
    font-weight: 800;
    color: var(--sg-ink);
    letter-spacing: -0.01em;
}

.sg-card p {
    margin: 0 0 12px;
    font-size: 14px;
    color: var(--sg-muted);
}

.sg-result {
    display: flex;
    justify-content: center;
    gap: 14px;
    margin: 4px 0 10px;
    font-size: 26px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.sg-result div {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px 6px 10px;
    border-radius: 14px;
    background: #f3f7ee;
}

.sg-result svg {
    width: 28px;
    height: 28px;
}

.sg-newbest {
    color: #b7791f !important;
    font-weight: 700;
}

.sg-group {
    margin: 0 0 10px;
    text-align: left;
}

.sg-label {
    display: block;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sg-muted);
    margin: 0 0 5px;
}

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

.sg-chip {
    flex: 1 1 auto;
    min-width: 56px;
    padding: 7px 10px;
    border: 2px solid #e3eadb;
    border-radius: 11px;
    background: #f7faf3;
    color: #2f3d27;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}

.sg-chip:hover {
    border-color: #b7d29c;
}

.sg-chip[aria-pressed="true"] {
    background: var(--sg-accent);
    border-color: var(--sg-accent);
    color: #fff;
}

.sg-play {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 6px;
    padding: 12px 18px;
    border: 0;
    border-radius: 14px;
    background: var(--sg-accent);
    color: #fff;
    font: inherit;
    font-size: 18px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--sg-accent-dark);
}

/* Keeps Play visible when the settings card has to scroll on short boards. */
.sg-actions {
    position: sticky;
    bottom: -16px;
    margin: 0 -18px -16px;
    padding: 6px 18px 16px;
    background: linear-gradient(rgba(255, 255, 255, 0), #fff 30%);
}

.sg-play:hover {
    filter: brightness(1.06);
}

.sg-play:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--sg-accent-dark);
}

.sg-link {
    margin-top: 10px;
    border: 0;
    background: none;
    color: var(--sg-bar);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

.sg-hint {
    margin-top: 10px !important;
    margin-bottom: 0 !important;
    font-size: 12px !important;
    color: #8a9483 !important;
}

/* ---------- leaderboard status in game-over card ---------- */
.sg-lbstatus:empty {
    display: none;
}

.sg-lbstatus {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 14px;
    background: #f6f4ec;
}

.sg-points {
    font-size: 15px;
    font-weight: 800;
    color: var(--sg-ink);
}

.sg-lbmsg {
    margin: 4px 0 0 !important;
    font-size: 13px !important;
}

.sg-rank {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    background: #ffd54f;
    color: #5c4300;
    font-weight: 800;
}

.sg-nameform {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.sg-nameform input {
    flex: 1;
    min-width: 0;
    padding: 9px 10px;
    border: 2px solid #dfe5d6;
    border-radius: 10px;
    font: inherit;
    font-size: 16px;
    color: var(--sg-ink);
    background: #fff;
    user-select: text;
    -webkit-user-select: text;
}

.sg-nameform input:focus {
    outline: none;
    border-color: var(--sg-accent);
}

.sg-nameform input.sg-invalid {
    border-color: #e7471d;
}

.sg-save {
    padding: 9px 12px;
    border: 0;
    border-radius: 10px;
    background: var(--sg-bar);
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
}

.sg-skip {
    margin-top: 6px;
    font-size: 13px;
}

/* ---------- fullscreen + iOS fallback ---------- */
.sg:fullscreen,
.sg.sg--max {
    max-width: none;
    width: 100%;
    height: 100%;
    margin: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.sg.sg--max {
    position: fixed;
    inset: 0;
    z-index: 100000;
}

.sg:fullscreen .sg-stage,
.sg.sg--max .sg-stage {
    flex: 1;
    align-items: center;
}

@media (max-width: 480px) {
    .sg {
        border-radius: 16px;
    }

    .sg-bar {
        height: 48px;
        gap: 6px;
        padding: 0 8px;
        font-size: 17px;
    }

    .sg-stat {
        min-width: 0;
        height: 32px;
        padding: 0 10px 0 6px;
    }

    .sg-stat svg {
        width: 20px;
        height: 20px;
    }

    .sg-mode {
        display: none;
    }

    .sg-icon-btn {
        width: 32px;
        height: 32px;
    }

    .sg-stage {
        padding: 6px;
    }

    .sg-card {
        padding: 14px 12px 12px;
    }

    .sg-card h2 {
        font-size: 18px;
    }

    .sg-actions {
        bottom: -12px;
        margin: 0 -12px -12px;
        padding: 4px 12px 12px;
    }

    .sg-group {
        margin-bottom: 6px;
    }

    .sg-chip {
        padding: 6px;
        font-size: 13px;
        min-width: 44px;
    }
}
