/* ============================================================
   Game Base — Shared styles for all GameHub games
   ============================================================ */

/* ─── Light Theme (default) ─── */
html:not(.dark) {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --text: #2d3436;
    --dim: #636e72;
    --text-dim: #636e72;
    --border: #dfe6e9;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --success: #00b894;
    --danger: #d63031;
    --gold: #fdcb6e;
    --warn: #f39c12;
    --input-bg: #f8f9fa;
    --hover-bg: #f0f2f5;
    /* Ships overrides */
    --cell-empty: #e8ecf0;
    --cell-ship: #74b9ff;
    --cell-hit: #e17055;
    --cell-sunk: #d63031;
    --cell-miss: #b2bec3;
}

/* ─── Dark Theme ─── */
html.dark {
    --bg: #1a1a2e;
    --panel: #16213e;
    --text: #eee;
    --dim: #aaa;
    --text-dim: #888;
    --border: rgba(255,255,255,0.1);
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --success: #4ade80;
    --danger: #ef4444;
    --gold: #ffd700;
    --warn: #f39c12;
    --input-bg: #0f1729;
    --hover-bg: #1e2d4a;
    /* Ships overrides */
    --cell-empty: #1e2d4a;
    --cell-ship: #2c5282;
    --cell-hit: #e53e3e;
    --cell-sunk: #c53030;
    --cell-miss: #4a5568;
}

