:root {
  --bg: #000;
  --elev: #141416;
  --elev-2: #1c1c1e;
  --text: #fff;
  --muted: #a1a1a6;
  --faint: #6e6e73;
  --yellow: #fffc00;
  --danger: #ff453a;
  --online: #30d158;
  --line: rgba(255, 255, 255, 0.08);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-left: var(--sal);
  padding-right: var(--sar);
  overscroll-behavior: none;
}

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

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

img, video { display: block; max-width: 100%; }

::selection { background: var(--yellow); color: #000; }

:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 2px;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
}

.screen, .thread, .camera, .auth, .splash {
  min-height: 100vh;
  min-height: 100dvh;
}

.screen, .thread, .camera {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.screen, .thread {
  display: flex;
  flex-direction: column;
}

.splash {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(28px + var(--sat)) 24px calc(24px + var(--sab));
  text-align: center;
}

.auth {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  text-align: center;
}

.auth-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: calc(20px + var(--sat)) 24px 8px;
}

.auth-scroll .logo { margin: 0 auto; }
.auth-card { align-self: stretch; }

.auth-footer {
  padding: 8px 24px calc(12px + var(--sab));
}

.auth-footer .btn.primary { margin-top: 0; }
.auth-footer .linkish { margin-top: 4px; }

.logo, .brand-mark {
  display: grid;
  place-items: center;
  background: var(--yellow);
  color: #fff;
}

.logo {
  width: 104px;
  height: 104px;
  border-radius: 32px;
  box-shadow: 0 16px 40px rgba(255, 252, 0, 0.18);
}

.logo svg { width: 72px; height: 72px; }

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex: none;
}

.brand-mark svg { width: 22px; height: 22px; }

.word {
  margin: 18px 0 0;
  font-size: 40px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: -0.045em;
}

.tagline {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 16px;
  max-width: 280px;
}

.auth-card {
  width: min(100%, 380px);
  margin-top: 28px;
  text-align: left;
}

label {
  display: block;
  margin: 14px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.field, .composer textarea, .search input {
  width: 100%;
  border: 1px solid transparent;
  background: var(--elev-2);
  border-radius: 14px;
  padding: 15px 16px;
  font-size: 16px;
  outline: none;
}

.field:focus, .composer textarea:focus, .search input:focus {
  border-color: var(--yellow);
}

.hint {
  margin: 6px 2px 0;
  color: var(--faint);
  font-size: 12px;
}

.form-error {
  min-height: 1.2em;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 600;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 750;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.btn.primary {
  width: 100%;
  margin-top: 16px;
  background: var(--yellow);
  color: #000;
}

.btn.slim,
.actions .btn,
.person .btn {
  width: auto;
  margin-top: 0;
}

.preview-actions .btn { margin-top: 0; width: 100%; }

.btn.primary:disabled { opacity: 0.45; }

.btn.ghost {
  background: var(--elev-2);
  color: #fff;
}

.btn.slim {
  min-height: 40px;
  padding: 0 14px;
  font-size: 14px;
}

.btn.danger { color: var(--danger); }

.linkish {
  display: block;
  width: 100%;
  margin-top: 16px;
  color: var(--yellow);
  font-weight: 700;
  text-align: center;
  min-height: 44px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + var(--sat)) 16px 10px;
}

.brand, .who {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand { font-weight: 800; font-size: 22px; letter-spacing: -0.04em; }

.handle-chip {
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  font-weight: 600;
}

.conn {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  flex: none;
}

.conn.on { background: var(--online); }

.list, .messages, .sheet-list, .search-results {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.row, .person {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 16px;
  text-align: left;
}

.row-main, .person-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  text-align: left;
  padding: 4px 0;
}

.avatar {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  flex: none;
  color: #fff;
}

.avatar.sm { width: 40px; height: 40px; font-size: 15px; }

.avatar.hot { box-shadow: 0 0 0 2px #000, 0 0 0 4px var(--yellow); }

.presence {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--online);
  border: 2px solid #000;
  display: none;
}

.presence.show { display: block; }

.row-body, .person-copy {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.name-row, .preview-row, .person-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.title, .person-name {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.time, .meta, .at {
  color: var(--faint);
  font-size: 12px;
  flex: none;
}

.preview {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview.unread { color: #fff; font-weight: 650; font-weight: 600; }
.preview.snap { color: var(--yellow); font-weight: 750; font-weight: 700; }

.pill, .badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--yellow);
  color: #000;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
}

.badge { display: none; position: absolute; top: -6px; right: -8px; }

.badge.show { display: inline-grid; }

.view-chip {
  flex: none;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--yellow);
  color: #000;
  font-size: 13px;
  font-weight: 800;
}

.tabbar {
  display: grid;
  grid-template-columns: 1fr 88px 1fr;
  align-items: end;
  padding: 6px 12px calc(8px + var(--sab));
  background: #000;
  border-top: 1px solid var(--line);
}

.tab {
  position: relative;
  min-height: 48px;
  color: var(--faint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 700;
}

.tab svg { width: 26px; height: 26px; display: block; }
.tab.active { color: var(--yellow); }

.tab-icon { position: relative; display: grid; place-items: center; }

.cam-btn {
  width: 68px;
  height: 68px;
  margin: 0 auto 4px;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 4px #000, 0 0 0 6px #fff;
}

.empty {
  margin: 28px 24px;
  color: var(--muted);
  text-align: center;
}

.empty strong { display: block; color: #fff; font-size: 18px; margin-bottom: 6px; }

.thread-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + var(--sat)) 10px 8px;
  border-bottom: 1px solid var(--line);
}

.back, .icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
}

.back svg, .icon-btn svg { width: 22px; height: 22px; }

.thread-name { font-weight: 750; font-weight: 700; }
.thread-sub { color: var(--muted); font-size: 12px; }

.messages {
  padding: 12px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day {
  align-self: center;
  margin: 10px 0;
  color: var(--faint);
  font-size: 12px;
  font-weight: 700;
}

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}

.bubble.in {
  align-self: flex-start;
  background: var(--elev-2);
  border-bottom-left-radius: 6px;
}

.bubble.out {
  align-self: flex-end;
  background: var(--yellow);
  color: #000;
  border-bottom-right-radius: 6px;
}

.receipt {
  align-self: flex-end;
  color: var(--faint);
  font-size: 12px;
  font-weight: 650;
  font-weight: 600;
  margin: 2px 6px 0;
}

.empty-thread {
  margin: auto;
  color: var(--muted);
  text-align: center;
}

#snap-slot { padding: 0 12px 8px; }

.snap-banner {
  width: 100%;
  min-height: 56px;
  border-radius: 16px;
  background: var(--yellow);
  color: #000;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
}

.snap-banner small { font-weight: 650; font-weight: 600; font-size: 12px; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(10px + var(--sab));
  background: #000;
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  padding: 12px 14px;
  border-radius: 22px;
}

.send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--yellow);
  color: #000;
  display: grid;
  place-items: center;
  flex: none;
}

