/**
 * Boomfection - Main Stylesheet
 * @copyright reDim GmbH | @link https://www.redim.de | @contact team@redim.de
 */

/* ============================================================================
   CSS VARIABLES / DESIGN TOKENS
   ============================================================================ */

:root {
    /* Colors - Primary */
    --color-primary: #ff8c32;
    --color-primary-dark: #e07020;
    --color-primary-light: #ffaa55;
    --color-primary-glow: rgba(255, 140, 50, 0.4);

    /* Colors - Background */
    --color-bg-dark: #0a0a0f;
    --color-bg-medium: #1a1a2e;
    --color-bg-light: #2a2a3a;
    --color-bg-panel: rgba(15, 15, 25, 0.95);

    /* Colors - Text */
    --color-text: #e0e0e0;
    --color-text-muted: #888888;
    --color-text-dark: #666666;

    /* Colors - Status */
    --color-success: #64c864;
    --color-warning: #ffc832;
    --color-error: #ff5050;
    --color-info: #64c8ff;

    /* Colors - Players */
    --color-player-red: #e63946;
    --color-player-blue: #4361ee;
    --color-player-green: #2a9d8f;
    --color-player-yellow: #f4a261;
    --color-player-purple: #9b5de5;
    --color-player-cyan: #00b4d8;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-round: 50%;
    --radius-pill: 9999px;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px var(--color-primary-glow);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;

    /* Typography */
    --font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'Fira Code', 'Consolas', monospace;

    /* Z-Index */
    --z-base: 1;
    --z-dropdown: 100;
    --z-modal: 1000;
    --z-toast: 2000;
}

/* ============================================================================
   RESET & BASE
   ============================================================================ */

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    background: linear-gradient(135deg, var(--color-bg-dark) 0%, var(--color-bg-medium) 50%, var(--color-bg-dark) 100%);
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.5;
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================================================
   TYPOGRAPHY
   ============================================================================ */

h1, h2, h3, h4 {
    color: var(--color-primary);
    font-weight: 600;
    line-height: 1.2;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1rem; }

.text-muted { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-error { color: var(--color-error); }
.text-center { text-align: center; }

/* ============================================================================
   LAYOUT
   ============================================================================ */

#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

#canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;
}

canvas:active {
    cursor: grabbing;
}

/* ============================================================================
   PANELS
   ============================================================================ */

.panel {
    position: absolute;
    background: var(--color-bg-panel);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 140, 50, 0.3);
    border-radius: var(--radius-xl);
    padding: var(--space-lg);
    box-shadow: var(--shadow-lg);
}

.panel.hidden {
    display: none !important;
}

.panel-header {
    margin-bottom: var(--space-lg);
}

.panel-header h2 {
    margin-bottom: var(--space-xs);
}

.panel-header .subtitle {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Panel Positions */
.panel-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.panel-top-left {
    top: var(--space-lg);
    left: var(--space-lg);
}

.panel-top-right {
    top: var(--space-lg);
    right: var(--space-lg);
}

.panel-bottom-left {
    bottom: var(--space-lg);
    left: var(--space-lg);
}

.panel-bottom-right {
    bottom: var(--space-lg);
    right: var(--space-lg);
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: linear-gradient(135deg, #3a3a5a 0%, #2a2a4a 100%);
    color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) {
    background: linear-gradient(135deg, #4a4a6a 0%, #3a3a5a 100%);
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-ghost:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.05);
    color: var(--color-text);
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-sm {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
}

.btn-lg {
    padding: var(--space-lg) var(--space-xl);
    font-size: 1.125rem;
}

/* ============================================================================
   FORMS
   ============================================================================ */

.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.form-control {
    width: 100%;
    padding: var(--space-md);
    background: var(--color-bg-light);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    color: var(--color-text);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(255, 140, 50, 0.1);
}

.form-control::placeholder {
    color: var(--color-text-dark);
}

.form-row {
    display: flex;
    gap: var(--space-md);
}

.form-row > * {
    flex: 1;
}

/* Checkbox */
.checkbox {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
}

.checkbox input {
    width: 18px;
    height: 18px;
    accent-color: var(--color-primary);
}

/* ============================================================================
   COLOR PICKER
   ============================================================================ */

.color-picker {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.color-option {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-round);
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform var(--transition-fast), border-color var(--transition-fast);
    position: relative;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: #fff;
}

.color-option.selected::after {
    content: '';
    position: absolute;
    inset: -6px;
    border: 2px solid var(--color-primary);
    border-radius: var(--radius-round);
    animation: pulse-ring 1.5s ease infinite;
}

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

/* ============================================================================
   VIRUS PICKER
   ============================================================================ */

.virus-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
}

.virus-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-md);
    background: rgba(40, 40, 60, 0.3);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.virus-option:hover {
    background: rgba(50, 50, 70, 0.5);
    transform: translateY(-2px);
}

.virus-option.selected {
    border-color: var(--color-primary);
    background: rgba(255, 140, 50, 0.1);
}

.virus-option .virus-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.virus-option .virus-name {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-align: center;
}

.virus-option.selected .virus-name {
    color: var(--color-primary);
}

/* ============================================================================
   GAME CODE DISPLAY
   ============================================================================ */

.game-code {
    font-family: var(--font-mono);
    font-size: 2.5rem;
    font-weight: bold;
    letter-spacing: 6px;
    text-align: center;
    color: var(--color-primary);
    padding: var(--space-md);
    background: rgba(255, 140, 50, 0.1);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-lg);
    user-select: all;
}

