/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-dark: #0a0a0a;
    --bg-overlay: rgba(0, 0, 0, 0.8);
    --bg-surface: rgba(30, 30, 30, 0.95);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.4);
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --success: #22c55e;
    --border: rgba(255, 255, 255, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
}

#app {
    height: 100%;
}

.hidden {
    display: none !important;
}

/* Screens */
.screen {
    height: 100%;
    width: 100%;
}

/* Join Screen */
#join-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #0a0a0a 100%);
}

.join-card {
    background: var(--bg-surface);
    padding: 3rem;
    border-radius: var(--radius);
    text-align: center;
    max-width: 360px;
    width: 90%;
    border: 1px solid var(--border);
}

.join-card h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.join-card p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.join-card input {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.join-card input:focus {
    border-color: var(--accent);
}

.join-card input::placeholder {
    color: var(--text-muted);
}

/* Buttons */
.btn {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn.primary {
    background: var(--accent);
    color: white;
    width: 100%;
}

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

.btn.small {
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}

/* Main Screen — portrait phone layout, centered on desktop */
#main-screen {
    position: relative;
    display: flex;
    flex-direction: column;
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

/* Video Wrapper */
.video-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
}

.video-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.placeholder-content {
    text-align: center;
    color: var(--text-secondary);
}

.placeholder-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

.placeholder-content p {
    font-size: 1rem;
}

.placeholder-content .hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.video-player {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Chat Log (Twitch-style prompt feed) */
.chat-log {
    position: absolute;
    bottom: 6rem;
    left: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 340px;
    pointer-events: none;
    z-index: 10;
}

.chat-entry {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    padding: 0.1rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    line-height: 1.3;
    color: var(--text-secondary);
    animation: chatSlideIn 0.3s ease;
}

.chat-entry .chat-name {
    font-weight: 600;
    color: var(--accent);
    margin-right: 0.35rem;
}

.chat-entry.system-msg {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.75rem;
}

.chat-entry.system-msg .chat-name {
    color: var(--success);
}

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

/* Floating Controls */
.floating-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: flex-end;
    padding: 1.5rem;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    gap: 0.5rem;
}

/* Icon Buttons */
.icon-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.icon-btn.primary {
    background: var(--accent);
}

.icon-btn.primary:hover {
    background: var(--accent-hover);
}

.icon-btn.danger {
    background: var(--danger);
}

.icon-btn.danger:hover {
    background: var(--danger-hover);
}

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

.icon-btn:disabled:hover {
    background: var(--bg-surface);
}

.icon-btn .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--accent);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* Prompt Bar */
.prompt-bar {
    flex: 1;
    max-width: 600px;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 0.5rem;
    border: 1px solid var(--border);
}

.prompt-bar textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    padding: 0.5rem;
    resize: none;
    outline: none;
    max-height: 120px;
    line-height: 1.4;
}

.prompt-bar textarea::placeholder {
    color: var(--text-muted);
}

/* Popovers */
.popover {
    position: absolute;
    bottom: 5.5rem;
    left: 1.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-width: 280px;
    max-width: 320px;
    max-height: 60vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.2s ease;
    z-index: 100;
}

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

.popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.popover-header h4 {
    font-size: 0.9rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-primary);
}

/* Player List */
.player-list {
    list-style: none;
    padding: 0;
}

.player-list li {
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.player-list li.me {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent);
    font-weight: 500;
}

/* History */
.history {
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
}

.history-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
    font-size: 0.875rem;
}

.history-item {
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
}

.history-item.system {
    color: var(--text-muted);
    font-style: italic;
}

.history-item.start {
    color: var(--success);
}

.history-item.end {
    color: var(--danger);
}

.history-item.interact {
    color: var(--accent);
}

/* Settings / Menu */
.settings-content {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.menu-section {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.menu-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.menu-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.btn-leave {
    width: 100%;
    padding: 0.625rem 1rem;
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--danger);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-leave:hover {
    background: var(--danger);
    color: white;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    margin-bottom: 1rem;
}

.checkbox-label input {
    accent-color: var(--accent);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.form-group input[type="file"] {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.image-preview {
    margin-top: 0.75rem;
    position: relative;
}

.image-preview img {
    max-width: 100%;
    max-height: 100px;
    border-radius: var(--radius-sm);
}

.image-preview .btn {
    margin-top: 0.5rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 6rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: white;
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

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

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Responsive */
@media (max-width: 640px) {
    .floating-controls {
        padding: 1rem;
    }

    .popover {
        left: 1rem !important;
        right: 1rem;
        max-width: none;
        bottom: 5rem;
    }

    .icon-btn {
        width: 40px;
        height: 40px;
    }

    .icon-btn svg {
        width: 18px;
        height: 18px;
    }

    .chat-log {
        bottom: 5rem;
        left: 1rem;
        right: 4rem;
        max-width: none;
    }
}
