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

:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #6b7280;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --background: #f9fafb;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-light: #6b7280;
    --border: #e5e7eb;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
}

/* Common Elements */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
}

.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background: #4b5563;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.125rem;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
}

input[type="text"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 1rem;
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
}

select {
    padding: 0.5rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: white;
}

/* Home Page */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-light);
    font-size: 1.125rem;
}

.home-content {
    display: grid;
    gap: 1.5rem;
}

@media (min-width: 768px) {
    .home-content {
        grid-template-columns: 1fr 1fr;
    }

    .how-to-play {
        grid-column: span 2;
    }
}

.card h2 {
    margin-bottom: 0.75rem;
    font-size: 1.25rem;
}

.card p {
    color: var(--text-light);
    margin-bottom: 1rem;
}

.how-to-play ol {
    padding-left: 1.5rem;
}

.how-to-play li {
    margin-bottom: 0.75rem;
    line-height: 1.5;
}

footer {
    text-align: center;
    margin-top: 2rem;
    color: var(--text-light);
}

/* Game Container */
.game-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.view {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Lobby View */
.lobby-header {
    background: var(--card-bg);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.lobby-header h1 {
    font-size: 1.5rem;
}

.room-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.room-code {
    font-size: 1.125rem;
}

.lobby-content {
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.join-section,
.players-section,
.settings-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

.players-section ul {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

.players-section li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.players-section li:last-child {
    border-bottom: none;
}

.player-host-badge {
    background: var(--primary);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.setting label {
    font-weight: 500;
}

/* Campus Filters */
.filters-section {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.filters-section h3 {
    font-size: 1rem;
    margin-bottom: 0.25rem;
    color: var(--text);
}

.campus-count {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-bottom: 0.75rem;
}

.campus-count strong {
    color: var(--text);
    font-weight: 600;
}

.filter-group {
    margin-bottom: 0.5rem;
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-light);
    min-width: 60px;
    flex-shrink: 0;
}

.filter-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.filter-btn {
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--background);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text-light);
    user-select: none;
}

.filter-btn:hover:not(.disabled) {
    border-color: var(--secondary);
    color: var(--text);
}

.filter-btn.active {
    background: #e8edff;
    border-color: #a5b4fc;
    color: #3730a3;
}

.filter-btn:not(.active) {
    opacity: 0.55;
}

/* State picker dropdown */
.state-picker {
    position: relative;
    flex: 1;
}

.state-picker-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--background);
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text);
    min-height: 1.75rem;
}

.state-picker-arrow {
    font-size: 0.65rem;
    color: var(--text-light);
    margin-left: 0.5rem;
}

.state-picker-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: white;
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    margin-top: 0.25rem;
    max-height: 14rem;
    overflow-y: auto;
}

.state-picker-dropdown.open {
    display: block;
}

.state-picker-actions {
    display: flex;
    gap: 0.35rem;
    padding: 0.35rem 0.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: white;
}

.state-action-btn {
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--background);
    font-size: 0.7rem;
    cursor: pointer;
    color: var(--text-light);
}

.state-action-btn:hover {
    border-color: var(--secondary);
    color: var(--text);
}

.state-picker-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    padding: 0.25rem;
}

.state-checkbox {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.2rem 0.3rem;
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 3px;
    color: var(--text);
}

.state-checkbox:hover {
    background: var(--background);
}

.state-checkbox input {
    width: 0.85rem;
    height: 0.85rem;
    margin: 0;
    accent-color: var(--primary);
}

@media (max-width: 600px) {
    .state-picker-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .state-picker-dropdown {
        position: fixed;
        left: 1rem;
        right: 1rem;
        top: auto;
        bottom: 1rem;
        max-height: 50vh;
    }
}

.filter-btn.disabled {
    cursor: not-allowed;
    pointer-events: none;
}

@media (max-width: 600px) {
    .filter-group {
        flex-direction: column;
        gap: 0.2rem;
    }

    .filter-group label {
        min-width: unset;
    }

    .filter-btn {
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }
}

#waiting-message {
    text-align: center;
    padding: 2rem;
    color: var(--text-light);
}

.instructions-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

.instructions-section h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.instructions-section ol {
    padding-left: 1.5rem;
    margin-bottom: 1.5rem;
}

.instructions-section li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

.scoring-info {
    background: #f0f4ff;
    padding: 1rem;
    border-radius: 8px;
    border-left: 4px solid var(--primary);
}

.scoring-info h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.scoring-info p {
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.scoring-example {
    color: var(--text-light);
    font-style: italic;
    margin-top: 0.5rem;
}

/* Game View */
.game-header {
    background: var(--card-bg);
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.round-info {
    font-size: 1.25rem;
    font-weight: 600;
}

.timer {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary);
}

.timer.warning {
    color: var(--warning);
}

.timer.urgent {
    color: var(--error);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.game-main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 1rem;
    padding: 1rem;
}

@media (max-width: 900px) {
    #game-view {
        height: 100svh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    #lobby-view {
        height: 100svh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .lobby-content {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .game-header {
        flex-shrink: 0;
    }

    .game-main {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
        flex: 1;
        overflow: hidden;
    }

    #map-container {
        min-height: 0;
        flex: 1;
    }

    .answer-section {
        padding: 0.5rem;
        gap: 0.5rem;
        flex-shrink: 0;
    }

    .players-status {
        display: none;
    }

    .choices-container {
        gap: 0.4rem;
    }

    .choice-btn {
        padding: 0.6rem 0.75rem;
        min-height: unset;
        font-size: 0.85rem;
    }
}

#map-container {
    position: relative;
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    min-height: 500px;
}

