@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap');

:root {
    --font-main: 'Outfit', sans-serif;
    --bg-gradient: radial-gradient(circle at top right, #2c2c44, #1e1e2f 40%, #151520 100%);
    --color-red: #ff4757;
    --color-blue: #1e90ff;
    --color-white: #f1f2f6;
    --color-black: #2f3542;
    --color-hidden: #ffffff;
    --color-text: #ffffff;
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.5);
    --border-radius: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background: var(--bg-gradient);
    color: var(--color-text);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

h1,
h2,
h3,
h4 {
    font-weight: 600;
}

input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    background: rgba(0, 0, 0, 0.2);
    color: #fff;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

input:focus {
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(0, 0, 0, 0.4);
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.btn:active {
    transform: translateY(0);
}

.primary {
    background: #ff4d4d;
    color: white;
    box-shadow: 0 4px 15px rgba(255, 77, 77, 0.3);
}

.secondary {
    background: #3498db;
    color: white;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.3);
}

.action-btn {
    background: #2ed573;
    box-shadow: 0 4px 15px rgba(46, 213, 115, 0.3);
}

#app {
    width: 100%;
    max-width: 1400px;
    padding: 20px;
    min-height: 90vh;
    display: flex;
    flex-direction: column;
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    animation: fadeIn 0.4s ease forwards;
}

.view-active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes shimmer {
    0% {
        filter: brightness(1);
    }

    50% {
        filter: brightness(1.3) contrast(1.1);
    }

    100% {
        filter: brightness(1);
    }
}

@keyframes revealFlip {
    0% {
        transform: rotateY(0deg) scale(1);
    }

    50% {
        transform: rotateY(90deg) scale(1.1);
    }

    100% {
        transform: rotateY(0deg) scale(1);
    }
}

/* Menu */
.logo {
    font-size: 3rem;
    margin-bottom: 30px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.subtitle {
    font-weight: 400;
    font-size: 1.2rem;
    opacity: 0.6;
    display: block;
    letter-spacing: 4px;
    margin-top: 5px;
}

.menu-box {
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 40px;
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 650px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.menu-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: end;
}

#btn-create-room,
.join-box {
    width: 100%;
}

#btn-create-room {
    height: 42px;
    /* Explicitly match common button height */
    padding: 0 24px;
    /* Ensure content doesn't dictate width */
}


.join-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.join-box input {
    text-align: center;
    letter-spacing: 2px;
    font-weight: 600;
}

/* Lobby */
.header {
    text-align: center;
    width: 100%;
    margin-bottom: 20px;
}

.header h2 {
    font-size: 2.5rem;
    margin-bottom: 5px;
}

.room-info {
    font-size: 1.2rem;
    margin-bottom: 10px;
    opacity: 0.8;
}

.highlight {
    font-weight: bold;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    letter-spacing: 2px;
}

.lobby-content {
    display: flex;
    gap: 30px;
    width: 100%;
    justify-content: center;
    flex-wrap: wrap;
}

.team-container {
    flex: 1;
    min-width: 300px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    padding: 20px;
    border-radius: var(--border-radius);
    border-top: 5px solid transparent;
}

.red-team {
    border-top-color: var(--color-red);
}

.blue-team {
    border-top-color: var(--color-blue);
}

.team-container h3,
.sidebar-team h4 {
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
}

.player-list {
    list-style: none;
    min-height: 150px;
    margin-bottom: 20px;
}

.player-list li {
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    margin-bottom: 8px;
    border-radius: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.role-badge {
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
}

.team-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.spymaster-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    opacity: 0.8;
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 16px;
    border-radius: 20px;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.spymaster-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.1);
    opacity: 1;
}

.spymaster-toggle input {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--color-white);
}

.lobby-footer {
    margin-top: 40px;
    text-align: center;
    width: 100%;
}

.error-text {
    color: #ff6b81;
    margin-top: 15px;
    min-height: 24px;
}

/* Game Layout */
.game-layout {
    flex-direction: row !important;
    align-items: flex-start !important;
    gap: 30px;
}

.game-sidebar {
    width: 250px;
    flex-shrink: 0;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.game-sidebar h3 {
    font-size: 1.2rem;
    text-align: center;
    margin-bottom: 10px;
}

.sidebar-list {
    list-style: none;
}

.sidebar-list li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 0.95rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-online {
    background: #2ed573;
    box-shadow: 0 0 5px #2ed573;
}

.status-offline {
    background: #747d8c;
}

.game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

/* In-game banner for Game Over */
.game-over-banner {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid var(--glass-border);
    padding: 20px;
    border-radius: var(--border-radius);
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.game-over-banner.hidden {
    display: none;
}

.game-over-banner h2 {
    font-size: 2rem;
    margin-bottom: 5px;
}

.game-over-banner p {
    font-size: 1.2rem;
    margin-bottom: 15px;
}

.game-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    background: var(--glass-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--glass-border);
    gap: 20px;
}

.turn-indicator {
    font-size: 1.5rem;
    font-weight: bold;
}

.turn-red {
    color: var(--color-red);
    text-shadow: 0 0 10px rgba(255, 71, 87, 0.5);
    animation: shimmer 3s infinite ease-in-out;
}

.turn-blue {
    color: var(--color-blue);
    text-shadow: 0 0 10px rgba(30, 144, 255, 0.5);
    animation: shimmer 3s infinite ease-in-out;
}

/* Clue Display made larger */
.clue-display {
    font-size: 1.8rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 10px 20px;
    border-radius: 8px;
    text-align: center;
    flex: 1;
}

.spymaster-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: var(--border-radius);
    align-items: center;
}

