/* ---- Tokens ---- */
:root {
  --ink:        #e9e7e0;
  --ink-dim:    #9a978c;
  --ink-faint:  #6c6a63;
  --bg:         #101216;
  --bg-raised:  #1b1e24;
  --bg-raised2: #21252c;
  --bg-inset:   #0c0e1180;
  --line:       #2a2d34;
  --line-soft:  #23262c;
  --accent:     #6fd9b8;
  --accent-dim: #4a9a82;
  --accent-ink: #07120e;
  --accent-glow: rgba(111,217,184,0.15);
  --warn:       #e0a85c;
  --danger:     #e07a7a;
  --danger-dim: #a85050;
  --radius:     12px;
  --radius-sm:  9px;
  --shadow:     0 6px 24px -8px rgba(0,0,0,.5);
  --shadow-lg:  0 18px 50px -12px rgba(0,0,0,.65);
  --mono:       ui-monospace,'SF Mono','Cascadia Code','JetBrains Mono',Menlo,Consolas,monospace;
  --sans:       -apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(111,217,184,.06), transparent 70%),
    radial-gradient(600px 500px at 100% 100%, rgba(80,120,200,.04), transparent 70%);
}

#app {
  position: relative; z-index: 1;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
}

.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ---- Landing ---- */
#view-landing {
  align-items: center; justify-content: center;
  padding: 24px; gap: 22px; overflow-y: auto;
}

.landing-card {
  width: 100%; max-width: 380px;
  background: linear-gradient(180deg, var(--bg-raised), var(--bg-raised2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 30px 28px; box-shadow: var(--shadow-lg);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.brand-mark { color: var(--accent); font-size: 22px; filter: drop-shadow(0 0 8px var(--accent-glow)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name { font-family: var(--mono); font-size: 16px; letter-spacing: .06em; font-weight: 700; }
.brand-sub  { font-size: 11px; color: var(--ink-faint); letter-spacing: .04em; }

.tagline { color: var(--ink-dim); font-size: 13px; line-height: 1.55; margin: 0 0 22px; }

.identity-row {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 12px; margin-bottom: 20px;
  background: var(--bg-inset); border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
}
.identity-row .avatar { flex: 0 0 auto; }
.identity-fields { flex: 1; min-width: 0; }
.identity-fields label {
  display: block; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--ink-faint); margin-bottom: 3px;
}

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 11.5px; color: var(--ink-dim); margin-bottom: 6px; }

.field input, .compose input, .name-input {
  width: 100%; background: var(--bg-inset); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 11px 13px;
  color: var(--ink); font-size: 14px; font-family: var(--sans);
  transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder, .compose input::placeholder { color: var(--ink-faint); }
.field input:focus, .compose input:focus, .name-input:focus {
  outline: none; border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.field input.small { font-size: 12px; padding: 8px 10px; }

.name-input {
  padding: 4px 0; background: transparent; border: none; border-radius: 0;
  font-size: 14.5px; font-weight: 600;
}
.name-input:focus { box-shadow: none; border-bottom: 1px solid var(--accent-dim); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 700; color: #0a0c0a;
  background: var(--c, var(--accent)); text-transform: uppercase; user-select: none;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; padding: 11px 16px; border-radius: var(--radius-sm); border: none;
  font-size: 14px; font-weight: 600; font-family: var(--sans); cursor: pointer;
  transition: transform .08s, filter .15s, background .15s;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:hover  { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); filter: brightness(.95); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 14px -4px var(--accent-glow); }
.btn-secondary { background: var(--bg-raised2); color: var(--ink); border: 1px solid var(--line); }
.btn-ghost     { background: transparent; color: var(--ink-dim); border: 1px solid var(--line); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-small     { width: auto; padding: 8px 14px; font-size: 13px; }

.divider {
  display: flex; align-items: center; color: var(--ink-faint); font-size: 12px; margin: 18px 0;
}
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--line); }
.divider span { padding: 0 12px; }

.error-text { color: var(--danger); font-size: 13px; margin: 14px 0 0; }

.my-rooms { width: 100%; max-width: 380px; }
.my-rooms h3 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-dim); margin: 0 0 10px;
}
.my-room-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 15px; background: var(--bg-raised); border: 1px solid var(--line);
  border-radius: var(--radius-sm); margin-bottom: 8px; cursor: pointer;
  font-size: 13.5px; transition: border-color .15s, background .15s, transform .08s;
}
.my-room-item:hover  { border-color: var(--accent-dim); background: var(--bg-raised2); }
.my-room-item:active { transform: translateY(1px); }
.my-room-item .dim   { color: var(--ink-dim); font-size: 12px; }

.admin-badge {
  font-family: var(--mono); font-size: 10px; letter-spacing: .04em;
  background: rgba(111,217,184,.1); color: var(--accent-dim);
  border: 1px solid rgba(111,217,184,.18); border-radius: 4px;
  padding: 1px 5px; margin-left: 7px; vertical-align: middle;
}

/* ---- Room layout ---- */
.room-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--bg-raised); box-shadow: 0 1px 0 rgba(0,0,0,.2);
  flex-shrink: 0;
}
.room-header-left  { display: flex; align-items: center; gap: 12px; min-width: 0; }
.room-header-right { display: flex; align-items: center; gap: 8px; min-width: 0; }

