:root {
    /* Brand Colors */
    --twitch-purple: #9146FF;
    --primary: #A970FF;
    --primary-hover: #b98afa;
    --background: #0f0f13;
    --surface: #18181f;
    --surface-hover: #22222a;
    --border: #2a2a35;

    /* Text Colors */
    --text-main: #f0f0f5;
    --text-muted: #a0a0b0;

    /* Layout */
    --radius: 12px;
    --radius-lg: 20px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: var(--background);
    color: var(--text-main);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Glassmorphism helpers */
.glass {
    background: rgba(24, 24, 31, 0.7);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    /* border: 1px solid var(--border); */
}

.button {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.button-twitch {
    background: var(--twitch-purple);
}

.button-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.button-outline:hover {
    background: var(--surface-hover);
}

/* Base Layout Container */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 240px 1fr 300px;
    gap: 24px;
    padding: 24px;
    min-height: 100vh;
}

/* Sidebar navigation */
nav.sidebar {
    position: sticky;
    top: 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    height: calc(100vh - 48px);
    /* fill viewport minus top/bottom padding */
}

nav.sidebar a {
    color: var(--text-main);
    text-decoration: none;
    padding: 10px 14px;
    border-radius: var(--radius);
    transition: background 0.2s ease;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
}

nav.sidebar a:hover {
    background: var(--surface);
}

/* Main Feed */
.feed-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.post-composer {
    position: relative;
    z-index: 10;
}

.post-composer,
.post-card {
    border-radius: var(--radius-lg);
    padding: 20px;
}

.post-composer textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1rem;
    resize: none;
    outline: none;
    min-height: 80px;
    font-family: inherit;
}

.post-composer .actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

/* User Identity */
.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.live-ring {
    border-color: #ff4545;
    box-shadow: 0 0 10px rgba(255, 69, 69, 0.4);
}

.onboarding-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.onboarding-card {
    padding: 40px;
    width: 100%;
    max-width: 400px;
    border-radius: var(--radius-lg);
    text-align: center;
}

.form-group {
    text-align: left;
    margin-bottom: 20px;
}

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

.form-control {
    width: 100%;
    background: var(--background);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 12px;
    border-radius: var(--radius);
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
}

.form-control:focus {
    border-color: var(--primary);
}

/* Style Native Select Options */
select option {
    background-color: var(--surface);
    color: var(--text-main);
    padding: 8px;
}

/* Custom Select Widget */
.custom-select-container {
    position: relative;
    user-select: none;
    width: 100%;
}

.custom-select-trigger {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: var(--background);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    font-size: 0.95rem;
}

.custom-select-trigger:hover,
.custom-select-container.open .custom-select-trigger {
    border-color: var(--primary);
}

.custom-select-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    padding: 4px 0;
}

.custom-select-container.open .custom-select-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.custom-select-option {
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
    color: var(--text-muted);
}

.custom-select-option:hover {
    background: var(--surface-hover);
    color: var(--text-main);
}

.custom-select-option.selected {
    background: rgba(169, 112, 255, 0.1);
    color: var(--primary);
    font-weight: 500;
}

/* Custom scrollbar for custom select */
.custom-select-menu::-webkit-scrollbar {
    width: 6px;
}

.custom-select-menu::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.custom-select-menu::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.custom-select-menu::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}


/* Custom Dark Theme Checkbox */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--background);
    margin: 0;
    font: inherit;
    color: currentColor;
    width: 1.25em;
    height: 1.25em;
    border: 1px solid var(--border);
    border-radius: 4px;
    display: inline-grid;
    place-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

input[type="checkbox"]::before {
    content: "";
    width: 0.65em;
    height: 0.65em;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 1em 1em var(--primary);
    background-color: var(--primary);
    transform-origin: center;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

input[type="checkbox"]:checked {
    border-color: var(--primary);
    background-color: rgba(169, 112, 255, 0.1);
}

input[type="checkbox"]:checked::before {
    transform: scale(1);
}

/* Comment Reply Highlight */
@keyframes highlightPulse {
    0% {
        border-color: var(--primary);
        box-shadow: 0 0 15px rgba(169, 112, 255, 0.4);
        background: rgba(169, 112, 255, 0.05);
    }

    100% {
        border-color: transparent;
        box-shadow: none;
        background: rgba(255, 255, 255, 0.03);
    }
}

.highlight-comment {
    animation: highlightPulse 2s ease-out forwards;
}

/* Threading & Nesting */
.replies-list {
    margin-top: 12px;
}

.reply-item-container {
    padding: 12px 0 12px 12px;
    border-left: 2px solid transparent;
    transition: background 0.2s;
}

/* Indentation for nested replies */
.reply-nested {
    margin-left: 12px;
    padding-left: 20px;
    border-left: 2px solid var(--border);
    margin-top: -8px;
    margin-bottom: 8px;
}

.reply-item-content {
    background: rgba(255, 255, 255, 0.03);
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    position: relative;
}

/* Mention Dropdown Styles */
.mention-dropdown {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 9999;
    max-height: 250px;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    display: none;
    width: 250px;
}

.mention-item {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

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

.mention-item.active,
.mention-item:hover {
    background: var(--surface-hover);
}

.mention-item img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

/* ==========================================================================
   Messenger Layout 
   ========================================================================== */

.conversation-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    cursor: pointer;
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.2);
    transition: background 0.2s;
    border: 1px solid transparent;
}

