:root {
    /* Core Colors */
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --pvp-gradient: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    --spectator-bg: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);

    --text-color: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.7);

    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;

    /* Grid Specifics */
    --grid-cell-size: min(40px, 8vw);
    --grid-gap: 4px;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--primary-gradient);
    color: var(--text-color);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

/* Page Themes */
body.pvp-mode {
    background: var(--pvp-gradient);
}

body.spectator-mode {
    background: var(--spectator-bg);
    /* font-family: 'Courier New', monospace; - Removed to match app style */
    color: var(--text-color);
    /* Restored to white/default */
}

body.admin-mode {
    background: linear-gradient(135deg, #1e3a8a 0%, #991b1b 100%);
}

/* Typography */
h1,
h2,
h3 {
    margin-bottom: 0.5em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

h1 {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Layout & Containers */
.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 10px;
}

.main-content {
    display: grid;
    gap: 2rem;
    grid-template-columns: 1fr;
}

@media (min-width: 900px) {
    .main-content {
        grid-template-columns: 1fr 400px;
    }

    .main-content.pvp-lobby {
        grid-template-columns: 1fr 1fr;
    }
}

/* Glassmorphism Cards */
.card,
.info-panel,
.grid-container,
.leaderboard-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--glass-shadow);
    margin-bottom: 20px;
}

/* Game Grid Layout - Responsive & Accessible */
.grid-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: auto;
    width: 100%;
    max-width: 100%;
    min-height: 0;
    max-height: 600px;
}

