/* thethread — see /DESIGN.md for the direction contract this implements.
   THESIS: a lit window seen from a dark street, not a chat app UI.
   Two-temperature palette (cold void / warm room), presence and identity
   both ride each speaker's own hue (no green, no generic accent).
   Flat by default — the only depth cue is the room/void contrast and one
   soft edge vignette on the feed. No shadows, no borders, no cards. */

:root {
  --void: #07070a;
  --room: #1f180f;
  --room-edge: #110d08;
  --ink: #ece4d6;
  --ink-muted: #8f8578;
  --ink-faint: #5a5347;

  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-label: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Consolas, monospace;
  /* type ramp - exactly 3 sizes (DESIGN.md Typography): 16 body / 14 name / 12 label */
  --text-name: 14px;
  --text-label: 12px;

  --radius-bubble: 16px;
  --radius-anchor: 5px;
  --radius-hairline: 2px;

  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 14px;
  --sp-lg: 28px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--void);
  color: var(--ink);
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 640px;
  height: 100%;
  margin: 0 auto;
  background: var(--room);
  display: flex;
  flex-direction: column;
  position: relative;
  /* the void is the street outside the window; on mobile the window fills
     the whole screen, which is correct - up close you don't see past it */
}

@media (min-width: 641px) {
  /* the one named exception to "no shadows" (DESIGN.md, Single Glow rule):
     light spilling from the room into the street is the thesis, not decor.
     mobile has no street left to light, so this stays desktop-only. */
  #app {
    box-shadow:
      0 0 80px 10px rgba(150, 110, 60, 0.05),
      0 0 220px 40px rgba(120, 90, 55, 0.045),
      0 0 420px 80px rgba(90, 70, 45, 0.03);
  }
}

/* ---------- top strip ---------- */

#top-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-md) var(--sp-md);
  gap: var(--sp-md);
}

.peer {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  min-width: 0;
}

.peer-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.peer-info.align-right { align-items: flex-end; text-align: right; }

.peer .name {
  font-size: var(--text-name);
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.peer-status {
  font-family: var(--font-label);
  font-size: var(--text-label);
  letter-spacing: 0.02em;
  color: var(--ink-muted); /* legible in both states - presence lives in the dot, not text dimming */
}

.avatar {
  position: relative;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: hsl(var(--hue) 30% 14%);
  color: hsl(var(--hue) 35% 70%);
  font-family: var(--font-label);
  font-size: var(--text-label);
  font-weight: 600;
}

.online-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: hsl(var(--hue) 15% 25%);
  border: 2px solid var(--room);
  transition: background 600ms ease;
}
.online-dot[data-online="true"] {
  background: hsl(var(--hue) 55% 60%);
}

/* ---------- feed ---------- */

#feed {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-md) var(--sp-md) var(--sp-lg);
  display: flex;
  flex-direction: column;
  position: relative;
  scrollbar-width: thin;
}

#app::before,
#app::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 36px;
  pointer-events: none;
  z-index: 2;
}
#app::before { top: 0; background: linear-gradient(var(--room-edge), transparent); }
#app::after { bottom: 0; background: linear-gradient(transparent, var(--room-edge)); }

.day-divider {
  align-self: center;
  font-family: var(--font-label);
  font-size: var(--text-label);
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  margin: var(--sp-lg) 0 var(--sp-md);
  text-transform: lowercase;
}

.cluster {
  display: flex;
  gap: var(--sp-sm);
  margin-top: var(--sp-lg);
  max-width: 88%;
}
.cluster.side-left { align-self: flex-start; flex-direction: row; }
.cluster.side-right { align-self: flex-end; flex-direction: row-reverse; }

