:root {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --secondary: #334155;
    --secondary-hover: #475569;
    --accent: #a78bfa;
    --danger: #f87171;
    --danger-hover: #ef4444;
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --radius: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#app {
    width: 100%;
    max-width: 480px;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.view {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    padding: 20px;
    padding-top: 10vh;
    /* Shift visual center down */
}

.view.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
    position: relative;
    z-index: 100;
}

/* Typography */
h1.logo {
    font-size: 4rem;
    font-weight: 900;
    background: linear-gradient(135deg, #a78bfa, #c084fc, #e879f9, #f0abfc);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    background-size: 200% 200%;
    letter-spacing: 0.1rem;
    margin-bottom: 30px;
    text-transform: uppercase;
    position: relative;
    animation: gradientShift 3s ease infinite;
    filter: drop-shadow(0 0 20px rgba(167, 139, 250, 0.3));
}

@keyframes gradientShift {

    0%,
    100% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }
}

h2 {
    font-size: 1.5rem;
    font-weight: 500;
}

.hidden {
    display: none !important;
}

.info-text {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Components */
.card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: var(--radius);
    width: 100%;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

input {
    width: 100%;
    padding: 20px;
    border-radius: 16px;
    border: 2px solid var(--secondary);
    background: var(--bg-color);
    color: var(--text-main);
    font-size: 1.2rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    text-align: center;
}

input:focus {
    border-color: var(--primary);
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

.join-group {
    display: flex;
    gap: 8px;
}

.join-group input {
    flex: 1;
    width: auto;
    min-width: 0;
    text-transform: uppercase;
}

.join-group .btn {
    width: auto;
    padding-left: 24px;
    padding-right: 24px;
    flex-shrink: 0;
}

button.btn {
    padding: 20px;
    border: none;
    border-radius: 16px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
    width: 100%;
    font-family: inherit;
}

button.btn:active {
    transform: scale(0.98);
}

.btn.primary {
    background-color: var(--primary);
    color: white;
}

.btn.primary:hover {
    background-color: var(--primary-hover);
}

.btn.secondary {
    background-color: var(--secondary);
    color: var(--text-main);
}

.btn.secondary:hover {
    background-color: var(--secondary-hover);
}

.btn.danger {
    background-color: var(--danger);
    color: white;
}

.btn.danger:hover {
    background-color: var(--danger-hover);
}

/* Player List */
.player-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.player-list::-webkit-scrollbar {
    display: none;
}

.player-item {
    background: var(--card-bg);
    padding: 12px 16px;
    border-radius: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.player-item.me {
    border: 1px solid var(--primary);
}

/* Game View Specifics */
.role-reveal {
    text-align: center;
    margin-bottom: 20px;
    cursor: pointer;
    user-select: none;
}

.secret {
    font-size: 2.5rem;
    margin: 10px 0;
    transition: filter 0.3s;
}

.secret.blur {
    filter: blur(12px);
    opacity: 0.5;
}

/* Voting Grid */
.voting-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    width: 100%;
}

.vote-btn {
    background: var(--card-bg);
    border: 2px solid transparent;
    padding: 24px;
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100px;
}

.vote-btn:hover {
    border-color: var(--primary);
}

.vote-btn.selected {
    background: var(--primary);
    border-color: var(--primary);
}

.vote-btn.has-votes {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.1);
}

.vote-btn .name {
    font-weight: 700;
    margin-bottom: 4px;
}

.vote-btn .vote-count {
    font-size: 0.9rem;
    color: var(--primary);
}

.vote-btn .voters-list {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-style: italic;
}

/* Results */
#result-title {
    font-size: 2.5rem;
    color: var(--accent);
}

#reveal-word {
    color: var(--primary);
    font-weight: 700;
}

.results-summary {
    background: transparent;
    padding: 0;
    width: 100%;
    text-align: left;
    margin-top: 20px;
}

.results-summary h3 {
    font-size: 1.2rem;
    margin-bottom: 12px;
    color: var(--text-muted);
    width: 100%;
}

.tally-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    width: 100%;
}

