:root {
    --primary-color: #0f766e;
    --secondary-color: #22d3ee;
    --accent-color: #a3ff12;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5f5;
    --text-muted: #8b97b5;
    --bg-primary: #050b1a;
    --bg-secondary: #0f172a;
    --bg-card: #16233d;
    --border-color: #223352;
    --shadow-light: rgba(34, 211, 238, 0.12);
    --shadow-medium: rgba(5, 18, 38, 0.35);
    --shadow-heavy: rgba(5, 12, 26, 0.65);
    --gradient-primary: linear-gradient(140deg, #0f172a 0%, #0f766e 45%, #22d3ee 100%);
    --gradient-accent: linear-gradient(140deg, #d4ff5e 0%, #7fff45 45%, #4ade80 100%);
    --border-radius: 16px;
    --border-radius-small: 10px;
    --transition-fast: 0.18s ease;
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    --text-primary: #0f172a;
    --text-secondary: #1f2937;
    --text-muted: #4b5563;
    --bg-primary: #f1f5f9;
    --bg-secondary: #e2e8f0;
    --bg-card: #f8fafc;
    --border-color: #cbd5e1;
    --shadow-light: rgba(15, 118, 110, 0.08);
    --shadow-medium: rgba(15, 23, 42, 0.12);
    --shadow-heavy: rgba(15, 23, 42, 0.18);
    --accent-color: #16a34a;
    --gradient-primary: linear-gradient(135deg, #67e8f9 0%, #22d3ee 45%, #0ea5e9 100%);
    --gradient-accent: linear-gradient(135deg, #bbf7d0 0%, #4ade80 50%, #16a34a 100%);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background-color var(--transition-smooth), color var(--transition-smooth);
}

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.top-nav {
    background: var(--bg-secondary);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-controls {
    display: flex;
    gap: 0.5rem;
}

.app-title {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-small);
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.nav-btn:hover {
    background: var(--gradient-primary);
    border-color: var(--primary-color);
    color: var(--text-primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-light);
}

.nav-btn .icon {
    font-size: 1rem;
}

.main-content {
    flex: 1;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

.game-header {
    margin-bottom: 2rem;
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    text-align: center;
    transition: all var(--transition-smooth);
}

.stat-box:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px var(--shadow-medium);
}

.stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--border-radius-small);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
}

.btn-secondary {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px var(--shadow-light);
}

.btn:active {
    transform: translateY(0);
}

.game-board-section {
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(12, 50px);
    grid-template-rows: repeat(12, 50px);
    gap: 2px;
    background: var(--bg-secondary);
    padding: 2px;
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px var(--shadow-heavy);
}

.cell {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

.cell:hover:not(.revealed) {
    background: var(--shadow-light);
    transform: scale(1.05);
}

.cell.revealed {
    cursor: default;
    background: var(--bg-secondary);
}

.cell.ship {
    background: var(--gradient-accent);
    color: white;
    animation: shipFound 0.5s ease;
}

.cell.number {
    color: var(--secondary-color);
}

.cell.empty {
    color: var(--text-muted);
}

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

.legend-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    max-width: 600px;
    margin: 0 auto;
}

.legend-section h3 {
    text-align: center;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.legend-cell {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-weight: 700;
}

.legend-cell.empty {
    color: var(--text-muted);
}

.legend-cell.number {
    color: var(--secondary-color);
}

.legend-cell.ship {
    background: var(--gradient-accent);
    color: white;
}

.leaderboard-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    max-width: 800px;
    margin: 2rem auto 0;
}

.leaderboard-section h3 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.leaderboard-content {
    margin-bottom: 1rem;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard-table thead {
    background: var(--bg-secondary);
}

.leaderboard-table th {
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.leaderboard-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-table tr:hover {
    background: var(--bg-secondary);
}

.leaderboard-table tr.current-player {
    background: linear-gradient(90deg, rgba(34, 211, 238, 0.1) 0%, rgba(34, 211, 238, 0.05) 100%);
    border-left: 3px solid var(--secondary-color);
}

.leaderboard-table tr.current-player td {
    font-weight: 600;
    color: var(--secondary-color);
}

.personal-best {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-small);
    padding: 1rem;
    text-align: center;
    margin-top: 1rem;
}

.personal-best p {
    margin: 0;
    color: var(--text-secondary);
}

.personal-best strong {
    color: var(--text-primary);
}

.loading-text {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.no-data {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

.error-text {
    text-align: center;
    color: var(--danger-color);
    padding: 2rem;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px var(--shadow-heavy);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
}

.modal-body {
    padding: 2rem;
    text-align: center;
}

.modal-body p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    gap: 1rem;
}

@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }

    .top-nav {
        padding: 0.875rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .app-title {
        font-size: 1.1rem;
        position: static;
        transform: none;
        width: 100%;
        text-align: center;
        order: -1;
    }

    .game-board {
        grid-template-columns: repeat(12, 40px);
        grid-template-rows: repeat(12, 40px);
        gap: 1px;
    }

    .cell {
        font-size: 1.2rem;
    }

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

    .game-controls {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 600px) {
    .game-board {
        grid-template-columns: repeat(12, 28px);
        grid-template-rows: repeat(12, 28px);
    }

    .cell {
        font-size: 1rem;
    }
}

.name-input {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-small);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.name-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--shadow-light);
}

.name-input::placeholder {
    color: var(--text-muted);
}

.error-message {
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

#youtube-player {
    position: fixed;
    top: -9999px;
    left: -9999px;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}
