/* frontend/style.css */

:root {
    --bg-main: #0f172a;
    --bg-panel: #1e293b;
    --board-bg: #334155;
    --cell-bg: #475569;
    --cell-hover: #526075;
    --cell-highlight: #10b981; 
    
    --p1-color: #38bdf8; 
    --p2-color: #f43f5e; 
    --wall-color: #fbbf24; 
    --wall-hover: rgba(251, 191, 36, 0.5);
    
    --accent-green: #10b981;
    --accent-green-glow: rgba(16, 185, 129, 0.4);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    /* Default Desktop Scale */
    --cell-size: 55px;
    --wall-thickness: 16px;
    
    --board-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Mobile Responsiveness: Scaling & Touch Targets --- */
.btn, .icon-btn, .styled-select, .form-control {
    min-height: 44px; 
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 600px) {
    :root {
        --cell-size: 32px;
        --wall-thickness: 8px;
    }
    .board-container { padding: 1rem; }
    .pawn { width: 75%; height: 75%; }
}

@media (min-width: 601px) and (max-width: 768px) {
    :root {
        --cell-size: 40px;
        --wall-thickness: 10px;
    }
}

/* --- SPA Screen Transitions --- */
.screen-fade {
    transition: opacity 0.4s ease-in-out;
}

/* --- Lobby Styles --- */
#lobby-screen {
    position: relative;
    width: 100%;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding-top: 4rem; 
}

.lobby-title {
    font-size: 4.5rem;
    font-weight: 900;
    letter-spacing: 4px;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, var(--p1-color), var(--p2-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 2;
}

.live-stats {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-bottom: 2.5rem;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 2;
}

.live-dot {
    width: 10px;
    height: 10px;
    background-color: var(--accent-green);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--accent-green);
    animation: pulse-dot 1.5s infinite alternate ease-in-out;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    width: 100%;
    max-width: 340px;
    z-index: 2;
}

.menu-buttons .btn {
    width: 100%;
    padding: 1.2rem;
    font-size: 1.1rem;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.menu-buttons .btn i {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

/* --- Twin Side Panels (Glassmorphism) --- */
.side-panel {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 280px;
    background: rgba(30, 41, 59, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    z-index: 1;
}

.left-panel { left: 2.5rem; }
.right-panel { right: 2.5rem; }

.side-panel h3 {
    color: var(--p1-color);
    margin-bottom: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.2rem;
}

.leaderboard-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.leaderboard-list li {
    display: flex;
    align-items: center;
    font-size: 0.95rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.leaderboard-list li.empty-slot {
    color: var(--text-muted);
    justify-content: center;
    border: none;
}

.leaderboard-list .rank {
    font-weight: bold;
    color: var(--text-muted);
    width: 24px;
}

.leaderboard-list .name {
    flex-grow: 1;
    color: var(--text-main);
}

.leaderboard-list .score {
    color: var(--wall-color);
    font-weight: bold;
}

.rooms-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-main);
    min-width: 220px;
}

.rooms-table th, .rooms-table td {
    padding: 0.6rem 0.2rem;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 0.9rem;
    white-space: nowrap;
}

.rooms-table th { color: var(--text-muted); font-weight: 500; }
.rooms-table tbody tr:hover { background: rgba(255,255,255,0.02); }

.btn.small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

/* Mobile Lobby Stacking Logic */
@media (max-width: 768px) {
    #lobby-screen {
        padding-top: 5rem;
        gap: 1.5rem;
    }
    .lobby-title { order: 1; margin-bottom: 0; font-size: 3.5rem; }
    .live-stats { order: 2; margin-bottom: 0; }
    .menu-buttons { order: 3; margin-bottom: 1rem; }
    
    .side-panel {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        transform: none;
        width: 100%;
        max-width: 340px;
        margin: 0 auto;
    }
    .left-panel { order: 4; }
    .right-panel { order: 5; }
}

/* --- Online Hub Screen (Live Lobby - Matched Theme) --- */
#online-hub-screen {
    width: 100%;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 4rem;
    min-height: 100vh;
}

