/* ============================================
   Anatomy Blaster - Medical Edition
   Responsive Styles - Mobile Optimizations
   Mobile, tablet, and desktop overrides,
   orientation handling, and touch optimization
   ============================================ */

/* ---------- Small Mobile (< 360px) ---------- */
@media (max-width: 360px) {
    .hud {
        padding: 4px 6px;
    }

    .hud-left, .hud-right, .hud-center {
        padding: 4px 8px;
        gap: 2px;
    }

    .hud-value {
        font-size: 12px;
    }

    .hud-value.combo {
        font-size: 15px;
    }

    .hud-label {
        font-size: 6px;
        letter-spacing: 1px;
    }

    .health-bar-container {
        width: 60px;
        height: 6px;
    }

    .xp-bar-container {
        max-width: 120px;
        height: 4px;
    }

    .typing-display {
        font-size: 14px;
        padding: 8px 12px;
        min-height: 40px;
        letter-spacing: 2px;
    }

    .input-area {
        padding: 4px 6px 8px;
    }

    .game-title {
        font-size: 24px;
    }

    .game-subtitle {
        font-size: 9px;
        letter-spacing: 3px;
        margin-bottom: 20px;
    }

    .menu-btn {
        font-size: 11px;
        padding: 10px 24px;
        min-width: 160px;
        margin: 4px;
    }

    .diff-btn {
        font-size: 9px;
        padding: 6px 10px;
    }

    .powerup-indicators {
        top: 40px;
        gap: 4px;
    }

    .powerup-indicator {
        width: 28px;
        height: 28px;
        border-width: 1px;
    }

    .powerup-indicator .icon-sm {
        width: 12px;
        height: 12px;
    }

    .powerup-timer {
        width: 22px;
        height: 3px;
        bottom: -3px;
    }

    .keyboard-btn {
        width: 42px;
        height: 42px;
        bottom: 60px;
        right: 8px;
    }

    .pause-btn {
        width: 34px;
        height: 34px;
        right: 46px;
    }

    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
        gap: 6px;
    }

    .level-cell .level-number {
        font-size: 13px;
    }

    .level-cell .level-stars-mini {
        gap: 1px;
    }

    .level-cell .level-stars-mini .mini-star {
        width: 6px;
        height: 6px;
    }

    .stat-card .stat-value {
        font-size: 18px;
    }

    .stat-card .stat-label {
        font-size: 8px;
    }

    .stats-grid {
        gap: var(--space-sm);
    }

    .stat-card {
        padding: 8px;
    }

    .screen-title {
        font-size: 18px;
        margin-bottom: var(--space-lg);
    }

    .leaderboard {
        max-height: 30vh;
    }

    .lb-rank {
        font-size: 12px;
        width: 24px;
    }

    .lb-score {
        font-size: 13px;
    }

    .lb-details {
        font-size: 9px;
    }

    .settings-panel {
        padding: var(--space-sm);
    }

    .setting-row {
        padding: 8px 0;
    }

    .setting-label {
        font-size: 12px;
    }

    .toggle-switch {
        width: 42px;
        height: 22px;
    }

    .toggle-switch::after {
        width: 18px;
        height: 18px;
    }

    .toggle-switch.active::after {
        left: 20px;
    }

    .wave-banner {
        font-size: 20px;
    }

    .float-text {
        font-size: 14px;
    }

    .achievement-popup {
        padding: 8px 16px;
        top: 50px;
    }

    .achievement-popup .achieve-title {
        font-size: 9px;
    }

    .achievement-popup .achieve-name {
        font-size: 12px;
    }

    .modal-container {
        max-width: 95vw;
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-title {
        font-size: 18px;
    }

    .modal-close-btn {
        width: 36px;
        height: 36px;
    }

    .modal-content {
        padding: 14px;
    }

    .htp-section {
        padding: 12px;
    }

    .htp-heading {
        font-size: 15px;
    }

    .htp-text {
        font-size: 13px;
    }
}

