:root {
    color-scheme: light;
    --bg: #0b4f8f;
    --bg-pattern: #0a467f;
    --panel: #c0c0c0;
    --panel-dark: #9d9d9d;
    --panel-light: #f1f1f1;
    --text: #111111;
    --muted: #2d2d2d;
    --accent: #003c8f;
    --accent-2: #7a001c;
    --border: #7b7b7b;
    --shadow: rgba(0, 0, 0, 0.25);
    --focus: #ffcc00;
    --link: #0000ee;
    --visited: #551a8b;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: Verdana, Tahoma, "MS Sans Serif", sans-serif;
    font-size: 15px;
    line-height: 1.45;
    background:
        linear-gradient(45deg, transparent 25%, rgba(255, 255, 255, 0.08) 25%, rgba(255, 255, 255, 0.08) 50%, transparent 50%, transparent 75%, rgba(255, 255, 255, 0.08) 75%) 0 0 / 18px 18px,
        linear-gradient(180deg, var(--bg), var(--bg-pattern));
    color: var(--text);
}

.skip-link {
    position: absolute;
    left: 10px;
    top: -48px;
    z-index: 1000;
    padding: 8px 12px;
    background: #fff7a8;
    border: 2px solid #111;
    color: #111;
    text-decoration: none;
    font-weight: 700;
}

.skip-link:focus {
    top: 10px;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-header,
.rooms-panel,
.auth-panel,
.side-panel,
.chat-panel {
    border-top: 2px solid #ffffff;
    border-left: 2px solid #ffffff;
    border-right: 2px solid #555555;
    border-bottom: 2px solid #555555;
    box-shadow: 2px 2px 0 var(--shadow);
    background: var(--panel);
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    margin: 12px 12px 0;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    min-width: 0;
}

.brand-mark {
    height: 40px;
    width: auto;
    display: block;
    object-fit: contain;
    image-rendering: pixelated;
}

.brand-name {
    font-size: 1rem;
    font-weight: 700;
    color: #000;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin: inherit;
}

.brand-tag {
    color: var(--muted);
    font-size: 0.82rem;
}

.session {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.status-pill {
    padding: 5px 10px;
    border-top: 2px solid #555;
    border-left: 2px solid #555;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    background: #d5d5d5;
    font-size: 0.84rem;
    font-weight: 700;
}

.app-main {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr) 300px;
    gap: 12px;
    padding: 12px;
}

.rooms-panel,
.auth-panel,
.side-panel,
.chat-panel {
    padding: 12px;
}

.rooms-panel h2,
.auth-panel h2,
.side-panel h2,
.chat-panel h2 {
    margin: 0 0 10px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text);
    padding: 4px 8px;
    background: linear-gradient(90deg, #0e6268, #5fb4ba);
    color: #ffffff;
    border: 1px solid #0e6268;
}

.rooms-list {
    list-style: none;
    padding: 0;
    margin: 0 0 10px;
    display: grid;
    gap: 6px;
}

.rooms-list button {
    width: 100%;
    text-align: left;
}

.rooms-note {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
}

.chat-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

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

.chat-top h2 {
    margin: 0;
    font-size: 1rem;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    background: none;
    padding: 0;
    border: 0;
}

.chat-top p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 0.84rem;
}

.message-pane {
    flex: 1;
    min-height: 280px;
    background: #ffffff;
    border-top: 2px solid #585858;
    border-left: 2px solid #585858;
    border-right: 2px solid #f5f5f5;
    border-bottom: 2px solid #f5f5f5;
    padding: 10px;
    overflow-y: auto;
    position: relative;
}

.message-pane.no-scroll {
    overflow: hidden;
}

.history-indicator {
    position: sticky;
    top: 0;
    background: #fcf2b1;
    border: 1px solid #787878;
    padding: 6px 8px;
    font-size: 0.8rem;
    color: #111;
    margin-bottom: 8px;
}

.message-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.message {
    padding: 8px;
    border-top: 1px solid #f7f7f7;
    border-left: 1px solid #f7f7f7;
    border-right: 1px solid #696969;
    border-bottom: 1px solid #696969;
    background: #ececec;
}

.message.own {
    border-right-color: #2b4f7a;
    border-bottom-color: #2b4f7a;
    background: #deebfb;
}

.message-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    font-family: "Courier New", Courier, monospace;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 4px;
}

.message-user {
    color: var(--accent);
    font-weight: 700;
}

.badge {
    display: inline-block;
    padding: 1px 5px;
    font-size: 0.68rem;
    font-weight: 700;
    font-family: "Courier New", Courier, monospace;
    border: 1px solid #666;
    background: #efefef;
    color: #1a1a1a;
    vertical-align: middle;
    line-height: 1.4;
}

