/*
 * Rotrix HTML5 demo styles.
 *
 * The reset, theme variables, game screen and overlays come from the app build so the
 * board looks identical; the start and controls screens are demo-only.
 */

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    width: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* CSS Custom Properties for theming */
:root {
    --theme-ui-bg: #1a1a1a;
    --theme-ui-bg-secondary: #000000;
    --theme-ui-text: #ffffff;
    --theme-ui-text-secondary: rgba(255, 255, 255, 0.7);
    --theme-overlay-bg: rgba(0, 0, 0, 0.9);
    --theme-overlay-light: rgba(255, 255, 255, 0.1);
    --theme-overlay-medium: rgba(255, 255, 255, 0.15);
    --theme-overlay-heavy: rgba(255, 255, 255, 0.2);
    --theme-accent-gold: rgba(255, 215, 0, 0.2);
    --theme-accent-gold-medium: rgba(255, 215, 0, 0.3);
    --theme-accent-gold-light: rgba(255, 215, 0, 0.1);

    /* Height of the strip under the score row that holds the level-up and
       gravity-changing signs. Reserved by the header and subtracted from the
       canvas height so the board still fits. */
    --notice-height: 20px;
}

body {
    margin: 0;
    padding: 0;
    background: var(--theme-ui-bg);
    color: var(--theme-ui-text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
    /* Prevent layout shifts during animations */
    contain: layout;
    /* Fullscreen - no padding, content fills entire screen */
    padding: 0;
    background-color: var(--theme-ui-bg) !important;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* Remove flex centering - content should fill screen */
    display: block;
    /* Smooth theme transitions */
    transition: background-color 0.3s ease, color 0.3s ease;
}

.game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    overflow: hidden;
    padding: 0;
    padding-top: max(-30px, env(safe-area-inset-top) - 30px); /* Move up by 30px (half button height) */
    padding-bottom: max(30px, env(safe-area-inset-bottom) + 30px); /* Reduced bottom padding, moved up */
    box-sizing: border-box;
    margin: 0;
    /* Ensure game container is completely hidden during splash screen */
    visibility: hidden;
    opacity: 0;
    /* Hardware acceleration for smoother animations */
    transform: translateZ(0);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    /* Set from JS to the board's rendered width, so the header and the next-piece
       preview line up with the canvas instead of spanning the whole viewport */
    max-width: var(--board-width, 100%);
    margin-bottom: 2px;
    gap: 8px;
    padding: 2px 8px calc(2px + var(--notice-height));
    flex-shrink: 0;
    position: relative;
    /* Prevent repaints during score updates */
    will-change: contents;
}

.game-info {
    display: flex;
    flex-direction: row;
    gap: 12px;
    font-size: 12px;
    font-weight: 600;
    flex: 1;
    align-items: center;
    /* Optimize text rendering */
    text-rendering: optimizeSpeed;
}

.score, .level, .lines {
    color: #FFD700;
    /* Reduce repaints for frequently changing text */
    contain: layout style;
    white-space: nowrap;
    font-size: 12px;
    line-height: 1.2;
}

.score-label, .level-label, .lines-label {
    color: var(--theme-ui-text-secondary);
    font-size: 9px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 1px;
}

/* Sits below the score row and above the board's top edge. Both signs are absolute
   inside it so they share one slot instead of stacking. */
.game-notice {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 2px;
    height: var(--notice-height);
    pointer-events: none;
}

.level-up-message {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease-in-out;
    z-index: 10;
}

.level-up-message.show {
    opacity: 1;
}

