*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #252836;
    --border: #2e3248;
    --accent: #6c63ff;
    --accent-hover: #857dff;
    --danger: #e05252;
    --text: #e4e6ef;
    --text-muted: #7a7f9a;
    --own-msg: #1e2a4a;
    --own-border: #2e4278;
    --radius: 10px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, sans-serif;
    font-size: 15px;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-bottom: 5rem;
}


label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: .35rem;
}

input,
textarea {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 15px;
    padding: .6rem .8rem;
    outline: none;
    transition: border-color .15s;
}

input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear {
    display: none;
}



input[type="text"]:focus,
textarea:focus {
    border-color: var(--accent);
}


.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: .65rem 1.2rem;
    font-size: 15px;
    cursor: pointer;
    transition: background .15s;
    white-space: nowrap;
}

.btn:hover {
    background: var(--accent-hover);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--surface2);
    color: var(--text);
}

.btn-sm {
    padding: .35rem .7rem;
    font-size: 13px;
    border-radius: 5px;
}

#open-chat-btn {
    width: 100%;
}

.error-msg {
    color: var(--danger);
    font-size: 13px;
    margin-top: .5rem;
    min-height: 1.2em;
}


.screen {
    display: none;
}

.screen.active {
    display: flex;
}


.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    width: 380px;
}

.card h1 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    text-align: center;
}


#screen-login {
    align-items: center;
    justify-content: center;
}

#login-form .field {
    margin-bottom: 1rem;
}

#login-form .actions {
    display: flex;
    gap: .6rem;
    margin-top: 1rem;
}

#login-form .actions .btn {
    flex: 1;
}

/* ── Topic screen ── */
#screen-topics {
    align-items: center;
    justify-content: center;
}

.topic-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin-bottom: 1.2rem;
}

.topic-list li button {
    width: 100%;
    text-align: left;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: .7rem 1rem;
    cursor: pointer;
    font-size: 15px;
    transition: border-color .15s, background .15s;
}

.topic-list li button:hover,
.topic-list li button.selected {
    border-color: var(--accent);
    background: rgba(108, 99, 255, .15);
}

.topic-divider {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: .8rem 0;
    color: var(--text-muted);
    font-size: 13px;
}

.topic-divider::before,
.topic-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.user-selection {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .8rem;
    margin-bottom: 1rem;
}

.user-selection-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .5rem;
    margin-bottom: .6rem;
    font-size: 13px;
    color: var(--text-muted);
}

.status-note {
    font-size: 12px;
}

.user-selection-list {
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.user-selection-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .75rem;
    border-radius: 8px;
    background: var(--surface);
    cursor: pointer;
    transition: background .15s, border-color .15s;
    border: 1px solid transparent;
}

.user-selection-row:hover {
    border-color: var(--accent);
}

.user-selection-row.selected {
    border-color: var(--accent);
    background: rgba(108, 99, 255, .12);
}

.user-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.user-status.online {
    background: #4caf87;
}

.user-status.offline {
    background: #888;
}

.user-status-text,
.user-name {
    font-size: 14px;
    color: var(--text);
}

.topic-new {
    display: flex;
    gap: .5rem;
    margin-bottom: 1rem;
}

.topic-new input {
    flex: 1;
}

.footer-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
    display: flex;
    justify-content: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 100;
}

.footer-bar .nav-links {
    width: min(960px, 100%);
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    justify-content: center;
    margin: 0 auto;
}

.page-layout {
    width: min(960px, 100%);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem 1rem 0;
}

.page-panel,
.page-hero {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .15);
}

.page-hero h1,
.page-panel h1 {
    font-size: clamp(2rem, 3vw, 2.7rem);
    margin-bottom: 1rem;
    text-align: left;
}

.page-hero p,
.page-panel p,
.page-panel li,
.page-panel dd {
    line-height: 1.75;
    color: var(--text-muted);
}

.page-hero p {
    margin-bottom: 1rem;
}

.feature-list,
.detail-list {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    margin-top: 1rem;
    list-style: none;
    padding: 0;
}

.feature-list li,
.detail-list li {
    padding: 1rem;
    background: var(--surface2);
    border-radius: 14px;
}

.feature-list li strong {
    display: block;
    margin-bottom: .4rem;
    color: var(--text);
}

.page-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
}

.page-panel ul,
.page-panel ol {
    margin-left: 1.2rem;
    margin-top: .8rem;
    color: var(--text-muted);
}

.page-panel .actions {
    margin-top: 1.5rem;
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
}

.screen {
    display: none;
}

.screen.active {
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - 5rem);
}

.btn.active-link {
    border-color: var(--accent);
    background: rgba(108, 99, 255, .15);
}

.topic-actions {
    display: flex;
    gap: .6rem;
}

#screen-chat {
    flex-direction: column;
    width: 100%;
    padding: 0;
    align-items: stretch;
    margin: 0 auto;
}

.btn.active-link {
    border-color: var(--accent);
    background: rgba(108, 99, 255, .15);
}

.topic-actions {
    display: flex;
    justify-content: flex-end;
}


.chat-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: .7rem 1rem;
    display: flex;
    align-items: center;
    gap: .8rem;
    flex-shrink: 0;
}

.chat-header .topic-badge {
    flex: 1;
    font-weight: 600;
    font-size: 1rem;
}

.chat-header .user-badge {
    font-size: 13px;
    color: var(--text-muted);
}


.ws-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #888;
    flex-shrink: 0;
    transition: background .3s;
}

.ws-dot.connected {
    background: #4caf87;
}

.ws-dot.error {
    background: var(--danger);
}


.msg-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .6rem;
}


.msg {
    max-width: 70%;
    align-self: flex-start;
}

.msg.own {
    align-self: flex-end;
}

.msg-bubble {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px 12px 12px 3px;
    padding: .55rem .9rem;
}

.msg.own .msg-bubble {
    background: var(--own-msg);
    border-color: var(--own-border);
    border-radius: 12px 12px 3px 12px;
}

.msg-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: .25rem;
    display: flex;
    gap: .5rem;
    align-items: baseline;
}

.msg-meta .author {
    font-weight: 600;
    color: var(--text);
}

.msg-text {
    line-height: 1.45;
    word-break: break-word;
}

.msg-text abbr {
    text-decoration: underline dotted var(--text-muted);
    cursor: help;
}

/* System messages */
.msg-system {
    align-self: center;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--surface2);
    border-radius: 20px;
    padding: .2rem .8rem;
}

/* ── Compose bar ── */
.compose-bar {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: .75rem 1rem;
    flex-shrink: 0;
}

.compose-row {
    display: flex;
    gap: .5rem;
    align-items: flex-end;
}

.compose-row textarea {
    flex: 1;
    resize: none;
    min-height: 42px;
    max-height: 140px;
    line-height: 1.4;
    overflow-y: auto;
}

/* ── Scrollbar ── */
::-webkit-scrollbar {
    width: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}