/* Chat modal overlay for mobile */
@media (max-width: 700px) {
    .chat-sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        max-width: none !important;
        z-index: 2000 !important;
        border-radius: 0 !important;
        box-shadow: 0 0 0 9999px rgba(0,0,0,0.5);
        display: none;
        flex-direction: column !important;
        background-color: var(--bg-color);
        height: 100dvh !important;
        max-height: 100dvh !important;
        padding: 0 !important;
    }
    .chat-sidebar.mobile-active {
        display: flex !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
    }
    .chat-sidebar.hidden {
        display: none !important;
    }
    .chat-header {
        position: sticky !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        z-index: 10 !important;
        border-radius: 0 !important;
    }
    .chat-messages {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        margin-bottom: 0 !important;
        padding-top: 0 !important;
    }
    .chat-input-container {
        position: sticky !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        z-index: 11 !important;
        background: var(--grid-bg) !important;
        border-radius: 0 !important;
        padding: 10px 8px 10px 8px !important;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.08) !important;
        gap: 8px !important;
        flex-direction: row;
    }
    #chat-input, #chat-send {
        min-width: 0;
        max-width: none;
        box-sizing: border-box;
    }
    #chat-input {
        flex: 1 1 0%;
    }
    #chat-send {
        flex: 0 0 auto;
    }
}

/* Unread badge for chat button */
.chat-toggle-btn .unread-badge {
    display: inline-block;
    min-width: 18px;
    padding: 2px 6px;
    font-size: 12px;
    background: var(--mistake-color);
    color: #fff;
    border-radius: 12px;
    margin-left: 6px;
    vertical-align: middle;
    font-weight: bold;
}
/* Dark mode detection and color scheme */
:root {
    --bg-color: #FFFFFF;
    --grid-bg: #F0F0F0;
    --text-color: #000000;
    --empty-cell-bg: #FFFFFF;
    --empty-cell-fg: #000000;
    --prefilled-bg: #E8E8E8;
    --prefilled-fg: #333333;
    --timer-color: #0066CC;
    --mistake-color: #CC0000;
    --correct-color: #0066FF;
    --wrong-color: #FF3333;
    --player1-color: #0066FF;
    --player2-color: #00AA00;
    --spotify-green: #1DB954;
    --spotify-orange: #FF6600;
    --wave-color: #0066CC;
    --canvas-bg: #F5F5F5;
}

/* Dark mode colors */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #1E1E1E;
        --grid-bg: #2D2D2D;
        --text-color: #FFFFFF;
        --empty-cell-bg: #3A3A3A;
        --empty-cell-fg: #FFFFFF;
        --prefilled-bg: #4A4A4A;
        --prefilled-fg: #CCCCCC;
        --timer-color: #00AAFF;
        --mistake-color: #FF6666;
        --correct-color: #0066FF;
        --wrong-color: #FF3333;
        --player1-color: #0066FF;
        --player2-color: #00AA00;
        --spotify-green: #1DB954;
        --spotify-orange: #FF6600;
        --wave-color: #00AAFF;
        --canvas-bg: #2A2A2A;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s ease;
}

.app-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    gap: 20px;
    padding: 15px;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px;
    max-width: 550px;
    width: 100%;
}

/* Main frame and grid styling */
.main-frame {
    background-color: var(--grid-bg);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 15px;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 3px;
    width: 450px;
    height: 450px;
}

.subgrid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 3px;
    border: 3px solid var(--text-color);
    padding: 3px;
    background-color: var(--grid-bg);
}

.cell {
    width: 100%;
    height: 100%;
    border: 2px solid var(--text-color);
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    font-family: Arial, sans-serif;
    background-color: var(--empty-cell-bg);
    color: var(--empty-cell-fg);
    transition: none;
    cursor: pointer;
}

.cell:focus {
    outline: none;
    border-color: var(--timer-color);
    box-shadow: 0 0 5px var(--timer-color);
}

.cell.prefilled {
    background-color: var(--prefilled-bg);
    color: var(--prefilled-fg);
    cursor: not-allowed;
}

.cell.correct {
    background-color: var(--correct-color);
    color: white;
    cursor: not-allowed;
}

