html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    color-scheme: dark;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

body {
    font-family: 'Inter', Arial, sans-serif;
    margin: 0;
    padding: 0;
    /* Reserve space for the fixed input bar + iOS home indicator */
    padding-bottom: calc(70px + env(safe-area-inset-bottom));
    background-color: #0d1117;
    color: #c9d1d9;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    -webkit-tap-highlight-color: transparent;
}

.header {
    padding: 16px 0 8px;
    padding-top: calc(16px + env(safe-area-inset-top));
    text-align: center;
}

.header a {
    text-decoration: none;
    display: inline-block;
}

.header-logo {
    font-family: 'Inter', Arial, sans-serif;
    font-weight: 700;
    font-size: 3rem;
    color: #e6edf3;
    letter-spacing: -0.02em;
}

.header-logo-accent {
    font-weight: 300;
    color: #58a6ff;
}

.status {
    padding: 8px;
    text-align: center;
    color: #3fb950;
    font-size: 0.9em;
}

.messages {
    padding: 10px;
    padding-left: calc(10px + env(safe-area-inset-left));
    padding-right: calc(10px + env(safe-area-inset-right));
    flex-grow: 1;
}

.message {
    margin-bottom: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    max-width: 100%;
    box-sizing: border-box;
}

.user-message {
    background-color: #1f6feb;
    color: #ffffff;
}

.bot-message {
    background-color: #161b22;
    color: #c9d1d9;
    line-height: 1.5;
    border: 1px solid #21262d;
}

.bot-message ul,
.bot-message ol {
    margin: 8px 0;
    padding-left: 20px;
}

.bot-message li {
    margin: 4px 0;
}

.bot-message p {
    margin: 8px 0;
}

.bot-message a {
    color: #58a6ff;
}

.bot-message a:hover {
    color: #79c0ff;
}

.bot-message h1,
.bot-message h2,
.bot-message h3,
.bot-message h4 {
    color: #e6edf3;
    border-bottom: 1px solid #21262d;
    padding-bottom: 4px;
}

.bot-message strong {
    color: #e6edf3;
}

.bot-message blockquote {
    margin: 8px 0;
    padding: 4px 12px;
    border-left: 3px solid #30363d;
    color: #8b949e;
}

.bot-message pre {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background-color: #0d1117;
    border: 1px solid #30363d;
    padding: 10px;
    border-radius: 6px;
    white-space: pre;
    color: #e6edf3;
}

.bot-message code {
    word-break: break-word;
    overflow-wrap: anywhere;
    background-color: #0d1117;
    color: #79c0ff;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.9em;
}

.bot-message pre code {
    background-color: transparent;
    color: #e6edf3;
    padding: 0;
    font-size: 1em;
}

.bot-message img,
.bot-message table {
    max-width: 100%;
    height: auto;
}

.bot-message table {
    border-collapse: collapse;
}

.bot-message th,
.bot-message td {
    border: 1px solid #30363d;
    padding: 6px 10px;
}

.bot-message th {
    background-color: #161b22;
    color: #e6edf3;
}

.input-container {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    padding-left: calc(8px + env(safe-area-inset-left));
    padding-right: calc(8px + env(safe-area-inset-right));
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    gap: 8px;
    background-color: #0d1117;
    border-top: 1px solid #21262d;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

#messageInput {
    flex: 0 0 80%;
    min-width: 0;
    box-sizing: border-box;
    padding: 12px 14px;
    border: 1px solid #30363d;
    border-radius: 16px;
    height: 68px;
    min-height: 68px;
    max-height: 200px;
    resize: none;
    font-size: 18px;
    line-height: 24px;
    background-color: #161b22;
    color: #e6edf3;
    overflow-y: auto;
    -webkit-appearance: none;
    appearance: none;
    /* Prevent iOS Safari from expanding textarea on focus */
    -webkit-text-size-adjust: 100%;
}

#messageInput:focus {
    outline: none;
    border-color: #58a6ff;
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

#messageInput::placeholder {
    color: #6e7681;
    font-style: italic;
}

button {
    width: 64px;
    height: 64px;
    min-width: 64px;
    padding: 0;
    background-color: #1f6feb;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    appearance: none;
}