.hub-container {
    width: 100%;
    max-width: 900px;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.hub-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.hub-main-title {
    font-size: 2.5rem;
    font-weight: 900;
    letter-spacing: 2px;
    background: linear-gradient(to right, var(--p1-color), var(--p2-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin: 0 0 1.5rem 0;
    text-align: left;
}

.hub-glass-panel {
    background: rgba(30, 41, 59, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    margin-bottom: 1.5rem;
    width: 100%;
}

.hub-subtitle-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.8rem;
    margin-bottom: 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.hub-rooms-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-main);
    min-width: 400px;
}

.hub-rooms-table th, .hub-rooms-table td {
    padding: 1.2rem 1rem;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    white-space: nowrap;
}

.hub-rooms-table th {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
}

.hub-rooms-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.live-indicator {
    color: var(--accent-green);
    font-size: 0.5rem;
    margin-right: 8px;
    vertical-align: middle;
}

.hub-bottom-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0;
}

.room-code-input {
    display: flex;
    align-items: center;
    background-color: var(--bg-main);
    border: 1px solid var(--board-bg);
    border-radius: 8px;
    padding: 0.75rem 1.2rem;
    flex-grow: 1;
    transition: border-color 0.2s;
}

.room-code-input i {
    color: var(--text-muted);
    margin-right: 0.8rem;
}

.room-code-input input {
    background: transparent;
    border: none;
    color: white;
    outline: none;
    width: 100%;
    font-size: 1rem;
}

.room-code-input:focus-within {
    border-color: var(--p1-color);
}

/* Mobile Hub Bottom Bar Stacking */
@media (max-width: 600px) {
    .hub-bottom-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .hub-top-bar .btn {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
}

/* --- Wall Dispenser (Mobile D&D) --- */
.wall-dispenser {
    display: none; 
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

@media (max-width: 768px) {
    .wall-dispenser {
        display: flex;
        margin-top: 2rem;
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }
}

.wall-dispenser p {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

.dispenser-items {
    display: flex;
    gap: 4rem; 
    align-items: center;
    justify-content: center;
    background: rgba(30, 41, 59, 0.65);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 1.5rem 3rem; 
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.drag-wall {
    position: relative; 
    background-color: var(--wall-color);
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
    border-radius: 2px;
    cursor: grab;
    touch-action: none; 
    -webkit-user-select: none;
    user-select: none;
}

.drag-wall::before {
    content: '';
    position: absolute;
    top: -25px;
    bottom: -25px;
    left: -25px;
    right: -25px;
    z-index: 10;
}

.drag-wall:active {
    cursor: grabbing;
}

.h-drag {
    width: calc(var(--cell-size) * 2 + var(--wall-thickness));
    height: var(--wall-thickness);
}

.v-drag {
    width: var(--wall-thickness);
    height: calc(var(--cell-size) * 2 + var(--wall-thickness));
}

.dragging {
    position: fixed;
    pointer-events: none;
    z-index: 9999;
    transform: translate(-50%, -50%);
    opacity: 0.8;
    transition: opacity 0.2s;
}

body.is-dragging .cell,
body.is-dragging .pawn {
    pointer-events: none !important;
}

/* --- Toast Notifications --- */
#notification-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background-color: #ef4444; 
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    font-weight: 600;
    animation: slideDown 0.3s ease-out, fadeOut 0.5s ease-out 2.5s forwards;
}

@keyframes slideDown {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOut {
    to { opacity: 0; transform: translateY(-10px); }
}

/* --- Top Navigation --- */
.top-nav {
    width: 100%;
    padding: 1.5rem 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 50;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 1.8rem;
    cursor: pointer;
    transition: color 0.2s;
}

.icon-btn:hover { color: var(--p1-color); }

.nav-auth {
    display: flex;
    gap: 1rem;
}

.nav-login {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-main);
}

.nav-login:hover { background: var(--bg-panel); }

.nav-signup {
    background: var(--p1-color);
    color: var(--bg-main);
}

.nav-signup:hover { background: #0ea5e9; }

/* إظهار الأزرار بشكل مصغر في الهواتف بدلاً من إخفائها */
@media (max-width: 600px) {
    .nav-auth { 
        display: flex; 
        gap: 0.5rem; 
    }
    .nav-auth .btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
        min-height: 32px;
        border-radius: 6px;
    }
}

/* --- Sidebar & Overlay --- */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 90;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    background: var(--bg-panel);
    z-index: 100;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    box-shadow: 4px 0 15px rgba(0, 0, 0, 0.5);
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--board-bg);
    padding-bottom: 1rem;
}

.sidebar-links {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    flex-grow: 1;
}

.sidebar-links a {
    color: var(--text-main);
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: color 0.2s;
}

.sidebar-links a:hover { color: var(--p1-color); }

.sidebar-footer {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--board-bg);
}

.sidebar-footer a {
    color: var(--text-muted);
    font-size: 1.5rem;
    transition: color 0.2s, transform 0.2s;
}

.sidebar-footer a:hover {
    color: var(--text-main);
    transform: translateY(-2px);
}

/* --- Game Screen Core UI --- */
#game-screen {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.app-container {
    max-width: 800px;
    width: 100%;
    padding: 6rem 1rem 2rem; 
    display: flex;
    flex-direction: column;
    align-items: center;
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
}