.cell.wrong {
    background-color: var(--wrong-color);
    color: white;
}

.cell.player1 {
    background-color: var(--player1-color);
    color: white;
}

.cell.player2 {
    background-color: var(--player2-color);
    color: white;
}

/* Controls styling */
.controls-frame {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 10px;
    background-color: var(--bg-color);
}

.mode-frame, .diff-frame {
    display: flex;
    align-items: center;
    gap: 5px;
}

.control-label {
    font-size: 14px;
    font-weight: bold;
    color: var(--text-color);
}

.control-select {
    font-size: 12px;
    font-family: Arial, sans-serif;
    padding: 5px;
    border: 1px solid var(--text-color);
    border-radius: 4px;
    background-color: var(--bg-color);
    color: var(--text-color);
    cursor: pointer;
}

/* Timer and mistake labels */
.timer-label {
    font-size: 16px;
    font-weight: bold;
    color: var(--timer-color);
    margin-bottom: 10px;
    background-color: var(--bg-color);
}

.mistake-label {
    font-size: 16px;
    font-weight: bold;
    color: var(--mistake-color);
    margin-bottom: 5px;
    background-color: var(--bg-color);
}

.player-label {
    font-size: 14px;
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 5px;
    background-color: var(--bg-color);
    min-height: 20px;
}

/* Spotify section */
.spotify-frame {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 5px;
    background-color: var(--bg-color);
}

.soundwave-dropdown {
    position: relative;
    display: inline-block;
}

.soundwave-button {
    background-color: var(--spotify-green);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 12px;
    font-weight: bold;
    font-family: Arial, sans-serif;
    border-radius: 20px;
    cursor: pointer;
    margin-bottom: 5px;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.soundwave-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: var(--bg-color);
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1;
    border-radius: 8px;
    border: 1px solid var(--text-color);
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
}

.dropdown-content a {
    color: var(--text-color);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    font-size: 12px;
    transition: background-color 0.3s;
}

.dropdown-content a:hover {
    background-color: var(--grid-bg);
}

.dropdown-content a:first-child {
    border-radius: 8px 8px 0 0;
}

.dropdown-content a:last-child {
    border-radius: 0 0 8px 8px;
}

.soundwave-dropdown:hover .dropdown-content {
    display: block;
}

.soundwave-button.connected {
    background-color: var(--spotify-green);
    box-shadow: 0 0 10px rgba(29, 185, 84, 0.3);
}

.soundwave-button.connecting {
    background-color: #ff9500;
    animation: pulse 1.5s ease-in-out infinite;
}

.soundwave-button.soundwaves {
    background-color: var(--wave-color);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 149, 0, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(255, 149, 0, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(255, 149, 0, 0);
    }
}

.song-label {
    font-size: 12px;
    color: var(--text-color);
    background-color: var(--bg-color);
    text-align: center;
    min-height: 20px;
    padding: 5px;
    border-radius: 4px;
    transition: all 0.3s ease;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.song-label.playing {
    color: var(--spotify-green);
    font-weight: bold;
}

/* Wave canvas */
.wave-canvas {
    background-color: var(--canvas-bg);
    border: 1px solid #555555;
    border-radius: 8px;
    margin-top: 10px;
    transition: all 0.3s ease;
}

.wave-canvas.active {
    border-color: var(--spotify-green);
    box-shadow: 0 0 10px rgba(29, 185, 84, 0.2);
}

/* Win overlay styles */
.win-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    border-radius: 8px;
    animation: fadeIn 0.3s ease-in-out;
}

.win-content {
    background-color: var(--bg-color);
    color: var(--text-color);
    padding: 40px 30px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 3px solid var(--timer-color);
    max-width: 90%;
    animation: slideIn 0.4s ease-out;
}

.win-content h2 {
    font-size: 32px;
    margin-bottom: 15px;
    color: var(--timer-color);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.win-content p {
    font-size: 18px;
    margin-bottom: 15px;
    font-weight: bold;
}

.win-content #win-timer {
    font-size: 16px;
    color: var(--timer-color);
    font-weight: bold;
}

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