/* ---------- Mobile (< 480px) ---------- */
@media (max-width: 480px) {
    .hud {
        padding: 6px 8px;
    }

    .hud-left, .hud-right, .hud-center {
        padding: 6px 10px;
        gap: 3px;
    }

    .hud-value {
        font-size: 14px;
    }

    .hud-value.combo {
        font-size: 18px;
    }

    .hud-label {
        font-size: 7px;
    }

    .health-bar-container {
        width: 80px;
        height: 8px;
    }

    .xp-bar-container {
        max-width: 140px;
        height: 5px;
    }

    .typing-display {
        font-size: 16px;
        padding: 10px 14px;
        min-height: 44px;
    }

    .powerup-indicators {
        top: 50px;
        gap: 6px;
    }

    .powerup-indicator {
        width: 30px;
        height: 30px;
    }

    .powerup-indicator .icon-sm {
        width: 14px;
        height: 14px;
    }

    .settings-panel {
        padding: var(--space-md);
    }

    .setting-label {
        font-size: 13px;
    }

    .screen-overlay {
        padding: var(--space-md);
    }

    .leaderboard {
        max-height: 35vh;
    }

    .lb-score {
        font-size: 14px;
    }

    .lb-details {
        font-size: 10px;
    }

    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
        max-height: 45vh;
    }

    .level-cell {
        min-height: 52px;
    }

    .level-cell .level-number {
        font-size: 14px;
    }

    .stat-card {
        padding: 10px;
    }

    .stat-card .stat-value {
        font-size: 20px;
    }

    .stat-card .stat-label {
        font-size: 9px;
    }

    .menu-btn {
        font-size: 12px;
        padding: 12px 28px;
        min-width: 180px;
        margin: 5px;
    }

    .diff-btn {
        font-size: 10px;
        padding: 7px 12px;
    }

    .difficulty-selector {
        gap: 6px;
    }

    .game-subtitle {
        margin-bottom: 24px;
    }

    .wave-banner {
        font-size: 24px;
    }

    .modal-container {
        max-width: 92vw;
    }

    .modal-header {
        padding: 16px 18px;
    }

    .modal-title {
        font-size: 20px;
    }

    .modal-close-btn {
        width: 38px;
        height: 38px;
    }

    .modal-content {
        padding: 16px;
    }

    .htp-section {
        padding: 14px;
    }

    .htp-heading {
        font-size: 16px;
    }

    .htp-text {
        font-size: 14px;
    }

    .htp-example {
        padding: 10px 14px;
    }

    .htp-example-challenge,
    .htp-example-answer {
        font-size: 14px;
    }
}

