* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

body {
    font-family: "Arial", sans-serif;
    background: linear-gradient(135deg, #87ceeb 0%, #98fb98 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #2f4f2f;
    margin: 0;
    padding: 0;
    overflow: hidden;
    transition:
        background 0.3s ease,
        color 0.3s ease;
    -webkit-overflow-scrolling: touch;
}

body.dark-mode {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #e4e4e7;
}

.game-container {
    background: rgba(255, 255, 255, 0.95);
    text-align: center;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding:
        max(12px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(12px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
    transition: background 0.3s ease;
}

body.dark-mode .game-container {
    background: rgba(30, 30, 50, 0.95);
}

.game-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    color: #2f4f2f;
    transition: color 0.3s ease;
}

.game-title {
    font-size: clamp(15px, 2.2vw, 22px);
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.home-link {
    color: inherit;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border: 2px solid currentColor;
    border-radius: 999px;
    padding: 0 14px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    transition:
        background 0.2s ease,
        color 0.2s ease,
        transform 0.2s ease;
}

.home-link:hover {
    background: #2f4f2f;
    color: white;
    transform: translateY(-1px);
}

body.dark-mode .home-link:hover {
    background: #e6e6e6;
    color: #1a1a2e;
}

body.dark-mode .game-header {
    color: #e6e6e6;
}

/* Stat bar */

.stat-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    justify-content: center;
    gap: 6px;
    color: #2f4f2f;
    transition: color 0.3s ease;
}

body.dark-mode .stat-bar {
    color: #e6e6e6;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    min-width: 62px;
    padding: 5px 10px;
    border-radius: 10px;
    background: rgba(47, 79, 47, 0.08);
}

.stat[hidden] {
    display: none;
}

body.dark-mode .stat {
    background: rgba(255, 255, 255, 0.09);
}

.stat-value {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.1;
}

.stat-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.65;
}

.stat-wide .stat-value {
    font-size: 14px;
}

#timerDisplay .stat-value {
    color: #b22222;
}

body.dark-mode #timerDisplay .stat-value {
    color: #ff8a8a;
}

/* Play area */

.game-stage {
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
}

#gameCanvas {
    border: 4px solid #8b4513;
    border-radius: 8px;
    background: #90ee90;
    display: block;
    transition: border-color 0.3s ease;
    touch-action: none;
}

body.dark-mode #gameCanvas {
    border-color: #4a4a6a;
}

.game-over-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: none;
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    transition:
        background 0.3s ease,
        color 0.3s ease;
}

body.dark-mode .game-over-screen {
    background: rgba(30, 30, 50, 0.95);
    color: #e6e6e6;
}

.game-over-screen h2 {
    color: #b22222;
    margin-bottom: 20px;
    font-size: 28px;
}

.game-over-screen p {
    margin: 10px 0;
    font-size: 18px;
}

.start-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition:
        background 0.3s ease,
        color 0.3s ease;
    width: min(680px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
}

body.dark-mode .start-screen {
    background: rgba(30, 30, 50, 0.95);
    color: #e6e6e6;
}

.start-screen h1 {
    color: #2f4f2f;
    margin-bottom: 20px;
    font-size: 32px;
    transition: color 0.3s ease;
}

body.dark-mode .start-screen h1 {
    color: #e6e6e6;
}

.start-screen .goose-emoji {
    font-size: 48px;
    margin: 20px 0;
}

.daily-note {
    margin: 0 auto 8px;
    max-width: 28em;
    font-size: 14px;
    color: #555;
}

body.dark-mode .daily-note {
    color: #b4b4c4;
}

.controls {
    margin: 20px 0;
    font-size: 14px;
    color: #555;
}

.mode-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(120px, 1fr));
    gap: 8px;
    margin: 18px 0 10px;
}

.streak-panel {
    margin: 0 0 12px;
}

.streak-heading {
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 700;
}

.week-strip {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.week-day {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 2px;
    border-radius: 8px;
    background: rgba(47, 79, 47, 0.08);
    font-size: 10px;
    line-height: 1.2;
}

.week-day strong {
    font-size: 11px;
}

.week-day.played {
    background: rgba(50, 205, 50, 0.16);
}

.week-day.today {
    outline: 2px solid #32cd32;
}

body.dark-mode .week-day {
    background: rgba(255, 255, 255, 0.08);
}

body.dark-mode .week-day.played {
    background: rgba(50, 205, 50, 0.18);
}

.mode-button {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin: 0;
    padding: 12px;
    color: #2f4f2f;
    background: rgba(47, 79, 47, 0.08);
    border: 2px solid transparent;
}

.mode-button span {
    font-size: 11px;
    line-height: 1.3;
}

.mode-button:hover,
.mode-button.selected {
    color: #2f4f2f;
    background: rgba(50, 205, 50, 0.16);
    border-color: #32cd32;
}

body.dark-mode .mode-button {
    color: #e6e6e6;
    background: rgba(255, 255, 255, 0.08);
}

body.dark-mode .mode-button:hover,
body.dark-mode .mode-button.selected {
    color: #e6e6e6;
    background: rgba(50, 205, 50, 0.18);
}

.ghost-toggle {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
    margin: 0 0 12px;
    padding: 12px;
    color: #2f4f2f;
    background: rgba(47, 79, 47, 0.08);
    border: 2px solid transparent;
}

.ghost-toggle span {
    font-size: 11px;
    line-height: 1.3;
    font-weight: 400;
}

.ghost-toggle:hover,
.ghost-toggle[aria-pressed="true"] {
    color: #2f4f2f;
    background: rgba(50, 205, 50, 0.16);
    border-color: #32cd32;
}

body.dark-mode .ghost-toggle {
    color: #e6e6e6;
    background: rgba(255, 255, 255, 0.08);
}

body.dark-mode .ghost-toggle:hover,
body.dark-mode .ghost-toggle[aria-pressed="true"] {
    color: #e6e6e6;
    background: rgba(50, 205, 50, 0.18);
}

.start-button {
    margin-top: 0;
}

button {
    background: #32cd32;
    color: white;
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    border-radius: 8px;
    cursor: pointer;
    margin: 10px;
    transition: background 0.3s ease;
}

button:hover {
    background: #228b22;
}

button:active {
    transform: scale(0.95);
}

.pause-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    font-size: 24px;
    display: none;
}