h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 1px;
    background: linear-gradient(to right, var(--p1-color), var(--p2-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.controls-panel, .actions-panel {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.actions-panel { margin-bottom: 2rem; }

.btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    border-radius: 8px;
    border: none;
    outline: none;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn.primary {
    background-color: var(--p1-color);
    color: var(--bg-main);
}

.btn.primary:hover {
    background-color: #0ea5e9;
    transform: translateY(-2px);
}

.btn.secondary {
    background-color: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--board-bg);
}

.btn.secondary:hover:not(:disabled) {
    background-color: var(--board-bg);
    transform: translateY(-2px);
}

.btn.green-glow {
    background-color: var(--accent-green);
    color: var(--bg-main);
    box-shadow: 0 0 15px var(--accent-green-glow);
}

.btn.green-glow:hover {
    box-shadow: 0 0 25px rgba(16, 185, 129, 0.8);
    transform: translateY(-2px);
    background-color: #059669;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.hidden {
    display: none !important;
}

/* In-Game Difficulty Selector */
#in-game-diff-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

#in-game-diff-container label {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
}

.styled-select {
    background-color: var(--bg-panel);
    color: var(--text-main);
    border: 1px solid var(--board-bg);
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    border-radius: 8px;
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.styled-select.full-width {
    width: 100%;
}

.styled-select.small {
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
}

.status-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 650px;
    background: var(--bg-panel);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}

.player-card {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.player-name {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
}

.p1-card .player-name { color: var(--p1-color); }
.p2-card .player-name { color: var(--p2-color); }

.wall-count {
    background: var(--board-bg);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
}

.turn-display {
    text-align: center;
}

.turn-text {
    font-size: 1.25rem;
    font-weight: 800;
    transition: color 0.3s ease;
}

.board-container {
    position: relative;
    padding: 1.5rem;
    background-color: var(--board-bg);
    border-radius: 16px;
    box-shadow: var(--board-shadow);
}

.game-board {
    display: grid;
    grid-template-columns: repeat(8, var(--cell-size) var(--wall-thickness)) var(--cell-size);
    grid-template-rows: repeat(8, var(--cell-size) var(--wall-thickness)) var(--cell-size);
    gap: 0;
}

.cell {
    background-color: var(--cell-bg);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s ease;
    position: relative;
}

.cell.valid-move { cursor: pointer; }
.cell.valid-move:hover { background-color: var(--cell-hover); }
.cell.valid-move::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    background-color: var(--cell-highlight);
    border-radius: 50%;
    pointer-events: none;
    animation: pulse-dot 1.5s infinite alternate ease-in-out;
}

@keyframes pulse-dot {
    0% { transform: scale(0.8); opacity: 0.5; box-shadow: 0 0 5px var(--cell-highlight); }
    100% { transform: scale(1.1); opacity: 1; box-shadow: 0 0 15px var(--cell-highlight); }
}

.wall-slot {
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-radius: 2px;
}

.wall-slot.intersection { cursor: pointer; }

.wall-placed { 
    background-color: var(--wall-color) !important; 
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.4); 
    z-index: 2;
}

.wall-preview { background-color: var(--wall-hover) !important; }

.pawn {
    width: 60%;
    height: 60%;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 5;
}