/* ---------- Short Screens (landscape mobile) ---------- */
@media (max-height: 500px) {
    .hud {
        padding: 3px 6px;
    }

    .hud-left, .hud-right, .hud-center {
        padding: 4px 8px;
        gap: 2px;
    }

    .hud-value {
        font-size: 12px;
    }

    .hud-value.combo {
        font-size: 14px;
    }

    .hud-label {
        font-size: 6px;
    }

    .health-bar-container {
        width: 70px;
        height: 6px;
    }

    .xp-bar-container {
        max-width: 120px;
        height: 4px;
    }

    .input-area {
        padding: 3px 6px 6px;
    }

    .typing-display {
        min-height: 38px;
        padding: 8px 12px;
        font-size: 14px;
    }

    .powerup-indicators {
        top: 35px;
        gap: 4px;
    }

    .powerup-indicator {
        width: 26px;
        height: 26px;
    }

    .screen-overlay {
        padding: var(--space-sm);
        padding-top: 40px;
        padding-bottom: 60px;
    }

    .game-title {
        font-size: 22px;
        margin-bottom: 2px;
    }

    .game-subtitle {
        font-size: 9px;
        margin-bottom: 12px;
    }

    .menu-btn {
        padding: 8px 24px;
        margin: 3px;
        font-size: 11px;
        min-width: 160px;
    }

    .difficulty-selector {
        margin: 8px 0;
        gap: 4px;
    }

    .diff-btn {
        padding: 5px 10px;
        font-size: 9px;
    }

    .stats-grid {
        margin: 10px 0;
        gap: var(--space-sm);
    }

    .stat-card {
        padding: var(--space-sm);
    }

    .stat-card .stat-value {
        font-size: 16px;
    }

    .stat-card .stat-label {
        font-size: 8px;
    }

    .wave-banner {
        font-size: 22px;
    }

    .keyboard-btn {
        bottom: 55px;
        width: 44px;
        height: 44px;
    }

    .pause-btn {
        width: 36px;
        height: 36px;
    }

    .level-grid {
        max-height: 35vh;
        gap: 6px;
    }

    .level-cell {
        min-height: 46px;
    }

    .leaderboard {
        max-height: 30vh;
    }

    .settings-panel {
        max-height: 45vh;
        padding: var(--space-md);
    }

    .setting-row {
        padding: 8px 0;
    }

    .screen-title {
        font-size: 20px;
        margin-bottom: var(--space-md);
    }

    .modal-container {
        max-height: 88vh;
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-title {
        font-size: 18px;
    }

    .modal-content {
        padding: 14px;
    }

    .htp-section {
        padding: 12px;
        margin-bottom: var(--space-md);
    }

    .htp-heading {
        font-size: 15px;
        margin-bottom: 8px;
    }

    .htp-text {
        font-size: 13px;
        line-height: 1.5;
        margin-bottom: 8px;
    }

    .htp-example {
        padding: 8px 12px;
        margin: 8px 0;
    }
}

@media (max-height: 600px) {
    .hud {
        padding: 4px 8px;
    }

    .hud-left, .hud-right, .hud-center {
        padding: 5px 9px;
    }

    .input-area {
        padding: 4px 8px 8px;
    }

    .typing-display {
        min-height: 42px;
    }

    .screen-overlay {
        padding-top: 50px;
        padding-bottom: 70px;
    }

    .powerup-indicators {
        top: 45px;
    }
}

/* ---------- Tablet (481px - 768px) ---------- */
@media (min-width: 481px) and (max-width: 768px) {
    .hud {
        padding: 8px 12px;
    }

    .hud-left, .hud-right, .hud-center {
        padding: 8px 14px;
    }

    .hud-value {
        font-size: 16px;
    }

    .hud-value.combo {
        font-size: 20px;
    }

    .health-bar-container {
        width: 100px;
        height: 9px;
    }

    .xp-bar-container {
        max-width: 160px;
    }

    .typing-display {
        font-size: 18px;
        max-width: 500px;
        margin: 0 auto;
    }

    .powerup-indicator {
        width: 34px;
        height: 34px;
    }

    .powerup-indicator .icon-sm {
        width: 15px;
        height: 15px;
    }

    .level-grid {
        grid-template-columns: repeat(auto-fill, minmax(65px, 1fr));
        max-width: 450px;
        gap: 8px;
    }

    .level-cell {
        min-height: 65px;
    }

    .level-cell .level-number {
        font-size: 16px;
    }

    .stats-grid {
        width: min(80%, 380px);
    }

    .stat-card {
        padding: 12px;
    }

    .stat-card .stat-value {
        font-size: 24px;
    }

    .stat-card .stat-label {
        font-size: 10px;
    }

    .menu-btn {
        min-width: 220px;
        font-size: 14px;
        padding: 14px 32px;
    }

    .diff-btn {
        font-size: 11px;
        padding: 8px 14px;
    }

    .settings-panel {
        width: min(80%, 380px);
        padding: var(--space-lg);
    }

    .setting-label {
        font-size: 14px;
    }

    .leaderboard {
        max-height: 42vh;
    }

    .lb-score {
        font-size: 16px;
    }

    .lb-details {
        font-size: 11px;
    }

    .screen-title {
        font-size: 28px;
    }

    .game-title {
        font-size: 42px;
    }

    .wave-banner {
        font-size: 36px;
    }

    .modal-container {
        max-width: 650px;
    }

    .modal-header {
        padding: 20px 24px;
    }

    .modal-title {
        font-size: 24px;
    }

    .modal-content {
        padding: 24px;
    }

    .htp-section {
        padding: 18px;
    }

    .htp-heading {
        font-size: 19px;
    }

    .htp-text {
        font-size: 15px;
    }
}

/* ---------- Desktop (769px+) ---------- */
@media (min-width: 769px) {
    .keyboard-btn {
        display: none !important;
    }

    .game-keyboard {
        display: none !important;
    }

    .hud {
        padding: var(--space-sm) var(--space-lg);
    }

    .hud-left, .hud-right, .hud-center {
        padding: var(--space-sm) var(--space-md);
    }

    .hud-value {
        font-size: 20px;
    }

    .hud-value.combo {
        font-size: 24px;
    }

    .hud-label {
        font-size: 10px;
    }

    .health-bar-container {
        width: 150px;
        height: 12px;
    }

    .xp-bar-container {
        max-width: 200px;
        height: 6px;
    }

    .typing-display {
        font-size: 22px;
        max-width: 600px;
        margin: 0 auto;
        padding: 14px 20px;
        min-height: 56px;
    }

    .input-area {
        padding: var(--space-md) var(--space-xl) var(--space-lg);
    }

    .input-area.keyboard-open,
    .input-area.gk-active {
        bottom: 0 !important;
    }

    .level-grid {
        grid-template-columns: repeat(10, 1fr);
        max-width: 600px;
        gap: 10px;
    }

    .level-cell {
        min-height: auto;
    }

    .level-cell .level-number {
        font-size: 18px;
    }

    .powerup-indicator {
        width: 40px;
        height: 40px;
    }

    .powerup-indicator .icon-sm {
        width: 16px;
        height: 16px;
    }

    .powerup-timer {
        width: 32px;
        height: 4px;
    }

    .menu-btn {
        min-width: 240px;
        font-size: 16px;
        padding: 16px 40px;
    }

    .menu-btn:hover {
        transform: translateY(-2px);
    }

    .diff-btn {
        font-size: 12px;
        padding: 10px 18px;
    }

    .stats-grid {
        width: min(70%, 400px);
        gap: var(--space-lg);
    }

    .stat-card {
        padding: var(--space-lg);
    }

    .stat-card .stat-value {
        font-size: 26px;
    }

    .stat-card .stat-label {
        font-size: 11px;
    }

    .settings-panel {
        width: min(70%, 450px);
        padding: var(--space-xl);
    }

    .setting-row {
        padding: var(--space-lg) 0;
    }

    .setting-label {
        font-size: 15px;
    }

    .toggle-switch {
        width: 48px;
        height: 26px;
    }

    .toggle-switch::after {
        width: 22px;
        height: 22px;
    }

    .toggle-switch.active::after {
        left: 24px;
    }

    .leaderboard {
        max-height: 45vh;
    }

    .lb-rank {
        font-size: 15px;
        width: 32px;
    }

    .lb-score {
        font-size: 17px;
    }

    .lb-details {
        font-size: 12px;
    }

    .wave-banner {
        font-size: 48px;
    }

    .float-text {
        font-size: 18px;
    }

    .achievement-popup {
        padding: 14px 28px;
        top: 70px;
    }

    .achievement-popup .achieve-title {
        font-size: 11px;
    }

    .achievement-popup .achieve-name {
        font-size: 16px;
    }

    .pause-btn {
        width: 44px;
        height: 44px;
        right: 50px;
    }

    .screen-title {
        font-size: 36px;
    }

    .game-title {
        font-size: 56px;
    }

    .game-subtitle {
        font-size: 14px;
        margin-bottom: 32px;
    }

    .modal-container {
        max-width: 700px;
    }

    .modal-header {
        padding: 24px 28px;
    }

    .modal-title {
        font-size: 28px;
    }

    .modal-close-btn {
        width: 44px;
        height: 44px;
    }

    .modal-content {
        padding: 28px;
    }

    .htp-section {
        padding: 20px;
    }

    .htp-heading {
        font-size: 20px;
    }

    .htp-text {
        font-size: 16px;
    }

    .htp-example {
        padding: 12px 16px;
    }

    .htp-example-challenge,
    .htp-example-answer {
        font-size: 15px;
    }
}

/* ---------- Large Desktop (1200px+) ---------- */
@media (min-width: 1200px) {
    .typing-display {
        max-width: 700px;
        font-size: 24px;
        padding: 16px 24px;
        min-height: 60px;
    }

    .hud {
        padding: var(--space-md) var(--space-xl);
    }

    .hud-left, .hud-right, .hud-center {
        padding: var(--space-md) var(--space-lg);
    }

    .hud-value {
        font-size: 22px;
    }

    .hud-value.combo {
        font-size: 26px;
    }

    .hud-label {
        font-size: 11px;
    }

    .health-bar-container {
        width: 180px;
        height: 14px;
    }

    .xp-bar-container {
        max-width: 220px;
        height: 7px;
    }

    .powerup-indicator {
        width: 44px;
        height: 44px;
    }

    .powerup-indicator .icon-sm {
        width: 18px;
        height: 18px;
    }

    .wave-banner {
        font-size: 52px;
    }

    .menu-btn {
        min-width: 260px;
        font-size: 17px;
        padding: 18px 44px;
    }

    .stats-grid {
        width: min(65%, 450px);
    }

    .settings-panel {
        width: min(65%, 500px);
    }

    .game-title {
        font-size: 60px;
    }

    .screen-title {
        font-size: 40px;
    }
}

/* ---------- Touch Device Optimizations ---------- */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .menu-btn {
        padding: 16px 36px;
        min-height: 48px;
    }

    .diff-btn {
        padding: 10px 16px;
        min-height: 40px;
    }

    .toggle-switch {
        width: 50px;
        height: 28px;
    }

    .toggle-switch::after {
        width: 24px;
        height: 24px;
    }

    .toggle-switch.active::after {
        left: 24px;
    }

    .pause-btn {
        width: 44px;
        height: 44px;
    }

    .level-cell {
        min-height: 52px;
    }

    .reset-btn {
        padding: var(--space-sm) var(--space-xl);
        min-height: 40px;
    }

    .ad-close-btn {
        width: 40px;
        height: 40px;
    }

    .modal-close-btn {
        width: 42px;
        height: 42px;
    }

    .keyboard-btn {
        width: 50px;
        height: 50px;
    }

    /* Remove hover effects on touch devices */
    .menu-btn:hover::before {
        left: -100%;
    }

    .menu-btn:hover {
        transform: none;
    }

    .menu-btn:active {
        transform: translateY(1px);
    }

    .level-cell:hover:not(.locked) {
        transform: none;
    }

    .level-cell:active:not(.locked) {
        transform: scale(0.95);
    }

    .diff-btn:hover {
        border-color: var(--border-stone);
        color: var(--text-secondary);
    }

    .toggle-switch:hover {
        opacity: 1;
    }

    .stat-card:hover {
        border-color: var(--border-stone);
        box-shadow: 
            inset 2px 2px 4px rgba(0, 0, 0, 0.5),
            inset -2px -2px 4px rgba(255, 255, 255, 0.08),
            0 3px 8px rgba(0, 0, 0, 0.4);
    }

    .htp-section:hover {
        background: linear-gradient(135deg, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.1));
        border-left-color: var(--gold-dark);
        box-shadow: none;
        transform: none;
    }
}