.spymaster-panel input[type="text"] {
    flex: 1;
    min-width: 200px;
}

.clue-number-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.num-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--glass-border);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.num-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.num-btn.selected {
    background: var(--color-blue);
    border-color: rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 10px rgba(30, 144, 255, 0.6);
    transform: scale(1.05);
}

.spymaster-panel #btn-send-clue {
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 200px;
}

.btn-disabled {
    opacity: 0.5;
    pointer-events: none;
}

.board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    width: 100%;
    perspective: 1000px;
}

.card {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s;
}

/* Staggered entry for board cards - ONLY on initial load */
.board-animate-initial .card {
    animation: slideUp 0.5s ease backwards;
}

.board-animate-initial .card:nth-child(1) {
    animation-delay: 0.05s;
}

.board-animate-initial .card:nth-child(2) {
    animation-delay: 0.1s;
}

.board-animate-initial .card:nth-child(3) {
    animation-delay: 0.15s;
}

.board-animate-initial .card:nth-child(4) {
    animation-delay: 0.2s;
}

.board-animate-initial .card:nth-child(5) {
    animation-delay: 0.25s;
}

.board-animate-initial .card:nth-child(6) {
    animation-delay: 0.1s;
}

.board-animate-initial .card:nth-child(7) {
    animation-delay: 0.15s;
}

.board-animate-initial .card:nth-child(8) {
    animation-delay: 0.2s;
}

.board-animate-initial .card:nth-child(9) {
    animation-delay: 0.25s;
}

.board-animate-initial .card:nth-child(10) {
    animation-delay: 0.3s;
}

.board-animate-initial .card:nth-child(11) {
    animation-delay: 0.15s;
}

.board-animate-initial .card:nth-child(12) {
    animation-delay: 0.2s;
}

.board-animate-initial .card:nth-child(13) {
    animation-delay: 0.25s;
}

.board-animate-initial .card:nth-child(14) {
    animation-delay: 0.3s;
}

.board-animate-initial .card:nth-child(15) {
    animation-delay: 0.35s;
}

.board-animate-initial .card:nth-child(16) {
    animation-delay: 0.2s;
}

.board-animate-initial .card:nth-child(17) {
    animation-delay: 0.25s;
}

.board-animate-initial .card:nth-child(18) {
    animation-delay: 0.3s;
}

.board-animate-initial .card:nth-child(19) {
    animation-delay: 0.35s;
}

.board-animate-initial .card:nth-child(20) {
    animation-delay: 0.4s;
}

.card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5);
    z-index: 5;
}

.zoom-active .card:hover {
    transform: scale(1.8);
    z-index: 100;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
}

.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}

.card img,
.card-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    background-repeat: no-repeat;
}

.card-color-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 5px solid transparent;
    pointer-events: none;
    transition: background 0.3s, border-color 0.3s;
    z-index: 2;
}

.card.color-red .card-color-overlay {
    border-color: var(--color-red);
}

.card.color-blue .card-color-overlay {
    border-color: var(--color-blue);
}

.card.color-white .card-color-overlay {
    border-color: #bbb;
}

.card.color-black .card-color-overlay {
    border: 5px solid transparent;
    background: repeating-linear-gradient(45deg,
            #000,
            #000 8px,
            #444 8px,
            #444 16px) border-box;
    -webkit-mask:
        linear-gradient(#fff 0 0) padding-box,
        linear-gradient(#fff 0 0);
    -webkit-mask-composite: destination-out;
    mask-composite: exclude;
}

.card.color-black .card-image {
    filter: brightness(0.75);
}

.card.revealed .card-color-overlay {
    border-width: 8px;
}

.card.revealed.color-red .card-color-overlay {
    background: rgba(255, 71, 87, 0.4);
}

.card.revealed.color-blue .card-color-overlay {
    background: rgba(30, 144, 255, 0.4);
}

.card.revealed.color-white .card-color-overlay {
    background: rgba(255, 255, 255, 0.4);
}

.card.revealed .card-color-overlay {
    background: rgba(0, 0, 0, 0.7);
}

.card.revealed .card-inner {
    animation: revealFlip 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-lock {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: var(--glass-bg);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    cursor: pointer;
    z-index: 4;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s, transform 0.2s;
    font-weight: bold;
}

.card:hover .btn-lock {
    opacity: 1;
}

.btn-lock:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(1.1);
}

.card.revealed .btn-lock {
    display: none;
}

.card-highlighters {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    gap: 6px;
    z-index: 3;
}

.highlighter-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.6);
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from {
        transform: scale(1);
    }

    to {
        transform: scale(1.2);
    }
}

.game-footer {
    display: flex;
    justify-content: center;
    margin-top: 10px;
    width: 100%;
}

.game-footer .btn {
    padding: 15px 40px;
    font-size: 1.2rem;
}

@media (max-width: 1000px) {
    .game-layout {
        flex-direction: column !important;
    }

    .game-sidebar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .game-sidebar .sidebar-team {
        flex: 1;
        min-width: 200px;
    }
}

@media (max-width: 768px) {
    .board {
        grid-template-columns: repeat(4, 1fr);
    }

    .clue-display {
        font-size: 1.2rem;
    }
}

@media (max-width: 500px) {
    .board {
        grid-template-columns: repeat(2, 1fr);
    }

    .spymaster-panel {
        flex-wrap: wrap;
    }

    .spymaster-panel #btn-send-clue {
        width: 100%;
        min-width: auto;
    }
}