/* MEYS Tetris 2.0 - Easter Egg Styles
   Arcade-Cabinet-Look: dunkles Panel, Teal-Neon (MEYS #1599A8), Scanlines, Pixelfont.
   Responsive: Desktop = Board + Side-Panels, Mobil = kompakte Strips + Touch-Buttons. */

@font-face {
    font-family: 'Press Start 2P';
    src: url('../fonts/PressStart2P.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

.tetris-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at 50% 35%, rgba(21, 153, 168, 0.14), rgba(2, 6, 12, 0.96) 70%);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    touch-action: none;
    overscroll-behavior: contain;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

/* ===== Cabinet-Rahmen ===== */
.tetris-cabinet {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(94vw, 900px);
    height: min(96vh, 860px);  /* Fallback fuer Browser ohne dvh */
    height: min(96dvh, 860px);
    padding: 14px 18px;
    border-radius: 18px;
    background: linear-gradient(160deg, #101B2C 0%, #0B1220 55%, #081018 100%);
    border: 1px solid rgba(124, 244, 255, 0.28);
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.6),
        0 0 34px rgba(21, 153, 168, 0.35),
        0 24px 60px rgba(0, 0, 0, 0.65),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    overflow: hidden;
}

/* Scanline-Atmosphaere */
.tetris-cabinet::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: repeating-linear-gradient(to bottom,
            rgba(255, 255, 255, 0.022) 0px,
            rgba(255, 255, 255, 0.022) 1px,
            transparent 1px,
            transparent 3px);
    pointer-events: none;
}

.tetris-level-pulse {
    animation: tetrisLevelPulse 0.9s ease-out;
}

@keyframes tetrisLevelPulse {
    0% { box-shadow: 0 0 34px rgba(21, 153, 168, 0.35), 0 24px 60px rgba(0, 0, 0, 0.65); }
    35% { box-shadow: 0 0 90px rgba(124, 244, 255, 0.95), 0 24px 60px rgba(0, 0, 0, 0.65); }
    100% { box-shadow: 0 0 34px rgba(21, 153, 168, 0.35), 0 24px 60px rgba(0, 0, 0, 0.65); }
}

/* ===== Header ===== */
.tetris-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex: 0 0 auto;
}

.tetris-title {
    font-family: 'Press Start 2P', 'Consolas', monospace;
    font-size: clamp(13px, 2.4vw, 20px);
    color: #FFFFFF;
    letter-spacing: 2px;
    text-shadow: 0 0 12px rgba(124, 244, 255, 0.7);
    white-space: nowrap;
}

.tetris-title-accent {
    color: #7CF4FF;
    margin-left: 8px;
    text-shadow: 0 0 16px #1599A8, 0 0 4px #7CF4FF;
}

.tetris-header-btns {
    display: flex;
    gap: 8px;
}

.tetris-icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    border: 1px solid rgba(124, 244, 255, 0.35);
    background: rgba(21, 153, 168, 0.14);
    color: #CFF9FF;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tetris-icon-btn:hover { background: rgba(21, 153, 168, 0.32); }
.tetris-icon-btn:active { transform: scale(0.92); }
.tetris-icon-btn.tetris-btn-off { opacity: 0.35; }

.tetris-close-btn {
    border-color: rgba(255, 71, 87, 0.55);
    background: rgba(255, 71, 87, 0.14);
    color: #FFB3BB;
}

.tetris-close-btn:hover { background: rgba(255, 71, 87, 0.32); }

/* ===== Hauptbereich: Side-Panels + Board ===== */
.tetris-main {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr) 200px;
    grid-template-areas: 'sl board sr';
    gap: 14px;
    flex: 1 1 auto;
    min-height: 0;
}

.tetris-side {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    min-width: 0;
}

.tetris-side-left { grid-area: sl; }
.tetris-side-right { grid-area: sr; }

.tetris-board-wrap {
    grid-area: board;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
    min-width: 0;
}

#tetrisBoard {
    border: 2px solid rgba(124, 244, 255, 0.45);
    border-radius: 6px;
    box-shadow: 0 0 26px rgba(21, 153, 168, 0.45), inset 0 0 18px rgba(0, 0, 0, 0.55);
    background: #060B14;
    touch-action: none;
    display: block;
}