/* ---------- Orientation: Landscape on Mobile ---------- */
@media (max-height: 420px) and (orientation: landscape) {
    .screen-overlay {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-items: center;
        gap: var(--space-sm);
        padding: var(--space-sm) var(--space-lg);
    }

    .game-title {
        font-size: 20px;
        width: 100%;
        margin-bottom: 0;
    }

    .game-subtitle {
        width: 100%;
        margin-bottom: var(--space-sm);
    }

    .difficulty-selector {
        margin: var(--space-sm) 0;
        width: 100%;
        justify-content: center;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
        width: min(90%, 500px);
        margin: var(--space-sm) 0;
    }

    .menu-btn {
        padding: 8px 20px;
        min-width: 150px;
        font-size: 10px;
    }

    .level-grid {
        max-height: 50vh;
    }

    .leaderboard {
        max-height: 45vh;
    }

    .settings-panel {
        max-height: 50vh;
    }

    .modal-container {
        max-height: 92vh;
    }

    .hud {
        padding: 3px 8px;
    }

    .hud-left, .hud-right, .hud-center {
        padding: 3px 6px;
    }

    .typing-display {
        font-size: 14px;
        min-height: 36px;
        padding: 6px 10px;
    }

    .input-area {
        padding: 2px 6px 6px;
    }

    .powerup-indicators {
        top: 32px;
    }

    .powerup-indicator {
        width: 24px;
        height: 24px;
    }
}