@keyframes popIn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.pawn.p1 { background: radial-gradient(circle at 30% 30%, #7dd3fc, var(--p1-color)); }
.pawn.p2 { background: radial-gradient(circle at 30% 30%, #fda4af, var(--p2-color)); }

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--text-muted);
    border-top-color: var(--wall-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.rules-footer {
    margin-top: 3rem;
    padding: 1.5rem;
    background: var(--bg-panel);
    border-radius: 12px;
    width: 100%;
    max-width: 650px;
    color: var(--text-muted);
}

.rules-footer h3 {
    color: var(--text-main);
    margin-bottom: 0.75rem;
}
.rules-footer ul {
    padding-left: 1.5rem;
    line-height: 1.6;
}

/* --- Modal Styles --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--bg-panel);
    padding: 2.5rem 2rem;
    border-radius: 16px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transform: scale(1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative; 
}

@media (max-width: 600px) {
    .modal-content { padding: 1.5rem 1rem; }
}

.modal-overlay.hidden .modal-content { transform: scale(0.8); }

.modal-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--wall-color);
    color: var(--bg-main);
    font-size: 2.5rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
}

.modal-content h2 {
    margin-bottom: 1rem;
    color: var(--text-main);
}
.modal-content p {
    color: var(--text-muted);
    margin-bottom: 2rem;
    line-height: 1.5;
}
.modal-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

/* --- Form Styles --- */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    margin-top: 1.5rem;
}
.form-group {
    display: flex;
    flex-direction: column;
    text-align: left;
    gap: 0.5rem;
}
.form-group label {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}
.form-control {
    background-color: var(--bg-main);
    border: 1px solid var(--board-bg);
    color: var(--text-main);
    padding: 0.8rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--p1-color);
}
.close-modal-btn {
    position: absolute;
    top: 1.25rem;
    right: 1.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s;
}
.close-modal-btn:hover { color: var(--text-main); }
.full-width { width: 100%; }

/* --- In-Game Timers Styles --- */
.player-timer {
    font-family: monospace;
    font-size: 1.25rem;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    border: 1px solid transparent;
    transition: all 0.3s ease;
}
.player-timer.active {
    color: var(--accent-green);
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}
.player-timer.low {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    animation: pulse-low-time 1s infinite alternate;
}
@keyframes pulse-low-time {
    from { box-shadow: 0 0 5px rgba(239, 68, 68, 0.2); }
    to { box-shadow: 0 0 20px rgba(239, 68, 68, 0.7); }
}

/* --- Smart Board Flip System --- */
.game-board {
    transition: transform 0.5s ease;
}

.game-board.flipped {
    transform: rotate(180deg);
}

/* Counter-rotate pawns so lighting and pop-in animation look correct */
.game-board.flipped .pawn {
    animation: popInFlipped 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform: rotate(-180deg);
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

@keyframes popInFlipped {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    100% { transform: scale(1) rotate(-180deg); opacity: 1; }
}

/* Visually swap pawn colors when flipped so you are always Blue */
.game-board.flipped .pawn.p1 { 
    background: radial-gradient(circle at 30% 30%, #fda4af, var(--p2-color)); 
}

.game-board.flipped .pawn.p2 { 
    background: radial-gradient(circle at 30% 30%, #7dd3fc, var(--p1-color)); 
}
/* --- Mobile Table Fixes --- */
@media (max-width: 600px) {
    .hub-rooms-table, .rooms-table {
        min-width: 100%; 
    }
    
    .hub-rooms-table th, .hub-rooms-table td,
    .rooms-table th, .rooms-table td {
        padding: 0.6rem 0.2rem; 
        font-size: 0.75rem; 
        white-space: normal; 
        text-align: center;
    }
    .hub-rooms-table th:first-child, 
    .hub-rooms-table td:first-child {
        text-align: left;
    }
    .hub-rooms-table .btn, .rooms-table .btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.75rem;
        min-height: auto; 
    }

    .hub-rooms-table td span[style*="monospace"] {
        font-size: 0.8rem !important;
    }
}
/* --- Lobby Social Links --- */
.lobby-social-links {
    position: absolute;
    bottom: 2rem;
    display: flex;
    gap: 2rem;
    z-index: 2;
}

.social-icon {
    color: var(--text-muted);
    font-size: 1.8rem;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    justify-content: center;
    align-items: center;
    text-decoration: none;
}

.social-icon:hover {
    color: var(--p1-color);
    transform: translateY(-5px) scale(1.1);
    text-shadow: 0 10px 20px rgba(56, 189, 248, 0.4);
}


@media (max-width: 768px) {
    .lobby-social-links {
        position: relative;
        bottom: 0;
        margin-top: 2rem;
        order: 6; 
    }
}
/* --- Leaderboard Styles Upgrade --- */
.leaderboard-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 350px;
    overflow-y: auto;
    padding-right: 5px;
}

/* تخصيص شريط التمرير للوحة الصدارة */
.leaderboard-list::-webkit-scrollbar {
    width: 4px;
}
.leaderboard-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.leaderboard-list li {
    display: flex;
    align-items: center;
    font-size: 0.95rem;
    padding: 0.6rem 0.8rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 8px;
    border: 1px solid transparent;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.leaderboard-list li:hover:not(.empty-slot) {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(56, 189, 248, 0.3); /* لون اللاعب الأول الخفيف */
    transform: translateX(5px);
}

.leaderboard-list li.empty-slot {
    background: transparent;
    color: var(--text-muted);
    justify-content: center;
    border: none;
    padding-top: 1.5rem;
}

.leaderboard-list .rank {
    font-weight: 800;
    color: var(--text-muted);
    width: 28px;
    font-size: 1.1rem;
    display: flex;
    justify-content: center;
}

/* تأثير التوهج للميداليات (يعتمد على الألوان المضافة في الجافاسكريبت) */
.leaderboard-list .rank i {
    filter: drop-shadow(0 0 5px currentColor);
}

.leaderboard-list .name {
    flex-grow: 1;
    color: var(--text-main);
    margin-left: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-list .score {
    color: var(--p1-color);
    font-weight: 800;
    font-family: monospace;
    font-size: 1.1rem;
    background: rgba(56, 189, 248, 0.1);
    padding: 2px 8px;
    border-radius: 6px;
}
/* ================= INFO SCREENS (Rules, How to Play, FAQ) ================= */
.info-screen {
    width: 100%;
    min-height: 100vh;
    padding: 6rem 1rem 4rem;
    display: flex;
    justify-content: center;
    background-color: var(--bg-main);
    position: absolute;
    top: 0;
    left: 0;
    z-index: 40;
}

.info-container {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.info-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 1rem;
}

.info-header h2 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(to right, var(--p1-color), var(--text-main));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Rules Grid */
.rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.info-card {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--board-bg);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.info-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0,0,0,0.4);
    border-color: rgba(255,255,255,0.1);
}

.info-card.highlight-card {
    border: 1px solid var(--p2-color);
    background: linear-gradient(145deg, var(--bg-panel), rgba(244, 63, 94, 0.05));
}

.card-icon {
    font-size: 2.5rem;
    color: var(--p1-color);
    margin-bottom: 1rem;
}

.highlight-card .card-icon { color: var(--p2-color); }

.info-card h3 {
    margin-bottom: 0.8rem;
    color: var(--text-main);
    font-size: 1.25rem;
}

.info-card p {
    color: var(--text-muted);
    line-height: 1.6;
    font-size: 0.95rem;
}

/* How to Play Steps */
.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: 3rem;
}

.step-row {
    display: flex;
    align-items: center;
    gap: 3rem;
    background: var(--bg-panel);
    padding: 2.5rem;
    border-radius: 20px;
    border: 1px solid var(--board-bg);
}

.step-row.reverse {
    flex-direction: row-reverse;
}

.step-content {
    flex: 1;
}

.step-number {
    display: inline-block;
    background: rgba(56, 189, 248, 0.15);
    color: var(--p1-color);
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1rem;
}

.step-content h3 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
}

.step-content p {
    color: var(--text-muted);
    line-height: 1.7;
    font-size: 1.05rem;
}

/* CSS Mini-Boards for Instructions */
.step-visual {
    flex: 1;
    display: flex;
    justify-content: center;
}

.mini-board {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 12px;
    background: var(--board-bg);
    padding: 16px;
    border-radius: 12px;
    position: relative;
    box-shadow: var(--board-shadow);
}

.step-row:nth-child(3) .mini-board { grid-template-rows: repeat(3, 60px); grid-template-columns: 60px; } /* Vertical layout for jump */

.mc {
    background-color: var(--cell-bg);
    border-radius: 6px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.mc.valid-move::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background-color: var(--cell-highlight);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--cell-highlight);
}