/* ─── Theme transition ─── */
body, .screen, .btn, input, select, .game-card, .name-bar, .join-section {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ─── Screen Transition Animations ─── */
.screen.active {
    animation: ghScreenIn 0.35s ease-out;
}
@keyframes ghScreenIn {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Countdown overlay animation */
.countdown-overlay {
    animation: ghFadeIn 0.2s ease-out;
}
@keyframes ghFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes countPulse {
    0%   { transform: scale(0.5); opacity: 0; }
    50%  { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* ─── Theme Toggle Button ─── */
.gh-theme-toggle {
    position: fixed;
    top: 10px;
    right: 48px;
    z-index: 1000;
    background: var(--panel, #fff);
    border: 1px solid var(--border, #dfe6e9);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    box-shadow: var(--shadow, 0 2px 8px rgba(0,0,0,0.08));
    transition: background 0.3s, border-color 0.3s, transform 0.15s;
    padding: 0;
    line-height: 1;
}
.gh-theme-toggle:hover { transform: scale(1.1); }
.gh-theme-toggle:active { transform: scale(0.95); }

/* ─── Name Label ─── */
.gh-name-label {
    display: block;
    font-size: 0.85rem;
    color: var(--dim, #888);
    font-weight: 600;
    margin-bottom: 6px;
    text-align: center;
}

/* ─── Invite Section ─── */
.gh-invite {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 10px 0;
    flex-wrap: wrap;
}
.gh-invite-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border: 1px solid var(--border, #dfe6e9);
    border-radius: 8px;
    background: var(--panel, #fff);
    color: var(--dim, #636e72);
    font-size: 0.8rem;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.2s;
}
.gh-invite-btn:hover {
    background: var(--accent, #6c5ce7);
    color: #fff;
    border-color: var(--accent, #6c5ce7);
}
.gh-invite-btn.copied {
    background: var(--success, #00b894) !important;
    color: #fff !important;
    border-color: var(--success, #00b894) !important;
}

/* ─── Chat (inline in reaction bar) ─── */
.gh-chat-inline {
    display: flex;
    gap: 5px;
    align-items: center;
    margin-left: 6px;
    padding-left: 8px;
    border-left: 1px solid var(--border, rgba(255,255,255,0.15));
}
.gh-chat-input {
    width: 120px;
    padding: 5px 8px;
    border: 1px solid var(--border, rgba(255,255,255,0.15));
    border-radius: 6px;
    background: var(--input-bg, rgba(255,255,255,0.08));
    color: var(--text, #eee);
    font-size: 0.78rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, width 0.2s;
}
.gh-chat-input:focus {
    border-color: var(--accent, #6c5ce7);
    width: 150px;
}
.gh-chat-input::placeholder { color: var(--dim, #888); }
.gh-chat-send {
    padding: 5px 8px;
    background: var(--accent, #6c5ce7);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 700;
    transition: opacity 0.15s, transform 0.1s;
}
.gh-chat-send:hover { opacity: 0.85; }
.gh-chat-send:active { transform: scale(0.92); }

/* Chat floating messages */
.gh-chat-float {
    position: absolute;
    bottom: 0;
    padding: 5px 12px;
    background: var(--panel, rgba(22,33,62,0.92));
    border: 1px solid var(--border, rgba(255,255,255,0.1));
    border-radius: 10px;
    color: var(--text, #eee);
    font-size: 0.82rem;
    white-space: nowrap;
    pointer-events: none;
    animation: ghChatUp 3.5s ease-out forwards;
    box-shadow: var(--shadow, 0 2px 8px rgba(0,0,0,0.2));
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gh-chat-float b {
    color: var(--accent, #6c5ce7);
    margin-right: 4px;
}
@keyframes ghChatUp {
    0%   { opacity: 1; transform: translateY(0); }
    75%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(-120px); }
}

/* ─── Toast Notifications ─── */
.gh-toast {
    position: fixed;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel, #fff);
    color: var(--text, #2d3436);
    padding: 10px 22px;
    border-radius: 10px;
    border: 1px solid var(--border, #dfe6e9);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    font-size: 0.88rem;
    font-weight: 600;
    z-index: 2000;
    animation: ghToastIn 0.3s ease, ghToastOut 0.3s ease 2s forwards;
    pointer-events: none;
    white-space: nowrap;
}
@keyframes ghToastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes ghToastOut {
    to { opacity: 0; transform: translateX(-50%) translateY(-12px); }
}

/* ─── Tablet Responsiveness (768–1024px) ─── */
@media (min-width: 768px) and (max-width: 1199px) {
    body { font-size: 17px; }

    .screen {
        max-width: 620px;
        margin-left: auto;
        margin-right: auto;
    }

    /* Larger touch targets */
    .btn { padding: 14px 28px; font-size: 1.05rem; }
    .name-input { font-size: 1.05rem; padding: 13px 18px; }
    .room-code { font-size: 2rem; letter-spacing: 8px; }
    .player-tag { padding: 8px 15px; font-size: 0.95rem; }

    /* Reaction bar spacing */
    .reaction-bar { gap: 10px; padding: 10px 16px; }
    .reaction-btn { font-size: 1.5rem; padding: 6px 8px; }

    /* Chat input wider on tablet */
    .gh-chat-input { width: 160px; }
    .gh-chat-input:focus { width: 200px; }

    /* Grid games - cap size */
    .drawing-grid, .game-grid { max-width: 500px; margin: 0 auto; }
}

/* ─── Desktop (1200px+) ─── */
@media (min-width: 1200px) {
    .screen {
        max-width: 700px;
        margin-left: auto;
        margin-right: auto;
    }
    .gh-chat-input { width: 180px; }
}

/* ═══════════════════════════════════════════════════════════
   Light-mode overrides for shared components
   (higher specificity than per-game .name-input rules)
   ═══════════════════════════════════════════════════════════ */
html:not(.dark) .name-input {
    color: var(--text) !important;
    background: var(--input-bg) !important;
    border-color: var(--border) !important;
}
html:not(.dark) .name-input::placeholder {
    color: var(--dim) !important;
    opacity: 0.75;
}
html:not(.dark) .name-input:focus {
    border-color: var(--accent, #6c5ce7) !important;
}
html:not(.dark) .name-clear {
    color: var(--dim) !important;
}
html:not(.dark) .name-clear:hover {
    color: var(--accent, #6c5ce7) !important;
}
html:not(.dark) .btn-sound-test {
    border-color: var(--border);
    color: var(--dim);
}
html:not(.dark) .btn-sound-test:active {
    border-color: var(--accent, #6c5ce7);
    color: var(--text);
}

/* Room code + general inputs in light mode */
html:not(.dark) .room-code,
html:not(.dark) input[type="text"],
html:not(.dark) input[type="number"] {
    color: var(--text);
}

/* ── Generic: półprzezroczyste białe tła/ramki są niewidoczne na jasnym tle ── */
html:not(.dark) .board {
    background: rgba(0,0,0,0.04);
}
html:not(.dark) .cell:hover:not(.disabled):not(.x):not(.o) {
    background: rgba(108,92,231,0.08);
}

/* ── Postęp / kropki w sekwencji ── */
html:not(.dark) .prog-dot {
    background: var(--border);
}
html:not(.dark) .prog-dot.filled {
    background: var(--accent, #6c5ce7);
}

/* ── Ramki tabel (statki, literki itp.) ── */
html:not(.dark) .grid-table th {
    color: var(--dim);
}

/* ── Chipy/tagi z półprzezroczystym białym tłem ── */
html:not(.dark) .pill,
html:not(.dark) .tag,
html:not(.dark) .chip {
    background: var(--panel);
    border-color: var(--border);
    color: var(--text);
}

/* ── Feedback sukces/błąd — tekst ciemny na bardzo jasnym tle ── */
html:not(.dark) .stroop-area.correct { background: rgba(22,163,74,0.18); }
html:not(.dark) .stroop-area.wrong { background: rgba(220,38,38,0.18); }

/* ── Nieaktywne przełączniki ustawień (czas gry, trudność, rundy) ── */
html:not(.dark) .btn-time,
html:not(.dark) .btn-rounds,
html:not(.dark) .btn-diff,
html:not(.dark) .btn-size,
html:not(.dark) .btn-wins,
html:not(.dark) .btn-mode,
html:not(.dark) .btn-round,
html:not(.dark) .btn-toggle,
html:not(.dark) .btn-setting {
    border-color: var(--border) !important;
    color: var(--text);
}
html:not(.dark) .btn-time.active,
html:not(.dark) .btn-rounds.active,
html:not(.dark) .btn-diff.active,
html:not(.dark) .btn-size.active,
html:not(.dark) .btn-wins.active,
html:not(.dark) .btn-mode.active,
html:not(.dark) .btn-round.active,
html:not(.dark) .btn-toggle.active,
html:not(.dark) .btn-setting.active {
    /* Zielona (przyjazna) ramka, tło transparentne, tekst oryginalny ciemny */
    border-color: #16a34a !important;
    background: rgba(22,163,74,0.12) !important;
    color: var(--text) !important;
}

/* ── Ramki/tła panelowe z półprzezroczystym białym — domyślnie na jasnych tłach znikają ── */
html:not(.dark) .mode-indicator {
    border-color: var(--border);
}
html:not(.dark) .btn-change-game,
html:not(.dark) .btn-refresh {
    background: var(--panel);
    border-color: var(--border);
    color: var(--text);
}
html:not(.dark) .btn-change-game:hover,
html:not(.dark) .btn-refresh:hover {
    background: rgba(108,92,231,0.1);
    color: var(--text);
}

/* ── Rozgałęzienia reakcji / chat panele ── */
html:not(.dark) .reaction-bar {
    background: var(--panel);
    border: 1px solid var(--border);
}

/* ── Toast: „X wyszedł do Lobby" ── */
.gh-lobby-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-12px);
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: #fff;
    padding: 12px 22px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 0.95rem;
    box-shadow: 0 10px 30px rgba(108,92,231,0.4);
    opacity: 0;
    pointer-events: none;
    z-index: 9999;
    transition: opacity 0.3s, transform 0.3s;
}
.gh-lobby-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ── Auto-injected reaction bar (na ekranie wyników) ── */
.gh-reaction-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin: 20px auto 10px;
    padding: 8px 12px;
    max-width: 360px;
    background: var(--panel, #16213e);
    border: 1px solid var(--border, rgba(255,255,255,0.1));
    border-radius: 999px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.15);
}
.gh-reaction-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    transition: transform 0.1s, background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.gh-reaction-btn:hover { background: rgba(108,92,231,0.15); }
.gh-reaction-btn:active, .gh-reaction-btn.pulse { transform: scale(1.3); }

.gh-reaction-float {
    position: fixed;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    z-index: 9997;
    animation: ghFloatUp 2.5s ease-out forwards;
}
.gh-reaction-emoji { font-size: 2.2rem; }
.gh-reaction-name { font-size: 0.7rem; color: var(--dim); margin-top: 2px; }
@keyframes ghFloatUp {
    0%   { transform: translateY(0); opacity: 0; }
    10%  { opacity: 1; }
    80%  { opacity: 1; }
    100% { transform: translateY(-60vh); opacity: 0; }
}

/* ═══ Mobile: reaction-bar + chat muszą się zmieścić na szerokości ekranu ═══ */
@media (max-width: 500px) {
    .reaction-bar {
        flex-wrap: wrap !important;
        max-width: 96vw;
        gap: 6px !important;
        padding: 8px 10px !important;
        row-gap: 8px !important;
    }
    .gh-chat-inline {
        flex: 1 1 100%;
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        border-top: 1px solid var(--border, rgba(255,255,255,0.15));
        padding-top: 8px;
        gap: 6px;
    }
    .gh-chat-input {
        flex: 1 1 auto;
        width: auto !important;
        min-width: 0;
        font-size: 0.9rem;
        padding: 8px 10px;
    }
    .gh-chat-input:focus { width: auto !important; }
    .gh-chat-send {
        flex: 0 0 auto;
        padding: 8px 14px;
        font-size: 0.9rem;
    }
    .gh-reaction-bar {
        max-width: 96vw;
        flex-wrap: wrap;
    }
}

/* ─── Light theme fixes for dark-designed games ─── */
html:not(.dark) .btn-change-game {
    color: var(--dim);
}
html:not(.dark) .btn-change-game:hover {
    color: var(--text);
}
html:not(.dark) .btn-refresh {
    color: var(--dim);
    border-color: var(--border);
    background: var(--panel);
}
html:not(.dark) .spinner {
    border-color: var(--border);
    border-top-color: var(--accent);
}
html:not(.dark) .player-tag {
    background: var(--hover-bg);
    color: var(--text);
    border-color: var(--border);
}
html:not(.dark) .room-code {
    color: var(--accent);
}
html:not(.dark) .countdown-overlay {
    background: rgba(0,0,0,0.5);
}
html:not(.dark) .countdown-number {
    color: #fff;
}
html:not(.dark) .reaction-bar {
    background: var(--panel);
    border-color: var(--border);
}

/* ─── Smooth button press for all ─── */
.btn, .gh-invite-btn, .reaction-btn, .btn-play, .btn-rules, .btn-round, .btn-setting, .btn-rounds, .btn-distance {
    transition: transform 0.1s ease, background 0.2s ease, opacity 0.15s ease;
}
.btn:active, .reaction-btn:active {
    transform: scale(0.95);
}