/* ---------- High DPI / Retina ---------- */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .star {
        transform: scale(0.8);
    }

    .icon {
        filter: drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.7));
    }
}

/* ---------- Print (unlikely but good practice) ---------- */
@media print {
    body {
        background: #fff;
        color: #000;
    }

    .stars-container,
    .screen-overlay,
    .hud,
    .input-area,
    .pause-btn,
    .keyboard-btn,
    .ad-overlay,
    .modal-overlay,
    .game-keyboard {
        display: none !important;
    }

    #gameCanvas {
        border: 1px solid #000;
    }
}

/* ---------- Reduced Motion Accessibility ---------- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .star {
        animation: none !important;
        opacity: 0.3;
    }

    .shake,
    .shake-light {
        animation: none !important;
    }

    .pulse,
    .pulse-glow {
        animation: none !important;
    }

    .shimmer {
        animation: none !important;
        background: var(--gold);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    .menu-btn::before {
        display: none;
    }

    .loading-bar::after {
        display: none;
    }

    .notification-dot {
        animation: none !important;
    }
}

/* ---------- High Contrast Mode ---------- */
@media (prefers-contrast: high) {
    .hud-left, .hud-right, .hud-center {
        border: 2px solid var(--gold);
    }

    .menu-btn {
        border-width: 3px;
    }

    .typing-display {
        border-width: 3px;
    }

    .level-cell {
        border-width: 3px;
    }

    .stat-card {
        border-width: 2px;
    }
}