.mc.goal-line {
    border-bottom: 3px solid var(--p1-color);
    background: rgba(56, 189, 248, 0.1);
}

.mw {
    position: absolute;
    background-color: var(--wall-color);
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
    border-radius: 2px;
    z-index: 5;
}
.mw.h-wall { height: 10px; }

/* FAQ Accordion */
.faq-container {
    background: var(--bg-panel);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--board-bg);
}

.faq-category {
    color: var(--p1-color);
    margin: 2rem 0 1rem;
    font-size: 1.1rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.faq-category:first-child { margin-top: 0; }

.faq-item {
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--board-bg);
}

.faq-item:last-of-type { border-bottom: none; margin-bottom: 0; }

.faq-item summary {
    padding: 1.2rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-main);
    transition: color 0.2s;
}

.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
    content: '\f067'; /* FontAwesome Plus */
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    color: var(--text-muted);
    transition: transform 0.3s;
}

.faq-item[open] summary { color: var(--p1-color); }
.faq-item[open] summary::after {
    content: '\f068'; /* FontAwesome Minus */
    transform: rotate(180deg);
}

.faq-answer {
    padding-bottom: 1.5rem;
    color: var(--text-muted);
    line-height: 1.6;
}

@media (max-width: 768px) {
    .step-row, .step-row.reverse { flex-direction: column; text-align: center; gap: 2rem; padding: 1.5rem; }
    .info-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
    .info-header h2 { font-size: 2rem; }
}
/* --- Legal Content Styles (ToS & Privacy) --- */
.legal-content {
    text-align: left;
    padding: 2.5rem;
}