/* ===== Wells (HOLD / NEXT) ===== */
.tetris-well {
    background: rgba(6, 11, 20, 0.85);
    border: 1px solid rgba(124, 244, 255, 0.22);
    border-radius: 10px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.tetris-well-label {
    font-family: 'Press Start 2P', 'Consolas', monospace;
    font-size: 9px;
    color: #7CF4FF;
    letter-spacing: 2px;
    opacity: 0.85;
}

#tetrisHold { width: 92px; height: 66px; }
#tetrisNext { width: 92px; height: 190px; }

/* ===== Stats ===== */
.tetris-stats {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tetris-stat {
    background: rgba(6, 11, 20, 0.85);
    border: 1px solid rgba(124, 244, 255, 0.18);
    border-radius: 10px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tetris-stat-label {
    font-family: 'Press Start 2P', 'Consolas', monospace;
    font-size: 8px;
    color: rgba(207, 249, 255, 0.6);
    letter-spacing: 1.5px;
}

.tetris-stat-value {
    font-family: 'Press Start 2P', 'Consolas', monospace;
    font-size: 15px;
    color: #FFFFFF;
    text-shadow: 0 0 8px rgba(124, 244, 255, 0.5);
    overflow: hidden;
    text-overflow: ellipsis;
}

.tetris-stat-score .tetris-stat-value { color: #7CF4FF; }

/* ===== Tastatur-Legende (nur Desktop) ===== */
.tetris-keys {
    margin-top: auto;
    font-size: 11px;
    line-height: 1.9;
    color: rgba(207, 249, 255, 0.55);
}

.tetris-keys b {
    color: rgba(207, 249, 255, 0.9);
    font-weight: 600;
}

/* ===== Bestenliste ===== */
.tetris-leaderboard {
    background: rgba(6, 11, 20, 0.85);
    border: 1px solid rgba(124, 244, 255, 0.22);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    min-height: 0;
}

.tetris-lb-title {
    font-family: 'Press Start 2P', 'Consolas', monospace;
    font-size: 9px;
    color: #7CF4FF;
    letter-spacing: 2px;
    margin-bottom: 4px;
}

.tetris-lb-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    color: rgba(255, 255, 255, 0.85);
    padding: 3px 6px;
    border-radius: 6px;
}

.tetris-lb-row.tetris-lb-me {
    background: rgba(21, 153, 168, 0.28);
    border: 1px solid rgba(124, 244, 255, 0.4);
    color: #FFFFFF;
}

.tetris-lb-rank {
    flex: 0 0 24px;
    text-align: center;
    font-family: 'Press Start 2P', 'Consolas', monospace;
    font-size: 10px;
    color: rgba(207, 249, 255, 0.7);
}

.tetris-lb-name {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tetris-lb-score {
    flex: 0 0 auto;
    font-variant-numeric: tabular-nums;
    color: #7CF4FF;
    font-weight: 600;
}

.tetris-lb-empty {
    font-size: 12px;
    color: rgba(207, 249, 255, 0.45);
    font-style: italic;
}

/* ===== Game-Over-Panel ===== */
.tetris-gameover {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5;
    padding: 10px;
}

.tetris-gameover-card {
    background: linear-gradient(165deg, #101B2C, #081018);
    border: 1px solid rgba(255, 71, 87, 0.5);
    box-shadow: 0 0 40px rgba(255, 71, 87, 0.3), 0 18px 50px rgba(0, 0, 0, 0.7);
    border-radius: 14px;
    padding: 18px 20px;
    width: min(340px, 92%);
    max-height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: center;
    animation: tetrisGameOverIn 0.35s ease-out;
}

@keyframes tetrisGameOverIn {
    from { opacity: 0; transform: translateY(18px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.tetris-gameover-title {
    font-family: 'Press Start 2P', 'Consolas', monospace;
    font-size: 17px;
    color: #FF4757;
    text-shadow: 0 0 14px rgba(255, 71, 87, 0.8);
    letter-spacing: 2px;
}

.tetris-newbest {
    font-size: 13px;
    color: #FFD500;
    text-shadow: 0 0 10px rgba(255, 213, 0, 0.6);
    animation: tetrisBlink 1.1s ease-in-out infinite;
}

@keyframes tetrisBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

.tetris-gameover-score {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.9);
}

.tetris-gameover-score b {
    color: #7CF4FF;
    font-size: 17px;
}

.tetris-gameover-btns {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.tetris-btn {
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 18px;
    border-radius: 10px;
    border: 1px solid rgba(124, 244, 255, 0.45);
    background: rgba(21, 153, 168, 0.25);
    color: #E4FBFF;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.tetris-btn:hover { background: rgba(21, 153, 168, 0.45); }
.tetris-btn:active { transform: scale(0.95); }

.tetris-btn-danger {
    border-color: rgba(255, 71, 87, 0.5);
    background: rgba(255, 71, 87, 0.16);
    color: #FFD7DB;
}

.tetris-btn-danger:hover { background: rgba(255, 71, 87, 0.34); }

/* ===== Touch-Steuerung (nur auf Touch-Geraeten) ===== */
.tetris-touch-controls {
    display: none;
    flex: 0 0 auto;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 2px 4px;
}

.tetris-touch-hint {
    display: none;
    text-align: center;
    font-size: 10.5px;
    color: rgba(207, 249, 255, 0.45);
    flex: 0 0 auto;
}

.tetris-touch-group {
    display: flex;
    gap: 10px;
}

.tetris-touch-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 1px solid rgba(124, 244, 255, 0.4);
    background: radial-gradient(circle at 35% 30%, rgba(21, 153, 168, 0.45), rgba(21, 153, 168, 0.15));
    color: #E4FBFF;
    font-size: 24px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.tetris-touch-btn:active {
    background: radial-gradient(circle at 35% 30%, rgba(124, 244, 255, 0.6), rgba(21, 153, 168, 0.35));
    transform: scale(0.9);
    box-shadow: 0 0 16px rgba(124, 244, 255, 0.5);
}

.tetris-touch-btn-small {
    width: 48px;
    height: 48px;
    font-size: 17px;
}

@media (pointer: coarse) {
    .tetris-touch-controls { display: flex; }
    .tetris-touch-hint { display: block; }
    .tetris-keys { display: none; }
}

/* ===== Mobil / schmale Screens: kompaktes Layout ===== */
@media (max-width: 760px) {
    .tetris-overlay { padding: 0; }

    .tetris-cabinet {
        width: 100vw;
        height: 100vh;  /* Fallback fuer Browser ohne dvh */
        height: 100dvh;
        border-radius: 0;
        padding: calc(8px + env(safe-area-inset-top, 0px)) 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px;
        gap: 8px;
    }

    .tetris-main {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto minmax(0, 1fr);
        grid-template-areas:
            'sl sr'
            'board board';
        gap: 8px;
    }

    /* Side-Panels werden zu horizontalen Strips */
    .tetris-side { flex-direction: row; align-items: stretch; gap: 8px; }
    .tetris-side-right { justify-content: flex-end; }

    .tetris-well { padding: 5px; gap: 3px; flex: 0 0 auto; }
    .tetris-well-label { font-size: 7px; }
    #tetrisHold { width: 56px; height: 42px; }
    #tetrisNext { width: 56px; height: 42px; }

    .tetris-stats { flex-direction: row; flex-wrap: wrap; gap: 5px; flex: 1 1 auto; min-width: 0; }
    .tetris-stat { padding: 4px 7px; gap: 1px; flex: 1 1 auto; min-width: 0; justify-content: center; }
    .tetris-stat-label { font-size: 6px; }
    .tetris-stat-value { font-size: 11px; }

    /* Waehrend des Spiels keine Bestenliste (Platz!) - sie kommt im Game-Over-Panel */
    .tetris-side-right .tetris-leaderboard { display: none; }
    .tetris-keys { display: none; }

    .tetris-icon-btn { width: 38px; height: 38px; font-size: 16px; }
}

/* Sehr niedrige Landscape-Screens (Phone quer): Header schrumpfen */
@media (max-height: 500px) {
    .tetris-cabinet { gap: 4px; }
    .tetris-title { font-size: 11px; }
    .tetris-icon-btn { width: 34px; height: 34px; font-size: 14px; }
    .tetris-touch-btn { width: 46px; height: 46px; font-size: 19px; }
    .tetris-touch-hint { display: none; }
}

/* Reduzierte Bewegung respektieren */
@media (prefers-reduced-motion: reduce) {
    .tetris-level-pulse { animation: none; }
    .tetris-newbest { animation: none; }
    .tetris-gameover-card { animation: none; }
}
