@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap');

:root {
    /* Base Variables (Dark Mode Default) */
    --bg-main: #0a0a0c;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-modal: rgba(15, 15, 18, 0.95);
    --primary: #8a2be2;
    --primary-glow: rgba(138, 43, 226, 0.4);
    --secondary: #00f5d4;
    --secondary-glow: rgba(0, 245, 212, 0.3);
    --accent: #f15bb5;

    /* Text Colors */
    --text-primary: #ffffff;
    --text-secondary: #a0a0a8;
    --text-muted: #66666e;

    /* Status Colors */
    --danger: #ff4d4d;
    --success: #00f5d4;

    /* Glassmorphism */
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-bg: rgba(255, 255, 255, 0.05);

    /* Fonts */
    --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="light"] {
    --bg-main: #f0f2f5;
    --bg-card: rgba(255, 255, 255, 0.7);
    --bg-modal: rgba(255, 255, 255, 0.95);

    --text-primary: #1a1a1e;
    --text-secondary: #4a4a55;
    --text-muted: #888890;

    --glass-border: rgba(0, 0, 0, 0.08);
    --glass-bg: rgba(255, 255, 255, 0.6);
    --primary-glow: rgba(138, 43, 226, 0.15);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    width: 100%;
    max-width: 500px;
    height: 100%;
    position: relative;
    padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

@media (min-width: 501px) {
    #app {
        height: 90vh;
        max-height: 850px;
        border-radius: 32px;
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
        overflow: hidden;
        border: 1px solid var(--glass-border);
    }
}

.screen {
    position: absolute;
    inset: 0;
    padding: max(20px, env(safe-area-inset-top)) 24px max(20px, env(safe-area-inset-bottom));
    display: none;
    flex-direction: column;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-main);
}

.screen.active {
    display: flex;
    opacity: 1;
    transform: translateY(0);
    z-index: 10;
}

/* Typography */
h1 {
    font-size: 3.5rem;
    font-weight: 700;
    letter-spacing: -2px;
    line-height: 0.9;
}

h2 {
    font-size: 2.2rem;
    font-weight: 600;
    letter-spacing: -1px;
}

h3 {
    font-size: 1.5rem;
    font-weight: 600;
}

p {
    font-size: 1rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Config Screen */
.config-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding-top: 32px;
}

.game-header {
    margin-bottom: 20px;
}

:root {
    /* ... previous variables ... */

    /* Title Gradient */
    --title-gradient-start: #ffffff;
    --title-gradient-end: #a0a0a8;
}

[data-theme="light"] {
    /* ... previous variables ... */

    --title-gradient-start: #1a1a1e;
    --title-gradient-end: #4a4a55;
}

.game-title {
    background: linear-gradient(135deg, var(--title-gradient-start) 0%, var(--title-gradient-end) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.game-author {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 4px;
    margin-top: 8px;
    opacity: 0.5;
}

.config-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.config-footer {
    margin-top: auto;
    padding-top: 20px;
}

.config-tagline {
    text-align: center;
    margin-top: 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
    opacity: 0.7;
}

.config-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    backdrop-filter: blur(10px);
    overflow: hidden;
}

.config-item {
    display: flex;
    align-items: center;
    padding: 20px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--glass-border);
}

.config-item:last-child {
    border-bottom: none;
}

.config-item:active {
    background: rgba(255, 255, 255, 0.05);
}

.config-icon {
    font-size: 1.4rem;
    margin-right: 16px;
    width: 24px;
    text-align: center;
}

.config-label-container {
    flex: 1;
}

.config-label {
    font-size: 1rem;
    font-weight: 400;
    display: block;
}

.config-value {
    font-size: 0.9rem;
    color: var(--primary);
    font-weight: 600;
}

/* Toggles */
.toggle {
    width: 48px;
    height: 26px;
    background: rgba(120, 120, 128, 0.3);
    border-radius: 26px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
    flex-shrink: 0;
}

.toggle::after {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input[type="checkbox"] {
    display: none;
}

input[type="checkbox"]:checked+.toggle {
    background: var(--primary);
}

input[type="checkbox"]:checked+.toggle::after {
    transform: translateX(22px);
}

[data-theme="light"] .toggle {
    background: rgba(120, 120, 128, 0.25);
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 20px;
    border-radius: 20px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 30px var(--primary-glow);
    width: 100%;
    margin-top: 20px;
}

.btn-primary:active {
    transform: scale(0.96);
    box-shadow: 0 5px 15px var(--primary-glow);
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    padding: 18px;
    border-radius: 20px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.btn-secondary:active {
    background: var(--glass-bg);
}

/* Preparation Screen */
.prep-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
}

.player-avatar-large {
    width: 160px;
    height: 160px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 5rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}

/* Game Card */
.card-container {
    perspective: 2000px;
    width: 100%;
    max-width: 320px;
    aspect-ratio: 3/4.5;
    margin: 40px auto;
    position: relative;
}

.game-card {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
    cursor: pointer;
}

.card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    border-radius: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    border: 1px solid var(--glass-border);
}