.conversation-item:hover {
    background: var(--surface-hover);
    border-color: var(--border);
}

.conversation-item img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

.conversation-details {
    flex: 1;
    overflow: hidden;
}

.conversation-name {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-snippet {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-single-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 120px);
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    position: relative;
    padding: 0;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 20px;
    line-height: 1.4;
    word-wrap: break-word;
    font-size: 0.95rem;
}

.message-bubble.received {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message-bubble.sent {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.1);
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-input-area input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 14px 20px;
    border-radius: 24px;
    outline: none;
    font-size: 0.95rem;
}

.chat-input-area input:focus {
    border-color: var(--primary);
}

.chat-input-area button {
    border-radius: 50%;
    width: 48px;
    height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile Navigation Header */
.mobile-nav-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.mobile-nav-header .brand {
    font-weight: bold;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-main);
    text-decoration: none;
}

.mobile-menu-toggle {
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1999;
    display: none;
    backdrop-filter: blur(4px);
}

.sidebar-overlay.active {
    display: block;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .chat-single-layout {
        height: calc(100vh - 80px);
        /* Give top padding space */
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .app-container {
        grid-template-columns: 1fr;
        padding: 0;
        gap: 0;
    }

    .feed-container {
        padding: 16px;
    }

    aside.widgets {
        display: none !important;
    }

    .mobile-nav-header {
        display: flex;
    }

    /* Hide desktop header and composer text on mobile */
    .feed-header-bar {
        display: none !important;
    }

    .composer-btn-text {
        display: none !important;
    }

    nav.sidebar {
        position: fixed;
        top: 0;
        left: -300px;
        width: 280px;
        height: 100vh;
        background: var(--surface);
        z-index: 2000;
        padding: 24px 16px;
        overflow-y: auto;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
    }

    nav.sidebar.active {
        left: 0;
    }
}

/* =========================================================
   Twitch Clean Theme Overrides
   ========================================================= */
body.theme-twitch-clean {
    --background: #07060a;
    /* Deepest black-purple for high contrast */
    --surface: #12101b;
    /* Cooler, deeper surface */
    --surface-hover: #1c182a;
    /* Distinct interactive state */
    --primary: #b05cff;
    /* Highly vibrant, neon-style Twitch purple */
    --primary-hover: #c78aff;
    /* Extra bright hover state */
    --border: #2e2345;
    /* Purple-tinted borders that pop */
    --text-main: #ffffff;
    /* Pure white for popping contrast */
    --text-muted: #ada3c4;
    /* More readable, purple-tinted muted text */
}

body.theme-twitch-clean .feed-container {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    padding-left: 0;
    padding-right: 0;
    /* ensure there's no gap if we want lines to connect, but gap defaults to column gap */
}

/* Remove glass aesthetics from sidebars and widgets */
body.theme-twitch-clean nav.sidebar.glass,
body.theme-twitch-clean .widgets-container.glass,
body.theme-twitch-clean .settings-header.glass,
body.theme-twitch-clean .settings-section.glass {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    box-shadow: none;
}

/* In the center feed, we want headers or inner cards to also adapt */
body.theme-twitch-clean .post-composer.glass,
body.theme-twitch-clean .page-header-small.glass,
body.theme-twitch-clean .profile-header-container.glass,
body.theme-twitch-clean .connections-header.glass,
body.theme-twitch-clean .chat-single-layout.glass,
body.theme-twitch-clean .messages-container.glass,
body.theme-twitch-clean .explore-nav-bar.glass,
body.theme-twitch-clean .notifications-header.glass,
body.theme-twitch-clean .collab-board-header.glass,
body.theme-twitch-clean .my-collab-panel.glass,
body.theme-twitch-clean .composer-guest-card.glass,
body.theme-twitch-clean .feed-container>.glass:not(.custom-modal-content):not(.cropper-modal-content) {
    /* background: transparent !important; */
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-radius: 0 !important;
    border: none !important;
    border-bottom: 1px solid var(--border) !important;
    box-shadow: none !important;
}

body.theme-twitch-clean .messages-container.glass {
    background: transparent !important;
}