/*
 * File: style.css
 * Path: /assets/css/style.css
 * Role: Główny arkusz stylów gry Statki Online.
 *       Ciemny motyw morski, mobile-first, pełna responsywność.
 */

/* ─────────────────────────────────────────────────────────────────────────
   CSS VARIABLES – Design Tokens
───────────────────────────────────────────────────────────────────────── */
:root {
    /* Kolory bazowe */
    --bg-deep:        #070b14;
    --bg-dark:        #0a0e1a;
    --bg-card:        #0f1628;
    --bg-card-hover:  #141d35;
    --bg-elevated:    #192040;
    --bg-input:       #0d1526;

    /* Akcenty */
    --cyan:           #00d4ff;
    --cyan-dim:       #00a8cc;
    --cyan-glow:      rgba(0, 212, 255, 0.25);
    --blue:           #0066ff;
    --blue-dim:       #0052cc;
    --blue-glow:      rgba(0, 102, 255, 0.25);
    --purple:         #7b5cff;

    /* Status */
    --success:        #00e87a;
    --success-dim:    #00b85f;
    --success-bg:     rgba(0, 232, 122, 0.12);
    --danger:         #ff4757;
    --danger-dim:     #cc3a46;
    --danger-bg:      rgba(255, 71, 87, 0.12);
    --warning:        #ffa502;
    --warning-bg:     rgba(255, 165, 2, 0.12);

    /* Tekst */
    --text-primary:   #e8f0fe;
    --text-secondary: #7a8aaa;
    --text-muted:     #4a5568;
    --text-accent:    #00d4ff;

    /* Plansze */
    --cell-empty:     #0f1628;
    --cell-hover:     rgba(0, 212, 255, 0.1);
    --cell-ship:      #1a3a6e;
    --cell-ship-glow: rgba(0, 102, 255, 0.5);
    --cell-hit:       #ff4757;
    --cell-hit-glow:  rgba(255, 71, 87, 0.5);
    --cell-miss:      #1e2a3a;
    --cell-sunk:      #8b0000;
    --cell-border:    rgba(0, 212, 255, 0.25);

    /* Rozmiary */
    --cell-size:      min(8.5vw, 38px);
    --board-gap:      2px;
    --radius-sm:      6px;
    --radius-md:      12px;
    --radius-lg:      18px;
    --radius-xl:      24px;
    --radius-full:    9999px;

    /* Typografia */
    --font-main:      'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono:      'Courier New', monospace;

    /* Cienie */
    --shadow-sm:      0 2px 8px rgba(0,0,0,0.4);
    --shadow-md:      0 4px 20px rgba(0,0,0,0.5);
    --shadow-lg:      0 8px 40px rgba(0,0,0,0.6);
    --shadow-cyan:    0 0 20px rgba(0, 212, 255, 0.3);
    --shadow-blue:    0 0 20px rgba(0, 102, 255, 0.3);

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

/* ─────────────────────────────────────────────────────────────────────────
   RESET & BASE
───────────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    height: 100%;
    background: var(--bg-deep);
    color: var(--text-primary);
    font-family: var(--font-main);
    line-height: 1.5;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─────────────────────────────────────────────────────────────────────────
   SCREENS SYSTEM
───────────────────────────────────────────────────────────────────────── */
screen {
    display: none;
    position: fixed;
    inset: 0;
    overflow-y: auto;
    background: var(--bg-deep);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity var(--transition-normal), transform var(--transition-normal);
}

screen.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

screen.slide-in {
    animation: screenSlideIn 0.3s ease forwards;
}

screen.slide-out {
    animation: screenSlideOut 0.2s ease forwards;
}

@keyframes screenSlideIn {
    from { opacity: 0; transform: translateX(30px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes screenSlideOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(-30px); }
}

/* ─────────────────────────────────────────────────────────────────────────
   GLOBAL LOADER
───────────────────────────────────────────────────────────────────────── */
.global-loader {
    position: fixed;
    inset: 0;
    background: var(--bg-deep);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.global-loader.active {
    display: flex;
    opacity: 1;
}

.loader-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.loader-ship {
    width: 80px;
    height: 60px;
    animation: shipBob 1.5s ease-in-out infinite;
}

@keyframes shipBob {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-8px); }
}

.loader-dots {
    display: flex;
    gap: 8px;
}

.loader-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cyan);
    animation: dotPulse 1.2s ease-in-out infinite;
}

.loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.loader-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50%       { opacity: 1;   transform: scale(1.2); }
}

/* ─────────────────────────────────────────────────────────────────────────
   TOAST NOTIFICATIONS
───────────────────────────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(360px, calc(100vw - 32px));
    pointer-events: none;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid rgba(255,255,255,0.08);
    border-left: 3px solid var(--cyan);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-size: 14px;
    color: var(--text-primary);
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: toastIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    word-break: break-word;
}

.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error   { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-info    { border-left-color: var(--cyan); }

.toast.toast-out { animation: toastOut 0.25s ease forwards; }

@keyframes toastIn  { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0); }      to { opacity: 0; transform: translateY(-12px); } }

/* ─────────────────────────────────────────────────────────────────────────
   BUTTONS
───────────────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 22px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    transition: all var(--transition-fast);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    min-height: 48px;
    -webkit-tap-highlight-color: transparent;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.1);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.btn:active::after { opacity: 1; }

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* Primary */
.btn-primary {
    background: linear-gradient(135deg, #0066ff 0%, #0044bb 100%);
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 102, 255, 0.4);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0077ff 0%, #0055dd 100%);
    box-shadow: 0 6px 20px rgba(0, 102, 255, 0.55);
    transform: translateY(-1px);
}

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

/* Secondary */
.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--cyan-dim);
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.15);
    transform: translateY(-1px);
}

/* Accent (cyan) */
.btn-accent {
    background: linear-gradient(135deg, #00b8d9 0%, #0066ff 100%);
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.35);
}

.btn-accent:hover {
    box-shadow: 0 6px 20px rgba(0, 212, 255, 0.5);
    transform: translateY(-1px);
}

/* Ghost */
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid rgba(255,255,255,0.08);
}

.btn-ghost:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: rgba(255,255,255,0.15);
}

/* Sizes */
.btn-lg { padding: 14px 28px; font-size: 16px; min-height: 54px; border-radius: var(--radius-lg); }
.btn-sm { padding: 8px 14px; font-size: 13px; min-height: 36px; }

.btn-icon { font-size: 18px; }

/* Icon-only button */
.btn-icon-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.btn-icon-only svg { width: 20px; height: 20px; }
.btn-icon-only:hover { background: var(--bg-card); color: var(--text-primary); }

/* Back button */
.btn-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.btn-back svg { width: 20px; height: 20px; }
.btn-back:hover { background: var(--bg-elevated); color: var(--text-primary); }

/* ─────────────────────────────────────────────────────────────────────────
   INPUT FIELDS
───────────────────────────────────────────────────────────────────────── */
.input-field {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 16px;
    outline: none;
    transition: all var(--transition-fast);
    min-height: 48px;
    -webkit-appearance: none;
}

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

.input-field:focus {
    border-color: var(--cyan-dim);
    box-shadow: 0 0 0 3px var(--cyan-glow);
}

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

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

/* ─────────────────────────────────────────────────────────────────────────
   SCREEN HEADER
───────────────────────────────────────────────────────────────────────── */
.screen-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: rgba(10, 14, 26, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.screen-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
}

/* ─────────────────────────────────────────────────────────────────────────
   OCEAN BACKGROUND ANIMATION
───────────────────────────────────────────────────────────────────────── */
.ocean-bg {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.wave {
    position: absolute;
    bottom: -20px;
    left: -50%;
    width: 200%;
    height: 200px;
    border-radius: 40%;
    opacity: 0.04;
}

.wave-1 {
    background: var(--cyan);
    animation: waveFloat 8s ease-in-out infinite;
    bottom: -80px;
}

.wave-2 {
    background: var(--blue);
    animation: waveFloat 10s ease-in-out infinite reverse;
    bottom: -100px;
    opacity: 0.03;
}

.wave-3 {
    background: var(--purple);
    animation: waveFloat 12s ease-in-out infinite;
    bottom: -120px;
    opacity: 0.02;
}

@keyframes waveFloat {
    0%, 100% { transform: rotate(-3deg) translateX(0); }
    50%       { transform: rotate(3deg) translateX(2%); }
}

/* ─────────────────────────────────────────────────────────────────────────
   SCREEN HOME
───────────────────────────────────────────────────────────────────────── */
.screen-home {
    background: var(--bg-deep);
}

.home-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px 24px 40px;
    min-height: 100vh;
    gap: 28px;
}