.badge-bot { background: #d0f0ee; color: #005a52; }
.badge-botchat { background: #ece4ff; color: #4b2a8a; }

.message-text {
    white-space: pre-wrap;
    font-size: 0.9rem;
    line-height: 1.45;
}

.message-form {
    display: grid;
    gap: 6px;
}

.message-input-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: start;
}

textarea,
input,
select,
.admin-textarea {
    font: inherit;
    padding: 8px;
    border-top: 2px solid #5a5a5a;
    border-left: 2px solid #5a5a5a;
    border-right: 2px solid #ffffff;
    border-bottom: 2px solid #ffffff;
    background: #fff;
    color: var(--text);
    border-radius: 0;
}

textarea {
    min-height: 72px;
    resize: vertical;
}

textarea:focus,
input:focus,
button:focus,
select:focus,
.admin-textarea:focus {
    outline: 3px solid var(--focus);
    outline-offset: 1px;
}

label {
    font-size: 0.84rem;
    font-weight: 700;
}

.help {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
    min-height: 1.2em;
}

.auth-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-switch {
    display: flex;
    gap: 6px;
}

.auth-form {
    display: grid;
    gap: 6px;
}

.key-panel {
    border: 1px dashed #595959;
    padding: 10px;
    background: #efefef;
}

.key-title {
    margin: 0 0 6px;
    font-weight: 700;
}

.key-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    align-items: center;
}

.key-row input {
    min-width: 0;
}

.auth-info {
    border-top: 1px solid #6a6a6a;
    padding-top: 8px;
    font-size: 0.8rem;
    color: var(--muted);
}

.turnstile-widget {
    width: 100%;
    overflow: hidden;
}

.panel-faq-link {
    display: inline-block;
    margin-top: auto;
    padding-top: 10px;
    font-size: 0.8rem;
}

.participants-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 4px;
}

.participant {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border: 1px dotted #707070;
    background: #efefef;
    font-size: 0.84rem;
}

.participant-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #008000;
    flex-shrink: 0;
}

.participant.idle {
    color: #4a4a4a;
}

.participant.idle .participant-dot {
    background: #777;
}

.participant-self {
    font-weight: 700;
}

a {
    color: var(--link);
}

a:visited {
    color: var(--visited);
}

a:hover,
a:focus-visible {
    text-decoration-thickness: 2px;
}

.button {
    font: inherit;
    padding: 6px 10px;
    border-top: 2px solid #ffffff;
    border-left: 2px solid #ffffff;
    border-right: 2px solid #585858;
    border-bottom: 2px solid #585858;
    background: var(--panel-light);
    color: var(--text);
    cursor: pointer;
    border-radius: 0;
    min-height: 34px;
    width: fit-content;
}

.button:hover {
    background: #fafafa;
}

.button:active {
    border-top-color: #585858;
    border-left-color: #585858;
    border-right-color: #ffffff;
    border-bottom-color: #ffffff;
    background: #d6d6d6;
}

.button.primary {
    background: #1a5faa;
    color: #ffffff;
    border-top-color: #5b8fc8;
    border-left-color: #5b8fc8;
    border-right-color: #082a4d;
    border-bottom-color: #082a4d;
}

.button.ghost {
    background: #ececec;
}

.button.active {
    background: #dbeaff;
    border-top-color: #174781;
    border-left-color: #174781;
    border-right-color: #ffffff;
    border-bottom-color: #ffffff;
    color: #0b3567;
    font-weight: 700;
}

.img-btn {
    padding: 4px;
    line-height: 0;
    background: #ececec;
}

.img-btn img {
    display: block;
    height: 30px;
    width: auto;
    image-rendering: pixelated;
}

@media (min-width: 1101px) {
    /* Lock the app to the viewport on desktop so the send button stays visible.
       Min-height 640px ensures at least a few messages are always shown.
       Sidepanels scroll internally when their content is taller than the viewport. */
    .app {
        height: 100vh;
        min-height: 640px;
        overflow: hidden;
    }

    .app-main {
        overflow: hidden;
    }

    .rooms-panel,
    .side-panel,
    .auth-panel {
        overflow-y: auto;
    }
}

@media (max-width: 1100px) {
    .app-main {
        grid-template-columns: 1fr;
    }

    .chat-panel {
        order: 1;
    }

    .rooms-panel {
        order: 2;
    }

    .side-panel {
        order: 3;
    }

    .auth-panel {
        order: 4;
    }

    .message-input-row {
        grid-template-columns: 1fr;
    }

    /* On tablet/mobile the layout is stacked, so cap the message pane height
       and let it scroll internally — otherwise 100 messages would push the
       send form far off-screen. */
    .message-pane {
        height: 55vh;
        min-height: 300px;
    }
}