.icon-btn {
  background: none; border: none; color: var(--ink-dim);
  font-size: 18px; line-height: 1; cursor: pointer;
  padding: 5px 7px; border-radius: 8px;
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--ink); background: var(--bg-raised2); }

.room-title {
  font-size: 14px; font-weight: 600;
  display: flex; align-items: baseline; gap: 7px;
}
.room-id { color: var(--accent); font-size: 12px; }
.mono { font-family: var(--mono); }

.presence-line {
  font-size: 12px; color: var(--ink-dim); margin-top: 3px;
  display: flex; align-items: center; gap: 6px;
}
.presence-dot {
  display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; background: var(--ink-faint); flex: 0 0 auto;
}
.presence-line.live .presence-dot {
  background: var(--accent);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(111,217,184,.45); }
  70%  { box-shadow: 0 0 0 7px rgba(111,217,184,0); }
  100% { box-shadow: 0 0 0 0 rgba(111,217,184,0); }
}

.me-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 6px 5px 5px; border-radius: 999px;
  border: 1px solid transparent; cursor: text; max-width: 180px;
  transition: border-color .15s, background .15s;
}
.me-chip:hover { background: var(--bg-raised2); border-color: var(--line); }
.me-chip .avatar  { width: 28px; height: 28px; font-size: 12px; }
.me-chip .name-input { font-size: 13px; font-weight: 600; }

/* Two-column body: messages + members sidebar */
.room-body {
  flex: 1; display: flex; min-height: 0; overflow: hidden; position: relative;
}

.messages {
  flex: 1; overflow-y: auto; padding: 20px 18px 8px;
  display: flex; flex-direction: column; gap: 6px; scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb {
  background: var(--line); border: 3px solid var(--bg); border-radius: 999px;
}
.messages::-webkit-scrollbar-thumb:hover { background: #3a3e46; }

.empty-state {
  margin: auto; text-align: center; color: var(--ink-faint); max-width: 260px; padding: 20px;
}
.empty-state .es-mark { font-size: 28px; color: var(--accent-dim); opacity: .8; }
.empty-state p { font-size: 13px; line-height: 1.55; margin: 10px 0 0; }

/* Message rows */
.msg-row {
  display: flex; gap: 9px; max-width: 80%;
  animation: rise .18s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.msg-row.mine   { align-self: flex-end;  flex-direction: row-reverse; }
.msg-row.theirs { align-self: flex-start; }
.msg-row .avatar { width: 28px; height: 28px; font-size: 12px; align-self: flex-end; flex: 0 0 auto; }

.msg-col { display: flex; flex-direction: column; min-width: 0; }
.msg-row.mine .msg-col { align-items: flex-end; }

.msg-bubble {
  padding: 9px 13px; border-radius: 15px;
  font-size: 14px; line-height: 1.45; word-break: break-word; white-space: pre-wrap;
}
.msg-row.mine .msg-bubble {
  background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px;
}
.msg-row.theirs .msg-bubble {
  background: var(--bg-raised); border: 1px solid var(--line); border-bottom-left-radius: 5px;
}

.msg-meta { font-size: 10.5px; color: var(--ink-faint); margin-top: 4px; padding: 0 2px; font-family: var(--mono); }
.msg-nick  { font-weight: 600; }

.admin-star {
  color: var(--warn); font-size: 10px; margin-left: 4px;
  vertical-align: super; line-height: 1;
}

.msg-system {
  align-self: center; font-size: 12px; color: var(--ink-faint);
  font-family: var(--mono); padding: 4px 0;
}

/* Members sidebar */
.members-panel {
  width: 220px; min-width: 220px;
  border-left: 1px solid var(--line);
  background: var(--bg-raised);
  display: flex; flex-direction: column;
  overflow-y: auto;
  transition: transform .2s ease;
}

.members-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 10px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-dim); border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.members-close { display: none; font-size: 14px; }

.member-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; font-size: 13px; min-width: 0;
}

.member-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-faint); flex: 0 0 auto;
}
.member-dot.online { background: var(--accent); }