@keyframes slideIn {
    from { 
        transform: translateY(-50px) scale(0.9);
        opacity: 0;
    }
    to { 
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* Responsive design */
@media (max-width: 600px) {
    .sudoku-grid {
        width: 350px;
        height: 350px;
    }

    .cell {
        font-size: 16px;
    }

    .controls-frame {
        flex-direction: column;
        gap: 10px;
    }

    .container {
        padding: 10px;
    }

    /* Win overlay responsive styles */
    .win-content {
        padding: 30px 20px;
    }

    .win-content h2 {
        font-size: 24px;
    }

    .win-content p {
        font-size: 16px;
    }
}

/* Animation for wave bars */
@keyframes wavePulse {
    0% { opacity: 0.7; }
    50% { opacity: 1; }
    100% { opacity: 0.7; }
}

.wave-bar {
    animation: wavePulse 0.5s ease-in-out infinite;
}

/* Disabled state for cells */
.cell:disabled {
    cursor: not-allowed;
    opacity: 0.8;
}

/* Focus styles for accessibility */
.control-select:focus,
.spotify-button:focus {
    outline: 2px solid var(--timer-color);
    outline-offset: 2px;
} 

#notification-box,
#player-identity {
    color: var(--text-color); /* Black in light mode, white in dark mode */
}

/* Chat Sidebar Styles */
.chat-sidebar {
    width: 300px;
    height: 600px;
    background-color: var(--grid-bg);
    border: 2px solid var(--text-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 15px;
    transition: transform 0.3s ease;
}

.chat-header {
    background-color: var(--text-color);
    color: var(--bg-color);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 6px 6px 0 0;
    position: sticky;
    top: 0;
    z-index: 2;
}

.chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: bold;
}

.chat-toggle {
    background: none;
    border: none;
    color: var(--bg-color);
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-messages {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    background-color: var(--bg-color);
    border-radius: 0;
}

.chat-message {
    margin-bottom: 8px;
    padding: 6px 12px;
    border-radius: 16px;
    display: block;
    width: fit-content;
    max-width: 80%;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.4;
}

.chat-message.own {
    background-color: var(--player1-color);
    color: white;
    margin-left: auto;
    text-align: right;
}

.chat-message.other {
    background-color: var(--prefilled-bg);
    color: var(--text-color);
    margin-right: auto;
}

.chat-message.system {
    background-color: var(--spotify-green);
    color: white;
    margin: 0 auto 12px auto;
    text-align: center;
    font-style: italic;
    max-width: 90%;
    padding: 8px;
}

.chat-input-container {
    display: flex;
    flex-direction: row;
    gap: 8px;
    padding: 12px;
    background-color: var(--grid-bg);
    border-radius: 0 0 6px 6px;
}

#chat-input, #chat-send {
    min-width: 0;
    max-width: none;
    box-sizing: border-box;
}

#chat-input {
    flex: 1 1 0%;
}

#chat-send {
    flex: 0 0 auto;
}

#chat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--text-color);
    border-radius: 20px;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 16px; /* Prevent iOS zoom on focus */
    outline: none;
}

#chat-input:focus {
    border-color: var(--timer-color);
    box-shadow: 0 0 5px var(--timer-color);
}

#chat-send {
    padding: 8px 16px;
    background-color: var(--timer-color);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: background-color 0.2s;
}

#chat-send:hover {
    background-color: var(--player1-color);
}

#chat-send:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

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

.chat-toggle-btn {
    background-color: var(--timer-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    margin-top: 10px;
    transition: background-color 0.2s;
}

.chat-toggle-btn:hover {
    background-color: var(--player1-color);
}

.chat-toggle-btn.hidden {
    display: none;
}

/* Responsive adjustments */
@media (max-width: 1000px) {
    .app-container {
        flex-direction: column;
        align-items: center;
    }

    .chat-sidebar {
        width: 100%;
        max-width: 550px;
        height: 300px;
        position: relative;
        top: 0;
    }
}

@media (max-width: 600px) {
    .chat-sidebar {
        height: 250px;
    }

    .chat-message {
        font-size: 13px;
        padding: 6px 10px;
    }
}