.card-front {
    background: linear-gradient(135deg, #1a1a1e 0%, #0a0a0c 100%);
    z-index: 2;
}

.card-back {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    transform: rotateY(180deg);
    z-index: 1;
}

.game-card.flipped {
    transform: rotateY(180deg);
}

.role-badge {
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 24px;
}

.role-civil {
    background: rgba(0, 245, 212, 0.1);
    color: var(--secondary);
}

.role-impostor {
    background: rgba(255, 77, 77, 0.1);
    color: var(--danger);
}

.word-main {
    font-size: 2.5rem;
    font-weight: 700;
    text-align: center;
    letter-spacing: -1px;
    margin-bottom: 12px;
}

/* Timer */
.timer-display {
    text-align: center;
    margin: 80px 0;
}

.timer-time {
    font-size: 7rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    background: linear-gradient(180deg, #fff 0%, #555 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Voting Grid */
.players-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding: 20px 15px;
    padding-bottom: 30px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    max-height: 100%;
    width: 100%;
    align-content: start;
    -webkit-overflow-scrolling: touch;
}

#voting-screen {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Custom Scrollbar */
.players-grid::-webkit-scrollbar {
    width: 6px;
}

.players-grid::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

.players-grid::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 3px;
}

.player-vote-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s;
    cursor: pointer;
}

.player-vote-card.selected {
    border-color: var(--primary);
    background: rgba(138, 43, 226, 0.15);
    border-width: 2px;
    box-shadow: 0 4px 12px rgba(138, 43, 226, 0.3);
}

.avatar-small {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Impostor Reveal Grid */
.impostor-reveal-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin: 20px 0;
    width: 100%;
}

.impostor-reveal-grid .player-vote-card {
    width: 100px;
    padding: 12px 8px;
    flex: 0 0 auto;
}

.impostor-reveal-grid .avatar-small {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: none;
    align-items: flex-end;
    z-index: 100;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-modal);
    width: 100%;
    border-radius: 32px 32px 0 0;
    padding: 32px;
    max-height: 85vh;
    animation: slideUp 0.4s cubic-bezier(0.2, 1, 0.3, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.close-btn {
    background: var(--glass-bg);
    border: none;
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
}

[data-theme="light"] .close-btn {
    background: rgba(0, 0, 0, 0.05);
}

/* Utilities */
.text-center {
    text-align: center;
}

.mt-auto {
    margin-top: auto;
}

.mb-auto {
    margin-bottom: auto;
}

/* Responsive - Tablet */
@media (min-width: 768px) {
    body {
        align-items: center;
        justify-content: center;
        padding: 20px;
        background: linear-gradient(135deg, var(--primary) 0%, #000 100%);
    }

    body::before {
        background-size: 80px 80px, 50px 50px;
    }

    #app {
        max-width: 420px;
        min-height: auto;
        height: 92vh;
        max-height: 820px;
        border-radius: 40px;
        box-shadow:
            0 30px 90px rgba(0, 0, 0, 0.3),
            0 0 0 1px rgba(255, 255, 255, 0.1) inset;
        overflow: hidden;
        backdrop-filter: blur(10px);
    }

    .screen {
        height: 100%;
        padding: 24px;
        padding-top: 20px;
    }

    .config-footer {
        padding: 20px 0;
        padding-bottom: 10px;
    }

    .config-tagline {
        margin-top: 12px;
        font-size: 0.75rem;
    }

    .game-title {
        font-size: 3.2rem;
        margin-bottom: 5px;
        letter-spacing: -1px;
    }

    .game-author {
        font-size: 0.9rem;
        margin-bottom: 16px;
    }

    .config-content {
        gap: 16px;
        padding-top: 20px;
    }

    .config-card {
        border-radius: 18px;
        margin-bottom: 8px;
    }

    .config-item {
        padding: 14px 18px;
    }

    .config-label {
        font-size: 1.05rem;
    }

    .config-icon {
        font-size: 1.3rem;
    }

    .btn-primary {
        padding: 18px 50px;
        font-size: 1.15rem;
        border-radius: 32px;
    }

    .game-description {
        font-size: 0.85rem;
        margin-bottom: 12px;
    }

    .card-container {
        width: 320px;
        height: 450px;
    }

    .avatar {
        width: 200px;
        height: 200px;
    }

    .timer-time {
        font-size: 6rem;
    }

    .players-grid {
        max-width: 400px;
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
        margin: 0 auto;
    }

    .player-vote-card {
        padding: 20px;
    }

    .player-vote-avatar {
        width: 70px;
        height: 70px;
    }

    .modal-content {
        border-radius: 20px;
        margin-bottom: 20px;
    }

    .modal {
        align-items: center;
    }
}

/* Avatars placeholder */
.avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: min(4.5rem, 22vw);
    background: #ffffff;
    box-shadow:
        0 12px 32px rgba(0, 0, 0, 0.15),
        0 0 0 1px rgba(255, 255, 255, 0.8) inset,
        0 2px 8px rgba(0, 225, 198, 0.2);
}

