/**
 * Theme System - Light/Dark Mode Variables
 */

:root[data-theme="dark"] {
    --bg-primary: #0a0e17;
    --bg-secondary: rgba(30, 41, 59, 0.7);
    --bg-nav: rgba(10, 14, 23, 0.85);
    --border-color: rgba(100, 116, 139, 0.2);
    --border-nav: rgba(51, 65, 85, 0.6);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --card-hover: rgba(30, 41, 59, 0.9);
    --grid-color: rgba(59, 130, 246, 0.07);
    --glow-color: rgba(59, 130, 246, 0.15);
    --accent-blue: #3b82f6;
    --accent-green: #6ee7b7;
    --input-bg: rgba(30, 41, 59, 0.5);
    --input-border: rgba(100, 116, 139, 0.3);
    --button-hover: rgba(59, 130, 246, 0.1);
}

:root[data-theme="light"] {
    --bg-primary: #e8eaf0;
    --bg-secondary: rgba(248, 249, 251, 0.9);
    --bg-nav: rgba(242, 244, 248, 0.95);
    --border-color: rgba(203, 213, 225, 0.8);
    --border-nav: rgba(203, 213, 225, 1);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --card-hover: rgba(255, 255, 255, 0.95);
    --grid-color: rgba(59, 130, 246, 0.04);
    --glow-color: rgba(59, 130, 246, 0.1);
    --accent-blue: #2563eb;
    --accent-green: #059669;
    --input-bg: rgba(248, 249, 251, 0.8);
    --input-border: rgba(203, 213, 225, 0.8);
    --button-hover: rgba(59, 130, 246, 0.08);
}

/* Base Styles */
body {
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    transition: background-color 0.3s ease;
}

.card:hover {
    background: var(--card-hover);
}

nav {
    background: var(--bg-nav) !important;
    border-bottom-color: var(--border-nav) !important;
}

.text-secondary {
    color: var(--text-secondary) !important;
}

.text-muted {
    color: var(--text-muted) !important;
}

.hero-grid {
    background-image:
        linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 40px 40px;
}

.glow {
    box-shadow: 0 0 40px var(--glow-color);
}

/* Theme Toggle Button */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--button-hover);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
}

#theme-toggle:hover {
    background: var(--input-bg);
    transform: scale(1.05);
}

/* Form Elements */
input[type="text"],
input[type="email"],
textarea,
select {
    background: var(--input-bg) !important;
    border-color: var(--input-border) !important;
    color: var(--text-primary) !important;
}

input[type="text"]:focus,
input[type="email"]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent-blue) !important;
}

/* Links */
a {
    transition: color 0.2s ease;
}

nav a {
    color: var(--text-secondary) !important;
}

nav a:hover {
    color: var(--text-primary) !important;
}

/* Board cells for watch page */
[data-theme="light"] .board-cell {
    background: rgba(226, 232, 240, 0.3);
    border-color: rgba(148, 163, 184, 0.3);
}

[data-theme="light"] .board-cell.hit {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
}

[data-theme="light"] .board-cell.miss {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
}

[data-theme="light"] .board-cell.sunk {
    background: rgba(156, 163, 175, 0.3);
    border-color: rgba(107, 114, 128, 0.4);
}

/* Activity feed for light mode */
[data-theme="light"] .activity-item {
    background: rgba(241, 245, 249, 0.6);
    border-color: rgba(226, 232, 240, 0.8);
}

/* Gradient text works in both modes */
.gradient-text {
    background: linear-gradient(135deg, var(--accent-green), var(--accent-blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Smooth transitions for theme changes */
* {
    transition-property: background-color, border-color, color;
    transition-duration: 0.3s;
    transition-timing-function: ease;
}

/* Preserve fast transitions for hover effects */
button,
a,
.stat-card {
    transition-duration: 0.2s;
}

/* Text primary utility (theme-aware alternative to text-white) */
.text-primary {
    color: var(--text-primary) !important;
}

/* Input password (not covered by the text/email/textarea selectors above) */
input[type="password"] {
    background: var(--input-bg) !important;
    border-color: var(--input-border) !important;
    color: var(--text-primary) !important;
}

/* ── Light mode: fix hardcoded Tailwind color classes used across pages ── */

/* Greys that become invisible on a light background */
[data-theme="light"] .text-gray-300 { color: #374151 !important; }
[data-theme="light"] .text-gray-400 { color: #6b7280 !important; }

/* Dark card / code-block backgrounds */
[data-theme="light"] .bg-slate-900 {
    background: rgba(241, 245, 249, 0.9) !important;
    color: var(--text-primary);
}

/* Dark borders that disappear on a light background */
[data-theme="light"] .border-slate-600 { border-color: rgba(100, 116, 139, 0.4) !important; }
[data-theme="light"] .border-slate-700 { border-color: rgba(148, 163, 184, 0.4) !important; }
[data-theme="light"] .border-slate-800 { border-color: rgba(203, 213, 225, 0.6) !important; }

/* Footer border uses border-slate-800/60 (Tailwind opacity modifier) */
[data-theme="light"] footer { border-color: rgba(203, 213, 225, 0.6) !important; }

/* Placeholder colour in light mode */
[data-theme="light"] input::placeholder { color: #94a3b8; }

/* ── Mobile Navigation ────────────────────────────────────────────────────── */
.mobile-nav-panel {
    display: none;
    position: fixed;
    top: 4rem;
    left: 0;
    right: 0;
    z-index: 49;
    padding: 0.5rem 1rem 0.75rem;
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border-nav);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    flex-direction: column;
    gap: 0.125rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.mobile-nav-panel.open {
    display: flex;
}

.mobile-nav-link {
    display: block;
    padding: 0.6rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
}

.mobile-nav-link:hover,
.mobile-nav-link.active {
    background: var(--button-hover);
    color: var(--text-primary);
}

#mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--button-hover);
    border: 1px solid var(--border-color);
    cursor: pointer;
    color: var(--text-primary);
    transition: all 0.2s ease;
    flex-shrink: 0;
}

#mobile-menu-btn:hover {
    background: var(--input-bg);
    transform: scale(1.05);
}

@media (max-width: 767px) {
    #mobile-menu-btn {
        display: flex;
    }
    .mobile-nav-panel {
        display: none;
    }
    .mobile-nav-panel.open {
        display: flex;
    }
}

@media (min-width: 768px) {
    .mobile-nav-panel { display: none !important; }
    #mobile-menu-btn { display: none !important; }
}

/* ── Responsive table wrapper ─────────────────────────────────────────────── */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── Small-screen padding fix ─────────────────────────────────────────────── */
@media (max-width: 639px) {
    main.max-w-4xl,
    main.max-w-5xl {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}