.cluster .avatar { align-self: flex-end; }
.cluster .bubbles {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
  min-width: 0;
}
.cluster.side-right .bubbles { align-items: flex-end; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  background: hsl(var(--hue) 38% 17%);
  color: var(--ink);
  max-width: 100%;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 16px;
  line-height: 1.4;
}
.side-left .bubble { border-bottom-left-radius: var(--radius-anchor); }
.side-right .bubble { border-bottom-right-radius: var(--radius-anchor); }
.side-left .bubble:not(:first-child) { border-top-left-radius: var(--radius-bubble); }
.side-right .bubble:not(:first-child) { border-top-right-radius: var(--radius-bubble); }

.bubble-time {
  font-family: var(--font-label);
  font-size: var(--text-label);
  color: var(--ink-muted);
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.side-right .bubble-time { align-self: flex-end; }

/* read receipt - single check = delivered (inherits ink-muted from parent),
   double check tints from the sender's own hue when read (never gray on a
   colored signal - same rule as voice-duration). No green anywhere. */
.tick { font-size: inherit; }
.tick-read {
  color: hsl(var(--hue) 30% 78%);
  letter-spacing: -0.1em; /* the two checks sit closer together, like a real double-tick glyph */
}

/* voice-broken bubble */
.bubble-voice {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  border: none;
  cursor: pointer;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: hsl(var(--hue) 38% 17%);
}
.bubble-voice:hover { background: hsl(var(--hue) 38% 20%); }
.bubble-voice:focus-visible { outline: 2px solid hsl(var(--hue) 55% 60%); outline-offset: 2px; }
.voice-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 18px;
}
.voice-wave span {
  width: 2px;
  border-radius: var(--radius-hairline);
  background: hsl(var(--hue) 40% 55%);
  opacity: 0.8;
}
/* on the colored bubble surface, gray fails contrast - tint from the
   speaker's own hue instead (craft-floor: never gray on a colored surface) */
.voice-duration { font-family: var(--font-label); font-size: var(--text-label); color: hsl(var(--hue) 30% 78%); }
.voice-error {
  margin-top: var(--sp-xs);
  font-family: var(--font-label);
  font-size: var(--text-label);
  color: var(--ink-muted);
  padding: 0 4px;
}

/* typing indicator - same asymmetric shape as a real bubble, appended live */
.cluster.typing .bubble {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 12px 16px;
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: hsl(var(--hue) 40% 55%);
  opacity: 0.35;
  animation: typing-pulse 1200ms ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 160ms; }
.typing-dot:nth-child(3) { animation-delay: 320ms; }

@keyframes typing-pulse {
  0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
  30% { opacity: 0.9; transform: translateY(-2px); }
}

@media (prefers-reduced-motion: reduce) {
  .typing-dot { animation: none; opacity: 0.6; }
  .online-dot { transition: none; }
}

/* ---------- empty / loading states ---------- */

.feed-notice {
  margin: auto;
  text-align: center;
  color: var(--ink-muted);
  font-family: var(--font-label);
  font-size: var(--text-label);
  padding: var(--sp-lg);
}

/* ---------- bottom bar: viewer count (left) + auth (right) ---------- */

/* a real flex row below #feed, not an absolute overlay - an overlay would
   sit on top of scrolled-in message text with no backdrop (the "no pill"
   rule) and become unreadable wherever a bubble happened to land under it */
#bottom-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-sm) var(--sp-md);
  font-family: var(--font-label);
  font-size: var(--text-label);
  color: var(--ink-muted);
}
.viewers { display: flex; align-items: center; gap: 6px; }
.viewers-dot {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--ink-faint);
}
.auth-zone { display: flex; align-items: center; gap: var(--sp-sm); }
#account-info { font-family: var(--font-label); font-size: var(--text-label); color: var(--ink-muted); }

/* text-only, never a button - "войти" must never read as a CTA */
.quiet-link {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-label);
  font-size: var(--text-label);
  color: var(--ink-muted);
  cursor: pointer;
  text-decoration: none;
}
.quiet-link:hover { color: var(--ink); text-decoration: underline; }