/* Logo */
.logo-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.logo-icon {
    width: 100px;
    height: 80px;
    filter: drop-shadow(0 0 20px rgba(0, 212, 255, 0.4));
    animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0); }
    50%       { transform: translateY(-6px); }
}

.logo-title {
    font-size: clamp(36px, 10vw, 52px);
    font-weight: 900;
    letter-spacing: 8px;
    background: linear-gradient(135deg, #00d4ff 0%, #7b5cff 50%, #0066ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    filter: drop-shadow(0 0 20px rgba(0, 212, 255, 0.3));
}

.logo-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* Nick block */
.nick-block {
    width: 100%;
    max-width: 340px;
}

.nick-input-wrap {
    display: flex;
    gap: 8px;
}

/* Home actions */
.home-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 340px;
}

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

/* Rules block */
.rules-block {
    width: 100%;
    max-width: 400px;
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.rules-toggle {
    padding: 12px 16px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color var(--transition-fast);
    user-select: none;
}

.rules-toggle:hover { color: var(--text-primary); }

.rules-toggle::-webkit-details-marker { display: none; }

.rules-toggle::before {
    content: '▶';
    font-size: 10px;
    transition: transform var(--transition-fast);
}

details[open] .rules-toggle::before { transform: rotate(90deg); }

.rules-content {
    padding: 12px 16px 16px;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.7;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.rules-content p + p { margin-top: 6px; }
.rules-content strong { color: var(--text-primary); }

/* ─────────────────────────────────────────────────────────────────────────
   SCREEN LOBBY
───────────────────────────────────────────────────────────────────────── */
.lobby-content {
    padding: clamp(16px, 5vw, 32px) 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 440px;
    margin: 0 auto;
    width: 100%;
}

/* Zakładki (Tabs) */
.lobby-tabs {
    display: flex;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 4px;
    border: 1px solid rgba(255,255,255,0.05);
}

.lobby-tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 700;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-normal);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.lobby-tab.tab-active {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 102, 255, 0.3);
}

.lobby-tab:hover:not(.tab-active) {
    color: var(--text-primary);
    background: rgba(255,255,255,0.03);
}

/* Panele (Panels) */
.lobby-panel {
    display: none;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    animation: fadeIn 0.3s ease forwards;
}

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

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

.lobby-panel .nick-block {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-lg);
    padding: 18px;
}

.lobby-panel .btn-create-room {
    width: 100%;
}

/* Formularz dołączania */
.join-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-lg);
    padding: 18px;
}

.join-form .input-code {
    width: 100%;
}

.join-form .btn-accent {
    width: 100%;
    padding: 14px;
}

/* Mobile optimizations for lobby */
@media (min-width: 400px) {
    .join-form {
        flex-direction: row;
        align-items: stretch;
    }
    .join-form .input-code {
        flex: 1;
    }
    .join-form .btn-accent {
        width: auto;
    }
}

/* ─────────────────────────────────────────────────────────────────────────
   SCREEN WAITING
───────────────────────────────────────────────────────────────────────── */
.waiting-content {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 420px;
    margin: 0 auto;
}

.room-code-card {
    background: var(--bg-card);
    border: 1px solid rgba(0, 212, 255, 0.15);
    border-radius: var(--radius-xl);
    padding: 30px 24px 34px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 440px;
    margin: 0 auto;
}

.room-code-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.room-code-display {
    font-size: 36px;
    font-weight: 900;
    font-family: var(--font-mono);
    letter-spacing: 8px;
    color: var(--cyan);
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
    padding: 8px 16px;
    background: rgba(0, 212, 255, 0.05);
    border-radius: var(--radius-md);
    border: 1px solid rgba(0, 212, 255, 0.15);
}

.room-code-card .btn {
    flex: 1;
    min-width: 110px;
    justify-content: center;
    white-space: nowrap;
}

.room-code-card > div:last-of-type,
.room-code-card > .btn {
    display: inline-flex;
}

/* Przyciski obok siebie */
.room-code-card .btn-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.players-list {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.player-slot {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    transition: background var(--transition-fast);
}

.player-slot + .player-slot {
    border-top: 1px solid rgba(255,255,255,0.05);
}

.player-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
}

