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

:root {
    --primary: #8b5cf6;
    --primary-glow: rgba(139, 92, 246, 0.5);
    --secondary: #ec4899;
    --accent: #06b6d4;
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text: #f8fafc;
    /* Responsive wheel size calculation */
    --wheel-size: min(85vw, 320px, 50dvh);
    --pointer-width: calc(var(--wheel-size) * 0.12);
    --pointer-height: calc(var(--wheel-size) * 0.15);
}

html {
    font-size: 16px;
}

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

html, body {
    overflow-x: hidden;
}

body {
    font-family: 'Outfit', sans-serif;
    background: radial-gradient(circle at top right, #1e1b4b, #0f172a);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* Background animated blobs */
body::before,
body::after {
    content: '';
    position: absolute;
    width: 40vw;
    height: 40vw;
    min-width: 300px;
    min-height: 300px;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    animation: move 20s infinite alternate;
}

body::before {
    background: var(--primary-glow);
    top: -10vw;
    left: -10vw;
}

body::after {
    background: rgba(236, 72, 153, 0.3);
    bottom: -10vw;
    right: -10vw;
    animation-delay: -10s;
}

@keyframes move {
    from {
        transform: translate(0, 0) scale(1);
    }
    to {
        transform: translate(10vw, 10vh) scale(1.1);
    }
}

.container {
    width: 100%;
    max-width: 480px;
    height: 100dvh;
    padding: 20px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    text-align: center;
    animation: fadeIn 0.5s ease-out;
    max-height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Hide scrollbar for card container */
.card::-webkit-scrollbar {
    display: none;
}
.card {
    scrollbar-width: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.logo {
    font-size: clamp(2rem, 8vw, 2.5rem);
    font-weight: 800;
    margin-bottom: 1.5rem;
    letter-spacing: -1px;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    flex-shrink: 0;
}

.logo span {
    color: var(--primary);
    -webkit-text-fill-color: var(--primary);
}

/* Buttons */
.primary-btn,
.secondary-btn,
.spin-btn {
    width: 100%;
    padding: 14px 20px;
    border-radius: 12px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    color: white;
    box-shadow: 0 4px 15px var(--primary-glow);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--primary-glow);
}

.primary-btn:active {
    transform: translateY(1px);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    color: white;
    border: 1px solid var(--glass-border);
    margin-top: 12px;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Customizer for inputs */
input {
    width: 100%;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    color: white;
    font-family: inherit;
    font-size: 1rem;
    margin-bottom: 8px;
    outline: none;
    transition: all 0.2s ease;
}

input:focus {
    border-color: var(--primary);
    background: rgba(139, 92, 246, 0.1);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

.setup-container {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    text-align: left;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.setup-container:hover {
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(15, 23, 42, 0.6);
}

.identity-box {
    border-left: 4px solid var(--primary);
}

.create-box {
    border-left: 4px solid var(--accent);
}

.join-box {
    border-left: 4px solid var(--secondary);
}

.setup-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    color: #64748b;
    margin-bottom: 0.75rem;
    letter-spacing: 0.05em;
}

.custom-select {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    color: white;
    outline: none;
    margin-bottom: 1rem;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.custom-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.2);
}

/* Ensure dropdown options have good contrast */
.custom-select option {
    background-color: var(--bg-dark);
    color: white;
}

.divider {
    margin: 1.25rem 0;
    position: relative;
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0;
}

.divider span {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1e293b;
    padding: 0 10px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #cbd5e1;
    text-transform: uppercase;
    border-radius: 20px;
}

/* Game Interface */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
    gap: 8px;
    flex-shrink: 0;
}

.room-info {
    font-size: 0.875rem;
    color: #94a3b8;
}

.status-badge {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online {
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: #64748b;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.online-indicator {
    font-size: 0.65rem;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

#turn-status {
    width: 100%;
    margin-bottom: 1rem;
    justify-content: center;
    background: rgba(0,0,0,0.1);
    color: #94a3b8;
    flex-shrink: 0;
}

.score-board {
    display: flex;
    justify-content: space-around;
    background: rgba(0,0,0,0.2);
    padding: 10px;
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid var(--glass-border);
    flex-shrink: 0;
}

.score-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.user-id {
    font-size: 0.8rem;
    color: #64748b;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
}

/* The Wheel & Pointer */
.wheel-outer {
    position: relative;
    width: var(--wheel-size);
    height: var(--wheel-size);
    margin: 10px auto 20px auto;
    filter: drop-shadow(0 0 20px rgba(0, 0, 0, 0.4));
    flex-shrink: 0;
}

.wheel {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 6px solid #334155;
    position: relative;
    overflow: hidden;
    transition: transform 4s cubic-bezier(0.15, 0, 0.15, 1);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
    background-color: #1e293b;
}

.wheel::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.2);
    z-index: 4;
}

/* Golden center cap */
.wheel::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14%;
    height: 14%;
    min-width: 30px;
    min-height: 30px;
    background: radial-gradient(circle at 30% 30%, #475569, #1e293b);
    border: 3px solid #64748b;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.slice {
    position: absolute;
    width: 50%;
    height: 2px;
    top: 50%;
    left: 50%;
    transform-origin: left center;
    z-index: 2;
    overflow: hidden;
}

.slice-content {
    position: absolute;
    left: 12%;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
    transform: translateY(-50%);
    width: 70%;
    text-align: right;
    pointer-events: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pointer {
    position: absolute;
    top: calc(var(--pointer-height) * -0.4);
    left: 50%;
    transform: translateX(-50%);
    width: var(--pointer-width);
    height: var(--pointer-height);
    background: #f8fafc;
    clip-path: polygon(50% 100%, 0 0, 100% 0);
    z-index: 30;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.3));
}

.spin-btn {
    background: linear-gradient(135deg, #10b981, #059669);
    margin-top: 5px;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.spin-btn:disabled {
    background: rgba(255, 255, 255, 0.05);
    color: #475569;
    box-shadow: none;
    cursor: default;
}

/* History */
.history-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
    text-align: left;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.history-section h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: #64748b;
    margin-bottom: 0.5rem;
}

#game-log {
    list-style: none;
    max-height: 120px;
    overflow-y: auto;
    padding-right: 5px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

#game-log::-webkit-scrollbar {
    width: 4px;
}
#game-log::-webkit-scrollbar-track {
    background: transparent;
}
#game-log::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 10px;
}