/* ---------- ad slot: generic, unconnected, deliberately quiet ---------- */
.ad-slot {
  flex: none;
  margin: 0 var(--sp-md) var(--sp-md);
  padding: var(--sp-sm);
  text-align: center;
  font-family: var(--font-label);
  font-size: var(--text-label);
  color: var(--ink-faint);
  border: 1px dashed var(--room-edge);
  border-radius: var(--radius-anchor);
}

/* ---------- sheets: login/register and comments - the only overlays in
   the system, both explicitly requested (auth) or explicitly required to
   be structurally separate from the feed (comments) ---------- */
/* [hidden] must win over the flex below - an author rule targeting the same
   element as the UA's [hidden]{display:none} otherwise beats it on
   specificity, which is exactly the bug this once shipped as (both sheets
   visible on first paint, the one thing "no CTA on entry" cannot tolerate). */
.sheet[hidden] { display: none; }
.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(7, 7, 10, 0.6);
}
@media (min-width: 641px) {
  .sheet { align-items: center; }
}
.sheet-card {
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--room);
  border-radius: var(--radius-bubble) var(--radius-bubble) 0 0;
  padding: var(--sp-md);
  gap: var(--sp-sm);
  overflow: hidden;
}
@media (min-width: 641px) {
  .sheet-card { border-radius: var(--radius-bubble); max-height: 70vh; }
}
.sheet-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-name);
  font-weight: 600;
  color: var(--ink);
  padding-bottom: var(--sp-sm);
}
.sheet-error {
  font-family: var(--font-label);
  font-size: var(--text-label);
  color: var(--ink-muted);
}
.sheet hr { border: none; border-top: 1px solid var(--room-edge); margin: var(--sp-sm) 0; }

.sheet input, .sheet textarea {
  width: 100%;
  background: var(--room-edge);
  border: 1px solid var(--ink-faint);
  border-radius: var(--radius-anchor);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* prevents iOS auto-zoom on focus */
  padding: 10px 12px;
  margin-bottom: var(--sp-xs);
}
.sheet textarea { resize: vertical; min-height: 4.5em; }
.sheet label {
  display: block;
  font-family: var(--font-label);
  font-size: var(--text-label);
  color: var(--ink-muted);
  margin-bottom: var(--sp-xs);
}
.sheet button[type="submit"] {
  background: var(--room-edge);
  border: 1px solid var(--ink-faint);
  border-radius: var(--radius-anchor);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  cursor: pointer;
}
.sheet button[type="submit"]:hover { background: var(--ink-faint); }

.comments-context {
  flex: none;
  padding: var(--sp-sm);
  background: var(--room-edge);
  border-radius: var(--radius-anchor);
  color: var(--ink-muted);
  font-size: 14px;
}
.comments-list {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-sm);
}
.comment {
  padding-bottom: var(--sp-sm);
  border-bottom: 1px solid var(--room-edge);
}
.comment-author {
  font-family: var(--font-label);
  font-size: var(--text-label);
  color: var(--ink-muted);
  display: block;
  margin-bottom: 2px;
}
.comment-body { color: var(--ink); white-space: pre-wrap; word-wrap: break-word; }

/* ---------- per-message like / comment affordances (sit next to the tick) ---------- */
.msg-actions {
  display: inline-flex;
  gap: var(--sp-sm);
  margin-left: var(--sp-xs);
}
.side-right .msg-actions { margin-left: 0; margin-right: var(--sp-xs); }
.msg-action {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-label);
  font-size: var(--text-label);
  color: var(--ink-muted);
  cursor: pointer;
}
.msg-action:hover { color: var(--ink); }
.msg-action.liked { color: hsl(var(--hue) 45% 65%); }

/* ---------- scrollbar, quiet ---------- */
#feed::-webkit-scrollbar { width: 8px; }
#feed::-webkit-scrollbar-thumb { background: var(--room-edge); border-radius: 999px; }
#feed::-webkit-scrollbar-track { background: transparent; }
.comments-list::-webkit-scrollbar { width: 6px; }
.comments-list::-webkit-scrollbar-thumb { background: var(--room-edge); border-radius: 999px; }
