/* Weather Mood - Main Styles */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    max-width: 100vw; /* BUG-I-020 fix */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #333;
    overflow: hidden;
    overflow-x: hidden;
    height: 100vh;
    max-width: 100%;
    position: relative;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-content h1 {
    font-size: 2.5rem;
    margin: 1rem 0;
    font-weight: 300;
}

.loading-content p {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    opacity: 0.9;
}

.weather-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: float 3s ease-in-out infinite;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

/* Game Mode Selection Screen */
.game-mode-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    overflow-y: auto;
}

.mode-content {
    position: relative;
    text-align: center;
    color: white;
    max-width: 800px;
    width: 90%;
    padding: 2rem;
}

.mode-content h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    font-weight: 300;
}

.subtitle {
    font-size: 1.3rem;
    margin-bottom: 3rem;
    opacity: 0.9;
}

.game-modes {
    display: none; /* Hide mode selection since we only have progressive mode */
}

.mode-card {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 15px;
    padding: 2rem;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.mode-card:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-5px);
}

.mode-card.selected {
    background: rgba(255, 255, 255, 0.3);
    border-color: #FFD700;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
}

.mode-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.mode-card h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.mode-card p {
    margin-bottom: 1rem;
    opacity: 0.8;
}

.mode-difficulty {
    background: rgba(255, 215, 0, 0.2);
    border: 1px solid rgba(255, 215, 0, 0.4);
    border-radius: 20px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    font-weight: bold;
}

.mode-details {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    padding: 2rem;
    margin-top: 2rem;
    backdrop-filter: blur(10px);
}

.challenge-levels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.level-group {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 1rem;
    border-left: 4px solid;
}