.pause-hint {
    font-size: 15px;
    margin-top: 10px;
    opacity: 0.85;
}

/* Control hints follow the input the device actually has */

.controls-touch {
    display: none;
}

@media (pointer: coarse) {
    .controls-keys {
        display: none;
    }

    .controls-touch {
        display: block;
    }
}

@media (max-width: 768px) {
    .game-container {
        gap: 8px;
        padding:
            max(8px, env(safe-area-inset-top))
            max(8px, env(safe-area-inset-right))
            max(8px, env(safe-area-inset-bottom))
            max(8px, env(safe-area-inset-left));
    }

    .home-link {
        font-size: 0;
        padding: 0 12px;
        min-height: 38px;
    }

    .home-link::before {
        content: "←";
        font-size: 18px;
    }

    .stat-bar {
        flex-wrap: nowrap;
        gap: 4px;
    }

    .stat {
        flex: 1 1 0;
        min-width: 0;
        padding: 4px 2px;
    }

    .stat-extra {
        display: none;
    }

    .stat-value {
        font-size: 16px;
    }

    .stat-wide .stat-value {
        font-size: 12px;
    }

    .stat-label {
        font-size: 9px;
    }

    #gameCanvas {
        border-width: 2px;
    }

    .start-screen,
    .game-over-screen {
        padding: 18px;
        width: calc(100vw - 20px);
        max-width: 36rem;
        max-height: calc(100dvh - 20px);
    }

    .mode-picker {
        grid-template-columns: 1fr;
        gap: 6px;
        margin: 12px 0;
    }

    .mode-button {
        min-height: 0;
        padding: 9px 12px;
    }

    .ghost-toggle {
        padding: 9px 12px;
        min-height: 0;
    }

    .start-screen h1 {
        font-size: 24px;
    }

    .start-screen .goose-emoji {
        font-size: 32px;
    }

    .daily-note {
        font-size: 12px;
    }

    button {
        padding: 14px 22px;
        font-size: 17px;
        min-height: 48px;
    }

    .controls {
        font-size: 13px;
        margin: 12px 0;
    }

    .settings-menu {
        top: max(60px, calc(env(safe-area-inset-top) + 52px));
        right: max(10px, env(safe-area-inset-right));
        max-width: calc(100vw - 20px);
    }
}

@media (max-width: 380px) {
    .game-title {
        font-size: 0;
    }

    .game-title::before {
        content: "🪿";
        font-size: 20px;
    }
}

@media (max-height: 620px) and (orientation: landscape) {
    .game-container {
        display: grid;
        grid-template-columns: auto 1fr;
        grid-template-rows: auto 1fr;
        gap: 6px 10px;
        padding: 6px max(6px, env(safe-area-inset-right)) 6px
            max(6px, env(safe-area-inset-left));
    }

    .game-header {
        grid-column: 1 / -1;
    }

    .stat-bar {
        flex-direction: column;
        flex-wrap: nowrap;
        justify-content: center;
        width: 84px;
    }

    .stat {
        flex: 0 0 auto;
        width: 100%;
        padding: 3px 4px;
    }

    .stat-value {
        font-size: 14px;
    }

    .start-screen,
    .game-over-screen {
        width: min(560px, calc(100vw - 20px));
        padding: 12px 18px;
    }

    .start-screen .goose-emoji,
    .daily-note {
        display: none;
    }

    .mode-picker {
        grid-template-columns: repeat(3, 1fr);
    }
}

.settings-toggle {
    background: transparent;
    border: 2px solid #2f4f2f;
    color: #2f4f2f;
    padding: 12px;
    font-size: 20px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 1001;
    min-height: 48px;
    min-width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-toggle:hover {
    background: #2f4f2f;
    color: white;
    transform: scale(1.1) rotate(90deg);
}

body.dark-mode .settings-toggle {
    border-color: #e6e6e6;
    color: #e6e6e6;
}

body.dark-mode .settings-toggle:hover {
    background: #e6e6e6;
    color: #1a1a2e;
}

.settings-menu {
    position: fixed;
    top: 80px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #2f4f2f;
    border-radius: 12px;
    padding: 20px;
    min-width: 200px;
    z-index: 1000;
    display: none;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

body.dark-mode .settings-menu {
    background: rgba(30, 30, 50, 0.95);
    border-color: #e6e6e6;
    color: #e6e6e6;
}

.settings-menu h3 {
    margin: 0 0 15px 0;
    font-size: 18px;
    text-align: center;
    border-bottom: 1px solid #ccc;
    padding-bottom: 10px;
}

body.dark-mode .settings-menu h3 {
    border-bottom-color: #666;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-label {
    font-size: 16px;
    font-weight: 500;
}

.setting-button {
    background: #32cd32;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    min-width: 80px;
    transition: all 0.2s ease;
}

.setting-button:hover {
    background: #228b22;
    transform: scale(1.05);
}

.setting-button:active {
    transform: scale(0.95);
}

@media (max-width: 768px) {
    .settings-toggle {
        min-height: 44px;
        min-width: 44px;
        font-size: 19px;
    }

    .settings-menu {
        top: max(64px, env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
        min-width: 180px;
    }
}
