:root {
  color-scheme: dark;
  --bg: #111316;
  --surface: #191d22;
  --surface-2: #20262d;
  --surface-3: #252d35;
  --line: #37404a;
  --muted: #97a3af;
  --text: #eef2f5;
  --accent: #48c7b8;
  --accent-2: #8fb4ff;
  --warning: #f0b45d;
  --danger: #ff7b8a;
  --ok: #7bd88f;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button.primary {
  border-color: rgba(72, 199, 184, 0.7);
  background: #1e6f68;
}

button.active {
  background: #273846;
  border-color: var(--accent-2);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #101317;
  color: var(--text);
}

textarea {
  resize: vertical;
}

hr {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 22px;
  background: rgba(17, 19, 22, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
}

.brand small,
.node-badge small,
.node-card small,
.chat-head small,
.conversation span,
dd,
.empty,
.lede,
.status-panel p,
.explain-panel p,
.recovery-card p,
.details p {
  color: var(--muted);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #1e6f68;
  color: white;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  text-align: left;
}

nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

main {
  min-width: 0;
}

.notice {
  margin: 14px auto 0;
  width: min(1120px, calc(100% - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.notice.error {
  border-color: rgba(255, 123, 138, 0.55);
  color: #ffd5da;
}

.notice.warn {
  border-color: rgba(240, 180, 93, 0.6);
  color: #ffe1b5;
}

.landing-grid,
.form-page,
.settings-grid {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 18px;
}

.hero-panel,
.status-panel,
.form-panel,
.explain-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
}

.hero-panel {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.78rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: 4.2rem;
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.lede {
  max-width: 640px;
  line-height: 1.6;
}

.hero-actions,
.section-head {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.local-section {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto 32px;
}

.docs-layout {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 60px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 38px;
  align-items: start;
}

.docs-toc {
  position: sticky;
  top: 92px;
  display: grid;
  gap: 4px;
  padding-right: 22px;
  border-right: 1px solid var(--line);
}

.docs-toc strong {
  margin-bottom: 8px;
}

.docs-toc a {
  padding: 8px 0;
  color: var(--muted);
  text-decoration: none;
}

.docs-toc a:hover {
  color: var(--accent);
}

.docs-content {
  min-width: 0;
  max-width: 820px;
}

.docs-header {
  padding: 18px 0 30px;
  border-bottom: 1px solid var(--line);
}

.docs-header h1 {
  margin-bottom: 14px;
  font-size: 2.7rem;
  line-height: 1.05;
}

.docs-header > p:last-child,
.docs-section p,
.docs-section li,
.docs-definitions dd {
  color: #b9c2ca;
  line-height: 1.65;
}

.docs-section {
  scroll-margin-top: 90px;
  padding: 32px 0;
  border-bottom: 1px solid var(--line);
}

.docs-section h2 {
  margin-bottom: 18px;
  font-size: 1.45rem;
}

.docs-section h3 {
  margin: 24px 0 8px;
  font-size: 1rem;
}

.docs-section ol,
.docs-section ul {
  display: grid;
  gap: 8px;
  padding-left: 22px;
}

.docs-section code {
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #101317;
  color: #d8e5f2;
  overflow-wrap: anywhere;
}

.docs-callout {
  margin: 20px 0;
  padding: 14px 16px;
  border-left: 3px solid var(--accent-2);
  background: #171e26;
  color: #d7e1eb;
  line-height: 1.55;
}

.docs-callout.warning {
  border-left-color: var(--warning);
  background: #201a12;
}

.docs-callout.danger {
  border-left-color: var(--danger);
  background: #24161a;
}

.docs-definitions {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 10px 16px;
}

.docs-definitions dt {
  font-weight: 700;
  color: var(--text);
}

.docs-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.docs-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.docs-table th,
.docs-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.docs-table th {
  background: var(--surface-2);
  color: var(--text);
}

.docs-table td {
  color: #b9c2ca;
}

.docs-table tr:last-child td {
  border-bottom: 0;
}

.section-head {
  justify-content: space-between;
}

.node-grid,
.node-list {
  display: grid;
  gap: 10px;
}

.node-grid {
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

.node-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.node-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.node-card strong,
.peer-id {
  word-break: break-word;
}

.node-card small,
.node-card strong {
  display: block;
}

.node-profile {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.form-page {
  align-items: start;
}

.stack {
  display: grid;
  gap: 14px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.security-note {
  color: var(--muted);
  line-height: 1.5;
}

.security-warning {
  padding: 11px 12px;
  border-left: 3px solid var(--warning);
  background: #201a12;
  color: #ffe1b5;
  line-height: 1.5;
}

.transfer-output {
  margin-top: 16px;
}

.transfer-code {
  min-height: 150px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
}

.checkbox-line {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.checkbox-line input {
  width: auto;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.color-grid.compact {
  grid-template-columns: 1fr;
}

input[type="color"] {
  min-height: 44px;
  padding: 5px;
}

.link-button {
  margin-top: 12px;
  border: 0;
  padding-left: 0;
  background: transparent;
  color: var(--accent-2);
}

.recovery-key {
  display: block;
  margin: 18px 0;
  padding: 18px;
  border: 1px solid var(--warning);
  border-radius: 8px;
  background: #201a12;
  color: #ffdc9a;
  font-size: 1.75rem;
  text-align: center;
  word-break: break-word;
}

.progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #101317;
  border: 1px solid var(--line);
}

.progress span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 120ms linear;
}

.messenger {
  height: calc(100vh - 74px);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 280px;
  overflow: hidden;
}

.sidebar,
.details {
  min-width: 0;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 14px;
}

.details {
  border-right: 0;
  border-left: 1px solid var(--line);
}

.node-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.presence-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.presence-dot.online {
  background: var(--ok);
}

.search-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.search-results,
.conversation-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.conversation-filter {
  margin-top: 8px;
}

.conversation {
  display: grid;
  justify-items: start;
  gap: 4px;
  height: auto;
  min-height: 62px;
  text-align: left;
}

.conversation.selected {
  border-color: var(--accent);
  background: #1d3535;
}

.chat {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background: #14171b;
}

.chat[data-room-accent] {
  background: var(--room-bg, #14171b);
}

.chat[data-room-accent] .chat-head {
  border-bottom-color: color-mix(in srgb, var(--room-accent, var(--accent)) 60%, var(--line));
}

.chat[data-room-accent] .message.out {
  border-color: color-mix(in srgb, var(--room-accent, var(--accent)) 60%, transparent);
  background: color-mix(in srgb, var(--room-accent, var(--accent)) 22%, #12171c);
}

.chat[data-room-accent] .reply-quote {
  border-left-color: var(--room-accent, var(--accent));
}

.vault-import {
  align-self: center;
  justify-self: center;
  width: min(560px, calc(100% - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 72px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.chat-head h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.2;
}

.messages {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  width: min(72%, 640px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
}

.message.out {
  align-self: flex-end;
  background: #173f3c;
  border-color: rgba(72, 199, 184, 0.45);
}

.message p {
  margin-bottom: 8px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-photo {
  margin: 0 0 9px;
}

.message-photo img,
.photo-loading {
  display: block;
  width: 100%;
  max-height: min(52vh, 520px);
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1013;
  object-fit: contain;
}

.photo-loading {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.message-photo figcaption {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.message-sender {
  display: block;
  margin-bottom: 6px;
  color: var(--accent-2);
  overflow-wrap: anywhere;
}

.host-label {
  color: var(--warning);
  font-weight: 700;
}

.private-message-label {
  margin-bottom: 7px;
  color: #d8b4fe;
  font-size: 0.78rem;
  font-weight: 700;
}

.mention {
  border-radius: 3px;
  padding: 1px 3px;
  background: rgba(143, 180, 255, 0.15);
  color: #b8ceff;
  font-weight: 700;
}

.mention-self {
  background: rgba(240, 180, 93, 0.2);
  color: #ffdc9a;
}

.reply-quote {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent-2);
  background: rgba(143, 180, 255, 0.08);
  color: #cbd6e2;
}

.reply-quote strong,
.reply-quote span {
  display: block;
  overflow-wrap: anywhere;
}

.reply-quote span {
  color: var(--muted);
  font-size: 0.84rem;
}

.message footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.message footer button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 0.76rem;
}

.reply-composer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: #171e26;
}

.reply-composer strong,
.reply-composer span {
  display: block;
  overflow-wrap: anywhere;
}

.reply-composer span {
  color: var(--muted);
  font-size: 0.86rem;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.room-access-revoked {
  padding: 14px 18px;
  border-top: 1px solid rgba(255, 123, 138, 0.55);
  background: #24161a;
  color: #ffd5da;
}

.composer-status {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: var(--accent-2);
  font-size: 0.84rem;
}

.sending-spinner {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: sending-spin 0.8s linear infinite;
}

@keyframes sending-spin {
  to { transform: rotate(360deg); }
}

.photo-picker {
  align-self: stretch;
  display: grid;
  place-items: center;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
}

.photo-picker:hover {
  border-color: var(--accent);
}

.composer[aria-busy="true"] .photo-picker {
  cursor: wait;
  opacity: 0.5;
}

.photo-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.pending-photo {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 8px 10px;
  border-left: 3px solid var(--accent);
  background: #171e26;
  color: var(--muted);
}

.pending-photo span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.pending-photo strong {
  color: var(--text);
}

@media (prefers-reduced-motion: reduce) {
  .sending-spinner {
    animation: none;
  }
}

.details dl {
  display: grid;
  grid-template-columns: 95px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0 0 18px;
}

.room-members {
  margin: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 14px 0;
}

.room-members-head,
.room-member,
.room-member-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.room-members-head,
.room-member {
  justify-content: space-between;
}

.room-members-head h2 {
  margin: 0;
}

.room-members-head button,
.room-member button {
  min-height: 30px;
  padding: 0 8px;
  font-size: 0.75rem;
}

.room-member-list {
  display: grid;
  margin: 8px 0 14px;
}

.room-member {
  min-width: 0;
  flex-wrap: wrap;
  padding: 8px 0;
  border-bottom: 1px solid rgba(55, 64, 74, 0.65);
}

.room-member > div:first-child {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-wrap: anywhere;
}

.room-member-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.danger-button {
  border-color: rgba(255, 123, 138, 0.55);
  color: #ffd5da;
}

.room-settings-form {
  margin: 16px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11161c;
}

.room-settings-form h2 {
  margin-bottom: 2px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.empty-state,
.empty {
  display: grid;
  place-items: center;
  min-height: 120px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  text-align: center;
}

@media (max-width: 980px) {
  .landing-grid,
  .form-page,
  .settings-grid,
  .messenger {
    grid-template-columns: 1fr;
  }

  .messenger {
    height: auto;
    overflow: visible;
  }

  .sidebar,
  .details {
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat {
    height: calc(100vh - 96px);
    height: calc(100dvh - 96px);
    min-height: 420px;
    max-height: 760px;
  }

  .docs-layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .docs-toc {
    position: static;
    display: flex;
    gap: 6px 14px;
    flex-wrap: wrap;
    padding: 0 0 18px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .docs-toc strong {
    flex-basis: 100%;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hero-panel,
  .status-panel,
  .form-panel,
  .explain-panel {
    padding: 18px;
  }

  h1 {
    font-size: 2.6rem;
  }

  .recovery-key {
    font-size: 1.2rem;
  }

  .message {
    width: 94%;
  }

  .composer,
  .search-box,
  .color-grid {
    grid-template-columns: 1fr;
  }

  .photo-picker {
    min-height: 38px;
  }

  .chat {
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    min-height: 380px;
  }

  .docs-header h1 {
    font-size: 2.15rem;
  }

  .docs-definitions {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
