:root {
    /* Color Palette */
    --primary: #121212;
    /* Blackish */
    --secondary: #CCC5B9;
    /* Grayish */
    --accent: #4A90E2;
    /* Blue (was Orange) */
    --bg-color: #FAFAFA;
    /* Off-white background */

    --player-1: #4A90E2;
    /* Soft Blue */
    --player-2: #E25555;
    /* Soft Red */
    --board-bg: #FFFFFF;
    --board-shadow: rgba(0, 0, 0, 0.05);

    --text-main: #333333;
    --text-muted: #888888;

    /* Spacing & Sizes */
    --radius-lg: 24px;
    --radius-md: 12px;
    --radius-sm: 8px;

    /* Transitions */
    --transition-fast: 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --transition-bounce: 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);

    /* Component Colors (Light Mode Default) */
    --card-bg: #FFFFFF;
    --input-bg: #FFFFFF;
    --cell-empty: #F0F2F5;
    --icon-btn-bg: #FFFFFF;
}

/* Dark Mode Theme */
body.dark-mode {
    --bg-color: #1a1a2e;
    --board-bg: #16213e;
    --board-shadow: rgba(0, 0, 0, 0.3);
    --text-main: #e6e6e6;
    --text-muted: #a0a0a0;
    --primary: #e6e6e6;
    --secondary: #4a4a6a;

    /* Dark Mode Component Colors */
    --card-bg: #16213e;
    --input-bg: #0f1218;
    --cell-empty: #252a41;
    --icon-btn-bg: #16213e;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #C0C0C0;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #A0A0A0;
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #C0C0C0 transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    overflow: hidden;
    /* Prevent scrolling on game view */
    height: 100vh;
    /* Fallback */
    height: 100dvh;
    /* Dynamic viewport height for mobile */
    width: 100vw;
}

.app {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* --- Views Management --- */
.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
    padding: 24px;
}

.view.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

/* --- Menu View --- */
#view-menu {
    flex-direction: column;
    justify-content: space-between;
    /* Spreads content */
    align-items: center;
    text-align: center;
    padding-top: 15vh;
    /* Push logo down slightly from very top */
    padding-bottom: 80px;
    /* Space for footer */
}

.menu-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    flex: 1;
    /* Take up available space */
}

/* --- Lobby View --- */
#view-lobby {
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* Logo Styles */
.logo {
    font-size: 3.5rem;
    font-weight: 900;
    color: var(--primary);
    /* Solid black/white */
    letter-spacing: -2px;
    margin-bottom: 0;
    /* Let flex gap handle spacing */
    position: relative;
    z-index: 2;
}

.highlight {
    color: var(--accent);
    /* No shadow/glow - clean flat look */
    text-shadow: none;
    display: inline-block;
    animation: bounce 2s infinite;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    margin-bottom: 3rem;
    font-weight: 500;
}

.player-setup {
    width: 100%;
    width: 100%;
    max-width: 480px;
    margin-bottom: 2rem;
}

.menu-actions {
    width: 90%;
    max-width: 300px;
    /* Narrower for pill look */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    /* More breathing room */
    margin-top: auto;
    /* Push to vertical center */
    margin-bottom: auto;
    /* Push to vertical center */
}

.input-group {
    position: relative;
    margin-bottom: 1.5rem;
    text-align: left;
}

.input-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.input-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #E0E0E0;
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    transition: border-color var(--transition-fast);
    outline: none;
    background-color: var(--input-bg);
    color: var(--text-main);
}

.input-group input:focus {
    border-color: var(--text-main);
}

.color-dot {
    position: absolute;
    right: 16px;
    bottom: 14px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.p1-color {
    background-color: var(--player-1);
}

.p2-color {
    background-color: var(--player-2);
}

/* Checkbox Option */
.checkbox-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    margin-top: 12px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.checkbox-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--text-main);
    cursor: pointer;
}

.checkbox-option span {
    user-select: none;
}