.grid {
    display: grid;
    grid-template-columns: 30px repeat(10, minmax(30px, 1fr));
    grid-template-rows: 30px repeat(10, minmax(30px, 1fr));
    gap: var(--grid-gap);
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

/* Grid Cells */
.grid-cell,
.grid-label {
    aspect-ratio: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: bold;
}

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

.grid-cell {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Touch targets/A11y */
.grid-cell button {
    width: 100%;
    height: 100%;
    opacity: 0;
    /* Semantic click layer */
    cursor: pointer;
}

.grid-cell:hover,
.grid-cell:focus-within {
    transform: scale(1.05);
    background: rgba(255, 255, 255, 0.3);
    border-color: #fff;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Cell States */
.grid-cell.ship {
    background: rgba(16, 185, 129, 0.4);
    border-color: #10b981;
}

@keyframes healingPulse {
    0% {
        background-color: rgba(34, 197, 94, 0.4);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
        transform: scale(1);
    }

    50% {
        background-color: rgba(34, 197, 94, 0.8);
        box-shadow: 0 0 15px 5px rgba(34, 197, 94, 0.5);
        transform: scale(1.1);
    }

    100% {
        background-color: transparent;
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
        transform: scale(1);
    }
}

.grid-cell.healing {
    animation: healingPulse 2s ease-out;
    z-index: 20;
    position: relative;
}

.grid-cell.healing::after {
    content: '🛠️';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    pointer-events: none;
}


.grid-cell.hit {
    background: rgba(239, 68, 68, 0.6);
    border-color: #ef4444;
}

.grid-cell.miss {
    background: rgba(59, 130, 246, 0.4);
    border-color: #3b82f6;
}

.grid-cell.firing {
    animation: pulse 0.5s infinite;
    border-color: #fbbf24;
}

/* Spectator Overrides */
/* Spectator Overrides - Using standard grid styles */

.grids-wrapper {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (min-width: 900px) {
    .grids-wrapper {
        grid-template-columns: 1fr 1fr;
    }
}

.duel-info {
    display: flex;
    justify-content: space-around;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.player-stats {
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 8px;
    min-width: 200px;
}

.player-name {
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: var(--info);
}

.vs {
    font-size: 2rem;
    font-weight: 900;
    color: var(--warning);
}

.grid-title {
    text-align: center;
    font-size: 1.2rem;
    margin-bottom: 1rem;
    font-weight: bold;
}


body.spectator-mode .grid-cell.hit::after {
    content: '💥';
    font-size: 1.2rem;
}

body.spectator-mode .grid-cell.miss::after {
    content: '○';
}

/* UI Elements */
input[type="text"] {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    color: white;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

input[type="text"]:focus {
    border-color: var(--info);
}

button.btn,
.reset-btn,
.challenge-btn {
    width: 100%;
    padding: 12px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
    font-size: 1rem;
}

.reset-btn {
    background: var(--danger);
    color: white;
}

.challenge-btn {
    background: var(--success);
    color: white;
}

button:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

button:active {
    transform: translateY(0);
}

/* Leaderboard Podium */
.podium-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 15px;
    margin-bottom: 40px;
    height: 300px;
}

.podium-place {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding: 15px;
    border-radius: 12px 12px 0 0;
    backdrop-filter: blur(5px);
    width: 30%;
    max-width: 120px;
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: transform 0.3s;
}

.podium-place:hover {
    transform: translateY(-5px);
}

.podium-first {
    height: 100%;
    background: rgba(255, 215, 0, 0.3);
    border-color: #ffd700;
    z-index: 2;
}

.podium-second {
    height: 80%;
    background: rgba(192, 192, 192, 0.3);
    border-color: silver;
}

.podium-third {
    height: 60%;
    background: rgba(205, 127, 50, 0.3);
    border-color: #cd7f32;
}

/* Utilities */
.text-center {
    text-align: center;
}

.mb-4 {
    margin-bottom: 1.5rem;
}

.mt-4 {
    margin-top: 1.5rem;
}

.hidden {
    display: none;
}

/* --- Ship List --- */
.ship-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ship-item {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.health-bar {
    width: 60%;
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 5px;
}

.health-fill {
    height: 100%;
    background: linear-gradient(90deg, #10b981, #34d399);
    transition: width 0.3s ease;
}

/* --- Attack Log --- */
.attack-log {
    max-height: 250px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-right: 5px;
}

.log-entry {
    font-size: 0.9rem;
    padding: 8px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-left: 3px solid transparent;
}

.log-entry.hit {
    border-left-color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.log-entry.miss {
    border-left-color: var(--info);
    background: rgba(59, 130, 246, 0.1);
}

.log-entry.healing {
    border-left-color: var(--success);
    background: rgba(16, 185, 129, 0.1);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* --- Leaderboard List (Rank 4+) --- */
.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: rgba(255, 255, 255, 0.1);
    margin-bottom: 8px;
    border-radius: 10px;
    transition: transform 0.2s;
}

.leaderboard-entry:hover {
    transform: translateX(5px);
    background: rgba(255, 255, 255, 0.2);
}

.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    margin-right: 12px;
    font-weight: bold;
    font-size: 0.85rem;
}

/* --- PvP Components --- */
.player-list,
.pending-challenges,
.duel-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px;
    overflow-y: auto;
}

.player-item,
.challenge-item,
.duel-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.player-item:hover,
.duel-card:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(3px);
}

.challenge-item {
    border-left: 4px solid var(--warning);
    background: rgba(245, 158, 11, 0.1);
    flex-direction: column;
    align-items: stretch;
}

.challenge-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.challenge-actions button {
    flex: 1;
    padding: 8px;
    font-size: 0.9rem;
}

.duel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.duel-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
    border: 1px solid var(--glass-border);
}

.duel-status {
    margin-top: 10px;
    font-size: 0.9rem;
    padding: 4px 12px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.2);
}

/* --- Data Display Utilities --- */
.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.stat-box {
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 6px;
    text-align: center;
}

.stat-label {
    font-size: 0.85em;
    opacity: 0.8;
    margin-bottom: 5px;
}

.stat-value {
    font-size: 1.5em;
    font-weight: bold;
}

.empty-state {
    text-align: center;
    padding: 30px;
    opacity: 0.6;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.empty-state-icon {
    font-size: 2.5em;
}

/* --- Layout Utilities --- */
@media (min-width: 900px) {

    .col-span-full,
    .active-duels {
        grid-column: 1 / -1;
    }
}

/* Mobile Optimizations */
@media (max-width: 600px) {
    .container {
        padding: 10px;
    }

    h1 {
        font-size: 1.8rem;
    }

    .grid {
        gap: 2px;
    }

    .card {
        padding: 15px;
    }

    /* Ensure touch targets are distinct */
    .grid-cell {
        border-width: 0.5px;
    }

    .podium-container {
        height: 200px;
        gap: 5px;
    }

    .podium-place {
        padding: 10px 5px;
        font-size: 0.9rem;
    }

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

@keyframes pulse {
    0% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.7;
        transform: scale(0.95);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.status-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.status-card h3 {
    margin-bottom: 15px;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 8px;
}

/* === PvP Game Specific Styles === */

/* Game Status Banner */
.game-status {
    background: var(--glass-bg);
    padding: 15px 25px;
    border-radius: 12px;
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.game-status.your-turn {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.2);
    animation: pulse-glow 2s infinite;
}

.game-status.opponent-turn {
    border-color: var(--warning);
    background: rgba(245, 158, 11, 0.2);
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 0 10px rgba(16, 185, 129, 0.5);
    }

    50% {
        box-shadow: 0 0 20px rgba(16, 185, 129, 0.8);
    }
}

/* Ship Placement */
.ship-placement {
    max-width: 800px;
    margin: 0 auto;
}

.ship-placement .ship-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.ship-placement .ship-item {
    padding: 12px 20px;
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ship-placement .ship-item:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

.ship-placement .ship-item.selected {
    background: rgba(16, 185, 129, 0.3);
    border-color: var(--success);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.5);
}

.ship-placement .ship-item.placed {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(100, 100, 100, 0.2);
}

/* Grid Hover Preview for Ship Placement */
.grid-cell.hover-preview {
    background: rgba(16, 185, 129, 0.4) !important;
    border-color: var(--success) !important;
}

.grid-cell.hover-invalid {
    background: rgba(239, 68, 68, 0.4) !important;
    border-color: var(--danger) !important;
}

/* Battle Phase Layout */
.game-board {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (min-width: 900px) {
    .game-board {
        grid-template-columns: 1fr 1fr;
    }
}

.grid-header {
    text-align: center;
    font-size: 1.2rem;
    font-weight: bold;
    margin-bottom: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

/* Enemy grid - only clickable on your turn */
#enemyGrid .grid-cell {
    cursor: pointer;
}

#enemyGrid .grid-cell:disabled,
body:not(.your-turn) #enemyGrid .grid-cell {
    cursor: not-allowed;
    opacity: 0.6;
}

body.your-turn #enemyGrid .grid-cell:not(.hit):not(.miss):hover {
    background: rgba(255, 255, 255, 0.4);
    border-color: var(--warning);
}

/* Controls/Buttons */
.controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 20px;
}

.btn {
    padding: 12px 24px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
    min-width: 150px;
}

.btn-primary {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.btn-secondary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

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

/* Game Over Modal */
.game-over {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    z-index: 1000;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.game-over .result {
    font-size: 1.5rem;
    margin: 20px 0;
}

/* Mobile Optimization for PvP */
@media (max-width: 600px) {
    .game-board {
        grid-template-columns: 1fr;
    }

    .grid-container {
        max-height: 400px;
    }

    .controls {
        position: sticky;
        bottom: 10px;
        background: rgba(0, 0, 0, 0.8);
        padding: 10px;
        border-radius: 12px;
        margin: 10px -10px;
    }

    .btn {
        min-width: auto;
        flex: 1;
    }
}

/* === Notification/Toast System === */
.notification {
    position: fixed;
    top: 80px;
    right: 20px;
    min-width: 300px;
    max-width: 400px;
    padding: 16px 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border-radius: 12px;
    border: 2px solid;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    font-weight: 500;
    font-size: 1rem;
    z-index: 9999;
    animation: slideIn 0.3s ease-out;
    color: white;
}

.notification.success {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.2);
}

.notification.error {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.2);
}

.notification.info {
    border-color: var(--info);
    background: rgba(59, 130, 246, 0.2);
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* === Compact Player List === */
.players-header {
    margin-bottom: 15px;
}

.player-count {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.count-badge {
    background: var(--success);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: bold;
    margin-right: 8px;
}

.player-search {
    width: 100%;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-size: 0.95rem;
    margin-top: 10px;
}

.player-search::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.player-search:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.15);
}

.players-compact-list {
    max-height: 500px;
    overflow-y: auto;
    padding-right: 5px;
}

.player-compact-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.player-compact-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

.player-compact-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.player-online-dot {
    font-size: 0.7rem;
}

.player-compact-name {
    font-weight: 500;
    font-size: 0.95rem;
}

.player-compact-challenge {
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.3s ease;
}

.player-compact-challenge:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.show-more-container {
    margin-top: 15px;
    text-align: center;
}

.show-more-btn {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.show-more-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}