
@media (hover: none) {
    .check-btn:hover,
    .secondary-btn:hover,
    .volley-btn:hover,
    .keypad button:hover,
    .start-btn:hover {
        filter: none;
        transform: none;
    }
}

@media (max-width: 640px) {
    html,
    body {
        overscroll-behavior: none;
    }

    body {
        align-items: stretch;
        justify-content: flex-start;
        overflow: hidden;
        padding: 0;
    }

    .game-shell {
        border: 0;
        border-radius: 0;
        box-shadow: none;
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
        height: 100vh;
        height: 100svh;
        max-width: none;
        min-height: 0;
        overflow: hidden;
        width: 100vw;
    }

    @supports (height: 100dvh) {
        .game-shell {
            height: 100dvh;
        }
    }

    .play-section {
        min-height: 0;
        overflow: hidden;
    }

    .hud-bar {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
        padding: max(8px, env(safe-area-inset-top)) 10px 8px;
    }

    .hud-bar .badge {
        display: none;
    }

    .title-row {
        display: grid;
        gap: 5px;
        grid-template-columns: auto minmax(100px, 1fr) auto;
        margin-top: 0;
    }

    h1 {
        font-size: clamp(19px, 5.5vw, 23px);
        margin: 0;
        white-space: nowrap;
    }

    .heart-track {
        gap: 2px;
        justify-content: center;
        min-width: 0;
    }

    .heart {
        font-size: 18px;
        height: 20px;
        width: 20px;
    }

    .game-status {
        font-size: 11px;
        gap: 5px;
        justify-self: end;
        min-height: 24px;
        padding: 3px 7px;
    }

    .game-status strong {
        font-size: 12px;
    }

    .stat-strip {
        gap: 5px;
        grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
        width: 100%;
    }

    .stat {
        align-items: center;
        flex-direction: row;
        gap: 4px;
        justify-content: space-between;
        min-height: 32px;
        padding: 5px 7px;
    }

    .stat span {
        font-size: 10px;
    }

    .stat strong,
    .rank-stat strong {
        font-size: 17px;
    }

    .field {
        --archer-bottom: 46px;
        --archer-left: clamp(118px, 34vw, 150px);
        --archer-scale: 0.72;
        --farm-bottom: 28px;
        --farm-left: 0;
        --farm-scale: 0.66;
        --fence-back-bottom: 132px;
        --fence-front-bottom: 16px;
        flex: 1 1 auto;
        min-height: 230px;
    }

    .sun {
        height: 42px;
        top: 24px;
        width: 42px;
    }

    .cloud {
        transform: scale(0.72);
    }

    .cloud-b {
        display: none;
    }

    .rank-toast {
        font-size: 13px;
        max-width: calc(100% - 24px);
        padding: 8px 10px;
        top: 8px;
        white-space: nowrap;
    }

    .control-panel {
        border-left: 0;
        border-top: 1px solid var(--line);
        display: grid;
        gap: 7px;
        grid-template-columns: minmax(132px, 0.9fr) minmax(178px, 1.1fr);
        grid-template-rows: auto auto;
        overflow: hidden;
        padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    .problem-panel,
    .keypad-panel {
        padding: 8px;
    }

    .problem-panel {
        grid-column: 1;
        grid-row: 1;
        min-width: 0;
    }

    .keypad-panel {
        grid-column: 2;
        grid-row: 1;
        min-width: 0;
    }

    .action-panel {
        background: transparent;
        border: 0;
        box-shadow: none;
        gap: 7px;
        grid-column: 1 / -1;
        grid-row: 2;
        grid-template-columns: 1fr 1fr;
        padding: 0;
    }

    .panel-heading,
    .input-hint {
        display: none;
    }

    .problem {
        font-size: clamp(21px, 6vw, 26px);
        margin-top: 0;
        min-height: 46px;
        overflow: hidden;
        padding: 6px 4px;
        white-space: nowrap;
    }

    .answer-row {
        gap: 6px;
        grid-template-columns: minmax(54px, 1fr) 54px;
        margin-top: 7px;
    }

    #answer-input {
        font-size: 22px;
        height: 46px;
        padding: 0 6px;
    }

    .check-btn {
        min-height: 46px;
    }

    .check-btn svg {
        height: 28px;
        width: 28px;
    }

    .feedback {
        font-size: 11px;
        line-height: 1.2;
        margin-top: 7px;
        min-height: 30px;
        padding: 5px 7px;
    }

    .keypad {
        gap: 6px;
    }

    .keypad button {
        font-size: 20px;
        min-height: 42px;
        padding: 0;
        touch-action: none;
    }

    .volley-btn {
        font-size: 15px;
        gap: 1px;
        min-height: 48px;
    }

    .volley-btn small {
        font-size: 11px;
    }

    .secondary-btn {
        font-size: 15px;
        min-height: 48px;
    }

    .start-overlay {
        align-items: flex-start;
        justify-content: center;
        overflow: auto;
        padding: max(18px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
        -webkit-overflow-scrolling: touch;
    }

    .start-box {
        gap: 10px;
        grid-template-columns: 1fr;
        max-width: none;
        width: 100%;
    }

    .start-main {
        gap: 10px;
    }

    .start-box h2 {
        font-size: clamp(30px, 10vw, 42px);
    }

    .setup-card {
        gap: 8px;
        padding: 10px 12px;
    }

    .player-card input {
        min-height: 44px;
    }

    .start-btn {
        font-size: 21px;
        min-height: 56px;
    }

    .leaderboard-card {
        max-height: min(34vh, 250px);
        max-height: min(34svh, 250px);
        padding: 12px;
    }

    .leaderboard-heading {
        margin-bottom: 8px;
    }

    .leaderboard-heading span {
        font-size: 20px;
    }

    .leaderboard-row,
    .empty-rank {
        font-size: 13px;
        min-height: 32px;
        padding: 6px 8px;
    }

    .game-modal {
        padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
    }

    .modal-box {
        max-height: calc(100dvh - 24px);
        padding: 18px;
    }
}

@media (max-width: 640px) and (max-height: 700px) {
    .hud-bar {
        gap: 5px;
        padding: max(6px, env(safe-area-inset-top)) 8px 6px;
    }

    .title-row {
        gap: 4px;
        grid-template-columns: auto minmax(86px, 1fr) auto;
    }

    h1 {
        font-size: 18px;
    }

    .heart {
        font-size: 16px;
        height: 18px;
        width: 18px;
    }

    .game-status {
        font-size: 10px;
        min-height: 22px;
        padding: 3px 6px;
    }

    .game-status strong {
        font-size: 11px;
    }

    .stat-strip {
        gap: 4px;
        grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
    }

    .stat {
        min-height: 28px;
        padding: 4px 6px;
    }

    .stat strong,
    .rank-stat strong {
        font-size: 15px;
    }

    .field {
        --archer-bottom: 36px;
        --archer-left: clamp(108px, 33vw, 134px);
        --archer-scale: 0.64;
        --farm-bottom: 20px;
        --farm-scale: 0.58;
        --fence-back-bottom: 112px;
        --fence-front-bottom: 10px;
        min-height: 200px;
    }

    .control-panel {
        gap: 5px;
        grid-template-columns: minmax(118px, 0.86fr) minmax(168px, 1.14fr);
        padding: 6px max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    }

    .problem-panel,
    .keypad-panel {
        padding: 7px;
    }

    .problem {
        font-size: 20px;
        min-height: 40px;
    }

    .answer-row {
        grid-template-columns: minmax(50px, 1fr) 48px;
        margin-top: 5px;
    }

    #answer-input,
    .check-btn {
        height: 40px;
        min-height: 40px;
    }

    #answer-input {
        font-size: 20px;
    }

    .check-btn svg {
        height: 24px;
        width: 24px;
    }

    .feedback {
        display: none;
    }

    .keypad {
        gap: 5px;
    }

    .keypad button {
        font-size: 18px;
        min-height: 36px;
    }

    .action-panel {
        gap: 5px;
    }

    .volley-btn,
    .secondary-btn {
        font-size: 14px;
        min-height: 42px;
    }

    .volley-btn small {
        font-size: 10px;
    }
}

