/* =============================================================================
   Puzzle Player Stylesheet
   Full-screen layout, toolbar, settings modal, glassmorphism
   ============================================================================= */

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

body.player-body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #1a1a2e;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    user-select: none;
    -webkit-user-select: none;
}

/* --- Canvas --- */
#puzzle-canvas {
    position: absolute;
    top: 48px;
    left: 0;
    width: 100%;
    height: calc(100vh - 48px);
    display: block;
    cursor: grab;
}

#puzzle-canvas:active {
    cursor: grabbing;
}

/* --- Toolbar --- */
.player-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.75rem;
    background: rgba(15, 15, 26, 0.9);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 50;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.toolbar-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #a0a0b8;
    background: transparent;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #e8e8f0;
}

.toolbar-btn.active {
    background: rgba(108, 99, 255, 0.2);
    color: #6c63ff;
}

.timer-display {
    font-size: 0.95rem;
    font-weight: 600;
    color: #e8e8f0;
    padding: 0 0.75rem;
    font-variant-numeric: tabular-nums;
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 200;
}

.modal {
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 2rem;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
    animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal h2 {
    font-size: 1.3rem;
    font-weight: 700;
    color: #e8e8f0;
    margin-bottom: 1.5rem;
    text-align: center;
}

.modal-body {
    margin-bottom: 1.5rem;
}

/* --- Settings --- */
.setting-group {
    margin-bottom: 1.25rem;
}

.setting-group>label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #a0a0b8;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Piece count grid */
.piece-count-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
}

.piece-count-btn {
    padding: 0.625rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
    color: #a0a0b8;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.piece-count-btn:hover {
    background: rgba(108, 99, 255, 0.1);
    border-color: rgba(108, 99, 255, 0.3);
    color: #e8e8f0;
}

.piece-count-btn.active {
    background: #6c63ff;
    border-color: #6c63ff;
    color: white;
    box-shadow: 0 4px 16px rgba(108, 99, 255, 0.3);
}

/* Piece type grid */
.piece-type-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.piece-type-btn {
    padding: 0.5rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.8rem;
    font-weight: 500;
    color: #a0a0b8;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.piece-type-btn:hover {
    border-color: rgba(108, 99, 255, 0.3);
}

.piece-type-btn.active {
    background: #6c63ff;
    border-color: #6c63ff;
    color: white;
}

/* Background color grid */
.bg-color-grid {
    display: flex;
    gap: 0.625rem;
}

.bg-color-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.bg-color-btn:hover {
    transform: scale(1.15);
}

.bg-color-btn.active {
    border-color: #6c63ff;
    box-shadow: 0 0 0 2px rgba(108, 99, 255, 0.4);
}

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

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

.toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    cursor: pointer;
    transition: 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}

.toggle input:checked+.toggle-slider {
    background: #6c63ff;
}

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

/* --- Start/Action Button --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.btn-primary {
    background: #6c63ff;
    color: white;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(108, 99, 255, 0.3);
}

.btn-primary:hover {
    background: #5a52e0;
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: #e8e8f0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.05);
}

.btn-lg {
    padding: 0.875rem 2rem;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

/* --- Completion Modal --- */
.modal-celebration {
    text-align: center;
}

.celebration-icon {
    font-size: 4rem;
    margin-bottom: 0.5rem;
    animation: bounce 0.6s ease infinite alternate;
}

@keyframes bounce {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-8px);
    }
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-top: 1.5rem;
}

/* --- Reference Window --- */
.reference-window {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 250px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 60;
    cursor: move;
}

.reference-window img {
    width: 100%;
    height: auto;
}

.reference-close {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.75rem;
}

/* --- Menu Dropdown --- */
.menu-dropdown {
    position: fixed;
    top: 48px;
    left: 0.5rem;
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 0.5rem;
    min-width: 200px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 100;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    color: #a0a0b8;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
    transition: all 0.15s ease;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #e8e8f0;
}

/* --- Multiplayer UI --- */
.mp-players-panel {
    position: fixed;
    top: 56px;
    right: 0;
    width: 260px;
    max-height: calc(100vh - 56px);
    overflow-y: auto;
    background: rgba(15, 15, 26, 0.95);
    border-left: 1px solid rgba(255, 255, 255, 0.07);
    backdrop-filter: blur(16px);
    z-index: 80;
    padding: 0.75rem;
}

.mp-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    color: #e8e8f0;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.mp-panel-close {
    background: none;
    border: none;
    color: #a0a0b8;
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
}

.mp-player-list {
    list-style: none;
    margin: 0 0 0.75rem;
    padding: 0;
}

.mp-player-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.mp-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #6c63ff;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.mp-player-item.offline .mp-avatar {
    background: #555;
    opacity: 0.6;
}

.mp-player-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.mp-player-name {
    font-size: 0.85rem;
    color: #e8e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mp-player-score {
    font-size: 0.75rem;
    color: #a0a0b8;
}

.mp-scoreboard {
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    padding-top: 0.75rem;
}

.mp-score-header {
    font-size: 0.75rem;
    font-weight: 700;
    color: #a0a0b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.mp-score-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.mp-score-table th {
    color: #a0a0b8;
    text-align: left;
    padding: 2px 4px;
    font-weight: 600;
    font-size: 0.7rem;
}

.mp-score-table td {
    color: #e8e8f0;
    padding: 3px 4px;
}

.mp-score-row.my-row {
    background: rgba(108, 99, 255, 0.1);
    border-radius: 4px;
}

.mp-score-row.score-flash {
    animation: scoreFlash 0.5s ease;
}

@keyframes scoreFlash {
    0%, 100% { background: transparent; }
    50% { background: rgba(108, 99, 255, 0.3); }
}

.mp-score-val {
    font-weight: 700;
    color: #6c63ff;
}

.mp-room-code {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    font-size: 0.75rem;
    color: #a0a0b8;
    text-align: center;
}

/* Pause overlay */
.pause-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pause-card {
    background: #1a1a2e;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 2.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 280px;
}

.pause-icon {
    font-size: 3rem;
}

.pause-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #e8e8f0;
}

.pause-msg {
    font-size: 0.9rem;
    color: #a0a0b8;
}

.pause-wait {
    font-size: 0.85rem;
    color: #a0a0b8;
    font-style: italic;
}

/* Multiplayer notification toast */
.mp-notification {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(108, 99, 255, 0.9);
    color: white;
    padding: 0.5rem 1.25rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 400;
    animation: notifFade 3s ease forwards;
    white-space: nowrap;
}

@keyframes notifFade {
    0%   { opacity: 0; transform: translateX(-50%) translateY(10px); }
    15%  { opacity: 1; transform: translateX(-50%) translateY(0); }
    75%  { opacity: 1; }
    100% { opacity: 0; }
}

/* --- Mobile Touch Support --- */
@media (max-width: 640px) {
    body.player-body {
        -webkit-tap-highlight-color: transparent;
        touch-action: none;
    }

    .player-toolbar {
        height: 56px;
        padding: 0 0.5rem;
    }

    #puzzle-canvas {
        top: 56px;
        height: calc(100vh - 56px);
    }

    .toolbar-btn {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }

    .toolbar-left,
    .toolbar-center,
    .toolbar-right {
        gap: 0;
    }

    .modal {
        max-height: 90dvh;
        overflow-y: auto;
        padding: 1.5rem;
        width: 95%;
    }

    .reference-window {
        width: 160px;
        bottom: 0.5rem;
        right: 0.5rem;
    }

    .reference-close {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
    }

    .menu-dropdown {
        top: 56px;
    }

    .modal-actions {
        flex-direction: column;
    }
}