.send:disabled { opacity: 0.35; }
.send svg { width: 20px; height: 20px; }

.camera {
  position: relative;
  background: #000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#viewfinder, .preview {
  flex: 1;
  width: 100%;
  min-height: 0;
  object-fit: cover;
  background: #0a0a0a;
}

.camera-error {
  position: absolute;
  left: 20px;
  right: 20px;
  top: calc(24px + var(--sat));
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  text-align: center;
}

.cam-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(92px + var(--sab));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
}

.round {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.round svg { width: 22px; height: 22px; }

.shutter {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: var(--yellow);
  border: 5px solid #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.preview-actions {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(16px + var(--sab));
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 72%;
  background: #111;
  border-radius: 22px 22px 0 0;
  padding: 8px 0 calc(12px + var(--sab));
  display: flex;
  flex-direction: column;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.45);
}

.grab {
  width: 40px;
  height: 4px;
  border-radius: 99px;
  background: #3a3a3c;
  margin: 6px auto 8px;
}

.sheet h2 {
  margin: 4px 16px 8px;
  font-size: 18px;
}

.sheet-list { padding-bottom: 8px; }

.section-label {
  margin: 18px 16px 6px;
  color: var(--faint);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.search { padding: 0 16px 8px; }

.actions { display: flex; gap: 8px; flex: none; }

.profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 16px 12px;
}

.profile .copy { min-width: 0; }
.profile strong, .profile span {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile span { color: var(--muted); font-size: 14px; }

.logout {
  margin: 18px 16px calc(8px + var(--sab));
}

.snap-view {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #000;
  display: flex;
  flex-direction: column;
}

.snap-photo {
  flex: 1;
  width: 100%;
  min-height: 0;
  object-fit: contain;
  background: #000;
  -webkit-touch-callout: none;
  user-select: none;
}

.snap-top {
  position: absolute;
  top: calc(10px + var(--sat));
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 2;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}

.snap-from { font-weight: 800; }

.timer {
  position: relative;
  width: 40px;
  height: 40px;
  flex: none;
}

.timer svg { width: 40px; height: 40px; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 3; }
.timer .track { stroke: rgba(255, 255, 255, 0.28); }
.timer .prog {
  stroke: var(--yellow);
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 0;
}

.timer span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
}

.snap-close {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(16px + var(--sab));
  z-index: 2;
}

.snap-loading {
  margin: auto;
  color: var(--muted);
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--sab));
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--yellow);
  color: #000;
  font-weight: 750;
  font-weight: 700;
  text-align: center;
}

.noscript {
  padding: 24px;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (min-width: 900px) {
  body { background: #050505; }
  #app {
    min-height: 100dvh;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
  }
}