.level-group.pleasant { border-left-color: #FFD700; }
.level-group.moderate { border-left-color: #87CEEB; }
.level-group.severe { border-left-color: #FFA500; }
.level-group.extreme { border-left-color: #FF6B6B; }
.level-group.apocalyptic { border-left-color: #DC143C; }
.level-group.endtimes { border-left-color: #8B0000; }

.level-group h2 {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.level-group p {
    font-size: 0.9rem;
    opacity: 0.8;
    margin: 0;
}

.current-level {
    background: rgba(255, 215, 0, 0.2);
    border: 2px solid rgba(255, 215, 0, 0.4);
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 2rem;
}

.current-level h3 {
    color: #FFD700;
    margin-bottom: 0.5rem;
}

.city-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.city-card {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.9rem;
}

.city-card:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: scale(1.05);
}

.city-card.selected {
    background: rgba(255, 215, 0, 0.3);
    border-color: #FFD700;
}

.city-name {
    font-weight: bold;
    margin-bottom: 0.3rem;
}

.city-weather {
    font-size: 0.8rem;
    opacity: 0.8;
}

.tier-selection {
    margin-bottom: 2rem;
}

.tier-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.8rem;
    margin: 1rem 0;
}

.tier-card {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.8rem;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.tier-card:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.tier-card.selected {
    background: rgba(255, 215, 0, 0.3);
    border-color: #FFD700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

.tier-name {
    font-weight: bold;
    margin-bottom: 0.3rem;
    font-size: 0.9rem;
}

.tier-levels {
    font-size: 0.7rem;
    opacity: 0.8;
}

.start-btn {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    border: none;
    color: #333;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.3);
}

.start-btn:hover {
    background: linear-gradient(135deg, #FFA500, #FFD700);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 215, 0, 0.4);
}

.start-btn:active {
    transform: translateY(0);
}

/* Game Container */
.game-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: transparent;
}

.game-container.hidden {
    display: none;
}

.game-mode-screen.hidden {
    display: none !important;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.weather-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
    overflow: hidden;
    min-width: 0;
}

.weather-icon-small {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.weather-text {
    font-weight: 500;
    font-size: 0.9rem;
    max-width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.location-text {
    font-size: 0.9rem;
    opacity: 0.8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 25vw;
    min-width: 0;
}

.game-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    color: white;
}

.timer-display, .lives-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.timer {
    display: block;
    font-size: 1.8rem;
    font-weight: bold;
    line-height: 1;
    color: #FFD700;
}

.timer.warning {
    color: #FF6B6B;
    animation: timerWarning 1s infinite;
    font-size: 2rem;
    text-shadow: 0 0 10px #FF6B6B;
}

.timer.critical {
    color: #FF0000;
    animation: timerCritical 0.5s infinite;
    font-size: 2.2rem;
    text-shadow: 0 0 15px #FF0000;
}

.lives {
    display: block;
    font-size: 1.5rem;
    font-weight: bold;
    line-height: 1;
    color: #FF69B4;
}

.timer-label, .lives-label {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 0.2rem;
}

.score-display {
    text-align: right;
    color: white;
}

.score {
    display: block;
    font-size: 2rem;
    font-weight: bold;
    line-height: 1;
}

.score-label {
    font-size: 0.9rem;
    opacity: 0.8;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes notificationAppear {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px) scale(0.8);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

@keyframes notificationDisappear {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px) scale(0.8);
    }
}

/* Game Board */
.game-board {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.game-canvas {
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
}

.game-canvas:active {
    cursor: grabbing;
}

.touch-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* Instructions */
.instructions {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 2rem;
    border-radius: 10px;
    text-align: center;
    max-width: 80%;
    z-index: 100;
    transition: opacity 0.3s ease;
}

.instructions p {
    margin: 0.5rem 0;
    font-size: 1.1rem;
}

.instructions.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* Game Controls */
.game-controls {
    display: flex;
    justify-content: space-around;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    gap: 0.5rem;
}

.control-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
    max-width: 120px;
    backdrop-filter: blur(5px);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}

.control-btn:active {
    transform: translateY(0);
    background: rgba(255, 255, 255, 0.4);
}

/* ─── Suite-wide HUD pattern (per Games\_shared\ui\INTERACTIONS.md) ────── */
/* Hamburger button — top-right, 32×32 desktop, 44×44 touch (handled below). */
.hud-hamburger-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 100;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(20, 24, 32, 0.55);
    color: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(8px);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
.hud-hamburger-btn:hover { background: rgba(40, 48, 64, 0.7); }
.hud-hamburger-btn:active { transform: scale(0.95); }
.hud-hamburger-btn[aria-expanded="true"] { background: rgba(60, 72, 96, 0.85); }

/* Persistent small pause icon — top-center, lets the user pause in one click
   without opening the drawer. Mirrors Space-bar. */
.hud-pause-icon {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: rgba(20, 24, 32, 0.55);
    color: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(8px);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
.hud-pause-icon:hover { background: rgba(40, 48, 64, 0.7); }
.hud-pause-icon:active { transform: translateX(-50%) scale(0.95); }

/* Drawer — slides down from top-right under the hamburger. */
.hud-drawer {
    position: absolute;
    top: 56px;
    right: 12px;
    z-index: 99;
    min-width: 180px;
    max-width: 240px;
    background: rgba(20, 24, 32, 0.85);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    transform-origin: top right;
    animation: hudDrawerOpen 0.16s ease-out;
}
.hud-drawer.hidden {
    display: none;
}
@keyframes hudDrawerOpen {
    from { opacity: 0; transform: scale(0.94) translateY(-4px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.hud-drawer-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.92);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.92rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s;
}
.hud-drawer-btn:hover  { background: rgba(255, 255, 255, 0.10); }
.hud-drawer-btn:active { background: rgba(255, 255, 255, 0.18); }

@media (max-width: 600px) {
    .hud-hamburger-btn, .hud-pause-icon { width: 44px; height: 44px; }
    .hud-pause-icon { font-size: 18px; }
    .hud-drawer { right: 8px; top: 64px; min-width: 200px; }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #eee;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0.5rem;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s ease;
}

.close-btn:hover {
    background: #f0f0f0;
}

.modal-body {
    padding: 1.5rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

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

.setting-item label {
    font-weight: 500;
    color: #333;
}

.setting-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.update-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background-color 0.2s ease;
}

.update-btn:hover {
    background: #45a049;
}

/* ============================================================================
   BUG-I-012 PR2 — Settings modal shell (C-VAL-091 approved)
   Native <dialog> element with mobile-first sizing, ≥44px touch targets,
   and prefers-reduced-motion gate. Replaces previous <div class="modal">
   approach for #settingsModal (the .modal class is still used by
   #gameOverModal; do not remove .modal rules above).
   ============================================================================ */
.settings-toggle-btn {
    position: fixed;
    top: 0.75rem;
    right: 0.75rem;
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    z-index: 5;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.settings-toggle-btn:hover,
.settings-toggle-btn:focus-visible {
    background: rgba(255, 255, 255, 0.3);
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.settings-modal {
    border: none;
    padding: 0;
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    color: #333;
}

.settings-modal::backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.settings-modal:not([open]) {
    display: none;
}

.settings-close-btn {
    min-width: 44px;
    min-height: 44px;
}

@media (prefers-reduced-motion: reduce) {
    .settings-toggle-btn {
        transition: none;
    }
}

@media (max-width: 380px) {
    .settings-modal {
        width: 96%;
        max-width: 340px;
    }

    .settings-toggle-btn {
        top: 0.5rem;
        right: 0.5rem;
    }
}

/* Animations */
.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

.fade-out {
    animation: fadeOut 0.5s ease-in-out;
}

.modal-appear {
    animation: modalAppear 0.3s ease-out;
}

.modal-disappear {
    animation: modalDisappear 0.3s ease-in;
}

.score-pop {
    animation: scorePop 0.4s ease-out;
}

/* Score animation effect */
@keyframes scorePop {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes modalDisappear {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.8);
    }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

/* Combo text animation */
.combo-text {
    animation: comboAnimation 1s ease-out forwards;
}

@keyframes comboAnimation {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.5);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.2);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1) translateY(-50px);
    }
}

/* Game Over Modal */
.game-over-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 20px;
    width: 95%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    color: white;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: gameOverAppear 0.5s ease-out;
}

.game-over-header {
    text-align: center;
    padding: 2rem 2rem 1rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.game-over-header h1 {
    font-size: 2.5rem;
    margin: 0 0 0.5rem 0;
    font-weight: 300;
}

.final-level {
    font-size: 1.2rem;
    opacity: 0.8;
    margin: 0;
}

.stats-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr;
    gap: 1rem;
    padding: 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.stat-card {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 1.5rem;
    text-align: center;
    backdrop-filter: blur(10px);
}

.stat-card.primary {
    background: rgba(255, 215, 0, 0.2);
    border-color: rgba(255, 215, 0, 0.4);
}

.stat-card h2, .stat-card h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    opacity: 0.8;
    font-weight: normal;
}

.stat-card .score {
    font-size: 2.5rem;
    font-weight: bold;
    margin: 0.5rem 0;
    color: #FFD700;
}

.stat-card .value {
    font-size: 1.8rem;
    font-weight: bold;
    margin: 0.5rem 0;
}

.stat-card .rank {
    font-size: 0.9rem;
    opacity: 0.8;
    margin: 0;
}

.detailed-stats {
    padding: 1rem 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
}

.stat-label {
    opacity: 0.8;
}

.stat-value {
    font-weight: bold;
    color: #FFD700;
}

.leaderboards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    padding: 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.leaderboards h3 {
    margin: 0 0 1rem 0;
    font-size: 1.2rem;
}

.records-list, .ranking-list {
    space-y: 0.5rem;
}

.record, .rank-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    font-size: 0.9rem;
    opacity: 0.9;
}

.timing-records {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.timing-records h4, .global-timing h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1rem;
    opacity: 0.9;
}

.timing-list {
    font-size: 0.8rem;
}

.timing-item {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    opacity: 0.8;
}

.timing-item.personal-best {
    color: #FFD700;
    font-weight: bold;
    opacity: 1;
}

.timing-item.global-record {
    color: #FF6B6B;
    font-weight: bold;
    opacity: 1;
}

.speed-rating {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}

.speed-rating.lightning {
    color: #FFD700;
}

.speed-rating.fast {
    color: #87CEEB;
}

.speed-rating.average {
    color: #FFA500;
}

.speed-rating.slow {
    color: #FF6B6B;
}

.game-over-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    padding: 2rem;
}

.btn-primary, .btn-secondary {
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #333;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #FFA500, #FFD700);
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

@keyframes gameOverAppear {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(50px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes speedPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; transform: scale(1.05); }
}

@keyframes timerWarning {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1);
    }
    50% { 
        opacity: 0.7; 
        transform: scale(1.1);
    }
}

@keyframes timerCritical {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1) rotate(0deg);
    }
    50% { 
        opacity: 0.5; 
        transform: scale(1.2) rotate(2deg);
    }
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    /* Ensure full height usage on mobile */
    body {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
    }
    
    .game-container {
        height: 100vh;
        height: 100dvh;
    }
    
    .game-header {
        padding: 0.8rem 1rem;
        min-height: 60px;
    }
    
    .weather-text {
        font-size: 0.9rem;
    }
    
    .location-text {
        font-size: 0.8rem;
    }
    
    .score {
        font-size: 1.5rem;
    }
    
    .timer, .lives {
        font-size: 1.4rem;
    }
    
    .timer-label, .lives-label {
        font-size: 0.7rem;
    }
    
    .game-controls {
        padding: 0.8rem;
        gap: 0.5rem;
        min-height: 70px;
    }
    
    .control-btn {
        padding: 0.8rem 1rem;
        font-size: 0.9rem;
        min-height: 44px; /* iOS touch target guidelines */
        border-radius: 10px;
    }
    
    .instructions {
        padding: 1.5rem;
        max-width: 90%;
        font-size: 1.1rem;
    }
    
    .instructions p {
        font-size: 1.1rem;
        line-height: 1.4;
    }
    
    .loading-content h1 {
        font-size: 2rem;
    }
    
    .loading-content p {
        font-size: 1rem;
    }
    
    .weather-icon {
        font-size: 3rem;
    }
    
    /* Game Over Modal Mobile */
    .game-over-content {
        width: 98%;
        max-height: 95vh;
        max-height: 95dvh;
        margin: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 0.8rem;
        padding: 1.5rem;
    }
    
    .stat-card.primary {
        grid-column: 1 / -1;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-card .score {
        font-size: 2rem;
    }
    
    .stat-card .value {
        font-size: 1.4rem;
    }
    
    .leaderboards {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1.5rem;
    }
    
    .game-over-actions {
        grid-template-columns: 1fr 1fr;
        gap: 0.8rem;
        padding: 1.5rem;
    }
    
    .btn-primary, .btn-secondary {
        padding: 1rem;
        font-size: 0.9rem;
        min-height: 48px;
    }
}

/* Small Mobile Devices */
@media (max-width: 480px) {
    .game-header {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.8rem 0.5rem;
        min-height: 80px;
    }
    
    .weather-display {
        order: 2;
        text-align: center;
    }
    
    .game-status {
        order: 1;
        flex-direction: row;
        gap: 2rem;
        justify-content: center;
    }
    
    .score-display {
        order: 3;
        text-align: center;
    }
    
    .control-btn {
        padding: 0.8rem 0.6rem;
        font-size: 0.8rem;
        min-height: 48px;
    }
    
    .game-controls {
        padding: 0.6rem 0.4rem;
        gap: 0.3rem;
    }
    
    .modal-content, .game-over-content {
        width: 98%;
        margin: 0.5rem;
    }
    
    .modal-header, .game-over-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.6rem;
        padding: 1rem;
    }
    
    .stat-card {
        padding: 0.8rem;
    }
    
    .detailed-stats {
        padding: 0.8rem 1rem;
    }
    
    .stats-row {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .leaderboards {
        padding: 1rem;
    }
    
    .game-over-actions {
        grid-template-columns: 1fr;
        gap: 0.6rem;
        padding: 1rem;
    }
    
    /* Mode selection mobile optimization */
    .mode-content {
        padding: 1rem;
    }
    
    .game-modes {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .mode-card {
        padding: 1.5rem;
    }
    
    .tier-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.6rem;
    }
    
    .city-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.8rem;
    }
}

/* ============================================================================
   PR1 / BUG-I-013: Mobile 360px viewport layout (C-VAL-087 approved)
   ----------------------------------------------------------------------------
   The 480px breakpoint above mostly covers 360px, but on very narrow viewports
   (320–380px) headings can overflow and the tier-grid feels cramped. This
   defensive block tightens spacing/typography and ensures no element forces
   horizontal scroll, which was breaking visibility for I's Playwright e2e at
   360x640. UI_UX_STANDARDS phone viewport target: 360x640 portrait.
   ============================================================================ */
@media (max-width: 380px) {
    .mode-content {
        padding: 0.75rem;
        width: 100%;
    }

    .mode-content h1 {
        font-size: 1.8rem;
        line-height: 1.1;
    }

    .subtitle {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }

    .mode-card {
        padding: 1rem;
    }

    .mode-card h3 {
        font-size: 1.1rem;
    }

    .challenge-levels {
        grid-template-columns: 1fr;
        padding: 0.5rem;
    }

    .level-group h2 {
        font-size: 0.95rem;
    }

    .level-group p {
        font-size: 0.85rem;
    }

    .tier-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .tier-card {
        padding: 0.6rem;
    }

    .tier-name {
        font-size: 0.95rem;
    }

    .tier-levels {
        font-size: 0.8rem;
    }

    .current-level {
        padding: 0.75rem;
    }

    .current-level h3 {
        font-size: 1rem;
    }

    .start-btn,
    .help-btn {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
        min-height: 44px; /* meets touch-target minimum per UI_UX_STANDARDS */
    }

    /* Allow vertical scroll within mode-select on very tall content at 360px wide */
    .game-mode-screen {
        align-items: flex-start;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
        overflow-x: hidden;
    }

    .stats-grid { /* BUG-E-007 fix */
        grid-template-columns: 1fr;
    }

    .leaderboards { /* BUG-E-007 fix */
        grid-template-columns: 1fr;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .game-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Landscape orientation on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .game-header {
        flex-direction: row;
        padding: 0.4rem 0.8rem;
        min-height: 50px;
    }
    
    .game-status {
        flex-direction: row;
        gap: 1rem;
    }
    
    .timer, .lives {
        font-size: 1.2rem;
    }
    
    .game-controls {
        padding: 0.4rem;
        min-height: 50px;
    }
    
    .control-btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
        min-height: 40px;
    }
    
    .instructions {
        padding: 1rem;
        font-size: 0.9rem;
    }
    
    .game-over-content {
        max-height: 98vh;
    }
    
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        padding: 1rem;
    }
    
    .stat-card.primary {
        grid-column: 1 / 3;
    }
    
    .leaderboards {
        grid-template-columns: 1fr 1fr;
        padding: 1rem;
    }
}

