:root {
    color-scheme: dark;
    --bg: #05070f;
    --fg: #f4f6fb;
    --muted: #858aa1;
    --accent: #4b7bec;
    --accent-strong: #6b8fff;
    --accent-soft: rgba(75, 123, 236, 0.28);
    --card: rgba(13, 17, 30, 0.92);
    --card-border: rgba(255, 255, 255, 0.08);
    --card-shadow: 0 28px 60px rgba(10, 14, 28, 0.55);
    --bubble-border: rgba(75, 123, 236, 0.35);
    --bubble-reply-border: rgba(255, 186, 120, 0.42);
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 18% 18%, rgba(75, 123, 236, 0.25), transparent 48%),
        radial-gradient(circle at 80% -5%, rgba(141, 78, 206, 0.22), transparent 50%),
        var(--bg);
    color: var(--fg);
}

.top-link {
    display: flex;
    justify-content: center;
    padding: 1.15rem 1.5rem 0;
}

.top-link a {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1.15rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(12, 16, 30, 0.85);
    color: var(--fg);
    text-decoration: none;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 0.85rem;
    transition: border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.top-link a:hover,
.top-link a:focus-visible {
    border-color: var(--accent);
    color: var(--accent-strong);
    transform: translateY(-1px);
    outline: none;
}

main {
    max-width: 1180px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 4.5rem;
    display: flex;
    flex-direction: column;
    gap: 2.2rem;
}

.page-header {
    position: relative;
    padding: 3.2rem 1.5rem 4.2rem;
    text-align: center;
    overflow: hidden;
}

.page-header::before,
.page-header::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.page-header::before {
    background: linear-gradient(135deg, rgba(75, 123, 236, 0.62), rgba(141, 78, 206, 0.48));
    filter: blur(14px);
}

.page-header::after {
    background: radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.16), transparent 55%);
    mix-blend-mode: screen;
}

.header-content {
    position: relative;
    z-index: 1;
}

.page-header h1 {
    margin: 0;
    font-size: clamp(2.4rem, 5vw, 3.8rem);
    letter-spacing: 0.04em;
    color: var(--fg);
}

.page-header .tagline {
    margin: 0.65rem auto 0;
    max-width: 540px;
    font-size: 1.1rem;
    color: var(--muted);
}

