:root {
    --primary: #595aff;
    --bg: #121216;
    --card-bg: #1f232b;
    --card-bg-darker: #0f1115;
    --text: #ffffff;
    --text-muted: #9ba3af;
    --border: #393f4f;
    --accent: #2b90d9;
}

/* Keep narrow iframe/mobile layouts from growing wider than their viewport. */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    background-color: var(--bg);
    background-image: url('background-tile.png');
    /* Created with https://patternico.com/ */
    background-repeat: repeat;
    background-size: 250px;
    color: var(--text);
    margin: 0;
}

/* Global Navigation */
.navbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-brand {
    flex: 0 0 auto;
    font-weight: bold;
    color: var(--primary);
    text-decoration: none;
    font-size: 1.2rem;
    white-space: nowrap;
}

.nav-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

.nav-actions > a,
.nav-actions > span,
.nav-actions > form {
    flex: 0 0 auto;
}

.nav-actions form {
    margin: 0;
}

.nav-user {
    margin-right: 4px;
    font-size: 0.9rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.nav-user strong {
    color: var(--text);
}

/* Layout Grid */
.container {
    max-width: 1050px;
    width: 100%;
    min-width: 0;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    padding: 20px;
}

/* Profile Header */
.profile-header {
    grid-column: 1 / -1;
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 10px;
}

.cover-photo {
    height: 100px;
    background: linear-gradient(45deg, #282c37, #595aff);
    background-size: 400% 400%;
    animation: gradientMove 10s ease infinite;
}

@keyframes gradientMove {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.profile-info-bar {
    padding: 0 20px 20px 20px;
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.avatar-container {
    margin-top: -50px;
    width: 100px;
    height: 100px;
}

.avatar {
    width: 100px;
    height: 100px;
    border-radius: 10px;
    border: 4px solid var(--card-bg);
    background: #282c37 url('default-avatar.png') center/cover no-repeat;
    object-fit: cover;
    display: block;
}

.avatar-small {
    width: 45px;
    height: 45px;
    border: none;
}

.profile-titles {
    padding: 0 20px 20px;
}

.profile-name {
    margin: 0;
    font-size: 1.4rem;
}

.profile-handle {
    color: var(--text-muted);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Admin badge for the profile name */
.admin-badge {
    background-color: #eb4d4b;
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    margin-left: 8px;
    vertical-align: middle;
    text-transform: uppercase;
    font-weight: 700;
}

/* Admin badge for the navbar */
.admin-badge-nav {
    border: 1px solid #f0932b;
    color: #f0932b;
    font-size: 0.6rem;
    padding: 1px 4px;
    border-radius: 3px;
    margin-right: 10px;
    text-transform: uppercase;
}

/* Sidebar */
.sidebar {
    position: sticky;
    top: 60px;
    height: fit-content;
}

.stats-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

.divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 15px 0;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

/* Compose Box */
.compose-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.compose-textarea {
    width: 100%;
    background: #121216;
    border: 1px solid var(--border);
    color: white;
    padding: 12px;
    border-radius: 8px;
    resize: none;
    font-family: inherit;
    margin-bottom: 10px;
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
    font-size: 1rem;
    line-height: 1.4;
}

textarea.compose-textarea {
    min-height: 88px;
    resize: vertical;
}

.compose-textarea:hover {
    filter: brightness(120%);
}

.compose-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.compose-controls-left {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 0;
}

.compose-footer > .btn-primary {
    flex: 0 0 auto;
}

.visibility-select {
    background: var(--bg);
    color: white;
    border: 1px solid var(--border);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    min-width: 120px;
}

/* Multi-Tab Navigation */
.feed,
.sidebar,
.profile-header {
    min-width: 0;
}

.feed-tabs {
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
    background: var(--bg);
    /*position: sticky;*/
    top: 60px;
    border-radius: 12px;
    background: var(--card-bg);
    /* Sits below navbar */
    z-index: 900;
}

.feed-tab {
    padding: 15px 20px;
    cursor: pointer;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: bold;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.feed-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.feed-tab.active {
    border-bottom: 3px solid var(--primary);
    color: var(--text);
}

/* Entry Cards */
.entry-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 15px;
    position: relative;
    transition: background-color 0.2s ease;
}

.entry-card:hover {
    background-color: var(--card-bg-darker);
}

/* Clickable overlay */
.entry-card .main-card-link {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

.entry-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
    gap: 8px;
}

.header-text {
    min-width: 0;
    overflow-wrap: anywhere;
}

.entry-layout {
    display: flex;
    gap: 12px;
    min-width: 0;
}

.entry-body {
    flex: 1;
    min-width: 0;
}

.comments-section {
    position: relative;
    z-index: 2;
}

.entry-thread-section {
    margin: -6px 0 16px 52px;
}

.thread-header {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.thread-list {
    margin-top: 8px;
}

.thread-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
    margin-top: 8px;
    transition: background-color 0.2s ease;
}

.thread-card:hover {
    background-color: var(--card-bg-darker);
}

.thread-card-header {
    font-size: 0.86rem;
    margin-bottom: 4px;
}

.thread-card-content {
    font-size: 0.9rem;
    line-height: 1.35;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.entry-content {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.entry-content pre,
.thread-card-content pre {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.entry-content code,
.thread-card-content code {
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: break-spaces;
}

.entry-content table,
.thread-card-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.thread-card-actions {
    margin-top: 8px;
    display: flex;
    gap: 12px;
}

/* Single Entry View */
.single-entry-container {
    max-width: 700px;
    margin: 40px auto;
    padding: 0 20px;
    display: block;
}

/* Ensure images within markdown don't overflow the fixed width */
.entry-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
}

.single-entry-container .entry-card {
    border-color: var(--primary);
    /* Optional: highlight the card border */
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}


/* Author Links */
.author-link {
    text-decoration: none;
    color: var(--text);
    transition: color 0.2s ease;
    display: inline-block;
    position: relative;
    z-index: 2;
    /* Sits above clickable overlay */
}

.author-link:hover {
    color: var(--primary);
}

.author-link .author-name {
    font-size: 1rem;
    font-weight: 700;
    vertical-align: middle;
}

.author-link:hover .author-name {
    text-decoration: underline;
}

.avatar-link {
    text-decoration: none;
    display: block;
    flex-shrink: 0;
    transition: opacity 0.2s ease;
}

.avatar-link:hover {
    opacity: 0.85;
}

.github-indicator {
    color: var(--accent);
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
    font-weight: bold;
    text-transform: uppercase;
}

.accent-link {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.2s ease;
}

.accent-link:hover {
    color: var(--primary);
    text-decoration: underline;
}

.entry-footer {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 25px;
    position: relative;
    z-index: 2;
    /* Sits above clickable overlay */
}

.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    margin-top: 1rem;
    border-top: 1px solid var(--border-color, #eee);
}

.pagination-info {
    font-size: 0.9rem;
    color: #666;
}

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

.btn-outline.disabled,
.btn-primary.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
}

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

.visibility-badge {
    font-size: 0.65rem;
    text-transform: uppercase;
    background: #282c37;
    padding: 2px 8px;
    border-radius: 10px;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    text-decoration: none;
}

.btn-primary:hover {
    filter: brightness(120%);
}

.btn-outline {
    background: none;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
}

.btn-red-outline {
    background: none;
    border: 1px solid #ff4d4d;
    color: #ff4d4d;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
}

.btn-red-outline:hover {
    background: rgba(255, 77, 77, 0.12);
}

.btn-outline:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* Edit Profile */
.edit-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.photo-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.photo-preview {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid var(--border);
    object-fit: cover;
    background: #ffffff;
    flex: 0 0 auto;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* Shared wrapper for login/signup/settings pages. */
.auth-container {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0 12px;
    margin: 0 auto;
}

/*
 * Embedded portfolio views are often narrower than a normal desktop tab.
 * Keep the brand separate and let the action row scroll instead of allowing
 * navigation links to overlap or force the page wider than the iframe.
 */
@media (max-width: 1000px) {
    .navbar {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
        padding: 8px 12px;
    }

    .nav-brand {
        align-self: flex-start;
    }

    .nav-actions {
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 4px;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    .nav-actions::-webkit-scrollbar {
        height: 6px;
    }

    .nav-actions::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 999px;
    }

    .sidebar {
        top: 104px;
    }
}

@media (max-width: 640px) {
    .navbar {
        padding: 8px 10px;
    }

    .nav-brand {
        font-size: 1.05rem;
    }

    .nav-user {
        display: none;
    }

    .nav-actions .btn-outline,
    .nav-actions .btn-primary,
    .nav-actions .btn-red-outline {
        padding: 7px 10px;
        font-size: 0.82rem;
        white-space: nowrap;
    }
}

/*
 * The compose row runs out of room before the entire profile layout needs to
 * become single-column. Stack only the composer earlier, while keeping the
 * sidebar/profile layout unchanged until 768px.
 */
@media (max-width: 980px) {
    .compose-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .compose-controls-left {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 8px;
        width: 100%;
        min-width: 0;
    }

    .compose-controls-left > * {
        min-width: 0;
    }

    .compose-controls-left .btn-primary {
        grid-column: 1 / -1;
        width: 100%;
    }

    .visibility-select {
        width: 100%;
        min-width: 0;
    }

    .compose-footer > .btn-primary {
        width: 100%;
    }
}

@media (max-width: 768px) {
    .container {
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        padding: 10px;
    }

    /* Put the interactive feed before the stats card in narrow embeds. */
    .feed {
        order: 2;
        min-width: 0;
    }

    .sidebar {
        position: static;
        order: 3;
    }

    .profile-header {
        order: 1;
        margin-bottom: 0;
    }

    .compose-card,
    .entry-card {
        padding: 16px;
    }

    .compose-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .compose-controls-left {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 8px;
        width: 100%;
    }

    .compose-controls-left .btn-primary {
        grid-column: 1 / -1;
    }

    .visibility-select {
        width: 100%;
        min-width: 0;
    }

    .compose-footer > .btn-primary {
        width: 100%;
    }

    .entry-header {
        flex-wrap: wrap;
        align-items: center;
    }

    .entry-header .timestamp {
        flex-basis: 100%;
    }

    .entry-footer,
    .thread-card-actions {
        flex-wrap: wrap;
        gap: 12px;
    }

    /* Deep comment indentation consumes too much space inside an iframe. */
    .entry-thread-section {
        margin: -4px 0 14px 0;
    }

    .thread-card {
        margin-left: 0 !important;
        padding: 14px;
    }

    .single-entry-container {
        margin: 20px auto;
        padding: 0 10px;
    }

    .pagination-container {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .pagination-controls {
        justify-content: space-between;
    }

    .author-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .author-search-top {
        margin-top: 12px;
        padding: 16px;
    }

    .auth-container .compose-card {
        max-width: 100% !important;
        margin: 1rem auto !important;
        padding: 1.25rem !important;
    }

    .edit-header {
        flex-wrap: wrap;
        gap: 10px;
    }

    .feed-tabs {
        top: 50px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 8px;
    }

    .cover-photo {
        height: 80px;
    }

    .profile-info-bar {
        padding: 0 12px 12px;
        gap: 10px;
    }

    .profile-titles {
        padding: 0 12px 12px;
    }

    .profile-name {
        font-size: 1.2rem;
    }

    .profile-handle {
        font-size: 0.78rem;
    }

    .avatar-container,
    .avatar:not(.avatar-small) {
        width: 84px;
        height: 84px;
    }

    .avatar-container {
        margin-top: -42px;
    }

    .avatar-small {
        width: 36px;
        height: 36px;
    }

    .entry-layout {
        gap: 8px;
    }

    .compose-card,
    .entry-card,
    .stats-card {
        padding: 12px;
        border-radius: 10px;
    }

    .compose-controls-left {
        grid-template-columns: minmax(0, 1fr);
    }

    .compose-controls-left .btn-primary {
        grid-column: auto;
    }

    .feed-tab {
        padding: 12px 14px;
        font-size: 0.85rem;
    }

    .entry-footer {
        gap: 10px;
        padding-top: 12px;
        margin-top: 12px;
    }

    .thread-card {
        padding: 12px;
    }

    .empty-state {
        padding: 24px 12px;
    }

    .author-search-input-large {
        padding: 14px;
        font-size: 1rem;
    }
}

.author-search-page {
    display: block !important;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

.author-search-top {
    width: 100%;
    box-sizing: border-box;
    margin: 24px 0 20px 0;
    padding: 20px;
}

.author-search-input-large {
    width: 100%;
    box-sizing: border-box;
    padding: 18px 20px;
    font-size: 1.08rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #121216;
    color: white;
    outline: none;
}

.author-search-input-large::placeholder {
    color: var(--text-muted);
}

.author-count-line {
    margin-top: 14px;
    margin-bottom: 0;
}

.author-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 18px;
    width: 100%;
}

.author-search-card {
    margin: 0;
    width: 100%;
    box-sizing: border-box;
}

.author-search-page {
    display: block !important;
    max-width: 1300px;
    width: 100%;
    margin: 0 auto;
    box-sizing: border-box;
}

.author-search-top {
    width: 100%;
    box-sizing: border-box;
    margin: 24px 0 20px 0;
    padding: 20px;
}

.author-search-input-large {
    width: 100%;
    box-sizing: border-box;
    padding: 18px 20px;
    font-size: 1.08rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #121216;
    color: white;
    outline: none;
}

.author-search-input-large::placeholder {
    color: var(--text-muted);
}

.author-count-line {
    margin-top: 14px;
    margin-bottom: 0;
}

.author-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 18px;
    width: 100%;
}

.author-search-card {
    margin: 0;
    width: 100%;
    box-sizing: border-box;
}