/* ============== BASE STYLES ============== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    font-size: 16px !important;
}

:root {
    --ocean-deep: #0a1628;
    --ocean-mid: #122a4a;
    --ocean-light: #1a3a5c;
    --accent: #00a8ff;
    --danger: #ff4757;
    --success: #22c55e;
    --warning: #f59e0b;
    --text: #e8f0f8;
    --text-dim: #7a8fa0;
    /* Hull colors for submarines */
    --hull-dark: #2a3a4a;
    --hull-mid: #3a4a5a;
    --hull-light: #4a5a6a;
    --hull-highlight: #5a6a7a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--ocean-deep);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    touch-action: pan-x pan-y;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.hidden { display: none !important; }

/* ============== OCEAN ANIMATED BACKGROUND ============== */
.ocean-background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    transition: opacity 0.5s ease, filter 0.5s ease;
    opacity: 1;
}

.ocean-background.visible {
    opacity: 1;
    filter: none;
}

.ocean-background.dimmed {
    opacity: 0.4;
    filter: brightness(0.5) saturate(0.7);
}

.ocean-background.hidden {
    opacity: 0;
}

/* ============== CONNECTION STATUS ============== */
.connection-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 8px 16px;
    background: linear-gradient(135deg, var(--warning) 0%, #d97706 100%);
    color: #000;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    z-index: 300;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.connection-status.show { transform: translateY(0); }
.connection-status.error { background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%); color: white; }
.connection-status.success { background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%); color: white; }

/* ============== MENU OVERLAY ============== */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: max(80px, calc(env(safe-area-inset-top, 0px) + 80px));
    padding-bottom: 0;
    z-index: 250;
    transition: opacity 0.3s ease;
}

.menu-overlay.hidden { opacity: 0; pointer-events: none; }

.menu-title {
    font-size: 32px;
    font-weight: 900;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 6px;
    margin-bottom: 8px;
    text-shadow:
        0 0 20px rgba(0, 168, 255, 0.8),
        0 0 40px rgba(0, 168, 255, 0.5),
        0 0 60px rgba(0, 168, 255, 0.3),
        0 2px 4px rgba(0, 0, 0, 0.5);
    animation: title-glow 3s ease-in-out infinite;
}

@keyframes title-glow {
    0%, 100% {
        text-shadow:
            0 0 20px rgba(0, 168, 255, 0.8),
            0 0 40px rgba(0, 168, 255, 0.5),
            0 0 60px rgba(0, 168, 255, 0.3),
            0 2px 4px rgba(0, 0, 0, 0.5);
    }
    50% {
        text-shadow:
            0 0 30px rgba(0, 168, 255, 1),
            0 0 60px rgba(0, 168, 255, 0.7),
            0 0 90px rgba(0, 168, 255, 0.5),
            0 2px 4px rgba(0, 0, 0, 0.5);
    }
}

.menu-subtitle {
    font-size: 12px;
    color: rgba(200, 220, 255, 0.7);
    margin-bottom: 40px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    letter-spacing: 2px;
}

.menu-section {
    width: 280px;
    margin-bottom: 16px;
    margin-top: auto;
}

.menu-label {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
    text-align: center;
}

.menu-input {
    width: 100%;
    padding: 14px 16px;
    background: rgba(26, 58, 100, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 2px solid rgba(40, 80, 120, 0.9);
    border-radius: 10px;
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.menu-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 20px rgba(0, 168, 255, 0.3);
}
.menu-input::placeholder { color: var(--text-dim); font-weight: 400; }

/* Corner Buttons */
.menu-corner-btns {
    position: absolute;
    top: max(20px, env(safe-area-inset-top, 20px));
    left: 16px;
    right: 16px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    z-index: 10;
}

.corner-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 2px solid rgba(0, 168, 255, 0.3);
    background: linear-gradient(135deg, rgba(18, 42, 74, 0.85) 0%, rgba(10, 30, 55, 0.9) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: rgba(200, 220, 255, 0.9);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
    pointer-events: auto;
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.3),
        0 0 20px rgba(0, 168, 255, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.corner-btn:not(:disabled):hover {
    border-color: rgba(0, 168, 255, 0.6);
    color: #fff;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.4),
        0 0 30px rgba(0, 168, 255, 0.25);
}

.corner-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: rgba(100, 120, 140, 0.3);
}

.corner-btn:not(:disabled):active {
    transform: scale(0.92);
}

.corner-btn svg {
    width: 22px;
    height: 22px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

#soundToggleBtn .sound-off {
    display: none;
}

#soundToggleBtn.sound-muted .sound-on {
    display: none;
}

