/* ============ Game Hub - Shared Styles ============ */
:root {
    --bg: #0a0e27;
    --bg-2: #151a3a;
    --card: #1f2547;
    --card-hover: #2a3158;
    --accent: #7c4dff;
    --accent-2: #00d4ff;
    --accent-3: #ff4d8d;
    --text: #e8eaf6;
    --text-dim: #9fa8da;
    --border: #2a3158;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
    --p1: #00d4ff;
    --p2: #ff4d8d;
    --radius: 14px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px rgba(124, 77, 255, 0.3);
}

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

html, body {
    font-family: 'Vazirmatn', 'Tahoma', 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

body {
    background-image:
        radial-gradient(circle at 20% 10%, rgba(124, 77, 255, 0.15), transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(0, 212, 255, 0.1), transparent 40%),
        linear-gradient(135deg, var(--bg) 0%, var(--bg-2) 100%);
    background-attachment: fixed;
}

/* ============ Header ============ */
.hub-header {
    background: rgba(15, 18, 50, 0.7);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 16px 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.hub-header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.hub-logo {
    font-size: 22px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-2), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 10px;
}

.hub-logo-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-3));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: var(--shadow-glow);
}

.hub-back {
    color: var(--text-dim);
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: all 0.2s;
    font-size: 14px;
}

.hub-back:hover {
    color: var(--text);
    border-color: var(--accent);
    background: rgba(124, 77, 255, 0.1);
}

/* ============ Container ============ */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* ============ Hero ============ */
.hero {
    text-align: center;
    padding: 60px 20px 40px;
}

.hero h1 {
    font-size: clamp(32px, 5vw, 56px);
    font-weight: 900;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #fff 0%, var(--accent-2) 50%, var(--accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
}

.hero p {
    font-size: 18px;
    color: var(--text-dim);
    max-width: 600px;
    margin: 0 auto;
}

/* ============ Game Grid ============ */
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 40px;
}

.game-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    text-decoration: none;
    color: var(--text);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    cursor: pointer;
    display: block;
}

.game-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-2), var(--accent), var(--accent-3));
    opacity: 0;
    transition: opacity 0.3s;
}

.game-card:hover {
    transform: translateY(-4px);
    background: var(--card-hover);
    border-color: var(--accent);
    box-shadow: var(--shadow), var(--shadow-glow);
}

.game-card:hover::before {
    opacity: 1;
}

.game-card-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--accent), var(--accent-3));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin-bottom: 16px;
    box-shadow: 0 4px 16px rgba(124, 77, 255, 0.3);
}

.game-card h3 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
}

.game-card p {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 12px;
}

.game-card-tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    background: rgba(0, 212, 255, 0.15);
    color: var(--accent-2);
    font-size: 12px;
    font-weight: 600;
}

/* ============ Lobby ============ */
.lobby {
    max-width: 600px;
    margin: 40px auto;
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.lobby h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 24px;
}

.lobby-tabs {
    display: flex;
    gap: 8px;
    background: var(--bg-2);
    padding: 6px;
    border-radius: 10px;
    margin-bottom: 24px;
}

.lobby-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
}

.lobby-tab.active {
    background: var(--accent);
    color: white;
}

.lobby-panel {
    display: none;
}

.lobby-panel.active {
    display: block;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--text-dim);
}

.form-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.15);
}

.room-code-input {
    text-align: center;
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 6px;
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--accent), var(--accent-3));
    color: white;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    box-shadow: 0 4px 16px rgba(124, 77, 255, 0.3);
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(124, 77, 255, 0.4);
}

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

.btn-secondary {
    background: var(--bg-2);
    border: 1px solid var(--border);
    box-shadow: none;
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--accent);
    background: rgba(124, 77, 255, 0.1);
}

/* ============ Game Layout ============ */
.game-page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 16px 20px;
}

.game-info-bar {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.room-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.room-info .label {
    color: var(--text-dim);
}

.room-info .code {
    background: var(--bg-2);
    padding: 4px 10px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    color: var(--accent-2);
    letter-spacing: 2px;
}

.player-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    background: var(--bg-2);
    font-size: 13px;
    font-weight: 600;
}

.player-pill.p1 { border: 2px solid var(--p1); color: var(--p1); }
.player-pill.p2 { border: 2px solid var(--p2); color: var(--p2); }

.player-pill .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.player-pill.offline .dot {
    background: #666;
    opacity: 0.4;
}

.player-pill.active {
    background: rgba(124, 77, 255, 0.2);
    box-shadow: 0 0 12px rgba(124, 77, 255, 0.4);
}

/* ============ Chat ============ */
.chat-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 16px;
}

.chat-header {
    font-weight: 700;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-dim);
}

.chat-messages {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 10px;
    padding: 6px;
    background: var(--bg-2);
    border-radius: 8px;
    min-height: 80px;
}