@media (max-width: 380px) {
    .title-row {
        grid-template-columns: auto minmax(72px, 1fr) auto;
    }

    h1 {
        font-size: 17px;
    }

    .heart {
        font-size: 15px;
        height: 17px;
        width: 17px;
    }

    .game-status {
        gap: 4px;
        padding-left: 5px;
        padding-right: 5px;
    }

    .field {
        --archer-left: 104px;
        --farm-scale: 0.55;
        min-height: 190px;
    }

    .control-panel {
        grid-template-columns: minmax(110px, 0.82fr) minmax(162px, 1.18fr);
    }

    .problem {
        font-size: 18px;
        min-height: 38px;
    }

    .answer-row {
        grid-template-columns: minmax(46px, 1fr) 44px;
    }

    #answer-input,
    .check-btn {
        height: 38px;
        min-height: 38px;
    }
}

@media (max-height: 520px) and (orientation: landscape) {
    body {
        align-items: stretch;
        overflow: hidden;
        padding: 0;
    }

    .game-shell {
        border: 0;
        border-radius: 0;
        box-shadow: none;
        grid-template-columns: minmax(0, 1fr) minmax(260px, 34vw);
        height: 100vh;
        height: 100svh;
        max-width: none;
        min-height: 0;
        overflow: hidden;
        width: 100vw;
    }

    @supports (height: 100dvh) {
        .game-shell {
            height: 100dvh;
        }
    }

    .hud-bar {
        align-items: center;
        flex-direction: row;
        gap: 8px;
        min-height: 48px;
        padding: max(6px, env(safe-area-inset-top)) 8px 6px max(8px, env(safe-area-inset-left));
    }

    .hud-bar .badge {
        display: none;
    }

    .brand-lockup {
        min-width: 230px;
    }

    .title-row {
        gap: 7px;
        margin-top: 0;
    }

    h1 {
        font-size: 19px;
        margin: 0;
    }

    .heart {
        font-size: 17px;
        height: 19px;
        width: 19px;
    }

    .game-status {
        font-size: 10px;
        min-height: 22px;
        padding: 3px 6px;
    }

    .game-status strong {
        font-size: 11px;
    }

    .stat-strip {
        gap: 5px;
        grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
        min-width: 180px;
    }

    .stat {
        min-height: 32px;
        padding: 4px 6px;
    }

    .stat span {
        font-size: 10px;
    }

    .stat strong,
    .rank-stat strong {
        font-size: 16px;
    }

    .field {
        --archer-bottom: 34px;
        --archer-left: clamp(112px, 22vw, 166px);
        --archer-scale: 0.62;
        --farm-bottom: 18px;
        --farm-left: 0;
        --farm-scale: 0.56;
        --fence-back-bottom: 108px;
        --fence-front-bottom: 10px;
    }

    .control-panel {
        border-left: 1px solid var(--line);
        border-top: 0;
        gap: 6px;
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
        overflow: hidden;
        padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) 6px;
    }

    .problem-panel,
    .keypad-panel {
        padding: 7px;
    }

    .action-panel {
        background: transparent;
        border: 0;
        box-shadow: none;
        gap: 6px;
        grid-template-columns: 1fr 1fr;
        padding: 0;
    }

    .panel-heading,
    .input-hint,
    .feedback {
        display: none;
    }

    .problem {
        font-size: 24px;
        margin-top: 0;
        min-height: 40px;
    }

    .answer-row {
        gap: 6px;
        grid-template-columns: minmax(62px, 1fr) 52px;
        margin-top: 6px;
    }

    #answer-input,
    .check-btn {
        height: 40px;
        min-height: 40px;
    }

    #answer-input {
        font-size: 21px;
    }

    .check-btn svg {
        height: 24px;
        width: 24px;
    }

    .keypad {
        gap: 5px;
    }

    .keypad button {
        font-size: 18px;
        min-height: 32px;
        padding: 0;
    }

    .volley-btn,
    .secondary-btn {
        font-size: 13px;
        min-height: 38px;
    }

    .volley-btn small {
        font-size: 10px;
    }

    .start-overlay {
        align-items: flex-start;
        overflow: auto;
        padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    }

    .start-box {
        grid-template-columns: minmax(240px, 1fr) minmax(220px, 0.9fr);
        max-width: 720px;
    }

    .start-box h2 {
        font-size: 30px;
    }

    .leaderboard-card {
        max-height: calc(100svh - 32px);
    }
}