.tally-item {
    background: var(--card-bg);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 1rem;
    border: 1px solid var(--secondary);
    flex: 1 1 calc(50% - 10px);
    /* 2 columns */
    min-width: 140px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tally-item strong {
    color: var(--text-main);
    font-size: 1.1rem;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    width: fit-content;
    margin-top: 4px;
}

.badge.imposter {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
    border: 1px solid var(--danger);
}

.badge.ejected {
    background: rgba(148, 163, 184, 0.2);
    color: var(--text-muted);
    border: 1px solid var(--text-muted);
}

/* Tiebreaker View */
.tiebreaker-section {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    text-align: center;
}

.tiebreaker-title {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--danger), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tiebreaker-subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.tiebreaker-players {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.tiebreaker-player {
    background: var(--card-bg);
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 700;
    border: 2px solid var(--danger);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(248, 113, 113, 0);
    }
}

.tiebreaker-waiting {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    margin-top: 20px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--secondary);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.tiebreaker-arena {
    width: 100%;
    min-height: 200px;
    background: var(--card-bg);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.3s;
    user-select: none;
}

.tiebreaker-arena.active {
    min-height: 250px;
}

.tiebreaker-arena p {
    font-size: 1.8rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.game-instruction {
    color: var(--text-muted);
    font-size: 1rem;
}

.highlight-green {
    color: var(--primary);
    font-weight: 700;
}

#tiebreaker-result {
    margin-top: 20px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 2px solid var(--accent);
}

#tiebreaker-result h3 {
    color: var(--accent);
    font-size: 1.3rem;
}

/* Spectator Arena View */
.tiebreaker-players {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: center;
    width: 100%;
}

.spectator-arena-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 140px;
    max-width: 200px;
}

.spectator-arena {
    width: 100%;
    aspect-ratio: 1;
    background: var(--danger);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.spectator-arena.waiting {
    background: var(--danger);
    animation: pulse-arena 1.5s infinite;
}

.spectator-arena.completed {
    background: #22c55e;
}

.spectator-arena.failed {
    background: #333;
}

@keyframes pulse-arena {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.spectator-arena .status-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.spectator-player-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
}

.highlight-green {
    color: #22c55e;
    font-weight: 700;
}

/* Game View Layout - Keep button visible with many players */
#game-view {
    justify-content: flex-start;
    overflow-y: auto;
}

#game-view .player-list {
    max-height: 30vh;
    overflow-y: auto;
    flex-shrink: 0;
}

#game-view .actions {
    margin-top: auto;
    flex-shrink: 0;
    padding-bottom: 20px;
}

.game-status {
    text-align: center;
    width: 100%;
}

/* Turn Display & Carousel */
.turn-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 24px;
    align-items: center;
}

.current-turn {
    text-align: center;
    background: linear-gradient(135deg, rgba(129, 140, 248, 0.1), rgba(167, 139, 250, 0.1));
    padding: 24px;
    border-radius: 20px;
    border: 2px solid var(--primary);
    width: 100%;
    box-shadow: 0 0 20px rgba(129, 140, 248, 0.2);
    animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
    0% {
        box-shadow: 0 0 0 0 rgba(129, 140, 248, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(129, 140, 248, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(129, 140, 248, 0);
    }
}

.current-turn .label {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--primary);
    font-weight: 700;
    display: block;
    margin-bottom: 8px;
}

.current-turn h2 {
    font-size: 2.5rem;
    margin: 0;
    background: linear-gradient(to right, #fff, #cbd5e1);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.carousel-container {
    width: 100%;
    text-align: center;
}

.label-small {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    display: block;
}

.turn-carousel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-height: 200px;
    overflow-y: hidden;
    /* Hide scrollbar for cleaner look */
    position: relative;
    mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 50%, transparent 100%);
}

.turn-item {
    background: var(--card-bg);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--secondary);
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.turn-item:first-child {
    opacity: 1;
    transform: scale(1.02);
    border-color: var(--accent);
    color: var(--text-main);
}


/* Hidden Dev Button */
.dev-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 0 10px;
}

.dev-btn:hover {
    opacity: 1;
}

.header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}