.chat-msg {
    padding: 6px 10px;
    margin-bottom: 4px;
    border-radius: 6px;
    font-size: 13px;
    word-wrap: break-word;
}

.chat-msg.p1 { background: rgba(0, 212, 255, 0.1); border-right: 3px solid var(--p1); }
.chat-msg.p2 { background: rgba(255, 77, 141, 0.1); border-right: 3px solid var(--p2); }
.chat-msg .name { font-weight: 700; margin-left: 6px; }

.chat-input-row {
    display: flex;
    gap: 8px;
}

.chat-input-row input {
    flex: 1;
    padding: 10px 12px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
}

.chat-input-row input:focus { outline: none; border-color: var(--accent); }

.chat-input-row button {
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
}

/* ============ Status / Modal ============ */
.status-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.status-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.status-card .big-icon {
    font-size: 56px;
    margin-bottom: 12px;
}

.status-card h2 {
    margin-bottom: 8px;
    font-size: 22px;
}

.status-card p {
    color: var(--text-dim);
    margin-bottom: 20px;
}

.status-card .room-share {
    background: var(--bg-2);
    padding: 16px;
    border-radius: 10px;
    margin: 16px 0;
}

.status-card .room-share .label {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.status-card .room-share .code-big {
    font-size: 36px;
    font-weight: 900;
    font-family: 'Courier New', monospace;
    color: var(--accent-2);
    letter-spacing: 6px;
    margin: 8px 0;
}

.status-card .room-share .link {
    word-break: break-all;
    font-size: 11px;
    color: var(--text-dim);
    background: rgba(0,0,0,0.3);
    padding: 6px 8px;
    border-radius: 6px;
    font-family: monospace;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg-2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.pulse { animation: pulse 1.5s ease-in-out infinite; }

/* ============ Toast ============ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card);
    border: 1px solid var(--accent);
    color: var(--text);
    padding: 12px 24px;
    border-radius: 10px;
    z-index: 2000;
    box-shadow: var(--shadow);
    animation: slideUp 0.3s ease-out;
    max-width: 90%;
}

@keyframes slideUp {
    from { transform: translate(-50%, 100%); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

/* ============ Responsive ============ */
@media (max-width: 600px) {
    .container { padding: 12px; }
    .hero { padding: 24px 12px 16px; }
    .hero h1 { font-size: 28px; }
    .hero p { font-size: 15px; }
    .lobby { padding: 16px; }
    .game-info-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 10px 12px;
        gap: 8px;
    }
    .room-info { justify-content: space-between; font-size: 13px; }
    .info-left, .info-right {
        justify-content: center;
        gap: 8px;
        font-size: 13px;
    }
    .player-pill { padding: 4px 10px; font-size: 12px; }
    .hub-header { padding: 12px 14px; }
    .hub-header-inner { gap: 8px; flex-wrap: wrap; }
    .hub-logo { font-size: 18px; }
    .hub-logo-icon { width: 32px; height: 32px; font-size: 18px; }
    .hub-back { padding: 6px 10px; font-size: 13px; }
    .game-grid { grid-template-columns: 1fr; gap: 12px; }
    .game-card { padding: 16px; }
    .game-card-icon { width: 48px; height: 48px; font-size: 24px; }
    .game-card h3 { font-size: 18px; }
    .lobby-modal { padding: 20px; margin: 20px auto; }
    .room-code-input { font-size: 22px; letter-spacing: 4px; }
    .btn { padding: 14px 20px; font-size: 15px; }
    .game-wrap { padding: 10px 12px 30px; }
    .game-title { font-size: 22px; }
    .turn-indicator { font-size: 14px; padding: 10px; }
    .chat-messages { max-height: 160px; }
    .toast { font-size: 13px; padding: 10px 16px; bottom: 16px; }
    .waiting-card { padding: 24px; }
    .waiting-card .room-share .code-big { font-size: 32px; letter-spacing: 6px; }
    .modal-card { padding: 22px; }
    .modal-card .big-icon { font-size: 48px; }
}

/* Mobile touch optimization */
@media (max-width: 600px) {
    button, .btn, .game-card, .form-input, [onclick] {
        touch-action: manipulation;
    }
    /* Larger tap targets */
    .btn-icon { padding: 8px 12px; min-height: 36px; }
    .lobby-tab { padding: 12px 8px; min-height: 40px; }
    .connect4-col-btn { min-height: 36px; min-width: 36px; }
    /* Prevent text selection on game elements */
    .gomoku-cell, .connect4-cell, .bs-cell, .memory-card, .draw-color, .draw-size button {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
}

/* Tablet adjustments */
@media (min-width: 601px) and (max-width: 900px) {
    .game-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============ Utilities ============ */
.text-center { text-align: center; }
.text-dim { color: var(--text-dim); }
.text-p1 { color: var(--p1); }
.text-p2 { color: var(--p2); }
.hidden { display: none !important; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