.host-avatar  { background: linear-gradient(135deg, #0066ff, #004acc); color: #fff; }
.guest-avatar { background: var(--bg-elevated); color: var(--text-muted); }

.player-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.player-nick {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.player-badge {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    width: fit-content;
}

.badge-host  { background: rgba(0, 102, 255, 0.2); color: #5599ff; }
.badge-guest { background: rgba(255,255,255, 0.06); color: var(--text-secondary); }

.player-status {
    font-size: 18px;
    flex-shrink: 0;
}

.status-ready   { color: var(--success); }
.status-waiting { color: var(--text-muted); animation: blink 1.5s ease-in-out infinite; }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.waiting-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-secondary);
}

.pulse-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--cyan);
    flex-shrink: 0;
    animation: pulseDot 1.5s ease-in-out infinite;
}

@keyframes pulseDot {
    0%, 100% { box-shadow: 0 0 0 0 var(--cyan-glow); opacity: 1; }
    50%       { box-shadow: 0 0 0 8px transparent; opacity: 0.7; }
}

/* ─────────────────────────────────────────────────────────────────────────
   SCREEN PLACEMENT
───────────────────────────────────────────────────────────────────────── */
.placement-content {
    padding: 12px 12px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    max-width: 500px;
    margin: 0 auto;
}

/* Paleta statków */
.ships-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    width: 100%;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-lg);
}

.ship-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    border: 2px solid transparent;
    transition: all var(--transition-fast);
    min-width: 48px;
}

.ship-item:hover { background: rgba(0, 212, 255, 0.08); border-color: rgba(0, 212, 255, 0.2); }
.ship-item.selected { background: rgba(0, 212, 255, 0.12); border-color: var(--cyan); }
.ship-item.placed { opacity: 0.35; pointer-events: none; }

.ship-preview {
    display: flex;
    gap: 2px;
}

.ship-cell-preview {
    width: 14px;
    height: 14px;
    background: var(--blue);
    border-radius: 3px;
    box-shadow: inset 0 1px 2px rgba(255,255,255,0.15);
}

.ship-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
}

/* ─────────────────────────────────────────────────────────────────────────
   GAME BOARD (shared between placement + game)
───────────────────────────────────────────────────────────────────────── */
.placement-board-wrap,
.board-wrap {
    width: 100%;
}

.board-labels-row {
    display: flex;
    align-items: center;
}

.corner-cell {
    width: 24px;
    flex-shrink: 0;
}

.col-labels {
    display: flex;
    flex: 1;
}

.col-labels > span,
.row-labels > span {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    user-select: none;
}

.col-labels > span {
    flex: 1;
    height: 20px;
}

.board-with-rows {
    display: flex;
}