/* Settings Modal */
.settings-content {
    text-align: left;
    width: 100%;
}

.setting-group {
    margin-bottom: 16px;
}

.setting-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.setting-group input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid #E5E5E5;
    /* Light border */
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    outline: none;
    transition: border-color var(--transition-fast), background-color var(--transition-fast);
    background-color: #FAFAFA;
    /* Very light gray */
    color: var(--text-main);
}

.setting-group input:focus {
    border-color: var(--text-main);
    background-color: #FFFFFF;
}

.setting-group input:focus {
    border-color: var(--text-main);
}

.menu-footer {
    position: absolute;
    bottom: 24px;
    font-size: 0.8rem;
    color: var(--text-muted);
    opacity: 0.9;
    font-weight: 500;
}

/* --- Buttons --- */
.btn {
    border: none;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease, filter 0.2s ease;
    border-radius: 50px;
    /* Fully rounded as requested */
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.96);
}

.primary-btn {
    background-color: var(--primary);
    /* Solid Black */
    color: var(--bg-color);
    /* Contrast Text */
    padding: 18px 32px;
    font-size: 1rem;
    width: 100%;
    max-width: 100%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    /* Subtle shadow */
    letter-spacing: 0.5px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.difficulty-btn {
    background-color: #F0F2F5;
    color: var(--text-main);
    padding: 12px 24px;
    border-radius: 50px;
    /* Fully rounded */
    font-size: 1rem;
    flex: 1;
    min-width: 80px;
    white-space: nowrap;
}

.secondary-btn {
    background-color: transparent;
    color: var(--text-main);
    padding: 18px 32px;
    font-size: 1rem;
    width: 100%;
    max-width: 100%;
    border: 2px solid #E5E5E5;
    /* Minimal border */
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    box-shadow: none;
}

.secondary-btn:hover {
    border-color: var(--text-main);
    background-color: var(--cell-empty);
}

.icon-btn {
    background: var(--icon-btn-bg);
    border: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    /* Fully round */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    color: var(--text-main);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    border: 1px solid #F0F0F0;
}

/* --- Game View --- */
#view-game {
    justify-content: space-between;
    align-items: center;
    padding: 24px 16px;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    /* Safe area for iOS */
    max-width: 600px;
    left: 50%;
    transform: translateX(-50%);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-bottom: 20px;
}

.turn-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    border: 1px solid #F5F5F5;
    font-weight: 600;
    font-size: 0.9rem;
}

.turn-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: background-color var(--transition-fast);
}

.board-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 0;
    /* Important for flex child to shrink properly */
    padding: 10px 0;
}

.board {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 8px;
    padding: 12px;
    background: var(--board-bg);
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.05);
    width: 100%;
    aspect-ratio: 7/6;
    max-width: 100%;
    max-height: 100%;
    /* Ensure it fits in container */
}

/* Specific aspect ratio handling for very tall screens to avoid board being too small */
@media (aspect-ratio < 9/16) {
    .board {
        gap: 6px;
        padding: 8px;
    }
}

.col {
    display: flex;
    flex-direction: column-reverse;
    /* Stack from bottom up */
    cursor: pointer;
    position: relative;
    border-radius: var(--radius-sm);
    transition: background-color 0.1s;
}

/* Hover effect only on devices that support hover (not touch) */
@media (hover: hover) {
    .col:hover {
        background-color: rgba(0, 0, 0, 0.03);
    }
}

.cell {
    width: 100%;
    aspect-ratio: 1;
    /* Square */
    border-radius: 50%;
    background-color: var(--cell-empty);
    /* Empty slot color */
    margin-bottom: 8px;
    /* Gap handled by grid really, but flex col needs margin if not grid */
    margin: 0;
    /* Reset */
    border: 1px solid rgba(0, 0, 0, 0.02);
    /* Improve performance for updates */
    transform: translateZ(0);
}