.avatar-small .avatar-placeholder {
    font-size: min(3rem, 15vw);
}

.player-vote-avatar .avatar-placeholder {
    font-size: 1.8rem;
}

.impostor-avatar .avatar-placeholder {
    font-size: 2rem;
}

/* Category chips */
.category-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.category-chip {
    padding: 10px 20px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid transparent;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 0.9rem;
}

.category-chip:hover {
    background: rgba(255, 255, 255, 0.2);
}

.category-chip.selected {
    background: rgba(39, 174, 96, 0.3);
    border-color: var(--success);
}

/* Number selector */
.number-selector {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
    padding: 20px;
}

.number-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 2px solid var(--glass-border);
    background: transparent;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

[data-theme="light"] .number-btn {
    border-color: rgba(0, 0, 0, 0.15);
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.03);
}

.number-btn:hover {
    background: var(--glass-bg);
    border-color: var(--text-primary);
}

[data-theme="light"] .number-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    border-color: var(--primary);
}

.number-btn:active:not(:disabled) {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

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

.number-display {
    font-size: 3rem;
    font-weight: 700;
    min-width: 80px;
    text-align: center;
}

.modal-option {
    display: flex;
    align-items: center;
    padding: 15px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 5px;
    -webkit-tap-highlight-color: transparent;
}

.modal-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modal-option.selected {
    background: rgba(39, 174, 96, 0.2);
}

.modal-option input {
    margin-right: 15px;
    width: 20px;
    height: 20px;
    accent-color: var(--success);
}

.modal-option label {
    cursor: pointer;
    flex: 1;
}

.modal-confirm {
    display: block;
    width: 100%;
    padding: 15px;
    margin-top: 20px;
    background: var(--success);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.modal-confirm:hover {
    background: #219a52;
}

.modal-confirm:active {
    background: #1e8449;
    transform: scale(0.98);
}

/* Small mobile screens */
@media (max-height: 650px) {
    .game-title {
        font-size: 2rem;
        margin-bottom: 0;
        text-align: center;
    }

    .game-author {
        margin-bottom: 10px;
        text-align: center;
    }

    .config-card {
        margin-bottom: 8px;
    }

    .config-item {
        padding: 10px 14px;
        min-height: 46px;
    }

    .config-icon {
        font-size: 1rem;
        margin-right: 12px;
    }

    .config-label {
        font-size: 0.9rem;
    }

    .avatar-container {
        margin: 15px 0;
    }

    .avatar {
        width: 120px;
        height: 120px;
    }

    .prep-instruction {
        margin-bottom: 20px;
    }

    .card-container {
        margin: 10px 0;
        height: min(350px, 50vh);
    }

    .avatar-small {
        width: 100px;
        height: 100px;
        margin-bottom: 10px;
    }

    .card-instruction {
        font-size: 0.8rem;
    }

    .timer-title {
        margin-bottom: 20px;
    }

    .timer-display {
        margin-bottom: 20px;
    }

    .timer-instruction {
        margin-top: 15px;
    }

    .results-content {
        padding-top: 50px;
    }

    .results-title {
        font-size: 1.5rem;
    }

    .voting-title {
        font-size: 1.5rem;
        margin-bottom: 5px;
    }

    .voting-instruction {
        margin-bottom: 15px;
    }
}

/* Very small screens (iPhone SE, etc.) */
@media (max-width: 375px) {
    .screen {
        padding: 10px;
    }

    .game-title {
        font-size: 2rem;
        text-align: center;
    }

    .config-label {
        font-size: 0.85rem;
    }

    .btn-primary {
        padding: 12px 25px;
        font-size: 0.95rem;
    }

    .btn-secondary {
        padding: 12px 20px;
        font-size: 0.9rem;
    }

    .player-vote-card {
        padding: 10px 6px;
    }

    .player-vote-avatar {
        width: 40px;
        height: 40px;
    }

    .player-vote-name {
        font-size: 0.8rem;
    }

    .player-votes {
        font-size: 0.7rem;
    }

    .player-vote-avatar .avatar-placeholder {
        font-size: 1.5rem;
    }
}