#soundToggleBtn.sound-muted .sound-off {
    display: block;
}

#soundToggleBtn.sound-muted {
    color: rgba(255, 100, 100, 0.8);
    border-color: rgba(255, 100, 100, 0.3);
}

.settings-panel {
    background: rgba(18, 42, 74, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 20px;
    width: 280px;
    margin-top: 20px;
    border: 1px solid rgba(26, 58, 92, 0.8);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--ocean-light);
}

.setting-row:last-child { border-bottom: none; }

.setting-label { font-size: 13px; color: var(--text); }

.toggle-switch {
    position: relative;
    width: 48px;
    height: 26px;
    background: var(--ocean-deep);
    border-radius: 13px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-switch.on { background: var(--accent); }

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch.on::after { transform: translateX(22px); }

.menu-btn-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 280px;
    margin-top: 200px;
}

.menu-btn {
    padding: 16px;
    border: none;
    border-radius: 12px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
}

.menu-btn.play {
    padding: 28px 16px;
    font-size: 17px;
    background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%);
    color: white;
    box-shadow:
        0 4px 20px rgba(34, 197, 94, 0.4),
        0 0 40px rgba(34, 197, 94, 0.2);
    animation: play-btn-pulse 2s ease-in-out infinite;
}

@keyframes play-btn-pulse {
    0%, 100% {
        box-shadow:
            0 4px 20px rgba(34, 197, 94, 0.4),
            0 0 40px rgba(34, 197, 94, 0.2);
    }
    50% {
        box-shadow:
            0 4px 30px rgba(34, 197, 94, 0.6),
            0 0 60px rgba(34, 197, 94, 0.3);
    }
}

.menu-btn.play:disabled {
    background: rgba(50, 50, 50, 0.6);
    color: #666;
    box-shadow: none;
    animation: none;
}
.menu-btn.play:active:not(:disabled) { transform: scale(0.98); }
.menu-btn.secondary {
    background: rgba(18, 42, 74, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text);
    border: 1px solid rgba(26, 58, 92, 0.8);
}

/* Google Sign-in Button */
.google-btn-wrap {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 280px;
    margin-top: 21px;
    margin-bottom: auto;
    gap: 10px;
}

.google-signin-btn {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 11px;
    width: 100%;
    padding: 13px 16px;
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    opacity: 1;
    transition: all 0.2s;
    font-family: inherit;
    box-shadow:
        0 4px 20px rgba(220, 38, 38, 0.3),
        0 0 30px rgba(220, 38, 38, 0.15);
}

.google-signin-btn .google-icon-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    flex-shrink: 0;
}