.row-labels {
    width: 24px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.row-labels > span {
    flex: 1;
    font-size: 11px;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: var(--board-gap);
    flex: 1;
    background: rgba(0, 212, 255, 0.04);
    border: 1px solid rgba(0, 212, 255, 0.1);
    border-radius: var(--radius-md);
    padding: var(--board-gap);
}

/* Komórka planszy */
.board-cell {
    aspect-ratio: 1;
    background: var(--cell-empty);
    border-radius: 3px;
    border: 1px solid var(--cell-border);
    cursor: pointer;
    transition: background var(--transition-fast), transform var(--transition-fast);
    position: relative;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Stany komórki */
.board-cell.cell-ship {
    background: var(--cell-ship);
    border-color: rgba(0, 102, 255, 0.3);
    box-shadow: inset 0 1px 3px rgba(255,255,255,0.08);
}

.board-cell.cell-ship-hover {
    background: rgba(0, 102, 255, 0.25);
    border-color: rgba(0, 102, 255, 0.5);
}

.board-cell.cell-invalid {
    background: var(--danger-bg);
    border-color: rgba(255, 71, 87, 0.4);
}

.board-cell.cell-hit {
    background: radial-gradient(circle, #ff6b6b, #cc2233);
    border-color: #ff4757;
    box-shadow: 0 0 8px rgba(255, 71, 87, 0.6);
}

.board-cell.cell-hit::after {
    content: '✕';
    color: #fff;
    font-size: 12px;
    font-weight: 900;
}

.board-cell.cell-miss {
    background: var(--cell-miss);
    border-color: rgba(255,255,255,0.08);
}

.board-cell.cell-miss::after {
    content: '·';
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
}

.board-cell.cell-sunk {
    background: radial-gradient(circle, #8b1a1a, #4a0a0a);
    border-color: #8b0000;
    box-shadow: 0 0 6px rgba(139, 0, 0, 0.5);
}

.board-cell.cell-sunk::after {
    content: '✕';
    color: rgba(255,100,100,0.8);
    font-size: 12px;
    font-weight: 900;
}

.board-cell.cell-hover-valid {
    background: var(--cell-hover);
    border-color: rgba(0, 212, 255, 0.4);
    transform: scale(1.02);
}

.board-cell.cell-hover-invalid {
    background: var(--danger-bg);
    border-color: rgba(255, 71, 87, 0.4);
}

/* Enemy board – kursor strzałki gdy nie nasza tura */
.enemy-board.no-turn .board-cell {
    cursor: default;
}

.enemy-board.my-turn .board-cell:not(.cell-hit):not(.cell-miss):not(.cell-sunk):hover {
    background: rgba(0, 212, 255, 0.12);
    border-color: rgba(0, 212, 255, 0.5);
    transform: scale(1.05);
    z-index: 1;
}

/* Animacje trafień */
@keyframes hitAnim {
    0%   { transform: scale(1); }
    30%  { transform: scale(1.3); }
    60%  { transform: scale(0.9); }
    100% { transform: scale(1); }
}

@keyframes sunkAnim {
    0%   { transform: scale(1); opacity: 1; }
    25%  { transform: scale(1.2); }
    50%  { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 0.8; }
}

@keyframes missAnim {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.board-cell.anim-hit  { animation: hitAnim  0.4s ease; }
.board-cell.anim-sunk { animation: sunkAnim 0.6s ease; }
.board-cell.anim-miss { animation: missAnim 0.3s ease; }

/* ─────────────────────────────────────────────────────────────────────────
   PLACEMENT CONTROLS
───────────────────────────────────────────────────────────────────────── */
.placement-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
}

.placement-controls .btn {
    flex: 1;
    min-width: 90px;
    max-width: 140px;
    font-size: 13px;
    padding: 10px 12px;
}

.placement-controls .btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-ready {
    width: 100%;
    max-width: 320px;
    font-size: 17px;
}

.placement-waiting-msg {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 14px;
}

.placement-waiting-msg.hidden { display: none; }
.hidden { display: none !important; }

/* ─────────────────────────────────────────────────────────────────────────
   SCREEN GAME – TOPBAR
───────────────────────────────────────────────────────────────────────── */
.screen-game {
    display: none;
    flex-direction: column;
    background: var(--bg-deep);
}

.screen-game.active {
    display: flex;
}

.game-topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 8px 14px;
    background: rgba(10, 14, 26, 0.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    gap: 10px;
}

#btn-game-menu {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
}

@media (max-width: 500px) {
    .game-topbar {
        flex-direction: column;
        align-items: center;
        padding-bottom: 12px;
        gap: 6px;
        position: relative; /* Dla poprawnego pozycjonowania przycisku menu */
    }
    #btn-game-menu {
        top: 14px;
        transform: none;
    }
}

.turn-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

@media (max-width: 500px) {
    .turn-indicator {
        flex: none;
        width: 100%;
        justify-content: center;
        padding-top: 4px;
    }
}

.turn-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
    transition: background var(--transition-normal);
}

.turn-dot.enemy-turn { background: var(--danger); animation: pulseDot 1.5s infinite; }

#turn-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.game-stats {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    padding: 6px 12px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

@media (max-width: 400px) {
    .game-stats {
        padding: 4px 10px;
        gap: 6px;
    }
    .stat-label.label-traf,
    .stat-label.label-pudlo,
    .stat-label.label-opp {
        display: none;
    }
    .stat-value {
        font-size: 14px;
    }
    .game-nick {
        max-width: 70px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.stat-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-value {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.stat-separator {
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 2px;
}

/* ─────────────────────────────────────────────────────────────────────────
   GAME BOARDS LAYOUT
───────────────────────────────────────────────────────────────────────── */
.game-boards {
    display: flex;
    flex-direction: column;
    padding: 10px 12px 20px;
    gap: 16px;
    flex: 1;
    overflow-y: auto;
}

.board-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.board-section-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.board-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.enemy-board-title { color: var(--cyan); }

.board-subtitle {
    font-size: 12px;
    color: var(--text-muted);
}

/* Desktop layout – plansze obok siebie */
@media (min-width: 680px) {
    .game-boards {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 60px; /* Zwiększony odstęp między planszami */
        padding: 30px 40px;
    }

    .board-section {
        flex: 1;
        max-width: 520px; /* Znacznie powiększone (z 380px) */
    }

    .board-title {
        font-size: 18px; /* Większy tytuł */
    }

    .col-labels > span, .row-labels > span {
        font-size: 14px; /* Większe etykiety A-J, 1-10 */
        font-weight: bold;
    }
}

/* ─────────────────────────────────────────────────────────────────────────
   MODALS
───────────────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: overlayIn 0.2s ease;
}

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

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

.modal-box {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: var(--radius-xl);
    padding: 28px 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
}

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

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
    text-align: center;
}

.modal-close-btn {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.modal-close-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }

/* Game Over Modal */
.game-over-icon {
    font-size: 52px;
    text-align: center;
    margin-bottom: 8px;
    animation: bounceIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.game-over-title {
    font-size: 26px;
    font-weight: 900;
    text-align: center;
    margin-bottom: 6px;
}

.game-over-title.win  { color: var(--success); }
.game-over-title.lose { color: var(--danger); }

.game-over-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

.game-over-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 20px;
}

.game-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.game-stat-value {
    font-size: 22px;
    font-weight: 800;
    color: var(--cyan);
}

.game-stat-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.modal-actions .btn { width: 100%; }

/* Menu Modal */
.modal-menu {
    max-width: 300px;
}

.modal-menu-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-elevated);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-main);
    text-align: left;
    min-height: 52px;
}

.menu-item svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--text-secondary); }
.menu-item:hover { background: var(--bg-card-hover); border-color: rgba(255,255,255,0.1); }
.menu-item-danger { color: var(--danger); }
.menu-item-danger svg { color: var(--danger); }
.menu-item-danger:hover { background: var(--danger-bg); border-color: rgba(255,71,87,0.2); }