.game-code-input {
    text-transform: uppercase;
    letter-spacing: 4px;
    text-align: center;
    font-size: 1.5rem;
    font-family: var(--font-mono);
}

/* ============================================================================
   PLAYER LIST
   ============================================================================ */

.player-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.player-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: rgba(40, 40, 60, 0.3);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.player-item:hover {
    background: rgba(50, 50, 70, 0.4);
}

.player-item.current {
    border: 1px solid var(--color-primary);
    background: rgba(255, 140, 50, 0.1);
}

.player-item.eliminated {
    opacity: 0.4;
}

.player-item.eliminated .player-name {
    text-decoration: line-through;
}

.player-item.disconnected {
    opacity: 0.5;
}

.player-color {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-round);
    flex-shrink: 0;
}

.player-name {
    flex: 1;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-stats {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.player-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: var(--color-primary);
    color: #fff;
    text-transform: uppercase;
    font-weight: 600;
}

/* ============================================================================
   CURRENT TURN INDICATOR
   ============================================================================ */

.turn-indicator {
    padding: var(--space-md);
    background: rgba(255, 140, 50, 0.15);
    border-radius: var(--radius-lg);
    text-align: center;
    margin-bottom: var(--space-md);
}

.turn-indicator .label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-xs);
}

.turn-indicator .name {
    font-size: 1.3rem;
    font-weight: 600;
}

.turn-indicator.my-turn {
    background: rgba(100, 200, 100, 0.15);
    border: 1px solid rgba(100, 200, 100, 0.3);
    animation: pulse-glow 2s ease infinite;
}

.turn-indicator .placement-hint {
    margin-top: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: rgba(100, 200, 255, 0.2);
    border: 1px solid rgba(100, 200, 255, 0.4);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    color: var(--color-info);
    animation: pulse-glow 1.5s ease infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 10px rgba(100, 200, 100, 0.2); }
    50% { box-shadow: 0 0 20px rgba(100, 200, 100, 0.4); }
}

/* ============================================================================
   CHAT
   ============================================================================ */

.chat-container {
    display: flex;
    flex-direction: column;
    height: 280px;
    background: var(--color-bg-panel);
    border: 1px solid rgba(255, 140, 50, 0.2);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
}

.chat-message {
    margin-bottom: var(--space-sm);
    font-size: 0.85rem;
    line-height: 1.4;
}

.chat-message .sender {
    font-weight: 600;
}

.chat-message .text {
    color: var(--color-text-muted);
}

.chat-message.system {
    color: var(--color-primary);
    font-style: italic;
}

.chat-input-container {
    display: flex;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-input-container input {
    flex: 1;
    padding: var(--space-md);
    background: rgba(30, 30, 40, 0.8);
    border: none;
    color: var(--color-text);
    font-size: 0.9rem;
}

.chat-input-container input:focus {
    outline: none;
    background: rgba(40, 40, 50, 0.9);
}

.chat-input-container button {
    padding: var(--space-md) var(--space-lg);
    background: var(--color-primary);
    border: none;
    color: #fff;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-input-container button:hover {
    background: var(--color-primary-dark);
}

/* ============================================================================
   GAME LIST
   ============================================================================ */

.games-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-height: 400px;
    overflow-y: auto;
}

.game-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    background: rgba(40, 40, 60, 0.5);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.game-list-item:hover {
    background: rgba(60, 60, 80, 0.6);
}

.game-list-item .info {
    flex: 1;
}

.game-list-item .host {
    font-weight: 600;
    margin-bottom: 2px;
}

.game-list-item .meta {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.game-list-item .join-btn {
    padding: var(--space-sm) var(--space-md);
    background: var(--color-primary);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
}

.no-games {
    text-align: center;
    color: var(--color-text-dark);
    padding: var(--space-xxl);
}

/* ============================================================================
   CONNECTION STATUS
   ============================================================================ */

.connection-status {
    position: fixed;
    top: var(--space-md);
    right: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    z-index: var(--z-toast);
    transition: all var(--transition-normal);
}

.connection-status.connected {
    background: rgba(100, 200, 100, 0.2);
    color: var(--color-success);
    border: 1px solid rgba(100, 200, 100, 0.4);
}

.connection-status.disconnected {
    background: rgba(255, 80, 80, 0.2);
    color: var(--color-error);
    border: 1px solid rgba(255, 80, 80, 0.4);
}

.connection-status.connecting {
    background: rgba(255, 200, 50, 0.2);
    color: var(--color-warning);
    border: 1px solid rgba(255, 200, 50, 0.4);
}

/* ============================================================================
   ROUND INDICATOR
   ============================================================================ */

.round-indicator {
    position: absolute;
    top: var(--space-lg);
    right: var(--space-lg);
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-bg-panel);
    border-radius: var(--radius-pill);
    font-size: 0.9rem;
    border: 1px solid rgba(255, 140, 50, 0.2);
}