.thread {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 1.25rem;
    padding: 1.8rem;
    box-shadow: var(--card-shadow);
    backdrop-filter: blur(20px);

    position: relative;
    display: flex;
    flex-direction: column;
    gap: 1.6rem;
    min-height: clamp(32rem, 72vh, 48rem);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.section-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.section-tabs {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem;
    border-radius: 999px;
    background: rgba(20, 24, 40, 0.6);
}

.tab-button {
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    padding: 0.35rem 0.95rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.tab-button:hover,
.tab-button:focus-visible {
    outline: none;
    color: var(--accent);
}

.tab-button.is-active {
    background: rgba(75, 123, 236, 0.18);
    color: var(--fg);
}

.tab-button.is-active:hover,
.tab-button.is-active:focus-visible {
    color: var(--fg);
}


.section-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.thread-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.search-feedback {
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.search-feedback[hidden] {
    display: none;
}

.ghost-button {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: var(--muted);
    border-radius: 999px;
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
}

.ghost-button:hover,
.ghost-button:focus-visible {
    border-color: var(--accent);
    color: var(--accent);
    outline: none;
}

.status-message {
    margin: 1.5rem 0 0;
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(20, 24, 40, 0.78);
    backdrop-filter: blur(12px);
    color: var(--fg);
    font-weight: 500;
    transition: opacity 0.3s ease;
}

.status-message[hidden] {
    display: none;
}

.status-message.info {
    border-color: rgba(75, 123, 236, 0.32);
    background: rgba(75, 123, 236, 0.18);
}

.status-message.success {
    border-color: rgba(76, 175, 80, 0.35);
    background: rgba(76, 175, 80, 0.18);
}

.status-message.error {
    border-color: rgba(244, 67, 54, 0.32);
    background: rgba(244, 67, 54, 0.16);
}

.thread-root {
    margin-top: 1.2rem;
    flex: 1;
    overflow-y: auto;
    padding-right: 0.5rem;
    display: grid;
    gap: 1.1rem;
    scroll-behavior: smooth;
    min-height: 16rem;
    padding-bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
    overscroll-behavior: contain;
}

.thread-root:focus {
    outline: 2px solid var(--accent);
    outline-offset: 6px;
}

.thread-root::-webkit-scrollbar {
    width: 10px;
}

.thread-root::-webkit-scrollbar-thumb {
    background: rgba(75, 123, 236, 0.35);
    border-radius: 999px;
}

.thread-composer {
    margin-top: auto;
    display: grid;
    gap: 1rem;
    position: sticky;
    bottom: 0;
    padding: 1.1rem 1.25rem calc(1.35rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(180deg, rgba(11, 15, 26, 0.98), rgba(11, 15, 26, 0.92));
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 1.15rem;
    box-shadow: 0 18px 32px rgba(4, 8, 18, 0.45);
    backdrop-filter: blur(12px);
    z-index: 5;
}

.thread-composer form {
    display: grid;
    gap: 1rem;
}

.composer-suggestions {
    display: grid;
    gap: 0.6rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0.95rem;
    padding: 0.75rem 0.85rem;
    background: rgba(10, 14, 26, 0.85);
    max-height: 12.5rem;
    overflow-y: auto;
}

.composer-suggestions[hidden] {
    display: none;
}

.suggestion-list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    gap: 0.5rem;
}

.suggestion-item {
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.75rem;
    background: rgba(15, 18, 34, 0.88);
    transition: border-color 0.2s ease, background 0.2s ease;
}

.suggestion-item.suggestion-empty {
    border-style: dashed;
    background: rgba(15, 18, 34, 0.6);
}

.suggestion-button {
    width: 100%;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    padding: 0.6rem 0.75rem;
    display: grid;
    gap: 0.25rem;
    text-align: left;
    cursor: pointer;
}

.suggestion-button:hover,
.suggestion-button:focus-visible {
    outline: none;
    background: rgba(75, 123, 236, 0.1);
}

.suggestion-title {
    font-size: 0.9rem;
    font-weight: 600;
}

.suggestion-snippet {
    font-size: 0.85rem;
    color: var(--muted);
}

.suggestion-empty-content {
    padding: 0.6rem 0.75rem;
}

.gif-modal {
    border: none;
    border-radius: 1.2rem;
    padding: 0;
    width: min(720px, 92vw);
    background: rgba(12, 16, 28, 0.98);
    color: var(--fg);
    box-shadow: 0 32px 60px rgba(6, 10, 22, 0.65);
}

.gif-modal::backdrop {
    background: rgba(4, 6, 12, 0.75);
    backdrop-filter: blur(4px);
}

.gif-search-form {
    display: grid;
    gap: 1rem;
    padding: 1.5rem;
}

.gif-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.gif-modal-header h2 {
    margin: 0;
    font-size: 1.35rem;
}

.gif-search-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
}

.gif-search-bar input {
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 0.85rem;
    padding: 0.65rem 0.9rem;
    background: rgba(15, 20, 32, 0.9);
    color: var(--fg);
    font: inherit;
}

.gif-search-bar input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(75, 123, 236, 0.22);
}

.gif-search-button {
    border-radius: 0.85rem;
    padding: 0.65rem 1.1rem;
}

.gif-status {
    min-height: 1.4rem;
    font-size: 0.95rem;
    color: var(--muted);
}

.gif-status[data-variant="error"] {
    color: #ff9a9a;
}

.gif-status[data-variant="success"] {
    color: #9af7c2;
}

.gif-results {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.9rem;
    max-height: 360px;
    overflow-y: auto;
}

.gif-card {
    position: relative;
    border-radius: 0.85rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 0;
    background: rgba(18, 22, 36, 0.9);
}

.gif-card button {
    appearance: none;
    border: none;
    background: transparent;
    padding: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: pointer;
}

.gif-card img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gif-card button:focus-visible,
.gif-card button:hover {
    outline: none;
    box-shadow: inset 0 0 0 3px rgba(75, 123, 236, 0.35);
}

.gif-card span {
    position: absolute;
    inset: auto 0 0 0;
    padding: 0.35rem 0.55rem;
    background: linear-gradient(180deg, transparent, rgba(5, 8, 16, 0.85));
    font-size: 0.75rem;
    text-align: center;
    pointer-events: none;
    color: var(--fg);
    font-weight: 600;
}

.gif-attribution {
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.gif-attribution a {
    color: var(--accent);
}

.gif-embed {
    margin: 0.65rem 0;
    border-radius: 0.95rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(8, 10, 18, 0.75);
    width: min(260px, 100%);
}

.gif-embed img {
    display: block;
    width: 100%;
    height: auto;
}

.gif-archive-panel {
    display: flex;
    flex-direction: column;
    gap: 1.4rem;
}

.gif-archive-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.4rem;
}

.gif-archive-item {
    display: flex;
    flex-direction: column;
    background: rgba(8, 10, 18, 0.75);
    border-radius: 1rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--card-shadow);
}

