:root {
    --bg: #000000;
    --fg: #ffffff;
    --fg2: #a0a0a8;
    --fg3: #5c5c66;
    --line: #1c1c1f;
    --panel: #101012;
    --red: #e5484d;
    --green: #46a758;
    --yellow: #f5a623;
    --blue: #4c8dff;
    --radius: 6px;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--sans);
    font-size: 13px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
}

button,
input,
textarea {
    font: inherit;
    color: inherit;
}

button {
    background: none;
    border: 0;
    cursor: pointer;
    padding: 0;
}

input,
textarea,
button {
    outline: none;
}

.screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 24px 16px;
    z-index: 50;
}

.screen-inner {
    width: 100%;
    max-width: 340px;
    transform: translateY(-20vh);
}

.stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.stack .field {
    width: 110px;
    min-height: 36px;
    padding: 6px 8px;
    text-align: center;
}

.stack .status {
    align-self: stretch;
}

.field {
    width: 100%;
    background: var(--panel);
    color: var(--fg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 9px 10px;
    font-size: 13px;
    min-height: 40px;
}

.field:focus {
    border-color: var(--blue);
}

.stack .field:focus::placeholder {
    color: transparent;
}

.field::placeholder {
    color: var(--fg3);
    opacity: 1;
}

.room-field {
    font-family: var(--mono);
    font-size: 17px;
    letter-spacing: 0.12em;
}

.room-field::placeholder {
    font-family: var(--sans);
    font-size: 11px;
    letter-spacing: 0;
}

.name-field {
    font-size: 13.3px;
}

.status {
    min-height: 18px;
    margin: 4px 0 0;
    text-align: center;
    font-size: 12px;
    color: var(--fg2);
}

.note {
    margin: 14px 0 0;
    font-size: 11px;
    color: var(--fg3);
}

.start-footer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 14px;
    max-width: 720px;
    margin: 0 auto;
    padding: 0 16px;
    text-align: center;
    font-size: 10.5px;
    line-height: 1.5;
    color: var(--fg3);
}

.status.error {
    color: var(--red);
}

.status.warn {
    color: var(--yellow);
}

.status.info {
    color: var(--green);
}

.chat {
    position: fixed;
    top: var(--app-top, 0px);
    left: 0;
    right: 0;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    height: var(--app-height, 100dvh);
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.bar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    padding: 4px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.bar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 0 0 auto;
}

.room-icon {
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    display: block;
}

.room {
    font-family: var(--mono);
    font-size: 13px;
    color: var(--fg);
    white-space: nowrap;
}

.conn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 12px;
    color: var(--fg2);
    white-space: nowrap;
}

.conn.ok {
    color: var(--green);
}

.conn.warn {
    color: var(--fg3);
}

.user-icon {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.bar .field {
    min-height: 30px;
    height: 30px;
    padding: 4px 8px;
    font-size: 12px;
}

.key-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    margin-left: auto;
}

.key-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    pointer-events: none;
}

.key-field {
    width: calc(12ch + 16px);
    padding: 4px 8px;
    font-family: var(--mono);
}

.icon-btn {
    width: 30px;
    height: 30px;
    min-width: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--panel);
}

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

.icon-btn img {
    width: 16px;
    height: 16px;
    display: block;
}

.chat-main {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 16px;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.message-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    list-style: none;
    margin: 0;
    padding: 8px 0 16px;
    display: flex;
    flex-direction: column;
}

.message-list > li:first-child:not(.empty-state) {
    margin-top: auto;
}

.empty-state {
    margin: auto 0;
    padding: 40px 10px;
    text-align: center;
    color: var(--fg3);
    font-size: 12px;
}

.message {
    padding: 10px 0 11px;
    border-bottom: 1px solid var(--line);
}

.message:last-child {
    border-bottom: 0;
}

.message-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 100%;
}

.message.own .message-meta {
    align-items: flex-end;
    text-align: right;
}

.message-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.message.own .message-head {
    justify-content: flex-end;
}

.message-sender {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-sender.online {
    color: var(--green);
}

.message-sender.offline {
    color: var(--fg2);
}

.message-time {
    font-size: 11px;
    color: var(--fg3);
    white-space: nowrap;
}

.message-line {
    display: flex;
    align-items: baseline;
    gap: 6px;
    max-width: 100%;
    min-width: 0;
}

.message.own .message-line {
    justify-content: flex-end;
}

.message-body {
    min-width: 0;
    font-size: 13px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message.own .message-body {
    text-align: right;
}

.message-locked {
    width: 18px;
    height: 18px;
    display: block;
    opacity: 0.8;
}

.message-status {
    flex: 0 0 auto;
    font-size: 13px;
    line-height: 1;
    color: var(--fg3);
}

.message-status.delivered {
    color: var(--green);
}

.deletion-notice {
    padding: 8px 0;
    font-size: 11px;
    color: var(--fg3);
}

.composer {
    flex: 0 0 auto;
    border-top: 1px solid var(--line);
    padding: 12px 0 calc(14px + env(safe-area-inset-bottom));
}

.composer textarea {
    width: 100%;
    max-width: 800px;
    resize: none;
    min-height: 40px;
    max-height: 96px;
    line-height: 1.45;
    overflow-y: hidden;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translate(-50%, 8px);
    max-width: min(90vw, 420px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 9px 12px;
    font-size: 12px;
    color: var(--fg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 60;
}

.toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (max-width: 600px) {
    .bar {
        padding: 4px 8px;
        gap: 5px;
    }

    .bar-left {
        gap: 6px;
    }

    .room {
        font-size: 12px;
    }

    .chat-main {
        padding: 0 12px;
    }

    .screen-inner {
        transform: translateY(-15vh);
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition-duration: 0.001ms !important;
    }
}
