/* --- Compact, short landscape layouts --- */
@media (max-height: 500px) {
    :root {
        --control-top: max(6px, env(safe-area-inset-top, 0px));
        --control-clearance: calc(var(--control-top) + 54px);
        --tw-key-size: 44px;
    }

    .utility-controls {
        gap: 6px;
    }

    .utility-btn {
        padding: 8px 10px;
        font-size: 0.75rem;
    }

    .match-ui {
        top: calc(var(--control-clearance) + 2px);
    }

    .toy-instruction {
        font-size: 0.6875rem;
        letter-spacing: 0.1em;
    }

    .glass-panel {
        padding: 1rem 1.5rem;
        border-radius: 16px;
    }

    .start-title {
        margin-bottom: 0.25rem;
        font-size: 1.75rem;
    }

    #nav-bar {
        bottom: max(8px, env(safe-area-inset-bottom, 0px));
        gap: 4px;
        padding: 6px 8px;
    }

    .nav-btn {
        padding: 8px 10px;
    }

    #bubble-grid {
        gap: 8px;
        max-height: min(60dvh, 400px);
        padding: 12px;
    }

    #reset-bubbles {
        margin-top: 8px;
        padding: 10px 12px;
    }

    #typewriter-paper {
        height: 128px;
        min-height: 128px;
        margin-bottom: 8px;
        padding: 10px 14px;
        background-size: 100% 1.35em;
        font-size: 14px;
        line-height: 1.35;
    }

    #tw-keyboard-area {
        gap: 4px;
    }

    .key-row {
        gap: 4px;
    }

    .tw-key {
        min-width: 44px;
        min-height: 44px;
        border-width: 1px;
        box-shadow: 0 3px 0 #64748b, 0 5px 7px rgba(0, 0, 0, 0.25), inset 0 2px 3px rgba(255, 255, 255, 0.8);
        font-size: 14px;
    }

    .tw-key--space {
        width: min(150px, 42vw);
        min-width: 104px;
    }

    .tw-key--wide {
        width: 60px;
        min-width: 56px;
    }

    .tw-key.pressed {
        transform: translateY(3px);
        box-shadow: 0 0 0 #64748b, 0 2px 4px rgba(0, 0, 0, 0.3), inset 0 2px 3px rgba(255, 255, 255, 0.8);
    }
}

@media (max-width: 700px) {
    :root {
        --tw-key-size: clamp(30px, 8.7vw, 36px);
    }

    #tw-keyboard-area {
        gap: 6px;
        padding: 0;
    }

    .key-row {
        gap: 2px;
    }

    .tw-key {
        min-width: var(--tw-key-size);
        min-height: var(--tw-key-size);
    }
}

@media (max-height: 500px) and (min-width: 640px) {
    #toy-typewriter {
        flex-direction: row;
        gap: 12px;
        justify-content: center;
        overflow: hidden;
    }

    #typewriter-paper {
        flex: 0 0 30%;
        align-self: stretch;
        width: auto;
        min-width: 0;
        height: auto;
        min-height: 0;
        margin: 0;
        padding: 12px 14px;
    }

    .tw-controls {
        position: absolute;
        bottom: calc(var(--nav-pad) + 12px);
        left: 0;
        width: 30%;
        margin: 0;
    }

    #tw-keyboard-area {
        flex: 0 0 calc(70% - 12px);
        justify-content: center;
        min-width: 0;
        max-height: 100%;
        overflow-x: hidden;
        overflow-y: auto;
        padding: 0 4px 4px 0;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        --tw-key-size: 40px;
    }

    .key-row {
        gap: 3px;
    }

    .tw-key {
        min-width: 40px;
        min-height: 40px;
    }
}

@media (max-width: 360px) {
    .utility-btn {
        padding: 8px 10px;
        font-size: 0.75rem;
    }
}