.gif-archive-media {
    margin: 0;
}

.gif-archive-media img {
    display: block;
    width: 100%;
    height: auto;
}

.gif-archive-meta {
    padding: 0.75rem 0.85rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.gif-archive-meta strong {
    font-size: 0.95rem;
    color: var(--fg);
}

.gif-archive-meta time {
    font-size: 0.8rem;
    color: var(--muted);
}

.gif-archive-meta p {
    margin: 0;
    line-height: 1.4;
    font-size: 0.85rem;
    color: var(--fg);
}

.gif-archive-actions {
    display: flex;
    justify-content: flex-start;
    margin-top: 0.2rem;
}

.gif-archive-actions .ghost-button {
    font-size: 0.8rem;
    padding: 0.35rem 0.8rem;
}

.composer-field textarea {
    width: 100%;
    border: 1px solid var(--accent-soft);
    border-radius: 0.9rem;
    padding: 0.85rem 1rem;
    font: inherit;
    background: rgba(11, 15, 28, 0.92);
    color: var(--fg);
    resize: none;
    overflow: hidden;
    min-height: 2.6rem;
    line-height: 1.4;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    max-height: 320px;
}

.composer-field textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(75, 123, 236, 0.25);
    background: rgba(14, 18, 34, 0.95);
}

.composer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.composer-toolbar[hidden] {
    display: none;
}

.composer-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

.composer-actions[hidden] {
    display: none;
}

.composer-actions .secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.24);
    color: var(--fg);
    border-radius: 999px;
    padding: 0.45rem 0.9rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.composer-actions .secondary:hover,