button:hover {
    background-color: #388bfd;
}

button:disabled {
    background-color: #30363d;
    color: #6e7681;
    cursor: not-allowed;
}

/* Landing page and placeholder pages have no fixed input bar,
   so drop the bottom padding that reserves space for it. */
.landing-body {
    padding-bottom: env(safe-area-inset-bottom);
}

.header-subtitle {
    margin-top: 6px;
    color: #8b949e;
    font-size: 1rem;
    font-weight: 300;
    letter-spacing: 0.01em;
}

.landing {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 20px 48px;
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
    box-sizing: border-box;
}

.option-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 340px));
    gap: 20px;
    width: 100%;
    max-width: 720px;
}

.option-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 28px 24px;
    background-color: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    color: #c9d1d9;
    text-decoration: none;
    transition: border-color 0.15s ease, transform 0.15s ease, background-color 0.15s ease;
}

.option-card:hover {
    border-color: #58a6ff;
    background-color: #1b2230;
    transform: translateY(-2px);
}

.option-icon {
    color: #58a6ff;
    display: flex;
    align-items: center;
}

.option-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: #e6edf3;
    letter-spacing: -0.01em;
}

.option-desc {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #8b949e;
    flex-grow: 1;
}

.option-cta {
    margin-top: 4px;
    color: #58a6ff;
    font-weight: 700;
    font-size: 0.95rem;
}

.option-badge {
    position: absolute;
    top: 14px;
    right: 14px;
    padding: 3px 9px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #f0c674;
    background-color: rgba(240, 198, 116, 0.1);
    border: 1px solid rgba(240, 198, 116, 0.35);
    border-radius: 999px;
}

.placeholder-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
    padding: 40px 28px;
    background-color: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    max-width: 520px;
    width: 100%;
}

.placeholder-title {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 700;
    color: #e6edf3;
    letter-spacing: -0.01em;
}

.placeholder-desc {
    margin: 0;
    font-size: 1rem;
    line-height: 1.55;
    color: #8b949e;
}

.placeholder-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
    justify-content: center;
}

.btn-primary,
.btn-secondary {
    display: inline-block;
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.95rem;
    text-decoration: none;
    border: 1px solid transparent;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
    background-color: #1f6feb;
    color: #ffffff;
}

.btn-primary:hover {
    background-color: #388bfd;
}

.btn-secondary {
    background-color: transparent;
    color: #c9d1d9;
    border-color: #30363d;
}

.btn-secondary:hover {
    border-color: #58a6ff;
    color: #e6edf3;
}

@media (max-width: 640px) {
    .option-grid {
        grid-template-columns: 1fr;
        max-width: 420px;
    }

    .header-logo {
        font-size: 2.4rem;
    }

    .landing {
        padding: 20px 16px 32px;
    }
}

/* ---- User-to-user chat (/users.html) ---- */

/* Author rules like `.join-overlay { display: flex }` share specificity
   (0,1,0) with the UA `[hidden] { display: none }` and win the cascade
   tiebreaker, so the [hidden] attribute stops working. Explicit rules
   restore the expected behavior. */
.join-overlay[hidden],
.chat-layout[hidden] {
    display: none;
}

.chat-body {
    /* The chat layout manages its own scrolling areas; drop the
       reserved bottom padding that assumes the LLM input bar. */
    padding-bottom: env(safe-area-inset-bottom);
    /* No page-level header on /users.html, so respect the top safe area
       here (notched devices, PWA mode) instead of relying on .header. */
    padding-top: env(safe-area-inset-top);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* The ProtonChat sign on /users.html lives inside the scrollable
   messages area (first child of .chat-messages) so it scrolls away as
   new messages arrive, instead of sitting pinned at the top of the page. */
.chat-inline-header {
    padding: 16px 12px 18px;
    margin-bottom: 12px;
    border-bottom: 1px solid #21262d;
}

.join-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(13, 17, 23, 0.9);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 10;
}

.join-card {
    width: 100%;
    max-width: 420px;
    background-color: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    padding: 28px 24px;
    color: #c9d1d9;
}