.google-signin-btn .google-icon {
    width: 14px;
    height: 14px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cpath fill='%23EA4335' d='M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z'/%3E%3Cpath fill='%234285F4' d='M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z'/%3E%3Cpath fill='%2334A853' d='M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z'/%3E%3Cpath fill='%23FBBC05' d='M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}

.google-signin-btn .google-text {
    font-size: 15px;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* When logged in - shrink google button to make room for delete */
.google-signin-btn.linked {
    flex: 1;
    min-width: 0;
}

/* Delete account button - square, same height as Google button */
.delete-account-btn {
    width: 47px;
    height: 47px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow:
        0 4px 20px rgba(220, 38, 38, 0.3),
        0 0 30px rgba(220, 38, 38, 0.15);
}
.delete-account-btn:hover {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    transform: translateY(-1px);
    box-shadow:
        0 6px 25px rgba(220, 38, 38, 0.4),
        0 0 40px rgba(220, 38, 38, 0.2);
}
.delete-account-btn svg {
    width: 24px;
    height: 24px;
    fill: white;
}
.delete-account-btn.hidden {
    display: none;
}

.soon-tag {
    font-size: 11px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

/* Menu footer with legal links */
.menu-footer {
    margin-top: auto;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    text-align: center;
    white-space: nowrap;
}
.menu-footer .footer-link {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s;
}
.menu-footer .footer-link:hover {
    color: rgba(255, 255, 255, 0.8);
}
.menu-footer .footer-sep {
    margin: 0 8px;
    color: rgba(255, 255, 255, 0.2);
}

/* Legal popup overlay */
.legal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 20px;
}
.legal-overlay.hidden {
    display: none;
}
.legal-container {
    width: 100%;
    max-width: 580px;
    max-height: 80vh;
    background: linear-gradient(135deg, var(--ocean-mid) 0%, var(--ocean-deep) 100%);
    border: 1px solid var(--ocean-light);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.legal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
}
.legal-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}
.legal-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.6;
}
.legal-content::-webkit-scrollbar { width: 6px; }
.legal-content::-webkit-scrollbar-track { background: transparent; }
.legal-content::-webkit-scrollbar-thumb { background: var(--ocean-light); border-radius: 3px; }
.legal-date {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 12px;
}
.legal-summary {
    background: rgba(0, 168, 255, 0.1);
    padding: 12px 16px;
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    margin-bottom: 20px;
    color: var(--accent);
    font-weight: 500;
}
.legal-content h3 {
    color: var(--accent);
    font-size: 14px;
    margin: 20px 0 10px 0;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.legal-content h3:first-of-type { margin-top: 0; }
.legal-content h4 {
    color: var(--text);
    font-size: 13px;
    margin: 12px 0 8px 0;
}
.legal-content p {
    margin-bottom: 10px;
}
.legal-content ul {
    padding-left: 20px;
    margin-bottom: 10px;
}
.legal-content li {
    margin-bottom: 6px;
}
.legal-content strong {
    color: var(--text);
}

/* ============== QUEUE OVERLAY ============== */
.queue-overlay {
    position: fixed;
    inset: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 240;
}

.queue-content { text-align: center; }

.queue-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow:
        0 0 20px rgba(0, 168, 255, 0.8),
        0 0 40px rgba(0, 168, 255, 0.5),
        0 2px 4px rgba(0, 0, 0, 0.5);
}

.queue-dots {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 20px;
}

.queue-dots .dot {
    width: 12px;
    height: 12px;
    background: var(--accent);
    border-radius: 50%;
    animation: queue-pulse 1.5s ease-in-out infinite;
}

.queue-dots .dot:nth-child(2) { animation-delay: 0.15s; }
.queue-dots .dot:nth-child(3) { animation-delay: 0.3s; }
.queue-dots .dot:nth-child(4) { animation-delay: 0.45s; }
.queue-dots .dot:nth-child(5) { animation-delay: 0.6s; }

@keyframes queue-pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

.queue-timer {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 30px;
}

/* ============== PLACEMENT OVERLAY ============== */
.placement-overlay {
    position: fixed;
    inset: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    z-index: 230;
    padding: 10px;
    padding-top: 0;
}

.placement-overlay .top-bar {
    flex-shrink: 0;
    margin: 0 -10px;
    padding: 12px 16px;
}

.placement-overlay .turn-indicator {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    align-self: center;
    margin: 5px 0 10px 0;
}

@keyframes timer-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.placement-grid-container {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: transparent;
    border-radius: 12px;
    padding: 20px 5px 5px 5px;
}

#placementCanvas {
    max-width: 100%;
    max-height: 100%;
}

.placement-rack {
    display: flex;
    gap: 4px;
    padding: 8px;
    background: rgba(18, 42, 74, 0.8);
    border-radius: 12px;
    margin-top: 10px;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: center;
}

/* Hide empty rack */
.placement-rack:empty {
    display: none;
}

.rack-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5px;
    background: var(--ocean-dark);
    border: 2px solid var(--ocean-light);
    border-radius: 6px;
    cursor: grab;
    touch-action: none;
    user-select: none;
    transition: transform 0.2s, border-color 0.2s;
}

.rack-item:active {
    cursor: grabbing;
    transform: scale(1.05);
    border-color: var(--accent);
}

.rack-sub {
    display: flex;
    gap: 2px;
}

.rack-cell {
    width: 12px;
    height: 12px;
    background: linear-gradient(135deg, var(--hull-mid) 0%, var(--hull-dark) 100%);
    border-radius: 3px;
    border: 1px solid var(--hull-highlight);
}

.rack-label {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 4px;
    white-space: nowrap;
}

.placement-counter {
    text-align: center;
    font-size: 14px;
    color: var(--text-dim);
    margin-top: 10px;
}