/* The cells are visually 'holes' in the board, but we just style them as circles
   When filled, we change background color.
*/

.cell.filled {
    animation: dropIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.cell.player-1 {
    background-color: var(--player-1);
}

.cell.player-2 {
    background-color: var(--player-2);
}

/* Ghost preview for hover */
.cell.ghost-1 {
    background-color: var(--player-1);
    opacity: 0.35;
}

.cell.ghost-2 {
    background-color: var(--player-2);
    opacity: 0.35;
}

@keyframes dropIn {
    0% {
        transform: translateY(-400%);
        opacity: 0;
    }

    40% {
        opacity: 1;
    }

    70% {
        transform: translateY(8%);
    }

    85% {
        transform: translateY(-4%);
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Winning pieces highlight */
.cell.win {
    position: relative;
}

.cell.win::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40%;
    height: 40%;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.game-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-top: 20px;
}

.score-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--card-bg);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    min-width: 80px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.p1-score-label {
    color: var(--player-1);
    font-weight: 700;
    font-size: 0.8rem;
}

.p2-score-label {
    color: var(--player-2);
    font-weight: 700;
    font-size: 0.8rem;
}

#score-p1,
#score-p2 {
    font-size: 1.25rem;
    font-weight: 800;
}

.timer {
    font-family: 'Inter', monospace;
    /* Monospace for steady numbers */
    font-weight: 600;
    font-size: 1.5rem;
    color: var(--text-main);
    min-width: 40px;
    text-align: center;
    transition: color 0.3s ease, transform 0.3s ease;
}

/* Timer warning state (5 seconds or less) */
.timer.timer-warning {
    color: #F5A623;
}

/* Timer critical state (3 seconds or less) */
.timer.timer-critical {
    color: #E25555;
    animation: timer-pulse 0.5s infinite;
}

@keyframes timer-pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* --- Modal/Overlay --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    /* Dark Gray Transparent */
    backdrop-filter: blur(5px);
    z-index: 100;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 20px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
    display: flex;
}

.result-card {
    background: var(--card-bg);
    padding: 32px;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.05);
    /* Lighter shadow */
    text-align: center;
    width: 90%;
    max-width: 340px;
    transform: scale(0.9);
    transition: transform var(--transition-bounce);
    border: 1px solid rgba(0, 0, 0, 0.05);
    /* Subtle border */
}

.overlay.active .result-card {
    transform: scale(1);
}

#result-title {
    font-size: 1.5rem;
    margin-bottom: 24px;
    font-weight: 700;
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* --- Lobby UI --- */
.lobby-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    width: 100%;
    max-width: 360px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.lobby-section {
    margin-bottom: 4px;
    text-align: left;
}

.lobby-section h3 {
    font-size: 1rem;
    margin-bottom: 4px;
}

.small-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.id-display-group,
.join-input-group {
    display: flex;
    gap: 8px;
}

