* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: linear-gradient(145deg, #1a1410, #2d241b);
    font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
    min-height: 100vh;
    padding: 1rem;
    display: flex;
    justify-content: center;
    color: #e8ddd0;
}

.container {
    max-width: 800px;
    width: 100%;
}

/* GAME VIEW: cap board width on large screens so it doesn't fill the whole viewport */
.game {
    max-width: 640px;
    margin: 0 auto;
}

/* LOBBY */
.lobby {
    background: #1a1410;
    padding: 2rem;
    border-radius: 24px;
    border: 2px solid #3a2a1a;
    box-shadow: 0 20px 60px rgba(0,0,0,0.9);
}

.lobby-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.lobby-header h1 {
    font-size: 1.8rem;
    color: #f5c842;
}

.room-info {
    background: #0a0a0a;
    padding: 0.5rem 1rem;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid #3a2a1a;
}

.join-section {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.join-section input {
    flex: 1;
    min-width: 150px;
    padding: 0.7rem 1rem;
    border: 2px solid #3a2a1a;
    border-radius: 12px;
    background: #0a0a0a;
    color: #e8ddd0;
    font-size: 1rem;
}

.join-section input:focus {
    outline: none;
    border-color: #f5c842;
}

#gameInfo {
    background: #0a0a0a;
    padding: 0.5rem 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    border: 1px solid #3a2a1a;
}