@media (max-width: 760px) {
    body {
        font-size: 16px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .brand {
        width: 100%;
    }

    .brand-tag {
        display: none;
    }

    .session {
        width: 100%;
        justify-content: space-between;
    }

    .app-main {
        padding: 8px;
        gap: 8px;
    }

    .message-pane {
        height: 50vh;
        min-height: 260px;
    }

    .rooms-panel h2,
    .auth-panel h2,
    .side-panel h2,
    .chat-panel h2 {
        font-size: 0.86rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto;
    }
}

/* ── @mentions ─────────────────────────────────────────────────────────── */

.mention-wrap {
    position: relative;
}

.mention-wrap textarea {
    width: 100%;
}

/* Suggestions open above the input (it sits at the bottom of the page). */
.mention-list {
    position: absolute;
    left: 0;
    bottom: 100%;
    z-index: 20;
    min-width: 180px;
    max-height: 220px;
    overflow-y: auto;
    margin: 0 0 2px;
    padding: 2px;
    list-style: none;
    background: var(--panel-light);
    border-top: 2px solid #fff;
    border-left: 2px solid #fff;
    border-right: 2px solid #555;
    border-bottom: 2px solid #555;
    box-shadow: 2px 2px 0 var(--shadow);
    font-size: 0.9rem;
}

.mention-list li {
    padding: 3px 8px;
    cursor: pointer;
}

.mention-list li.active,
.mention-list li:hover {
    background: #008080;
    color: #fff;
}

.mention {
    font-weight: 700;
    color: #005a52;
    background: #d0f0ee;
    padding: 0 2px;
}

.message.mentions-me {
    border-left: 4px solid #008080;
    background: #e6f7f5;
}

.participant-name {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
}

.participant-name:hover {
    text-decoration: underline;
}

.participant-name:focus-visible {
    outline: 2px solid var(--focus);
}

/* Own participants entry: change the display name. */
.participant-edit {
    margin-left: auto;
    padding: 0 4px;
    border: 0;
    background: none;
    font: inherit;
    color: var(--link);
    cursor: pointer;
}

.participant-edit:hover {
    text-decoration: underline;
}

.participant-edit:focus-visible {
    outline: 2px solid var(--focus);
}

.participant.participant-editing {
    display: block;
}

.name-form {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.name-form input {
    flex: 1 1 100%;
    min-width: 0;
    padding: 3px 5px;
    font-size: 0.84rem;
}

.name-form .button {
    padding: 2px 10px;
    font-size: 0.78rem;
}

.name-form-hint {
    flex: 1 1 100%;
    margin: 2px 0 0;
    font-size: 0.74rem;
    color: var(--muted);
}

.name-form-hint.error {
    color: #a40000;
    font-weight: 700;
}

/* Display name with the username underneath: "(username)", smaller and lighter.
   #555 keeps a contrast of at least 6:1 on every message and participant background. */
.name-block {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}

.name-username {
    font-size: 0.72rem;
    font-weight: 400;
    color: #555;
    line-height: 1.2;
}

/* ── Room door ──────────────────────────────────────────────────────────── */

.rooms-list .room-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.rooms-list .room-item > .button {
    flex: 1 1 auto;
    min-width: 0;
}

/* Rooms I have entered: a dot before the name (also on rooms not shown right now). */
.room-entered {
    color: #006400;
    font-size: 0.8em;
}

/* Enter / Exit on the room shown right now: a link-like button, like ✎ on my name. */
.rooms-list .room-door {
    flex: 0 0 auto;
    width: auto;
    padding: 2px 4px;
    border: 0;
    background: none;
    font: inherit;
    font-size: 0.8rem;
    color: var(--link);
    cursor: pointer;
    white-space: nowrap;
}

.rooms-list .room-door:hover {
    text-decoration: underline;
}

.rooms-list .room-door:focus-visible {
    outline: 2px solid var(--focus);
}

/* My own entry when I haven't entered the room shown. */
.participant.outside {
    border-style: dashed;
    background: #f7f7f7;
}

.participant.outside .participant-dot {
    background: #ffffff;
    border: 1px solid #555;
}

.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;
}

/* Errors while signed in (door, send, history): the login panel is hidden then. */
.chat-error {
    color: #7a0000;
    font-weight: 700;
}

/* ── Themes ─────────────────────────────────────────────────────────────── */
/* Win9x is this file. The other themes (css/theme-*.css) apply when js/theme.js
   sets data-theme on <html>; their rules start with :root[data-theme="…"]. */

.theme-picker {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
    font-size: 0.8rem;
}

.theme-picker label {
    font-size: 0.8rem;
}

.theme-picker select {
    padding: 3px 6px;
    font-size: 0.8rem;
}

/* The GIF buttons belong to Win9x; the other themes show a text label instead.
   Only one of the two is displayed, so the button always has one accessible name. */
.img-btn-label {
    display: none;
}

:root[data-theme] .img-btn img {
    display: none;
}

:root[data-theme] .img-btn-label {
    display: inline;
}

:root[data-theme] .img-btn {
    line-height: 1.2;
    padding: 6px 16px;
}