#my-peer-id {
    flex: 1;
    background: #F5F5F5;
    padding: 10px;
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: 1.1rem;
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn-sm {
    background: var(--text-main);
    color: white;
    border: none;
    width: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.join-input-group input {
    flex: 1;
    padding: 10px;
    border: 2px solid #E0E0E0;
    border-radius: var(--radius-sm);
    font-family: monospace;
}

.primary-btn-sm {
    background: var(--text-main);
    color: white;
    border: none;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin: 16px 0;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #E0E0E0;
}

.divider span {
    padding: 0 10px;
}

.status-msg {
    margin-top: 16px;
    font-size: 0.9rem;
    font-weight: 600;
    min-height: 20px;
    color: var(--accent);
}

/* --- Toast Notification --- */
.toast {
    position: fixed;
    bottom: 140px;
    /* Raised above player name/score area */
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 24px;
    border-radius: 50px;
    font-size: 0.9rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
    pointer-events: none;
    text-align: center;
    width: max-content;
    max-width: 90%;
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* --- Color Palette (Lobby) --- */
.color-selection-group {
    margin-bottom: 20px;
    text-align: left;
}

.color-selection-group label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.color-palette {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    /* Center visuals */
}

.color-option {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: var(--primary);
    /* High contrast border for selection */
    transform: scale(1.15);
}

/* Landscape Mobile Tweaks */
@media screen and (orientation: landscape) and (max-height: 500px) {
    #view-game {
        flex-direction: row;
        align-items: center;
        max-width: 800px;
        padding: 10px;
    }

    .game-header,
    .game-footer {
        flex-direction: column;
        width: 80px;
        height: 100%;
        justify-content: center;
        gap: 16px;
        margin: 0;
    }

    .board-container {
        height: 100%;
        aspect-ratio: auto;
    }

    .board {
        height: 100%;
        width: auto;
        aspect-ratio: 7/6;
    }
}

/* Footer Buttons */
.footer-buttons {
    display: flex;
    gap: 24px;
    justify-content: center;
    align-items: center;
    margin-bottom: 12px;
}

.footer-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 6px 12px;
    transition: color 0.2s ease;
    text-decoration: none;
    letter-spacing: 0.3px;
}

.footer-btn:hover {
    color: var(--text-main);
}

/* Header Actions (Dark Mode + Restart) */
.header-actions {
    display: flex;
    gap: 8px;
}

/* Match Info (Timer + Counter) */
.match-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.match-counter {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Dark Mode specific overrides */
body.dark-mode .board {
    background: var(--board-bg);
    box-shadow: 0 20px 40px var(--board-shadow);
}

body.dark-mode .icon-btn {
    background: var(--board-bg);
    border-color: var(--secondary);
    color: var(--text-main);
}

body.dark-mode .turn-indicator {
    background: var(--board-bg);
}

body.dark-mode .score-pill {
    background: var(--board-bg);
}

body.dark-mode .result-card {
    background: var(--board-bg);
}

body.dark-mode .primary-btn {
    background-color: var(--accent);
}

body.dark-mode .secondary-btn {
    background-color: var(--board-bg);
    border-color: var(--secondary);
}

/* --- AI Mode Button (Minimal Style) --- */
.ai-btn {
    background: white;
    color: var(--text-main);
    padding: 16px 32px;
    border-radius: var(--radius-lg);
    font-size: 1.1rem;
    width: 100%;
    max-width: 320px;
    border: 2px solid #E0E0E0;
    transition: transform 0.2s, border-color 0.2s;
}

.ai-btn:hover {
    border-color: var(--text-main);
}

/* --- AI Difficulty Modal (Minimal Style) --- */
.difficulty-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.difficulty-btn {
    background: white;
    color: var(--text-main);
    padding: 14px 24px;
    border-radius: var(--radius-md);
    border: 2px solid #E0E0E0;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    font-size: 1rem;
    font-weight: 600;
}

.difficulty-btn:hover {
    border-color: var(--text-main);
    transform: scale(1.02);
}

.difficulty-btn:active {
    transform: scale(0.98);
}

/* AI Thinking indicator */
.ai-thinking {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

/* --- Chat Panel (Online Games) --- */
.chat-panel {
    position: fixed;
    bottom: 100px;
    right: 16px;
    z-index: 50;
}

.chat-panel.hidden {
    display: none;
}

.chat-toggle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--text-main);
    color: var(--bg-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    position: relative;
    transition: transform 0.2s;
}

.chat-toggle:hover {
    transform: scale(1.05);
}

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #E25555;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-badge.hidden {
    display: none;
}

.chat-window {
    position: absolute;
    bottom: 56px;
    right: 0;
    width: 280px;
    max-height: 300px;
    background: white;
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-window.hidden {
    display: none;
}

.chat-messages {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    max-height: 200px;
    min-height: 100px;
}

.chat-msg {
    margin-bottom: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    max-width: 85%;
    word-wrap: break-word;
}

.chat-msg.sent {
    background: var(--player-1);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.chat-msg.received {
    background: #F0F2F5;
    color: var(--text-main);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid #E0E0E0;
}

.chat-input-area input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #E0E0E0;
    border-radius: 20px;
    font-size: 0.85rem;
    outline: none;
}

.chat-input-area input:focus {
    border-color: var(--text-main);
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--text-main);
    color: var(--bg-color);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}