.placement-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    padding: 0 10px;
    padding-bottom: max(15px, env(safe-area-inset-bottom));
}

.placement-actions .btn {
    flex: 1;
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 10px;
}

/* ============== WAITING OVERLAY ============== */
.waiting-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 22, 40, 0.7);
    display: flex;
    flex-direction: column;
    z-index: 235;
}

.waiting-overlay .top-bar {
    flex-shrink: 0;
}

.waiting-overlay .turn-indicator {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    align-self: center;
    margin: 10px 0 20px 0;
}

.waiting-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.waiting-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 24px;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.waiting-dots {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.waiting-dots .dot {
    width: 12px;
    height: 12px;
    background: var(--ocean-light);
    border-radius: 50%;
    animation: waiting-pulse 1.5s ease-in-out infinite;
}

.waiting-dots .dot:nth-child(1) { animation-delay: 0s; }
.waiting-dots .dot:nth-child(2) { animation-delay: 0.15s; }
.waiting-dots .dot:nth-child(3) { animation-delay: 0.3s; }
.waiting-dots .dot:nth-child(4) { animation-delay: 0.45s; }
.waiting-dots .dot:nth-child(5) { animation-delay: 0.6s; }

@keyframes waiting-pulse {
    0%, 100% { background: var(--ocean-light); transform: scale(1); }
    50% { background: var(--accent); transform: scale(1.3); }
}

.waiting-text {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 30px;
}

.waiting-content .btn {
    min-width: 160px;
}

/* ============== GAME UI ============== */
.game-ui {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
}

/* Top bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(180deg, var(--ocean-mid) 0%, transparent 100%);
    z-index: 50;
}

.player-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.player-info { flex: 1; min-width: 0; }
.player-badge:last-child .player-info { text-align: right; }
.player-badge:last-child .fleet-pips { justify-content: flex-end; }

.player-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    background: var(--accent);
}

.player-icon.enemy { background: var(--danger); }
.player-name { font-size: 13px; font-weight: 600; }
.player-score { font-size: 11px; color: #fbbf24; font-weight: 500; display: block; margin-top: 2px; }

.fleet-pips { display: flex; gap: 5px; margin-top: 4px; }

.fleet-pip {
    width: 11px;
    height: 11px;
    background: var(--accent);
    border-radius: 2px;
}

.fleet-pip.damaged { background: #ff9500; }
.fleet-pip.sunk { background: #444; opacity: 0.5; }
.fleet-pip.enemy { background: var(--danger); }
.fleet-pip.enemy.sunk { background: var(--success); }

/* Timer */
.timer-container {
    position: relative;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.timer-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.timer-bg { fill: none; stroke: rgba(0, 168, 255, 0.2); stroke-width: 4; }

.timer-progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 4;
    stroke-linecap: round;
    transition: stroke-dashoffset 1s linear;
    filter: drop-shadow(0 0 4px var(--accent));
}

.timer-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    background: var(--ocean-deep);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
}

.timer-container.warning .timer-progress { stroke: var(--danger); filter: drop-shadow(0 0 6px var(--danger)); }
.timer-container.warning .timer-center { color: var(--danger); animation: timer-pulse 0.5s ease-in-out infinite; }

.waiting-dots-center {
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: center;
}

.waiting-dots-center .dot {
    width: 6px;
    height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: dot-pulse 1.4s ease-in-out infinite;
}

.waiting-dots-center .dot:nth-child(1) { animation-delay: 0s; }
.waiting-dots-center .dot:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots-center .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Turn Indicator (in top bar, below timer) */
.game-ui .turn-indicator {
    position: absolute;
    top: 42px;
    left: 50%;
    transform: translateX(-50%);
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

.turn-indicator.your-turn {
    background: var(--success);
    color: white;
}

.turn-indicator.opponent-turn {
    background: #475569;
    color: #cbd5e1;
}

/* Turn indicator in placement/waiting screens (larger) */
.placement-overlay .turn-indicator,
.waiting-overlay .turn-indicator {
    position: relative;
    top: auto;
    left: auto;
    transform: none;
    padding: 6px 16px;
    font-size: 11px;
    letter-spacing: 2px;
}

/* Battle Focus */
.battle-focus {
    position: fixed;
    top: 100px;
    left: 8px;
    right: 8px;
    bottom: 65px;
    display: flex;
    flex-direction: column;
}

.focus-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: rgba(18, 42, 74, 0.8);
    border-radius: 8px 8px 0 0;
}