.btn {
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: #2d7a4a;
    color: white;
}
.btn-primary:hover:not(:disabled) { background: #3a8a5a; }

.btn-success {
    background: #2d7a4a;
    color: white;
    font-size: 1.1rem;
}
.btn-success:hover:not(:disabled) { background: #3a8a5a; }

.btn-danger {
    background: #6a1f1f;
    color: white;
}
.btn-danger:hover:not(:disabled) { background: #8a2a2a; }

.btn-sm {
    padding: 0.3rem 0.8rem;
    font-size: 0.8rem;
}

.player-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.team-section {
    background: #0a0a0a;
    padding: 1rem;
    border-radius: 16px;
    border: 2px solid #3a2a1a;
}

.team-section h3 {
    margin-bottom: 0.8rem;
    font-size: 1rem;
}

.team-section.white-team { border-color: #5a4a3a; }
.team-section.black-team { border-color: #3a2a2a; }

.slots {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.slot {
    padding: 0.5rem 0.8rem;
    background: #1a1410;
    border-radius: 8px;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 2px solid transparent;
    transition: all 0.3s;
}

.slot.occupied {
    border-color: #2d7a4a;
    background: #0a1a0a;
}

.slot.occupied.white-slot { border-color: #8a7a6a; }
.slot.occupied.black-slot { border-color: #5a4a4a; }

.slot .status {
    font-size: 0.7rem;
    padding: 0.1rem 0.5rem;
    border-radius: 8px;
    background: #3a2a1a;
}

.slot .status.online { background: #2d7a4a; }
.slot .status.offline { background: #6a1f1f; }
.slot .status.me { background: #f5c842; color: #1a1410; }

.lobby-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    margin-top: 1rem;
}

#gameStatus {
    font-size: 0.9rem;
    color: #8a7a6a;
}

/* Chat */
.lobby-chat {
    margin-top: 1.5rem;
    border-top: 2px solid #3a2a1a;
    padding-top: 1rem;
}

.chat-messages {
    height: 120px;
    overflow-y: auto;
    background: #0a0a0a;
    padding: 0.5rem;
    border-radius: 12px;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    border: 1px solid #3a2a1a;
}

.chat-messages .msg {
    padding: 0.1rem 0;
    border-bottom: 1px solid #1a1410;
}

.chat-messages .msg .name {
    font-weight: 700;
    margin-right: 0.5rem;
}

.chat-messages .msg .time {
    color: #5a4a3a;
    font-size: 0.7rem;
    margin-left: 0.5rem;
}

.chat-input {
    display: flex;
    gap: 0.5rem;
}

.chat-input input {
    flex: 1;
    padding: 0.4rem 0.8rem;
    border: 2px solid #3a2a1a;
    border-radius: 8px;
    background: #0a0a0a;
    color: #e8ddd0;
}

.chat-input input:focus {
    outline: none;
    border-color: #f5c842;
}

/* GAME */
.game {
    background: #1a1410;
    padding: 1rem;
    border-radius: 24px;
    border: 2px solid #3a2a1a;
    box-shadow: 0 20px 60px rgba(0,0,0,0.9);
}

.game-header {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* NOW PLAYING */
.now-playing {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0.5rem 0 1rem 0;
    min-height: 50px;
}

/* Board */
.board-section {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

#teamBarsContainer {
    display: flex;
    flex-direction: column;
    gap: 2.0rem;
}

.board-wrapper {
    position: relative;
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1/1;
    background: #f0d9b5;
    cursor: pointer;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.team-bar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: #0a0a0a;
    padding: 0.3rem 0.6rem;
    border-radius: 14px;
    border: 2px solid #3a2a1a;
    flex-wrap: wrap;
}

.team-bar .team-name {
    font-weight: 700;
    font-size: 0.8rem;
    min-width: 70px;
    padding-right: 0.4rem;
    border-right: 1px solid #3a2a1a;
}

.team-bar .team-name.white-team { color: #f5f0e8; }
.team-bar .team-name.black-team { color: #8a7a6a; }

.team-bar .team-players {
    display: flex;
    gap: 0.3rem;
    flex-wrap: wrap;
    flex: 1;
}

.player-card {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: #1a1410;
    padding: 0.15rem 0.4rem 0.15rem 0.25rem;
    border-radius: 18px;
    font-size: 0.65rem;
    border: 2px solid transparent;
    transition: all 0.3s;
    cursor: default;
    color: #e8ddd0;
}

.player-card.active-player {
    border-color: #00cc55;
    background: #0a1a0a;
    box-shadow: 0 0 15px rgba(0, 200, 80, 0.2);
}

.player-card.turn-holder {
    border-color: #f5c842;
    background: #2a1a0a;
    box-shadow: 0 0 15px rgba(245, 200, 66, 0.2);
}

.player-card .avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}

.player-card .avatar.white-avatar { background: #f5f0e8; color: #1a1410; }
.player-card .avatar.black-avatar { background: #1a1410; color: #f5f0e8; border: 1px solid #3a2a1a; }

.player-card .player-name { font-weight: 600; font-size: 0.65rem; }

.player-card .player-status {
    font-size: 0.5rem;
    padding: 0.05rem 0.4rem;
    border-radius: 8px;
    background: #3a2a1a;
    font-weight: bold;
}

.player-card .player-status.active {
    background: #00cc55;
    color: #000;
}

.player-card .player-status.holder {
    background: #f5c842;
    color: #000;
}

.team-clock {
    margin-left: auto;
    background: #0a0a0a;
    color: #f5f0e8;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0.05rem 0.5rem;
    border-radius: 24px;
    border: 1px solid #3a2a1a;
    min-width: 60px;
    text-align: center;
}

.team-clock.running {
    background: #1a0a0a;
    border-color: #f5c842;
    box-shadow: 0 0 12px rgba(245, 200, 66, 0.2);
}

.team-clock.danger {
    color: #ff4444;
    animation: blink 0.8s infinite;
}

.resign-btn {
    background: #3a1a1a;
    border: 1px solid #5a2a2a;
    color: #f5e0e0;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 24px;
    cursor: pointer;
    margin-left: 0.4rem;
    flex-shrink: 0;
    transition: background 0.15s;
}

.resign-btn:hover:not(:disabled) { background: #5a2a2a; }
.resign-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Toast */
.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1a1410;
    color: #efe6d7;
    padding: 1.5rem 2rem;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.9);
    border: 2px solid #f5c842;
    z-index: 1000;
    max-width: 400px;
    text-align: center;
    display: none;
}

.toast-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 999;
    display: none;
    backdrop-filter: blur(4px);
}

.toast .toast-avatar { font-size: 3rem; display: block; }
.toast .toast-title { font-size: 1.2rem; font-weight: 700; margin: 0.5rem 0; }
.toast .toast-message { font-size: 0.95rem; color: #8a7a6a; margin-bottom: 1rem; white-space: pre-line; }

.toast-buttons { display: flex; gap: 0.8rem; justify-content: center; }

.btn-yes {
    background: #2d7a4a;
    color: white;
    padding: 0.4rem 1.5rem;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-weight: 700;
}

.btn-yes:hover { background: #3a8a5a; }

.btn-no {
    background: #5a3a2a;
    color: white;
    padding: 0.4rem 1.5rem;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-weight: 700;
}

.btn-no:hover { background: #6a4a3a; }

@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
    .lobby { padding: 1rem; }
    .player-grid { grid-template-columns: 1fr; }
    .team-bar { flex-wrap: wrap; }
    .player-card { font-size: 0.55rem; }
    .team-clock { font-size: 0.8rem; min-width: 50px; }
    .toast { max-width: 90%; padding: 1rem; }
    .now-playing { font-size: 0.9rem; }

    /* Strip the frame around the game panel so the board nearly fills the screen width */
    body { padding: 0.4rem; }
    .container { max-width: 100%; }
    .game {
        padding: 0.4rem;
        border-radius: 14px;
        border-width: 1px;
        max-width: 100%;
    }
}

@media (max-width: 400px) {
    .player-card .player-name { font-size: 0.45rem; }
    .team-clock { font-size: 0.7rem; min-width: 40px; }
    .team-bar .team-name { font-size: 0.6rem; min-width: 50px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0a0a; border-radius: 8px; }
::-webkit-scrollbar-thumb { background: #3a2a1a; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #5a4a3a; }

/* Now Playing Display Styles */
.now-playing > div {
    background: #0a0a0a;
    border: 2px solid #f5c842;
    padding: 0.5rem 1.5rem;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    box-shadow: 0 0 30px rgba(245, 200, 66, 0.1);
}

/* Active player glow - reduced brightness */
canvas .active-player-glow {
    filter: drop-shadow(0 0 10px rgba(0, 200, 80, 0.3));
}

/* Turn Notification Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.95); }
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Turn Notification Overlay */
#turnNotificationOverlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 20;
    backdrop-filter: blur(8px);
    cursor: pointer;
    animation: fadeIn 0.5s ease;
}

/* Board coordinate labels */
.coordinate-label {
    font-family: 'Segoe UI', sans-serif;
    font-size: 10px;
    color: #8a7a6a;
    pointer-events: none;
    user-select: none;
}

/* Board coordinate labels are drawn on the canvas itself; no extra margin needed */
.board-wrapper canvas {
    margin: 0;
}

/* Perspective indicator */
.perspective-indicator {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    color: #8a7a6a;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.6rem;
    pointer-events: none;
}