#map {
    height: 100%;
    width: 100%;
}

#map-overlay,
#countdown-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    z-index: 1000;
}

#countdown-overlay {
    flex-direction: column;
    gap: 1rem;
    padding: 1.5rem;
    text-align: center;
}

.countdown-summary {
    font-size: 1rem;
    opacity: 0.85;
    line-height: 1.5;
    max-width: 90%;
}

.countdown-number {
    font-size: 4rem;
    font-weight: 700;
    animation: pulse 1s infinite;
}

.answer-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: 12px;
    grid-column: 1;
}

.answer-section input {
    margin-bottom: 0;
}

.choices-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    width: 100%;
}

.choice-btn {
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: white;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    min-height: 60px;
}

.choice-btn:hover:not(:disabled) {
    border-color: var(--primary);
    background: #f0f0ff;
}

.choice-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.choice-btn.selected {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.choice-btn.correct {
    border-color: var(--success);
    background: var(--success);
    color: white;
}

.choice-btn.incorrect {
    border-color: var(--error);
    background: var(--error);
    color: white;
}

.free-type-container {
    display: flex;
    gap: 1rem;
    width: 100%;
}

.free-type-container input {
    flex: 1;
}

.players-status {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 1rem;
    grid-column: 2;
    grid-row: 1 / 3;
    max-height: 400px;
    overflow-y: auto;
}

@media (max-width: 900px) {
    .players-status {
        grid-column: 1;
        grid-row: auto;
        max-height: 200px;
    }
}

.players-status h3 {
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--card-bg);
}

.players-status ul {
    list-style: none;
}

.players-status li {
    padding: 0.5rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-score {
    font-weight: 600;
    color: var(--primary);
}

.player-locked {
    color: var(--success);
    font-size: 0.875rem;
}

/* Results View */
.results-view,
.final-view {
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.results-header,
.final-header {
    text-align: center;
    margin-bottom: 2rem;
}

.correct-answer {
    text-align: center;
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

.correct-answer h3 {
    font-size: 1.5rem;
    color: var(--primary);
    margin: 0.5rem 0;
}

.correct-answer p {
    color: var(--text-light);
}

.player-results {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    max-height: 50vh;
    overflow-y: auto;
}

.player-results ul,
#final-scores-list {
    list-style: none;
}

.player-results li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-results li:last-child {
    border-bottom: none;
}

.result-answer {
    flex: 1;
    margin: 0 1rem;
    color: var(--text-light);
    font-style: italic;
}

.result-correct {
    color: var(--success);
    font-weight: 600;
}

.result-incorrect {
    color: var(--error);
    font-weight: 600;
}

/* Final View */
.final-content {
    text-align: center;
}

.winner-section {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white;
    padding: 2rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

.winner-section h2 {
    font-size: 1.75rem;
}

.final-scores {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    max-height: 50vh;
    overflow-y: auto;
}

.final-scores h3 {
    margin-bottom: 1rem;
    position: sticky;
    top: 0;
    background: var(--card-bg);
    padding-bottom: 0.5rem;
}

#final-scores-list li {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
}

#final-scores-list li:first-child {
    font-weight: 600;
    color: var(--primary);
}

#final-scores-list li:last-child {
    border-bottom: none;
}

#play-again {
    margin-top: 1rem;
}

#waiting-for-host {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f0f4ff;
    border-radius: 8px;
    color: var(--text-light);
    font-style: italic;
}

/* Chat */
.chat-section {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
}

.chat-section h3 {
    margin-bottom: 0.75rem;
    font-size: 1rem;
}

.chat-messages {
    list-style: none;
    max-height: none;
    height: calc(6 * 1.6em);
    overflow-y: auto;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem;
}

.chat-messages li {
    padding: 0.25rem 0;
    font-size: 0.9rem;
    word-break: break-word;
}

.chat-messages li strong {
    color: var(--primary);
}

.chat-form {
    display: flex;
    gap: 0.5rem;
}

.chat-form input {
    flex: 1;
    margin-bottom: 0;
}

.chat-form button {
    flex-shrink: 0;
}

/* Leaflet overrides */
.leaflet-control-attribution {
    display: none !important;
}

/* Connection status banner */
#connection-status {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: 0.75rem 1rem;
    text-align: center;
    font-weight: 500;
    z-index: 9999;
    display: none;
}

.connection-warning {
    background: var(--warning);
    color: white;
}

.connection-error {
    background: var(--error);
    color: white;
}
