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

:root {
    --primary-color: #6366f1;
    --secondary-color: #64748b;
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --text-color: #f1f5f9;
    --border-color: #334155;
    --danger-color: #ef4444;
    --success-color: #10b981;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    overflow-x: hidden;
}

#app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: var(--surface-color);
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.header-controls {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-primary:hover {
    background: #4f46e5;
    transform: translateY(-1px);
}

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

.btn-secondary:hover {
    background: #475569;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: 0.5rem;
    max-width: 500px;
    width: 100%;
    border: 1px solid var(--border-color);
}

.modal-content h2 {
    margin-bottom: 0.5rem;
}

.modal-content .hint {
    color: var(--secondary-color);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

/* Input Tabs */
.input-mode-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    color: var(--secondary-color);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

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

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* Input Sections */
.input-section {
    margin-bottom: 1rem;
}

.input-section.hidden {
    display: none;
}

.modal-content input,
.modal-content textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    color: var(--text-color);
    font-size: 1rem;
    font-family: inherit;
}

.modal-content input:focus,
.modal-content textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.modal-content textarea {
    resize: vertical;
    min-height: 120px;
}

.hint-small {
    font-size: 0.75rem;
    color: var(--secondary-color);
    margin-top: 0.5rem;
}

.modal-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

/* Main Container */
main {
    flex: 1;
    padding: 1rem;
    display: grid;
    gap: 1rem;
}

/* Stream Container Layouts */
.stream-container.count-1 {
    grid-template-columns: 1fr;
}

.stream-container.count-2 {
    grid-template-columns: repeat(2, 1fr);
}

.stream-container.count-3,
.stream-container.count-4 {
    grid-template-columns: repeat(2, 1fr);
}

.stream-container.count-5,
.stream-container.count-6 {
    grid-template-columns: repeat(3, 1fr);
}

.stream-container.count-7,
.stream-container.count-8,
.stream-container.count-9 {
    grid-template-columns: repeat(3, 1fr);
}

/* Focus Mode */
.stream-container.focus-mode {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
}

.stream-container.focus-mode .stream-wrapper.focused {
    grid-column: 1;
    grid-row: 1;
}

.stream-container.focus-mode .thumbnail-row {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
    overflow-x: auto;
    background: var(--surface-color);
    border-radius: 0.375rem;
}

.stream-container.focus-mode .stream-wrapper:not(.focused) {
    width: 200px;
    height: 112px;
    flex-shrink: 0;
}

/* Stream Wrapper */
.stream-wrapper {
    position: relative;
    background: var(--surface-color);
    border-radius: 0.5rem;
    overflow: hidden;
    border: 2px solid var(--border-color);
    transition: all 0.3s;
    cursor: grab;
}

.stream-wrapper:active {
    cursor: grabbing;
}

.stream-wrapper.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.stream-wrapper.drag-over {
    border-color: var(--primary-color);
    transform: scale(1.02);
}

.stream-wrapper:hover {
    border-color: var(--primary-color);
}

.stream-wrapper.focused {
    border-color: var(--success-color);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Stream Content */
.stream-content {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
}

.stream-content iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* Stream Controls */
.stream-controls {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.25rem;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s;
}

.stream-wrapper:hover .stream-controls {
    opacity: 1;
}

.control-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 0.25rem;
    background: rgba(15, 23, 42, 0.9);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s;
}

.control-btn:hover {
    background: rgba(15, 23, 42, 1);
    transform: scale(1.1);
}

.control-btn.delete {
    background: rgba(239, 68, 68, 0.9);
}

.control-btn.delete:hover {
    background: rgba(239, 68, 68, 1);
}

/* Stream Info */
.stream-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(15, 23, 42, 0.9), transparent);
    padding: 0.5rem;
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.stream-wrapper:hover .stream-info {
    opacity: 1;
}

/* Empty State */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
}

.empty-state h2 {
    margin-bottom: 0.5rem;
}

.empty-state p {
    color: var(--secondary-color);
}

/* Responsive */
@media (max-width: 768px) {
    header {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.25rem;
    }

    .stream-container.count-2,
    .stream-container.count-3,
    .stream-container.count-4,
    .stream-container.count-5,
    .stream-container.count-6,
    .stream-container.count-7,
    .stream-container.count-8,
    .stream-container.count-9 {
        grid-template-columns: 1fr;
    }
}

/* Loading State */
.stream-wrapper.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}
