:root {
    --bg-dark: #0f0f13;
    --bg-card: #1a1a20;
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.4);
    --text-main: #ffffff;
    --text-muted: #a1a1aa;
    --border: #27272a;
    --glass: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --font-sans: 'Inter', sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-sans);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
.header {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: rgba(15, 15, 19, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}

.logo {
    font-weight: 700;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
}

.logo-icon {
    color: var(--primary);
    text-shadow: 0 0 10px var(--primary-glow);
}

.controls {
    display: flex;
    gap: 20px;
    align-items: center;
}

.input-group {
    display: flex;
    gap: 8px;
}

input {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-main);
    width: 300px;
    transition: all 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
}

.btn {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    font-weight: 500;
}

.btn:hover {
    background: var(--glass);
    border-color: var(--glass-border);
}

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

.btn-primary:hover {
    background: #4f46e5;
    box-shadow: 0 0 15px var(--primary-glow);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    opacity: 0.7;
}

.btn-sm:hover {
    opacity: 1;
}

.presets {
    display: flex;
    gap: 8px;
}

/* Grid */
.grid-container {
    flex: 1;
    padding: 20px;
    display: grid;
    gap: 20px;
    /* Default to 2x2 grid for 4 items, auto-fit otherwise */
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    grid-auto-rows: minmax(300px, 1fr);
    overflow-y: auto;
}

/* Stream Card */
.stream-card {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease-out;
}

.stream-card iframe {
    width: 100%;
    height: 100%;
    border: none;
    flex: 1;
}

.stream-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 10px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
    display: flex;
    justify-content: flex-end;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.stream-card:hover .stream-header {
    opacity: 1;
    pointer-events: auto;
}

.remove-btn {
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    line-height: 1;
}

.remove-btn:hover {
    background: #dc2626;
    transform: scale(1.1);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Responsive adjustments */
@media (max-width: 900px) {
    .header {
        height: auto;
        flex-direction: column;
        padding: 16px;
        gap: 16px;
    }

    .logo {
        margin-bottom: 0;
        align-self: flex-start;
    }

    .controls {
        flex-direction: column;
        width: 100%;
        gap: 16px;
    }

    .input-group {
        width: 100%;
    }

    input {
        width: 100%;
        flex: 1;
    }

    .presets {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 8px;
        justify-content: flex-start;
        /* Hide scrollbar */
        -ms-overflow-style: none;
        scrollbar-width: none;
    }

    .presets::-webkit-scrollbar {
        display: none;
    }

    .actions {
        width: 100%;
        justify-content: flex-end;
        padding-top: 8px;
        border-top: 1px solid var(--border);
    }
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    margin-top: auto;
    background: rgba(15, 15, 19, 0.5);
}

.app-footer a {
    color: var(--text-muted);
    text-decoration: none;
    margin: 0 8px;
    transition: color 0.2s;
}

.app-footer a:hover {
    color: var(--primary);
}

/* Toggle Layout Class */
.grid-container.layout-fixed {
    grid-template-columns: repeat(3, 1fr) !important;
    grid-auto-rows: minmax(250px, 1fr);
}

/* Clear Button */
.btn-danger {
    color: #ef4444;
    /* Red-500 */
    border-color: #7f1d1d;
    /* Red-900 */
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

@media (max-width: 1200px) {
    .grid-container.layout-fixed {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 768px) {
    .grid-container.layout-fixed {
        grid-template-columns: 1fr !important;
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.modal-overlay:not(.hidden) .modal {
    transform: scale(1);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 12px;
}

.modal-message {
    color: var(--text-muted);
    margin-bottom: 24px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Tools Section (Homepage) */
.tools-section {
    padding: 40px 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 24px;
    background: var(--primary);
    border-radius: 2px;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.tool-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tool-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.tool-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.tool-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-main);
}

.tool-description {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Collapsed Tools Section */
.tools-section.collapsed {
    padding: 8px 16px;
    opacity: 0.7;
    transition: all 0.2s;
}

.tools-section.collapsed:hover {
    opacity: 1;
}

.tools-section.collapsed .section-header {
    margin-bottom: 0 !important;
    /* Override inline style or high specificity */
}

.tools-section.collapsed .section-title {
    font-size: 0.9rem;
    font-weight: 500;
}