/* Touch-specific optimizations */
@media (hover: none) and (pointer: coarse) {
    /* This targets touch devices specifically */
    .control-btn, .btn-primary, .btn-secondary, .mode-card, .tier-card, .city-card {
        min-height: 48px;
        min-width: 48px;
    }
    
    .mode-card:hover, .tier-card:hover, .city-card:hover {
        transform: none; /* Remove hover effects on touch */
    }
    
    .btn-primary:hover, .btn-secondary:hover, .control-btn:hover {
        transform: none;
    }
}

/* High density displays (Retina) */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .game-canvas {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .loading-spinner {
        animation: none;
        border: 3px solid white;
    }
    
    .weather-icon {
        animation: none;
    }

    .game-over-content {
        animation: none;
    }
}

/* Help Modal Styles */
.help-section {
    margin-bottom: 2rem;
}

.help-section h3 {
    color: #2c3e50;
    margin-bottom: 1rem;
    font-size: 1.2rem;
    border-bottom: 2px solid #3498db;
    padding-bottom: 0.5rem;
}

.tutorial-btn {
    display: block;
    width: 100%;
    margin: 0.5rem 0;
    padding: 0.8rem 1rem;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tutorial-btn:hover {
    background: linear-gradient(135deg, #2980b9, #1f5f99);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.help-btn {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: white;
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    margin: 1rem auto;
    display: block;
    transition: all 0.3s ease;
}

.help-btn:hover {
    background: linear-gradient(135deg, #c0392b, #a93226);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

.menu-actions {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.help-section ul {
    list-style: none;
    padding: 0;
}

.help-section li {
    padding: 0.5rem 0;
    border-bottom: 1px solid #ecf0f1;
    font-size: 0.95rem;
    line-height: 1.4;
}

.help-section li:last-child {
    border-bottom: none;
}

.help-section li strong {
    color: #2c3e50;
    font-weight: 600;
}

/* Safe area handling for devices with notches */
@supports (padding: max(0px)) {
    .game-header {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-top: max(0.8rem, env(safe-area-inset-top));
    }
    
    .game-controls {
        padding-left: max(0.8rem, env(safe-area-inset-left));
        padding-right: max(0.8rem, env(safe-area-inset-right));
        padding-bottom: max(0.8rem, env(safe-area-inset-bottom));
    }
}

/* ============================================================================
   PR-CSS-1 (C-VAL-118): Phase 3 Object Depth-Zone Size Classes
   ----------------------------------------------------------------------------
   Sizes match DEC-018 constants in ts/constants.ts exactly:
     OBJ_SKY_FAR_PX=60, OBJ_SKY_MID_PX=100, OBJ_SKY_NEAR_PX=130
     OBJ_GROUND_FAR_PX=100, OBJ_GROUND_MID_PX=160, OBJ_GROUND_FORE_PX=210
   No animations → no prefers-reduced-motion guard needed (DEC-018 C-VAL-111).
   Merge gated on N a11y sign-off (DEC-018 Status).
   ============================================================================ */

/* Sky layer — air objects (upper ~40% of screen) */
.obj-sky-far  { width: 60px;  height: 60px;  }
.obj-sky-mid  { width: 100px; height: 100px; }
.obj-sky-near { width: 130px; height: 130px; }

/* Ground layer — ground objects (lower ~40% of screen) */
.obj-ground-far  { width: 100px; height: 100px; }
.obj-ground-mid  { width: 160px; height: 160px; }
.obj-ground-fore { width: 210px; height: 210px; }

/* ============================================================================
   PR-CSS-2 (C-VAL-119/124): Phase 3 Visibility Overlay System (DEC-019)
   ----------------------------------------------------------------------------
   B's ObjectRenderer creates a .visibility-overlay div and applies
   .tier-visibility-N class to it via setVisibility(tier). Color is driven by
   --visibility-overlay-color from css/weather-themes.css per condition class.
   Opacity values match DEC-019 VISIBILITY_TIER*_OPACITY constants exactly:
     T1-2=0.00, T3=0.15, T4=0.30, T5=0.50, T6=0.70, T7=0.90 (silhouette)
   prefers-reduced-motion: instant transitions only (no animation suppressed —
   the overlay itself does not animate game objects, just blurs/tints).
   Merge gated on N a11y sign-off (DEC-019 Status).
   ============================================================================ */
.visibility-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
    transition: background-color 0.5s ease, backdrop-filter 0.5s ease, opacity 0.3s ease;
}
/* Tier 1–2: clear (VISIBILITY_TIER1/2_OPACITY = 0.00) */
.visibility-overlay.tier-visibility-1,
.visibility-overlay.tier-visibility-2 { opacity: 0; }

/* Tier 3: Good visibility (VISIBILITY_TIER3_OPACITY = 0.15) */
.visibility-overlay.tier-visibility-3 {
    background-color: var(--visibility-overlay-color, rgba(180, 180, 200, 0.15));
    opacity: 1;
}
/* Tier 4: Moderate (VISIBILITY_TIER4_OPACITY = 0.30) */
.visibility-overlay.tier-visibility-4 {
    background-color: var(--visibility-overlay-color, rgba(100, 120, 140, 0.30));
    backdrop-filter: blur(1px);
    opacity: 1;
}
/* Tier 5: Poor (VISIBILITY_TIER5_OPACITY = 0.50) */
.visibility-overlay.tier-visibility-5 {
    background-color: var(--visibility-overlay-color, rgba(60, 80, 100, 0.50));
    backdrop-filter: blur(3px);
    opacity: 1;
}
/* Tier 6: Very Poor (VISIBILITY_TIER6_OPACITY = 0.70) */
.visibility-overlay.tier-visibility-6 {
    background-color: var(--visibility-overlay-color, rgba(30, 40, 50, 0.70));
    backdrop-filter: blur(6px);
    opacity: 1;
}
/* Tier 7: Near-Zero — silhouette only (VISIBILITY_TIER7_OPACITY = 0.90) */
.visibility-overlay.tier-visibility-7 {
    background-color: var(--visibility-overlay-color, rgba(0, 0, 0, 0.80));
    backdrop-filter: blur(10px);
    opacity: 1;
}
/* Silhouette filter applied to each object img in Tier 7 by B's renderer */
.tier-visibility-7 .game-object {
    filter: brightness(0);
    opacity: 0.35;
}
/* prefers-reduced-motion: instant overlay transitions only */
@media (prefers-reduced-motion: reduce) {
    .visibility-overlay { transition: none; }
}