/* Main Styles */
:root {
    /* Colors matching mockup */
    --bg-primary: #f8f8f8;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #000000;
    --text-secondary: #333333;
    --text-muted: #666666;
    --color-green: #22c55e;
    --color-amber: #f59e0b;
    --color-red: #ef4444;
    --border-color: #e5e5e5;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Courier New', monospace;
    
    /* Layout */
    --max-width-mobile: 428px;
    --header-height: 60px;
    --footer-height: 60px;
    
    /* Animations */
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
    --transition-slow: 500ms ease;
}

/* App Container */
#app {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    height: -webkit-fill-available; /* iOS Safari fullscreen */
    height: calc(var(--vh, 1vh) * 100); /* Custom viewport height */
    width: 100vw;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-primary);
    position: relative;
    overflow-x: hidden; /* Hide horizontal scroll but allow cards to animate */
    overflow-y: hidden;
    min-width: 375px; /* Minimum width for modern mobile devices */
    padding-bottom: env(safe-area-inset-bottom); /* Safe area for devices with home indicator */
    position: fixed; /* Prevent scroll */
    top: 0;
    left: 0;
}

/* Ensure HTML and body fill the viewport */
html {
    height: -webkit-fill-available;
}

body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Header */
#header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border-bottom: 1px solid #e0e0e0;
}

.header-content {
    width: 100%;
    max-width: var(--max-width-mobile);
    padding: 0 var(--spacing-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-title {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 700;
    font-style: italic;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.header-buttons {
    display: flex;
    gap: var(--spacing-md);
}

.about-button,
.debug-button {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 0;
    transition: color var(--transition-fast);
    text-decoration: underline;
}

.about-button:hover,
.debug-button:hover {
    color: var(--text-primary);
}

/* Main Game Area */
#game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: var(--spacing-md);
    overflow: visible;
    min-height: 0; /* Important for flex children */
}

/* Game Content Wrapper */
.game-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0; /* Remove gap, we'll position buttons explicitly */
    width: 100%;
    max-width: 480px;
    position: relative;
    margin-top: -150px; /* Move everything up by 150px */
}

/* Footer */
#footer {
    height: var(--footer-height);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border-top: none;
    padding-bottom: env(safe-area-inset-bottom, 20px); /* Account for Safari URL bar */
}

.footer-content {
    width: 100%;
    max-width: var(--max-width-mobile);
    padding: 0 var(--spacing-md);
}

.personal-stats {
    display: flex;
    justify-content: center;
    gap: var(--spacing-xl);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    /* Remove flex-wrap to keep all stats on one line */
}

.stat {
    letter-spacing: 0.02em;
    /* Allow text within each stat to wrap naturally */
    min-width: 0; /* Allow flex items to shrink */
    text-align: center;
}

.stat span {
    /* Keep the value on one line */
    white-space: nowrap;
}

/* Reduce gap on very small screens to prevent overflow */
@media (max-width: 400px) {
    .personal-stats {
        gap: var(--spacing-md);
        font-size: 11px;
    }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    z-index: 10001; /* Higher than splash screen */
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--bg-card);
    padding: calc(var(--spacing-xl) * 2);
    border-radius: 0;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid var(--border-color);
}

/* About modal - narrower than main container */
#about-modal .modal-content {
    width: 90%;
    max-height: 90vh;
    border-radius: 0;
    border: none;
    padding: 0;
}

#about-modal .modal-inner {
    overflow-y: auto;
    padding: var(--spacing-lg) 0;
}

.modal-content.game-over-content {
    max-width: 800px;
}

.final-stats {
    margin: var(--spacing-md) 0;
    padding: var(--spacing-md);
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-sm);
}

.final-stats h3 {
    margin: 0 0 var(--spacing-sm) 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.final-stats p {
    margin: var(--spacing-xs) 0;
    font-family: var(--font-mono);
    font-size: 14px;
}

.modal-close {
    position: absolute;
    top: 0;
    right: var(--spacing-md);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 0;
    transition: color var(--transition-fast);
    text-decoration: underline;
    background: none;
    border: none;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal h2 {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 14px; /* Even smaller */
    letter-spacing: 0.05em;
}

.modal h3 {
    margin-top: var(--spacing-lg);
    margin-bottom: var(--spacing-sm);
    font-family: var(--font-mono);
    font-size: 16px;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.modal p {
    margin: 0 0 var(--spacing-md) 0;
    font-family: var(--font-mono);
    font-size: 12px; /* Smaller font */
    line-height: 1.6;
}

.modal p:last-child {
    margin-bottom: 0;
}

.modal hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: var(--spacing-sm) 0;
}

.modal-footer {
    margin-top: var(--spacing-md);
    font-family: var(--font-mono);
    font-style: italic;
    color: var(--text-secondary);
    text-align: center;
}

/* About Modal Enhancements */
.about-section {
    margin-bottom: calc(var(--spacing-xl) * 1.5);
}

.about-section:last-of-type {
    margin-bottom: var(--spacing-xl);
}

.lead {
    font-size: 18px;
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: calc(var(--spacing-xl) * 1.5);
}

.inspiration-grid {
    display: grid;
    gap: var(--spacing-md);
}

.inspiration-grid p {
    margin: 0;
    padding: var(--spacing-sm) 0;
    border-left: 3px solid var(--border-color);
    padding-left: var(--spacing-md);
}

.disclaimer {
    font-size: 14px;
    color: var(--text-muted);
    font-style: italic;
    margin-top: var(--spacing-md);
}

#about-modal a {
    color: var(--color-green);
    text-decoration: none;
    border-bottom: 1px solid var(--color-green);
    transition: all var(--transition-fast);
}

#about-modal a:hover {
    opacity: 0.8;
}

/* Save Indicator */
.save-indicator {
    position: fixed;
    top: var(--spacing-md);
    right: var(--spacing-md);
    background-color: var(--bg-card);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
    opacity: 0;
    transform: translateY(-10px);
    transition: all var(--transition-normal);
    pointer-events: none;
    z-index: 1001;
}

.save-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

.save-indicator.error {
    background-color: #fee;
    color: var(--color-red);
}

/* Consequence Text */
.consequence-text {
    position: absolute;
    top: calc(50% - 50px); /* Nudged down by 100px */
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 400;
    color: var(--text-secondary);
    max-width: 300px;
    opacity: 0;
    pointer-events: none;
    z-index: 50;
    line-height: 1.6;
    letter-spacing: 0.05em;
    background: none;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
}

/* High Score Elements */
.new-best-score {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 700;
    color: var(--color-amber);
    text-align: center;
    margin: var(--spacing-lg) 0;
    animation: pulse 1s ease-in-out infinite;
}

.high-score-position {
    font-family: var(--font-mono);
    font-size: 16px;
    color: var(--color-green);
    text-align: center;
    margin: var(--spacing-md) 0;
}

.best-score {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-muted);
    text-align: center;
    margin: var(--spacing-sm) 0;
}

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