/* Rules Modal */
.modal-rules-box { max-width: 420px; max-height: 80vh; overflow-y: auto; }

.rules-modal-content h4 {
    color: var(--cyan);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-top: 16px;
    margin-bottom: 6px;
}

.rules-modal-content h4:first-child { margin-top: 0; }

.rules-modal-content ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rules-modal-content ul li::before {
    content: '▸ ';
    color: var(--cyan);
}

.rules-modal-content p,
.rules-modal-content li {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.rules-modal-content strong { color: var(--text-primary); }

/* ─────────────────────────────────────────────────────────────────────────
   UTILITIES
───────────────────────────────────────────────────────────────────────── */
.text-cyan    { color: var(--cyan); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-muted   { color: var(--text-muted); }

/* Scrollbar (Webkit) */
::-webkit-scrollbar       { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* Selection */
::selection { background: rgba(0, 212, 255, 0.3); color: #fff; }

/* ─────────────────────────────────────────────────────────────────────────
   RESPONSIVE TWEAKS
───────────────────────────────────────────────────────────────────────── */
@media (max-width: 360px) {
    :root { --cell-size: 7.5vw; }

    .placement-controls .btn { font-size: 12px; padding: 9px 8px; min-width: 72px; }
    .home-content { padding: 28px 16px 28px; gap: 20px; }
    .logo-title { letter-spacing: 5px; }
    .room-code-display { font-size: 28px; letter-spacing: 5px; }
}

@media (min-width: 768px) {
    .home-content { justify-content: center; }
    .placement-content { padding: 16px 20px 28px; max-width: 720px; }
    .ships-palette { justify-content: flex-start; }
    .board-cell { border-radius: 4px; }
}

/* PWA safe area */
@supports (padding: max(0px)) {
    .game-topbar  { padding-top: max(10px, env(safe-area-inset-top)); }
    .home-content { padding-bottom: max(40px, env(safe-area-inset-bottom)); }
    .game-boards  { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}

/* ─── Lobby tabs (added) ─── */
.lobby-tabs { display: flex; gap: 4px; margin-bottom: 20px; background: var(--bg-elevated); border-radius: 10px; padding: 4px; }
.lobby-tab { flex: 1; padding: 10px; border: none; border-radius: 8px; background: transparent; color: var(--text-secondary); font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.lobby-tab.tab-active { background: var(--accent-cyan); color: var(--bg-deep); }
.lobby-panel { display: none; }
.lobby-panel.active { display: flex; flex-direction: column; gap: 16px; }
.waiting-btns { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 8px; 
    justify-content: center; 
    width: 100%;
    margin-top: 15px;
}
/* ─── Game stats bar (added) ─── */
.game-nick { font-size: 12px; color: var(--accent-cyan); font-weight: 700; max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-group { display: flex; align-items: center; gap: 4px; }
.stat-separator { color: var(--text-muted); padding: 0 4px; }