.join-title {
    margin: 0 0 8px;
    color: #e6edf3;
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.join-desc {
    margin: 0 0 16px;
    color: #8b949e;
    font-size: 0.95rem;
    line-height: 1.5;
}

.join-desc code {
    background-color: #0d1117;
    color: #79c0ff;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.9em;
}

#joinForm {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

#usernameInput {
    flex: 1 1 200px;
    min-width: 0;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid #30363d;
    border-radius: 8px;
    background-color: #0d1117;
    color: #e6edf3;
    font-size: 1rem;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

#usernameInput:focus {
    outline: none;
    border-color: #58a6ff;
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

.join-submit {
    border: none;
    cursor: pointer;
    width: auto;
    height: auto;
    min-width: 0;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-family: inherit;
}

.join-error {
    margin-top: 12px;
    color: #f85149;
    font-size: 0.9rem;
    display: none;
}

.chat-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    /* minmax(0, 1fr) — without the 0-min the implicit row sizes to
       max-content and the messages area pushes the input bar out of view
       as the conversation grows. */
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
    flex-grow: 1;
    min-height: 0;
    padding: 0 12px 12px;
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
    box-sizing: border-box;
    overflow: hidden;
}

.chat-sidebar {
    background-color: #161b22;
    border: 1px solid #21262d;
    border-radius: 10px 0 0 10px;
    border-right: none;
    padding: 14px 12px;
    overflow-y: auto;
    min-height: 0;
    height: 100%;
}

.chat-sidebar-title {
    color: #8b949e;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-user-count {
    background-color: #21262d;
    color: #c9d1d9;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.8rem;
}

.chat-user-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chat-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    font-size: 0.95rem;
    color: #c9d1d9;
}

.chat-user.is-me .chat-user-name {
    color: #e6edf3;
    font-weight: 700;
}

.chat-user-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #3fb950;
    box-shadow: 0 0 4px rgba(63, 185, 80, 0.55);
    flex-shrink: 0;
}

.chat-user-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-user-tag {
    color: #6e7681;
    font-size: 0.8rem;
    margin-left: auto;
}

.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Same reason as .chat-layout — without min-height:0 the flex column's
       content dictates its height and pushes the input bar out of view. */
    min-height: 0;
    height: 100%;
    background-color: #0d1117;
    border: 1px solid #21262d;
    border-radius: 0 10px 10px 0;
}

.chat-status {
    padding: 8px 14px;
    border-bottom: 1px solid #21262d;
    font-size: 0.85rem;
    color: #8b949e;
}

.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 12px 14px;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.chat-msg {
    margin-bottom: 10px;
    max-width: 100%;
}

.chat-msg-system {
    color: #6e7681;
    font-size: 0.85rem;
    font-style: italic;
    text-align: center;
    padding: 4px 0;
}

.chat-msg-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 3px;
    font-size: 0.85rem;
}

.chat-msg-name {
    color: #e6edf3;
    font-weight: 700;
}

.chat-msg-mine .chat-msg-name {
    color: #79c0ff;
}

.chat-msg-tag {
    color: #6e7681;
    font-size: 0.75rem;
}

.chat-msg-time {
    color: #6e7681;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.chat-msg-body {
    color: #c9d1d9;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #21262d;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

#chatInput {
    flex: 1;
    min-width: 0;
    box-sizing: border-box;
    padding: 10px 14px;
    border: 1px solid #30363d;
    border-radius: 999px;
    background-color: #161b22;
    color: #e6edf3;
    font-size: 1rem;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

#chatInput:focus {
    outline: none;
    border-color: #58a6ff;
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

#chatSend {
    width: 44px;
    height: 44px;
    min-width: 44px;
    padding: 0;
    border-radius: 50%;
    flex-shrink: 0;
}

#chatSend svg {
    width: 24px;
    height: 24px;
}

@media (max-width: 720px) {
    .chat-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }
    .chat-sidebar {
        max-height: 120px;
        border-radius: 10px 10px 0 0;
        border-right: 1px solid #21262d;
        border-bottom: none;
    }
    .chat-main {
        border-radius: 0 0 10px 10px;
    }
    .chat-user-list {
        display: flex;
        flex-wrap: wrap;
        gap: 6px 12px;
    }
    .chat-user {
        padding: 2px 4px;
    }
    .chat-user-tag {
        margin-left: 4px;
    }
}
