:root {
    --bg-dark: #0a0814;
    --card-bg: rgba(18, 14, 38, 0.85);
    --border-cyan: #00f3ff;
    --border-pink: #ff0055;
    --border-purple: #b500ff;
    --text-main: #f0f4f8;
    --neon-yellow: #ffee00;
    --neon-green: #00ff66;
    --grid-bg: rgba(5, 3, 15, 0.92);
    --font-heading: 'Orbitron', sans-serif;
    --font-body: 'Rajdhani', sans-serif;
    --font-pixel: 'Press Start 2P', monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* CRT Scanline Filter */
body.crt::after {
    content: " ";
    display: block;
    position: fixed;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%);
    background-size: 100% 4px;
    z-index: 99;
    pointer-events: none;
    opacity: 0.6;
}

/* Background Canvas */
#bgCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    pointer-events: none;
}

/* App Container */
#gameContainer {
    position: relative;
    z-index: 10;
    width: 100%;
    max-width: 1100px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--border-cyan);
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.3);
    border-radius: 12px;
    padding: 12px 24px;
    backdrop-filter: blur(10px);
}

.badge-kd {
    background: linear-gradient(90deg, #ff0055, #b500ff);
    color: #fff;
    font-family: var(--font-pixel);
    font-size: 9px;
    padding: 3px 8px;
    border-radius: 4px;
    display: inline-block;
    margin-bottom: 4px;
    letter-spacing: 1px;
}

.glitch-title {
    font-family: var(--font-heading);
    font-size: 26px;
    font-weight: 900;
    letter-spacing: 2px;
    color: var(--border-cyan);
    text-shadow: 0 0 10px rgba(0, 243, 255, 0.8), 0 0 20px rgba(255, 0, 85, 0.5);
}

.subtitle {
    font-size: 13px;
    color: #a0aab8;
    letter-spacing: 1.5px;
    font-weight: 700;
}

.header-controls {
    display: flex;
    gap: 10px;
}

/* Cyber Buttons */
.cyber-btn {
    background: rgba(10, 8, 20, 0.8);
    border: 1px solid var(--border-cyan);
    color: var(--border-cyan);
    font-family: var(--font-heading);
    font-size: 13px;
    font-weight: 700;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 0 8px rgba(0, 243, 255, 0.2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.cyber-btn:hover {
    background: var(--border-cyan);
    color: #000;
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.8);
    transform: translateY(-2px);
}

.cyber-btn.sm {
    padding: 6px 12px;
    font-size: 11px;
}

.cyber-btn.primary-btn {
    background: linear-gradient(135deg, #00f3ff, #b500ff);
    border: none;
    color: #fff;
    font-size: 16px;
    padding: 12px 28px;
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.6);
}

.cyber-btn.primary-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(255, 0, 85, 0.9);
}

.cyber-btn.twitter-btn {
    background: #1da1f2;
    border: none;
    color: #fff;
    font-size: 13px;
    padding: 10px 18px;
    box-shadow: 0 0 15px rgba(29, 161, 242, 0.5);
}

.cyber-btn.twitter-btn:hover {
    background: #0d8bd9;
    box-shadow: 0 0 25px rgba(29, 161, 242, 0.9);
}

/* Mode Selector */
.mode-selector {
    display: flex;
    gap: 12px;
    width: 100%;
}

.mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 16px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s ease;
    backdrop-filter: blur(8px);
}

.mode-btn .mode-icon {
    font-size: 24px;
}

.mode-btn .mode-info {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.mode-btn .mode-title {
    font-family: var(--font-heading);
    font-size: 13px;
    font-weight: 700;
    color: #fff;
}

.mode-btn .mode-desc {
    font-size: 11px;
    color: #8a96a8;
}

.mode-btn.active, .mode-btn:hover {
    border-color: var(--border-pink);
    background: rgba(255, 0, 85, 0.12);
    box-shadow: 0 0 15px rgba(255, 0, 85, 0.3);
}

.mode-btn.active .mode-title {
    color: var(--border-pink);
}

.mode-btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

/* Boss Health Bar */
.boss-bar {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(40, 10, 20, 0.9);
    border: 2px solid var(--border-pink);
    border-radius: 10px;
    padding: 10px 16px;
    box-shadow: 0 0 20px rgba(255, 0, 85, 0.4);
}

.boss-bar.hidden {
    display: none;
}

.boss-avatar {
    font-size: 32px;
    animation: float 2s ease-in-out infinite;
}

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

.boss-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.boss-header {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 700;
}

.boss-name {
    color: var(--border-pink);
}

.boss-hp-track {
    height: 12px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border-pink);
}