#game-log li {
    font-size: 0.8rem;
    padding: 8px 0;
    color: #94a3b8;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

#game-log b {
    color: var(--primary);
}

/* Modal Overlay */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 20px;
}

.modal-content {
    background: #1e293b;
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem 1.5rem;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease-out;
}

#result-header {
    font-size: clamp(1.2rem, 5vw, 1.5rem);
    margin-bottom: 1rem;
    color: var(--primary);
    font-weight: 800;
}

#result-text {
    font-size: clamp(1rem, 4.5vw, 1.2rem);
    margin-bottom: 2rem;
    line-height: 1.5;
    color: #f8fafc;
}

/* Admin Dashboard */
#admin-panel {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg-dark);
    z-index: 200;
    padding: 1rem;
    overflow-y: auto;
}

.admin-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    padding: 1.5rem;
    border-radius: 16px;
    max-width: 800px;
    margin: 0 auto;
}

.admin-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 15px;
}

.admin-log-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-log-table th,
.admin-log-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid var(--glass-border);
}

.admin-log-table th {
    color: var(--primary);
    text-transform: uppercase;
}

/* Media Queries for Maximum Completeness */

/* Extremely small mobile devices (e.g. SE, folds) */
@media (max-width: 375px) {
    html {
        font-size: 14px;
    }
    .card {
        padding: 1rem;
    }
}

/* General Mobile / Portrait modes */
@media (max-width: 600px) {
    html {
        font-size: 15px;
    }
    
    .container {
        padding: 10px;
    }
    
    .card {
        padding: 1.5rem 1rem;
        height: 100%;
        border-radius: 20px;
    }

    .modal-content {
        padding: 2rem 1rem;
        width: 90%;
        max-width: none;
        margin: 0 auto;
    }

    #result-text {
        font-size: 0.95rem;
        word-wrap: break-word; /* Allows long words to break and wrap to the next line */
        overflow-wrap: break-word; /* Standard version of word-wrap */
        word-break: break-word; /* Non-standard but often useful */
        hyphens: auto; /* Adds hyphens if a word must break */
        white-space: normal;
    }
}

/* Short screens (landscape on mobile or highly resized windows) */
@media (max-height: 750px) {
    .container {
        justify-content: flex-start;
    }

    .card {
        padding: 1rem;
    }
    
    .logo {
        font-size: 1.8rem;
        margin-bottom: 0.75rem;
    }
    
    .setup-container {
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .wheel-outer {
        margin: 5px auto 10px auto;
    }
    
    .history-section {
        margin-top: 1rem;
        padding-top: 0.75rem;
    }
    
    #game-log {
        max-height: 80px;
    }
}

/* Very short landscape screens */
@media (max-height: 600px) {
    html {
        font-size: 14px;
    }
    
    /* In extremely short screens, auto-scroll becomes super smooth and items can flow naturally */
    .card {
        justify-content: flex-start;
    }
}