.member-av {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700; color: #0a0c0a;
  background: var(--c, var(--accent)); flex: 0 0 auto;
  text-transform: uppercase;
}

.member-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--ink-dim);
}
.member-item.offline .member-name { opacity: .55; }

.member-actions { display: flex; gap: 4px; flex-shrink: 0; }

.btn-action {
  background: none; border: 1px solid var(--line); color: var(--ink-dim);
  font-size: 11px; padding: 2px 7px; border-radius: 4px; cursor: pointer;
  font-family: var(--mono); transition: border-color .15s, color .15s, background .15s;
}
.btn-action:hover         { border-color: var(--warn); color: var(--warn); background: rgba(224,168,92,.08); }
.btn-action.danger:hover  { border-color: var(--danger); color: var(--danger); background: rgba(224,122,122,.08); }

/* Typing indicator */
.typing-indicator {
  padding: 2px 18px 8px; font-size: 12px; color: var(--ink-dim);
  display: flex; align-items: center; gap: 7px; flex-shrink: 0;
}
.typing-indicator .dots { display: inline-flex; gap: 3px; }
.typing-indicator .dots i {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--ink-dim); animation: blink 1.2s infinite ease-in-out;
  font-style: normal;
}
.typing-indicator .dots i:nth-child(2) { animation-delay: .2s; }
.typing-indicator .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }

/* Compose bar */
.compose {
  display: flex; gap: 10px; padding: 14px 18px;
  border-top: 1px solid var(--line); background: var(--bg-raised); flex-shrink: 0;
}
.compose input { flex: 1; }
.compose .btn  { width: auto; padding: 10px 20px; }

/* Modals */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(6,8,11,.65);
  backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50; animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 420px;
  background: linear-gradient(180deg, var(--bg-raised), var(--bg-raised2));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow-lg);
}
.modal h3 { margin: 0 0 8px; font-size: 16px; }
.modal-sub { font-size: 13px; color: var(--ink-dim); line-height: 1.5; margin: 0 0 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { width: auto; flex: 1; }
.copy-confirm { color: var(--accent); font-size: 12.5px; margin: 10px 0 0; }

/* Toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--bg-raised2); border: 1px solid var(--line);
  color: var(--ink); padding: 11px 18px; border-radius: 999px;
  font-size: 13px; z-index: 100; box-shadow: var(--shadow);
  animation: toastin .2s ease-out;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Mobile */
@media (max-width: 600px) {
  .members-panel {
    position: absolute; top: 0; right: 0; bottom: 0;
    transform: translateX(100%); z-index: 10;
    box-shadow: var(--shadow-lg);
  }
  .members-panel.open { transform: translateX(0); }
  .members-close { display: block; }
  .me-chip { display: none; }
  .room-header { padding: 11px 13px; }
  .messages { padding: 16px 13px 8px; }
  .msg-row  { max-width: 90%; }
}

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