:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1b2430;
  --muted: #5d6877;
  --line: #dde2e8;
  --accent: #2459d6;
  --accent-text: #ffffff;
  --mine: #2459d6;
  --mine-text: #ffffff;
  --theirs: #e8ecf1;
  --danger: #b42318;
  --dot: #e8590c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #1a1e24;
    --text: #e7eaee;
    --muted: #9aa5b3;
    --line: #2b313a;
    --accent: #7aa2ff;
    --accent-text: #0b1220;
    --mine: #3358b8;
    --mine-text: #ffffff;
    --theirs: #262c35;
    --danger: #ff8a7a;
    --dot: #ff9f5a;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; line-height: 1.2; }

/* ---------- form controls ---------- */

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

input, textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.danger { color: var(--danger); border-color: var(--danger); }

label { display: grid; gap: 0.3rem; font-size: 0.95rem; color: var(--muted); }

.stack { display: grid; gap: 0.9rem; }

label.check {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  color: var(--text);
}
label.check input { width: auto; margin-top: 0.25rem; flex: none; }

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

/* ---------- log in / ask to join ---------- */

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.5rem;
  display: grid;
  gap: 1rem;
}

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

/* ---------- the app ---------- */

.app {
  display: grid;
  grid-template-columns: 270px 1fr;
  grid-template-rows: auto 1fr;
  height: 100dvh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.icon-btn { display: none; padding: 0.35rem 0.7rem; font-size: 1.2rem; line-height: 1; }

.nav {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nav-title { font-weight: 700; padding: 0.25rem 0.5rem 0.5rem; overflow-wrap: anywhere; }

.nav h3 {
  margin: 0.9rem 0.5rem 0.2rem;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.55rem 0.5rem;
}

.nav-item.active { background: var(--bg); font-weight: 600; }

.dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--dot); flex: none; }

.badge {
  min-width: 1.4rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--dot);
  color: #1b1206;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

.nav-spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.msg { max-width: min(34rem, 85%); padding: 0.5rem 0.8rem; border-radius: 14px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); }
.msg.mine { align-self: flex-end; background: var(--mine); color: var(--mine-text); }
.msg .meta { font-size: 0.78rem; opacity: 0.8; margin-bottom: 0.1rem; }
.msg .meta button.link {
  all: unset;
  cursor: pointer;
  text-decoration: underline;
}
.msg .meta button.link:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }

.composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.panel { flex: 1; overflow-y: auto; padding: 1rem; display: grid; gap: 0.9rem; align-content: start; }
.panel h2 { font-size: 1.25rem; }

.card-row {
  display: grid;
  gap: 0.5rem;
  padding: 0.9rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  max-width: 40rem;
}

.card-row h3 { font-size: 1.05rem; overflow-wrap: anywhere; }
.quote { margin: 0; padding-left: 0.7rem; border-left: 3px solid var(--line); overflow-wrap: anywhere; white-space: pre-wrap; }
.row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }

.pill {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translate(-50%, 200%);
  max-width: min(90vw, 28rem);
  padding: 0.6rem 1rem;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  transition: transform 0.2s;
  z-index: 20;
}

.toast.show { transform: translate(-50%, 0); }

/* ---------- phones ---------- */

@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; }
  .icon-btn { display: inline-block; }

  .nav {
    position: fixed;
    top: 3.4rem;
    bottom: 0;
    left: 0;
    width: min(82vw, 300px);
    z-index: 10;
    transform: translateX(-105%);
    transition: transform 0.2s, box-shadow 0.2s;
  }

  .nav.open { transform: none; box-shadow: 4px 0 18px rgba(0, 0, 0, 0.25); }
}

@media (prefers-reduced-motion: reduce) {
  .nav, .toast { transition: none; }
}