.chat-send-btn:hover {
    opacity: 0.9;
}

/* Desktop Chat Position Adjustment */
@media (min-width: 768px) {
    .chat-panel {
        right: 46px;
        /* Shifted 30px more from edge (16px + 30px) */
    }
}

/* --- Custom Toggle Switch --- */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 16px;
    padding: 4px 0;
}

.setting-label {
    font-size: 0.95rem;
    color: var(--text-main);
    font-weight: 500;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked+.slider {
    background-color: var(--player-1);
    /* Blue Color */
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--player-1);
}

input:checked+.slider:before {
    transform: translateX(20px);
}

/* --- Dark Mode Config --- */
body.dark-mode {
    --bg-color: #050505;
    /* Deep Black */
    --board-bg: #222222;
    /* Lighter Dark Gray for Board */
    --text-main: #FFFFFF;
    --text-muted: #AAAAAA;
    --board-shadow: rgba(0, 0, 0, 0.8);
}

body.dark-mode .result-card,
body.dark-mode .chat-window,
body.dark-mode .modal-content,
body.dark-mode .lobby-card {
    background-color: #1A1A1A;
    /* Slightly lighter card bg */
    border: 1px solid #333;
    box-shadow: none;
}

body.dark-mode .board {
    border: 2px solid #333;
    /* Border to define board edge */
}

body.dark-mode .setting-group input,
body.dark-mode .chat-input-area input,
body.dark-mode .join-input-group input,
body.dark-mode .input-group input {
    background-color: #1A1A1A;
    border-color: #333;
    color: white;
}

body.dark-mode .secondary-btn,
body.dark-mode .difficulty-btn {
    background-color: #2D2D2D;
    color: #FFFFFF;
    border: 1px solid #444;
}

body.dark-mode .secondary-btn:hover,
body.dark-mode .difficulty-btn:hover {
    background-color: #3D3D3D;
    border-color: #555;
}

body.dark-mode .chat-msg.received {
    background-color: #333;
    color: white;
}

body.dark-mode .chat-input-area {
    border-top-color: #333;
}

body.dark-mode .slider {
    background-color: #444;
}

body.dark-mode .divider::before,
body.dark-mode .divider::after {
    border-color: #333;
}



/* Make Color Palette highly visible */
body.dark-mode .color-option {
    border: 2px solid #888;
    /* Bright border */
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

body.dark-mode .color-option.selected {
    border-color: white;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.4);
    transform: scale(1.15);
}

body.dark-mode .lobby-section,
body.dark-mode .lobby-section h3,
body.dark-mode .small-text,
body.dark-mode .section-title,
body.dark-mode .subtitle {
    color: #DDDDDD;
    /* Light gray for lobby text */
}

body.dark-mode #my-peer-id {
    background-color: #222;
    color: white;
}

body.dark-mode .icon-btn-sm,
body.dark-mode .primary-btn-sm {
    background-color: #333;
    color: white;
    border: 1px solid #444;
}

body.dark-mode .icon-btn-sm:hover,
body.dark-mode .primary-btn-sm:hover {
    background-color: #444;
}

/* Ensure Logo Highlight Pops */
/* Ensure Logo Highlight Pops */
body.dark-mode .highlight {
    /* text-shadow: 0 0 15px rgba(255, 255, 255, 0.6); */
    text-shadow: none;
}

/* Force Chat Icons to be Black on White in Dark Mode */
body.dark-mode .chat-toggle,
body.dark-mode .chat-send-btn {
    background-color: #FFFFFF !important;
    color: #000000 !important;
}