.level-up-label {
    color: #FFD700;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

/* Blinking sign shown in the header while the board flips.
   Shares the level-up message position so both read as the same slot. */
.gravity-change-message {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    z-index: 11;
}

.gravity-change-message.show {
    opacity: 1;
    animation: gravity-change-blink 600ms ease-in-out infinite;
}

/* Both signs share the one slot, so the flip sign wins while it is up */
.game-notice:has(.gravity-change-message.show) .level-up-message {
    opacity: 0;
}

.gravity-change-label {
    color: #FFD700;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

@keyframes gravity-change-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

/* The gravity sign is a long string: shrink it on narrow phones so it never
   collides with the score/lines/level block on its left. The extra .game-info
   specificity keeps these from being overridden by the header breakpoints below. */
@media (max-width: 400px) {
    .game-info .gravity-change-label {
        font-size: 11px;
        letter-spacing: 0;
    }
}

@media (max-width: 360px) {
    .game-info .gravity-change-label {
        font-size: 10px;
    }
}

.score-value, .level-value, .lines-value {
    color: #FFD700;
    font-size: 14px;
    font-weight: 700;
}

.next-piece {
    width: 50px;
    height: 50px;
    border: 2px solid #444;
    background: var(--theme-ui-bg-secondary);
    flex-shrink: 0;
    /* GPU acceleration */
    transform: translateZ(0);
}

canvas {
    border: 2px solid #444;
    background: var(--theme-ui-bg-secondary);
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    /* Ensure canvas fits within viewport - account for header only */
    max-height: calc(100vh - 80px - var(--notice-height));
    max-height: calc(100dvh - 80px - var(--notice-height)); /* Dynamic viewport height */
    object-fit: contain;
    /* Optimize canvas rendering */
    image-rendering: pixelated;
    /* Prevent canvas clearing flicker */
    will-change: transform;
}

/* Game canvas wrapper for overlay positioning */
.game-canvas-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: var(--board-width, 100%);
    flex-shrink: 1;
    flex-grow: 0;
}

/* Blur canvas when paused */
#gameCanvas.paused-blur {
    filter: blur(16px) brightness(0.3);
    -webkit-filter: blur(16px) brightness(0.3);
}

/* Game overlay (pause / game over buttons) */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: none;
}

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

.game-overlay-title {
    color: white;
    font-size: 36px;
    font-weight: bold;
    font-family: Arial, sans-serif;
    text-align: center;
    pointer-events: none;
}

.game-overlay-buttons {
    display: flex;
    flex-direction: column;
    /* Stretch keeps both buttons the same width while the column itself
       grows to fit the longest label in the current language */
    align-items: stretch;
    gap: 14px;
    margin-top: 20px;
    pointer-events: auto;
}

/* Game over overlay needs more top margin to clear canvas-drawn score text */
#gameOverOverlay .game-overlay-buttons {
    margin-top: 95px;
}

.game-overlay-button {
    min-width: 170px;
    white-space: nowrap;
    padding: 14px 24px;
    background: rgba(40, 40, 40, 0.85);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 18px;
    font-weight: 600;
    transition: all 0.15s;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.game-overlay-button:active {
    background: rgba(80, 80, 80, 0.9);
    transform: scale(0.96);
}

.game-overlay-button.primary {
    background: rgba(255, 215, 0, 0.2);
    border-color: #FFD700;
    color: #FFD700;
}

.game-overlay-button.primary:active {
    background: rgba(255, 215, 0, 0.35);
    transform: scale(0.96);
}

/* Main Menu Styles */

.main-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 500px;
    height: 100vh;
    height: 100dvh;
    padding: 20px;
    box-sizing: border-box;
}

.main-menu.hidden {
    display: none;
}

.menu-title {
    font-size: 48px;
    font-weight: bold;
    color: #FFD700;
    margin-bottom: 60px;
    text-align: center;
}