.boss-hp-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff0055, #ffcc00);
    transition: width 0.3s ease;
    box-shadow: 0 0 10px #ff0055;
}

.boss-attack-warn {
    font-family: var(--font-heading);
    font-size: 11px;
    color: var(--neon-yellow);
    animation: blink 0.5s infinite alternate;
}

@keyframes blink {
    from { opacity: 0.3; }
    to { opacity: 1; }
}

/* Game Layout Grid */
.game-layout {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 18px;
}

/* Cards & Panels */
.panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 200px;
}

.cyber-card {
    background: var(--card-bg);
    border: 1px solid rgba(0, 243, 255, 0.3);
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.cyber-card h3 {
    font-family: var(--font-heading);
    font-size: 11px;
    color: var(--border-cyan);
    margin-bottom: 10px;
    text-align: center;
    letter-spacing: 1px;
}

.canvas-box {
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--grid-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 8px;
}

/* Stats */
.stat-item {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
}

.stat-item:last-child {
    margin-bottom: 0;
}

.stat-label {
    font-size: 11px;
    color: #8a96a8;
    font-weight: 700;
}

.stat-val {
    font-family: var(--font-heading);
    font-size: 20px;
    font-weight: 900;
    color: #fff;
}

.glow-cyan {
    color: var(--border-cyan);
    text-shadow: 0 0 8px var(--border-cyan);
}

.glow-pink {
    color: var(--border-pink);
    text-shadow: 0 0 8px var(--border-pink);
}

/* Main Canvas Wrapper */
.canvas-container {
    display: flex;
    justify-content: center;
    width: 100%;
}

.tetris-wrapper {
    position: relative;
    width: min(100%, 304px);
    border: 2px solid var(--border-cyan);
    border-radius: 12px;
    box-shadow: 0 0 25px rgba(0, 243, 255, 0.4), inset 0 0 15px rgba(0, 243, 255, 0.2);
    overflow: hidden;
    background: var(--grid-bg);
}

#tetrisCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 2;
}

/* Overlay */
.game-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(8, 5, 20, 0.88);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    z-index: 20;
    padding: 20px;
    transition: opacity 0.3s ease;
}

.game-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

#overlayTitle {
    font-family: var(--font-heading);
    font-size: 24px;
    color: var(--border-cyan);
    text-shadow: 0 0 12px var(--border-cyan);
}

#overlaySubtitle {
    font-size: 14px;
    color: #b0bac8;
    max-width: 240px;
}

.share-section {
    margin-top: 10px;
}

.share-section.hidden {
    display: none;
}

/* AI Commentator */
.commentator-card {
    border-color: var(--border-purple);
}

.commentator-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.ai-avatar {
    font-size: 22px;
}

.ai-avatar.pulse {
    animation: pulseGlow 1.5s infinite alternate;
}