.composer-actions .secondary:focus-visible {
    outline: none;
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

.identity-hint {
    margin: 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.identity-hint-inline {
    margin: 0.8rem 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.identity-error {
    margin: 0;
    padding: 0.75rem 1rem;
    border-radius: 0.85rem;
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.35);
    color: #fca5a5;
    font-size: 0.9rem;
}

.identity-error[hidden] {
    display: none;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.bubble {
    position: relative;
    background: linear-gradient(145deg, rgba(27, 34, 58, 0.95), rgba(18, 22, 40, 0.9));
    border: 1px solid var(--bubble-border);
    border-radius: 1.25rem;
    padding: 1.25rem 1.5rem;
    box-shadow: 0 26px 44px -28px rgba(7, 9, 20, 0.65);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.bubble::after {
    content: "";
    position: absolute;
    left: 2rem;
    bottom: -14px;
    width: 22px;
    height: 18px;
    background: inherit;
    border-left: 1px solid var(--bubble-border);
    border-bottom: 1px solid var(--bubble-border);
    border-bottom-left-radius: 18px;
    transform: skewX(-25deg);
}

.bubble.reply {
    background: linear-gradient(140deg, rgba(50, 35, 18, 0.92), rgba(34, 24, 16, 0.92));
    border-color: var(--bubble-reply-border);
}

.bubble.reply::after {
    left: 1.5rem;
    border-color: var(--bubble-reply-border);
}

.bubble.suggestion-focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(75, 123, 236, 0.3);
    transition: border-color 0.3s ease;
}

.thread.has-search .bubble.search-context {
    opacity: 0.72;
}

.thread.has-search .bubble.search-hit {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(75, 123, 236, 0.32);
    opacity: 1;
}

.bubble mark {
    background: rgba(75, 123, 236, 0.35);
    color: var(--fg);
    padding: 0 0.1em;
    border-radius: 0.2em;
}

.bubble-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.55rem;
}

.author {
    font-weight: 700;
}

.timestamp {
    font-size: 0.8rem;
    color: var(--muted);
}

.bubble-content {
    line-height: 1.6;
    margin: 0.5rem 0 1rem;
    white-space: pre-wrap;
}

.bubble-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.bubble-actions button {
    background: none;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--bubble-border);
    font-size: 0.85rem;
    color: var(--muted);
}

.bubble-actions button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.bubble-actions .reply-toggle {
    background: rgba(24, 30, 54, 0.75);
    border: 1px solid rgba(75, 123, 236, 0.35);
}

.bubble-actions .reply-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.bubble.replying,
.bubble.replies-open {
    border-color: var(--accent);
    box-shadow: 0 18px 38px -20px rgba(75, 123, 236, 0.65);
}

.children {
    margin-left: clamp(1.5rem, 4vw, 3rem);
    margin-top: 1rem;
    display: grid;
    gap: 1rem;
}

.children[hidden] {
    display: none;
}

.bubble.has-replies {
    cursor: pointer;
}

.empty-state {
    margin: 0;
    color: var(--muted);
    font-style: italic;
}

.identity-modal {
    border: none;
    border-radius: 18px;
    padding: 1.8rem;
    background: rgba(8, 12, 24, 0.95);
    color: var(--fg);
    min-width: min(420px, 90vw);
    box-shadow: 0 26px 60px rgba(4, 8, 18, 0.65);
}

.identity-modal::backdrop {
    background: rgba(5, 8, 16, 0.75);
    backdrop-filter: blur(6px);
}

.identity-form {
    display: grid;
    gap: 1rem;
}

.identity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.identity-sub {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.field {
    display: grid;
    gap: 0.4rem;
}

.field span {
    font-weight: 600;
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.94);
}

input,
textarea {
    border: 1px solid var(--accent-soft);
    border-radius: 0.85rem;
    padding: 0.8rem 1rem;
    font: inherit;
    background: rgba(11, 15, 28, 0.92);
    color: var(--fg);
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(75, 123, 236, 0.25);
}

.form-actions {
    display: flex;
    gap: 0.85rem;
    flex-wrap: wrap;
}

button {
    cursor: pointer;
    border: none;
    border-radius: 0.85rem;
    padding: 0.75rem 1.35rem;
    font: inherit;
    font-weight: 600;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease, color 0.2s ease;
    min-height: 44px;
    touch-action: manipulation;
}

button.primary {
    background: linear-gradient(120deg, var(--accent), var(--accent-strong));
    color: #fff;
    box-shadow: 0 20px 40px -18px rgba(75, 123, 236, 0.75);
}

button.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 24px 46px -18px rgba(107, 143, 255, 0.75);
}

.link-button {
    background: none;
    color: var(--accent-strong);
    padding: 0;
}

.link-button:hover,
.link-button:focus-visible {
    color: #fff;
}

@media (max-width: 720px) {
    main {
        padding: 1.6rem 0.85rem 2.4rem;
        padding-bottom: calc(9.5rem + env(safe-area-inset-bottom, 0px));
    }

    .thread {
        min-height: auto;
        padding: 1.2rem 0.85rem;
    }

    .thread-root {
        max-height: none;
        padding-right: 0.2rem;
        padding-bottom: calc(9.5rem + env(safe-area-inset-bottom, 0px));
    }

    .page-header {
        padding: 2.6rem 1rem 3rem;
    }

    .bubble {
        padding: 1rem 1.2rem;
    }

    .thread-composer {
        position: fixed;
        left: 0;
        right: 0;
        bottom: env(safe-area-inset-bottom, 0px);
        margin: 0;
        border-radius: 1rem 1rem 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        padding: 0.95rem 1rem calc(1.2rem + env(safe-area-inset-bottom, 0px));
        max-width: 100vw;
        z-index: 30;
    }
}

@media (max-width: 520px) {
    .children {
        margin-left: clamp(1.1rem, 5vw, 2rem);
    }
}

@media (max-width: 600px) {
    .identity-modal {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
        padding: 1.4rem;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .identity-form {
        width: 100%;
        max-width: 420px;
        max-height: calc(100vh - 2.8rem);
        overflow-y: auto;
    }
}

/* Back-to-top button */
.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 40;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--border, #2a2f3c);
    background: var(--card, #161a24);
    color: var(--fg, #e5e7eb);
    font-size: 1.4rem;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
}
.back-to-top.visible {
    opacity: 1;
    pointer-events: auto;
}
.back-to-top:hover {
    transform: translateY(-3px);
    border-color: var(--accent, #6366f1);
}
@media (max-width: 600px) {
    .back-to-top {
        bottom: 1.2rem;
        right: 1.2rem;
        width: 42px;
        height: 42px;
    }
}