.focus-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.focus-title.attack { color: var(--danger); }
.focus-title.defense { color: var(--accent); }
.focus-hint { font-size: 9px; color: var(--text-dim); }

.canvas-wrap {
    flex: 1;
    background: transparent;
    border-radius: 0 0 8px 8px;
    padding: 20px 5px 5px 5px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

#mainCanvas { max-width: 100%; max-height: 100%; border-radius: 4px; }

/* Danger glow (opponent's turn - board glows red) */
.battle-focus.danger-glow #mainCanvas {
    border-radius: 0;
    box-shadow:
        0 1px 8px 4px rgba(255, 70, 50, 0.5),
        0 1px 16px 8px rgba(255, 70, 50, 0.3),
        0 1px 32px 16px rgba(255, 70, 50, 0.15);
    animation: danger-pulse-canvas 1.8s ease-in-out infinite;
}

@keyframes danger-pulse-canvas {
    0%, 100% {
        box-shadow:
            0 1px 8px 4px rgba(255, 70, 50, 0.5),
            0 1px 16px 8px rgba(255, 70, 50, 0.3),
            0 1px 32px 16px rgba(255, 70, 50, 0.15);
    }
    50% {
        box-shadow:
            0 1px 12px 6px rgba(255, 70, 50, 0.65),
            0 1px 24px 12px rgba(255, 70, 50, 0.4),
            0 1px 40px 20px rgba(255, 70, 50, 0.2);
    }
}

.mini-board-container.danger-glow {
    box-shadow: 0 0 25px rgba(255, 70, 50, 0.6);
    border-color: rgba(255, 70, 50, 0.7);
    animation: danger-pulse-mini 1.8s ease-in-out infinite;
}

@keyframes danger-pulse {
    0%, 100% { box-shadow: 0 0 40px rgba(255, 70, 50, 0.6), inset 0 0 25px rgba(255, 70, 50, 0.15); }
    50% { box-shadow: 0 0 60px rgba(255, 70, 50, 0.8), inset 0 0 35px rgba(255, 70, 50, 0.25); }
}

@keyframes danger-pulse-mini {
    0%, 100% { box-shadow: 0 0 25px rgba(255, 70, 50, 0.6); }
    50% { box-shadow: 0 0 40px rgba(255, 70, 50, 0.8); }
}

/* Active glow (your turn - attack board glows green) */
.battle-focus.active-glow #mainCanvas {
    border-radius: 0;
    box-shadow:
        0 1px 8px 4px rgba(34, 197, 94, 0.5),
        0 1px 16px 8px rgba(34, 197, 94, 0.3),
        0 1px 32px 16px rgba(34, 197, 94, 0.15);
    animation: active-pulse-green 2s ease-in-out infinite;
}

@keyframes active-pulse-green {
    0%, 100% {
        box-shadow:
            0 1px 8px 4px rgba(34, 197, 94, 0.5),
            0 1px 16px 8px rgba(34, 197, 94, 0.3),
            0 1px 32px 16px rgba(34, 197, 94, 0.15);
    }
    50% {
        box-shadow:
            0 1px 12px 6px rgba(34, 197, 94, 0.65),
            0 1px 24px 12px rgba(34, 197, 94, 0.4),
            0 1px 40px 20px rgba(34, 197, 94, 0.2);
    }
}

.mini-board-container.active-glow {
    box-shadow: 0 0 25px rgba(0, 168, 255, 0.5);
    border-color: rgba(0, 168, 255, 0.6);
    animation: active-pulse-mini 2s ease-in-out infinite;
}

@keyframes active-pulse {
    0%, 100% { box-shadow: 0 0 40px rgba(0, 168, 255, 0.5), inset 0 0 25px rgba(0, 168, 255, 0.1); }
    50% { box-shadow: 0 0 55px rgba(0, 168, 255, 0.7), inset 0 0 30px rgba(0, 168, 255, 0.15); }
}

@keyframes active-pulse-mini {
    0%, 100% { box-shadow: 0 0 25px rgba(0, 168, 255, 0.5); }
    50% { box-shadow: 0 0 35px rgba(0, 168, 255, 0.7); }
}