@keyframes pulseGlow {
    from { transform: scale(1); filter: drop-shadow(0 0 2px #b500ff); }
    to { transform: scale(1.15); filter: drop-shadow(0 0 10px #b500ff); }
}

.ai-name {
    font-family: var(--font-heading);
    font-size: 11px;
    color: var(--border-purple);
    font-weight: 700;
}

.speech-bubble {
    background: rgba(181, 0, 255, 0.1);
    border: 1px solid rgba(181, 0, 255, 0.3);
    border-radius: 8px;
    padding: 10px;
    font-size: 12px;
    color: #e2d3f5;
    line-height: 1.4;
    min-height: 70px;
    display: flex;
    align-items: center;
}

/* Floating Actions Text Overlay */
#floatingTextContainer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 15;
    overflow: hidden;
}

.floating-msg {
    position: absolute;
    font-family: var(--font-heading);
    font-weight: 900;
    text-shadow: 0 0 10px currentColor;
    animation: floatUpFade 1.2s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
    white-space: nowrap;
}

@keyframes floatUpFade {
    0% { transform: translate(-50%, 0) scale(0.5); opacity: 0; }
    30% { transform: translate(-50%, -15px) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -60px) scale(0.9); opacity: 0; }
}

/* Mobile Controls */
.touch-controls {
    display: none;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
}

.touch-row {
    display: flex;
    justify-content: space-around;
    gap: 8px;
}

.touch-btn {
    flex: 1;
    height: 50px;
    background: rgba(18, 14, 38, 0.9);
    border: 1px solid var(--border-cyan);
    color: var(--border-cyan);
    font-family: var(--font-heading);
    font-size: 16px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
}

.touch-btn.highlight {
    background: linear-gradient(135deg, #00f3ff, #ff0055);
    color: #fff;
    border: none;
    font-weight: 900;
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    position: relative;
    max-width: 500px;
    width: 90%;
    max-height: 90dvh;
    overflow-y: auto;
    border-color: var(--border-cyan);
}

.modal-close {
    position: absolute;
    top: 12px; right: 12px;
    background: none;
    border: none;
    color: var(--border-pink);
    font-size: 18px;
    cursor: pointer;
}

.controls-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 15px 0;
    font-size: 14px;
}

kbd {
    background: #251c48;
    border: 1px solid var(--border-cyan);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 12px;
    color: #fff;
}

.cyber-divider {
    border: none;
    border-top: 1px dashed rgba(0, 243, 255, 0.3);
    margin: 12px 0;
}

/* Screen Shake Animation */
.shake {
    animation: cameraShake 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes cameraShake {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(3px, -2px, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 2px, 0); }
    40%, 60% { transform: translate3d(4px, -1px, 0); }
}

/* Responsive Scaling */
@media (max-width: 850px) {
    #gameContainer {
        max-width: 680px;
    }

    .game-header {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 12px;
    }

    .header-controls {
        flex-wrap: wrap;
    }

    .mode-selector {
        flex-wrap: wrap;
    }

    .mode-btn {
        min-width: 200px;
    }

    .game-layout {
        flex-direction: column;
        align-items: center;
    }
    .panel {
        width: 100%;
        max-width: 300px;
        flex-direction: row;
        justify-content: space-between;
    }
    .touch-controls {
        display: flex;
    }
}

@media (max-width: 520px) {
    #gameContainer {
        padding: 8px;
        gap: 10px;
    }

    .game-header {
        padding: 10px 12px;
    }

    .glitch-title {
        font-size: clamp(18px, 7vw, 24px);
        letter-spacing: 1px;
    }

    .subtitle {
        font-size: 11px;
    }

    .header-controls {
        width: 100%;
        gap: 6px;
    }

    .header-controls .cyber-btn {
        flex: 1 1 30%;
        padding-inline: 6px;
        white-space: nowrap;
    }

    .mode-selector {
        flex-direction: column;
        gap: 7px;
    }

    .mode-btn {
        min-width: 0;
        width: 100%;
        padding: 8px 12px;
    }

    .mode-btn .mode-icon {
        font-size: 20px;
    }

    .boss-bar {
        gap: 8px;
        padding: 8px 10px;
    }

    .boss-avatar {
        font-size: 24px;
    }

    .boss-header {
        gap: 8px;
        font-size: 10px;
    }

    .panel {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        max-width: 304px;
        gap: 8px;
    }

    .cyber-card {
        min-width: 0;
        padding: 10px;
    }

    .canvas-box {
        padding: 4px;
        overflow: hidden;
    }

    .panel canvas {
        max-width: 100%;
        height: auto;
    }

    .touch-controls {
        margin-top: 0;
        gap: 7px;
    }

    .touch-row {
        gap: 6px;
    }

    .touch-btn {
        min-width: 0;
        height: 48px;
        padding: 4px;
        font-size: 13px;
    }

    #overlayTitle {
        font-size: 20px;
    }
}

@media (max-width: 350px) {
    .header-controls .cyber-btn {
        flex-basis: 100%;
    }

    .panel {
        grid-template-columns: 1fr;
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    #gameContainer {
        padding-block: 6px;
    }

    .game-header,
    .mode-selector,
    .panel {
        scroll-margin-top: 6px;
    }
}

@media (hover: none) and (pointer: coarse) {
    .touch-controls {
        display: flex;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