.menu-button {
    width: 200px;
    padding: 16px 24px;
    margin: 12px 0;
    background: var(--theme-overlay-light);
    border: 2px solid #444;
    border-radius: 8px;
    color: var(--theme-ui-text);
    font-size: 18px;
    font-weight: 600;
    transition: all 0.2s;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

.menu-button:active {
    background: var(--theme-overlay-medium);
    transform: scale(0.98);
}

.menu-button.primary {
    background: var(--theme-accent-gold);
    border-color: #FFD700;
    color: #FFD700;
}

.game-container.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.game-container:not(.hidden) {
    visibility: visible;
    opacity: 1;
    transition: opacity 0.3s ease-in;
}

@media (max-width: 768px) {
    body {
        padding: 0;
        padding-top: env(safe-area-inset-top);
    }

    .game-container {
        max-width: 100%;
        padding: 0;
        padding-top: max(-30px, env(safe-area-inset-top) - 30px); /* Move up by 30px */
        padding-bottom: max(30px, env(safe-area-inset-bottom) + 30px); /* Reduced bottom padding */
    }
    
    .game-header {
        flex-direction: row;
        margin-bottom: 2px;
        gap: 8px;
        padding: 2px 6px calc(2px + var(--notice-height));
        align-items: center;
    }

    .game-notice {
        left: 6px;
        right: 6px;
    }

    .game-info {
        font-size: 11px;
        gap: 10px;
    }

    .score-label, .level-label, .lines-label {
        font-size: 9px;
    }

    .score-value, .level-value, .lines-value, .level-up-label, .gravity-change-label {
        font-size: 13px;
    }

    .next-piece {
        width: 45px;
        height: 45px;
    }
    
    canvas {
        max-height: calc(100dvh - 60px - var(--notice-height));
    }
    
    .game-container {
        padding-top: max(-30px, env(safe-area-inset-top) - 30px); /* Move up by 30px */
        padding-bottom: max(30px, env(safe-area-inset-bottom) + 30px); /* Reduced bottom padding */
    }
    
    canvas {
        max-height: calc(100vh - 60px - var(--notice-height));
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .game-container {
        padding: 5px;
        padding-top: max(5px, env(safe-area-inset-top));
        padding-bottom: max(5px, env(safe-area-inset-bottom));
    }
    
    .game-info {
        font-size: 12px;
    }

    .score, .level {
        font-size: 12px;
    }

    .next-piece {
        width: 60px;
        height: 60px;
    }
    
    canvas {
        max-height: calc(100dvh - 60px - var(--notice-height));
    }
    
    .game-header {
        padding: 2px 4px calc(2px + var(--notice-height));
        margin-bottom: 2px;
    }
    
    .game-notice {
        left: 4px;
        right: 4px;
    }

    .game-info {
        gap: 8px;
        font-size: 10px;
    }
    
    .score-value, .level-value, .lines-value {
        font-size: 12px;
    }
    
    .score-label, .level-label, .lines-label {
        font-size: 8px;
    }
    
    .score-value, .level-value, .lines-value, .level-up-label, .gravity-change-label {
        font-size: 12px;
    }
    
    .next-piece {
        width: 40px;
        height: 40px;
    }
    
    .game-container {
        padding-top: max(-30px, env(safe-area-inset-top) - 30px); /* Move up by 30px */
        padding-bottom: max(30px, env(safe-area-inset-bottom) + 30px); /* Reduced bottom padding */
    }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 0;
        padding-top: env(safe-area-inset-top);
    }
    
    .game-container {
        padding: 5px;
        padding-top: max(5px, env(safe-area-inset-top));
        padding-bottom: max(5px, env(safe-area-inset-bottom));
    }

    .game-container {
        flex-direction: row;
        align-items: flex-start;
        gap: 10px;
    }

    .game-header {
        flex-direction: column;
        width: auto;
        margin-bottom: 0;
    }

    .next-piece {
        width: 60px;
        height: 60px;
    }

    canvas {
        max-width: calc(100vh - 100px);
        max-height: calc(100vh - 60px - var(--notice-height));
    }

}

/* Reduce repaints for frequently changing elements */
#scoreDisplay, #levelDisplay {
    will-change: contents;
}

/* Reduce repaints for frequently changing elements */
#scoreDisplay, #levelDisplay {
    will-change: contents;
}


/* ---------------------------------------------------------------------------
   Demo-only screens: start and controls
   --------------------------------------------------------------------------- */

.main-menu {
    margin: 0 auto;
}

.menu-title {
    margin-bottom: 12px;
}

.menu-tagline {
    color: var(--theme-ui-text-secondary);
    font-size: 15px;
    text-align: center;
    margin-bottom: 48px;
    max-width: 320px;
}

.controls-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    padding: 20px;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    overflow-y: auto;
}

.controls-screen.hidden {
    display: none;
}

.controls-card {
    width: 100%;
    max-width: 460px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 22px;
}

.controls-title {
    margin: 0;
    font-size: 28px;
    font-weight: bold;
    color: #FFD700;
    letter-spacing: 2px;
}

.controls-list {
    list-style: none;
    margin: 0;
    padding: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 14px;
    background: var(--theme-overlay-light);
    border: 1px solid #333;
    border-radius: 8px;
}

.control-keys {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    min-width: 96px;
}

kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    background: var(--theme-overlay-medium);
    border: 2px solid #555;
    border-bottom-width: 3px;
    border-radius: 6px;
    color: var(--theme-ui-text);
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

.control-keys .separator {
    color: var(--theme-ui-text-secondary);
    font-size: 14px;
}

.control-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.control-name {
    font-size: 16px;
    font-weight: 600;
}

.control-hint {
    font-size: 13px;
    color: var(--theme-ui-text-secondary);
}

.controls-note {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--theme-ui-text-secondary);
    text-align: center;
}

.controls-buttons {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.controls-buttons .menu-button {
    width: 150px;
    margin: 0;
}

@media (max-width: 480px) {
    .menu-title {
        font-size: 40px;
    }

    .controls-card {
        gap: 16px;
    }

    .control-row {
        padding: 10px 12px;
        gap: 12px;
    }

    .control-keys {
        min-width: 84px;
    }

    kbd {
        min-width: 30px;
        height: 30px;
        font-size: 14px;
    }

    .control-name {
        font-size: 15px;
    }
}