/* ============================================================================
   WINNER OVERLAY
   ============================================================================ */

.winner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    animation: fadeIn 0.5s ease;
}

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

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

.winner-content {
    text-align: center;
    animation: scaleIn 0.5s ease 0.2s both;
}

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

.winner-content h1 {
    font-size: 3.5rem;
    margin-bottom: var(--space-lg);
    text-shadow: 0 0 30px var(--color-primary-glow);
}

.winner-content .winner-name {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: var(--space-xl);
}

.winner-content .stats {
    display: flex;
    justify-content: center;
    gap: var(--space-xl);
    margin-bottom: var(--space-xl);
    color: var(--color-text-muted);
}

.winner-content .stat {
    text-align: center;
}

.winner-content .stat-value {
    font-size: 2rem;
    font-weight: 600;
    color: var(--color-text);
}

.winner-content .stat-label {
    font-size: 0.85rem;
}

/* ============================================================================
   TOOLTIP
   ============================================================================ */

.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 140, 50, 0.5);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    font-size: 0.85rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: var(--z-dropdown);
    max-width: 200px;
}

.tooltip.visible {
    opacity: 1;
}

.tooltip-title {
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: var(--space-xs);
}

.tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: var(--space-md);
}

.tooltip-label {
    color: var(--color-text-muted);
}

/* ============================================================================
   LOADING SPINNER
   ============================================================================ */

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 140, 50, 0.2);
    border-top-color: var(--color-primary);
    border-radius: var(--radius-round);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    padding: var(--space-xxl);
    color: var(--color-text-muted);
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
    :root {
        --space-lg: 16px;
        --space-xl: 24px;
    }

    .panel {
        padding: var(--space-md);
        border-radius: var(--radius-lg);
    }

    .panel-center {
        width: calc(100% - 32px) !important;
        max-width: 400px;
    }

    .panel-top-left,
    .panel-bottom-left {
        left: var(--space-md);
        right: var(--space-md);
        width: auto !important;
    }

    h1 { font-size: 2rem; }
    h2 { font-size: 1.25rem; }

    .game-code {
        font-size: 1.8rem;
        letter-spacing: 4px;
    }

    .btn {
        padding: var(--space-md);
    }

    .color-option {
        width: 36px;
        height: 36px;
    }

    .form-row {
        flex-direction: column;
    }

    .winner-content h1 {
        font-size: 2.5rem;
    }

    .winner-content .winner-name {
        font-size: 1.8rem;
    }

    .chat-container {
        height: 200px;
    }

    .round-indicator {
        top: var(--space-md);
        right: var(--space-md);
        font-size: 0.8rem;
        padding: var(--space-xs) var(--space-md);
    }
}

@media (max-width: 480px) {
    .panel-top-left {
        top: auto;
        bottom: var(--space-md);
    }

    .connection-status {
        font-size: 0.65rem;
        padding: var(--space-xs) var(--space-sm);
    }

    .virus-picker {
        grid-template-columns: repeat(2, 1fr);
    }

    .virus-option {
        padding: var(--space-sm);
    }

    .virus-option .virus-icon {
        font-size: 1.2rem;
    }

    .player-list {
        max-height: 150px;
        overflow-y: auto;
    }

    .turn-indicator .name {
        font-size: 1.1rem;
    }
}

/* Landscape mobile optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .panel-center {
        max-height: 90vh;
        overflow-y: auto;
    }

    .panel-header {
        margin-bottom: var(--space-md);
    }

    .panel-header h1 {
        font-size: 1.5rem;
    }

    .form-group {
        margin-bottom: var(--space-sm);
    }

    .game-code {
        font-size: 1.5rem;
        padding: var(--space-sm);
        margin-bottom: var(--space-md);
    }
}

/* Touch-friendly targets */
@media (pointer: coarse) {
    .btn {
        min-height: 44px;
    }

    .color-option {
        width: 44px;
        height: 44px;
    }

    .virus-option {
        min-height: 60px;
    }

    .quickchat-btn {
        min-height: 40px;
        min-width: 80px;
    }

    .chat-input-container input {
        font-size: 16px; /* Prevents iOS zoom */
    }

    .form-control {
        font-size: 16px; /* Prevents iOS zoom */
        min-height: 44px;
    }
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

.animate-fade-in {
    animation: fadeIn 0.3s ease;
}

.animate-slide-up {
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-bounce {
    animation: bounce 0.5s ease;
}

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

/* ============================================================================
   UTILITIES
   ============================================================================ */

.hidden { display: none !important; }
.invisible { visibility: hidden; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.flex-wrap { flex-wrap: wrap; }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.w-full { width: 100%; }