/* Mini board */
.mini-board-container {
    position: fixed;
    bottom: 75px;
    right: 20px;
    width: 126px;
    height: 154px;
    background: rgba(18, 42, 74, 0.85);
    border-radius: 12px;
    border: 2px solid var(--ocean-light);
    z-index: 20;
    cursor: pointer;
    overflow: hidden;
}

.mini-header {
    padding: 8px 12px;
    background: rgba(10, 22, 40, 0.9);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    display: flex;
    justify-content: space-between;
}

.mini-header.yours { color: var(--accent); }
.mini-header.enemy { color: var(--danger); }

#miniCanvas { width: 100%; height: auto; display: block; }

/* Action bar */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: rgba(18, 42, 74, 0.9);
    display: flex;
    gap: 8px;
}

.coord-display {
    padding: 10px 12px;
    background: var(--ocean-deep);
    border-radius: 8px;
    font-family: monospace;
    font-size: 14px;
    font-weight: bold;
    min-width: 50px;
    text-align: center;
}

.btn {
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.btn.surrender { background: transparent; color: #94a3b8; border: 1px solid #475569; }

.btn.fire {
    flex: 1;
    background: linear-gradient(135deg, var(--danger) 0%, #cc2244 100%);
    color: white;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn.fire:disabled { background: #333; color: #666; }
.btn.primary { background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%); color: white; }
.btn.primary.locked { background: linear-gradient(135deg, #22c55e 0%, #10b981 100%); box-shadow: 0 0 12px rgba(34, 197, 94, 0.6); pointer-events: none; }
.btn.primary.expired { background: #444; color: #888; pointer-events: none; }
.btn.secondary { background: var(--ocean-mid); color: var(--text); border: 1px solid var(--ocean-light); }
.btn.danger { background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%); color: white; }

/* Alert message */
.alert-message {
    position: fixed;
    bottom: 75px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    white-space: nowrap;
    text-align: center;
}

.alert-message.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.alert-message.success { color: var(--success); border: 1px solid var(--success); }
.alert-message.warning { color: var(--warning); border: 1px solid var(--warning); }
.alert-message.danger { color: var(--danger); border: 1px solid var(--danger); }
.alert-message.info { color: var(--accent); border: 1px solid var(--accent); }

/* Hit overlay */
.hit-overlay {
    position: fixed;
    inset: 0;
    background: var(--danger);
    opacity: 0;
    pointer-events: none;
    z-index: 100;
}

.hit-overlay.flash { animation: hit-flash 0.3s ease-out; }

@keyframes hit-flash {
    0% { opacity: 0.4; }
    100% { opacity: 0; }
}

.result-text {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 48px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 8px;
    z-index: 101;
    pointer-events: none;
    text-shadow: 0 0 40px currentColor;
}

.result-text.show { animation: result-pop 0.6s ease-out forwards; }
.result-text.hit { color: var(--danger); }
.result-text.miss { color: #556; }

@keyframes result-pop {
    0% { transform: translate(-50%, -50%) scale(0); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* Pause overlay */
.pause-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 22, 40, 0.92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 150;
}

.pause-container {
    background: linear-gradient(135deg, var(--ocean-mid) 0%, var(--ocean-deep) 100%);
    border: 1px solid var(--ocean-light);
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.pause-title {
    font-size: 28px;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 24px;
    text-transform: uppercase;
    letter-spacing: 4px;
    text-shadow: 0 0 20px rgba(0, 168, 255, 0.4);
}

.pause-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 240px;
}

.pause-buttons .btn {
    width: 100%;
    padding: 16px;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.pause-buttons .settings-panel {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--ocean-light);
    border-radius: 12px;
    padding: 16px;
    margin: 8px 0;
    width: 100%;
}

.pause-buttons .btn.surrender {
    margin-top: 12px;
    background: transparent;
    border: 2px solid var(--danger);
    color: var(--danger);
}

.pause-buttons .btn.surrender:active {
    background: var(--danger);
    color: white;
}

/* Confirmation dialog */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    animation: fade-in 0.2s ease-out;
}

.confirm-overlay.hidden {
    display: none;
}

.confirm-dialog {
    background: linear-gradient(135deg, var(--ocean-mid) 0%, var(--ocean-deep) 100%);
    border: 2px solid var(--danger);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    max-width: 300px;
    box-shadow: 0 0 40px rgba(255, 71, 87, 0.3);
    animation: scale-in 0.2s ease-out;
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes scale-in {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.confirm-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--danger);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.confirm-message {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 24px;
    line-height: 1.5;
}

.confirm-message strong {
    color: var(--danger);
    display: block;
    margin-top: 12px;
}

.confirm-list {
    list-style: none;
    padding: 0;
    margin: 12px 0;
    text-align: left;
}

.confirm-list li {
    padding: 6px 0;
    padding-left: 20px;
    position: relative;
}

.confirm-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--danger);
}

.confirm-buttons {
    display: flex;
    gap: 12px;
}

.confirm-buttons .btn {
    flex: 1;
    padding: 14px;
    font-size: 14px;
    font-weight: 700;
}

/* Game over overlay */
.game-over-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.game-over-result {
    font-size: 48px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 6px;
    margin-bottom: 10px;
    animation: result-scale 0.6s ease-out;
}

.game-over-result.victory { color: var(--success); text-shadow: 0 0 40px rgba(34, 197, 94, 0.6); }
.game-over-result.defeat { color: var(--danger); text-shadow: 0 0 40px rgba(255, 71, 87, 0.6); }

@keyframes result-scale {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

.game-over-subtitle { font-size: 16px; color: #94a3b8; margin-bottom: 30px; }

.game-over-stats { display: flex; gap: 20px; margin-bottom: 40px; }

.stat-box {
    text-align: center;
    padding: 15px 25px;
    background: var(--ocean-mid);
    border-radius: 12px;
    border: 1px solid var(--ocean-light);
}

.stat-value { font-size: 28px; font-weight: 800; color: var(--text); }
.stat-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-top: 4px; }

.game-over-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 200px;
}

.game-over-buttons .btn { width: 100%; padding: 14px; }

/* Score change stat */
.stat-box.score-change {
    min-width: 90px;
}

.stat-value.positive {
    color: #4ade80;
}

.stat-value.negative {
    color: #f87171;
}

/* ============== LEADERBOARD OVERLAY ============== */
.leaderboard-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 22, 40, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.leaderboard-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.leaderboard-container {
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    background: linear-gradient(135deg, var(--ocean-mid) 0%, var(--ocean-deep) 100%);
    border: 1px solid var(--ocean-light);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--ocean-light);
}

.leaderboard-header h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0;
}

.header-btns {
    display: flex;
    gap: 8px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--ocean-light);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--ocean-light);
    color: var(--text);
}

.btn-icon svg {
    width: 20px;
    height: 20px;
}

.btn-icon.spinning svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.leaderboard-columns {
    display: grid;
    grid-template-columns: 40px 1fr 70px 60px 50px;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.15);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.leaderboard-content {
    flex: 1;
    overflow-y: auto;
    min-height: 200px;
    max-height: 50vh;
}

.lb-virtual {
    position: relative;
}

.lb-row {
    display: grid;
    grid-template-columns: 40px 1fr 70px 60px 50px;
    gap: 8px;
    padding: 12px 16px;
    align-items: center;
    border-bottom: 1px solid rgba(26, 58, 92, 0.3);
    font-size: 13px;
    height: 48px;
    box-sizing: border-box;
}

.lb-row.me {
    background: rgba(0, 168, 255, 0.15);
    border-left: 3px solid var(--accent);
}

.lb-row.guest {
    background: rgba(255, 193, 7, 0.15);
    border-left: 3px dashed #ffc107;
}

.lb-row.guest .lb-rank {
    color: #ffc107;
    font-style: italic;
}

.lb-row.guest small {
    font-size: 9px;
    color: #ffc107;
    opacity: 0.8;
}

.lb-rank {
    font-weight: 700;
    color: var(--text-dim);
}

.lb-row:nth-child(-n+3) .lb-rank {
    color: var(--warning);
}

.lb-name {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-score {
    font-weight: 700;
    color: var(--accent);
}

.lb-winrate {
    color: var(--success);
}

.lb-games {
    color: var(--text-dim);
}

/* Google logout button state */
.google-signin-btn.linked {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    box-shadow:
        0 4px 20px rgba(220, 38, 38, 0.3),
        0 0 30px rgba(220, 38, 38, 0.15);
    cursor: pointer;
}