.legal-content .last-updated {
    color: var(--p1-color);
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 2rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.legal-content h3 {
    color: var(--text-main);
    font-size: 1.3rem;
    margin-top: 2rem;
    margin-bottom: 0.8rem;
    border-bottom: 1px solid var(--board-bg);
    padding-bottom: 0.5rem;
}

.legal-content p {
    color: var(--text-muted);
    line-height: 1.7;
    font-size: 1rem;
    margin-bottom: 1rem;
}

@media (max-width: 768px) {
    .lobby-social-links {
        margin-bottom: 50px; 
    }
    
    #lobby-screen {
        padding-bottom: 40px; 
    }
}
/* =========================================
   Desktop Centered Layout & Zoom Controls
   ========================================= */
.desktop-only {
    display: none !important;
}

/* التفعيل على شاشات الكمبيوتر فقط للحفاظ على الهاتف كما هو */
@media (min-width: 901px) {
    .desktop-only { 
        display: inline-flex !important; 
        align-items: center; 
        justify-content: center; 
    }
    
    /* تقليل المسافة العلوية لرفع الإحصائيات لتكون ظاهرة دائماً */
    .app-container { 
        padding-top: 3rem; 
    }
    
    .board-container {
        /* الحجم الافتراضي 85% لضمان ظهور كل شيء على الشاشة */
        transform: scale(var(--board-scale, 0.85)); 
        /* نقطة التكبير من المنتصف العلوي حتى لا تغطي اللوحة على الإحصائيات */
        transform-origin: top center; 
        transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    }
}
/* إصلاح تداخل واجهة اللوبي في الشاشات المتوسطة (نصف الشاشة أو التابلت) */
@media (max-width: 1150px) {
    #lobby-screen {
        padding-top: 6rem;
        gap: 1.5rem;
        overflow-y: auto; /* السماح بالتمرير إذا كانت الشاشة قصيرة */
        padding-bottom: 3rem;
        justify-content: flex-start;
    }
    
    .lobby-title { order: 1; margin-bottom: 0; font-size: 3.2rem; }
    .live-stats { order: 2; margin-bottom: 0; }
    .menu-buttons { order: 3; margin-bottom: 1rem; }
    
    /* تحويل القوائم الجانبية إلى كتل عمودية أسفل الأزرار */
    .side-panel {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        transform: none;
        width: 100%;
        max-width: 380px; 
        margin: 0 auto;
    }
    
    .left-panel { order: 4; }
    .right-panel { order: 5; margin-top: 1rem; }

    .lobby-social-links {
        position: relative;
        bottom: auto;
        margin-top: 2rem;
        order: 6; 
    }
}