/* ==========================================================================
   Loom web — dark, mobile-matching styles.
   Palette: #0a0a0f background, #14141a cards, #818CF8 accent.
   ========================================================================== */

:root {
  --bg: #0a0a0f;
  --surface: #14141a;
  --surface-2: #1a1a23;
  --surface-3: #20202b;
  --border: #262631;
  --border-strong: #343440;
  --text: #ececf3;
  --text-2: #a8a8ba;
  --muted: #7d7d92;
  --accent: #818cf8;
  --accent-hover: #949dfb;
  --accent-soft: rgba(129, 140, 248, 0.12);
  --accent-ring: rgba(129, 140, 248, 0.4);
  --verified: #4f9cf9;
  --like: #fb7185;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image: radial-gradient(
      1000px 520px at 50% -220px,
      rgba(129, 140, 248, 0.13),
      transparent 70%
    ),
    radial-gradient(700px 400px at 110% 10%, rgba(99, 102, 241, 0.06), transparent 65%);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-wrap: break-word;
}

body.modal-open {
  overflow: hidden;
}

img {
  max-width: 100%;
}

button {
  font-family: inherit;
}

a {
  color: var(--accent);
}

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

::selection {
  background: rgba(129, 140, 248, 0.35);
  color: #fff;
}

/* Scrollbars (WebKit/Blink) */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: #2c2c38;
  border: 2px solid var(--bg);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #3a3a4a;
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(10, 10, 15, 0.82);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(38, 38, 49, 0.85);
}

.topbar-inner {
  max-width: 660px;
  margin: 0 auto;
  padding: 0 16px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: baseline;
  font-size: 1.18rem;
  font-weight: 800;
  letter-spacing: -0.035em;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
}

.brand span {
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Phase 27.1 — APK download: keep the label on one line and align the live
   progress bar with the header content instead of the viewport edge. */
#download-btn {
  white-space: nowrap;
  /* <button> does not inherit the page font the way <a> does. */
  font-family: inherit;
}

#download-btn:disabled {
  opacity: 0.75;
  cursor: progress;
}

#download-progress {
  max-width: 660px;
  margin: 0 auto;
  padding: 0 16px 12px;
}

/* Used only when the server omits Content-Length, so the percentage would be
   meaningless: slide a segment instead of pretending to know the total. */
#progress-bar.is-indeterminate {
  width: 40% !important;
  animation: download-slide 1.1s ease-in-out infinite;
}

@keyframes download-slide {
  0% {
    margin-left: -40%;
  }
  100% {
    margin-left: 100%;
  }
}

/* --------------------------------------------------------------------------
   Shell
   -------------------------------------------------------------------------- */

.app-shell {
  max-width: 660px;
  margin: 0 auto;
  padding: 22px 16px 40px;
}

.page-head {
  margin: 2px 4px 18px;
}

.page-head h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.footer {
  max-width: 660px;
  margin: 0 auto;
  padding: 0 16px 44px;
  text-align: center;
  color: #55556b;
  font-size: 0.74rem;
  letter-spacing: 0.02em;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease,
    color 0.16s ease, transform 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0b12;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: #454556;
}

.btn-small {
  padding: 8px 14px;
  font-size: 0.79rem;
}

.btn-block {
  width: 100%;
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

/* --------------------------------------------------------------------------
   Avatars + verification
   -------------------------------------------------------------------------- */

.avatar {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(135deg, #2b2b3d, #1b1b25);
  border: 1px solid rgba(129, 140, 248, 0.18);
  color: #b9bffb;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  user-select: none;
}

.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.avatar img.is-ready {
  opacity: 1;
}

.avatar-sm {
  width: 30px;
  height: 30px;
  font-size: 0.62rem;
}

.avatar-lg {
  width: 88px;
  height: 88px;
  font-size: 1.65rem;
  border-width: 4px;
  border-color: var(--surface);
}

.verified {
  display: inline-flex;
  flex: none;
  width: 14px;
  height: 14px;
  color: var(--verified);
}

.verified svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* --------------------------------------------------------------------------
   Thread card
   -------------------------------------------------------------------------- */

.thread-card {
  position: relative;
  cursor: pointer;
  outline: none;
  transition: border-color 0.18s ease, background-color 0.18s ease,
    transform 0.18s ease;
}

.thread-card:hover {
  border-color: var(--accent-ring);
  background: #16161e;
  transform: translateY(-1px);
}

.thread-card:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.thread-card--detail {
  cursor: default;
}

.thread-card--detail:hover {
  border-color: var(--border);
  background: var(--surface);
  transform: none;
}

.thread-card.is-deleted {
  opacity: 0.72;
}

.thread-head {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  min-width: 0;
}

.thread-meta {
  flex: 1;
  min-width: 0;
}

.thread-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.3;
}

.thread-name .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-sub {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 3px;
  font-size: 0.78rem;
  color: var(--muted);
  min-width: 0;
}

.thread-sub a {
  color: var(--muted);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 46vw;
}

.thread-sub a:hover {
  color: var(--accent);
}

.thread-sub time {
  white-space: nowrap;
}

.dot {
  opacity: 0.55;
}

.chip {
  display: inline-flex;
  align-items: center;
  max-width: 160px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #b9bffb;
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-title {
  margin: 13px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.012em;
  color: var(--text);
  overflow-wrap: anywhere;
}

.thread-card--detail .thread-title {
  margin-top: 17px;
  font-size: 1.34rem;
  line-height: 1.3;
}

.thread-body {
  margin: 7px 0 0;
  font-size: 0.93rem;
  line-height: 1.62;
  color: var(--text-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.thread-body.is-clamped {
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Media — full width, 12px corners (matches the Android card) */
.thread-media {
  margin: 14px 0 0;
}

.thread-media img {
  display: block;
  width: 100%;
  max-height: 560px;
  object-fit: cover;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

/* Voice note */
.voice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  padding: 11px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.voice-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-soft);
  font-size: 0.85rem;
}

.voice-body {
  flex: 1;
  min-width: 0;
}

.voice-label {
  display: block;
  color: var(--text-2);
  font-size: 0.78rem;
  font-weight: 600;
}

.voice-audio {
  display: block;
  width: 100%;
  height: 34px;
  margin-top: 6px;
  border-radius: 999px;
}

/* Engagement row */
.thread-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 600;
}

.stat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.stat svg {
  width: 15px;
  height: 15px;
  flex: none;
}

.stats-spacer {
  flex: 1;
}

.stat-btn {
  padding: 5px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font-size: 0.79rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.stat-btn:hover {
  background: var(--accent-soft);
}

/* --------------------------------------------------------------------------
   Thread detail
   -------------------------------------------------------------------------- */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 14px;
  padding: 6px 10px 6px 6px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
  background: var(--surface);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 4px 12px;
}

.section-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.section-head span {
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 600;
}

.cta-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 22px;
}

.replies {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reply {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.reply.is-deleted {
  opacity: 0.66;
}

.reply-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.reply-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  font-size: 0.77rem;
  color: var(--muted);
}

.reply-author {
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 650;
  text-decoration: none;
}

.reply-author:hover {
  color: var(--accent);
}

.reply-body {
  margin: 8px 0 0;
  font-size: 0.9rem;
  line-height: 1.58;
  color: var(--text-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.reply .thread-media {
  margin-top: 10px;
}

.reply .thread-media img {
  max-height: 420px;
}

.reply-stats {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.reply-stats .stat svg {
  width: 13px;
  height: 13px;
}

.reply-stats .stat-btn {
  font-size: 0.75rem;
}

/* --------------------------------------------------------------------------
   Profile
   -------------------------------------------------------------------------- */

.profile-card {
  padding: 0;
  overflow: hidden;
}

.profile-cover {
  height: 104px;
  background: radial-gradient(
      120% 170% at 18% 0%,
      rgba(129, 140, 248, 0.5),
      transparent 62%
    ),
    linear-gradient(118deg, #1c1c2d, #14141a 72%);
}

.profile-body {
  padding: 0 20px 20px;
}

.profile-avatar {
  position: relative;
  z-index: 1;
  margin-top: -46px;
  display: inline-block;
}

.profile-name {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
  font-size: 1.32rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.profile-name .verified {
  width: 17px;
  height: 17px;
}

.profile-handle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.9rem;
}

.profile-bio {
  margin: 12px 0 0;
  color: var(--text-2);
  font-size: 0.92rem;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.profile-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.79rem;
}

.profile-stats {
  display: flex;
  gap: 24px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.profile-stat b {
  display: block;
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.2;
}

.profile-stat span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.profile-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(4, 4, 9, 0.72);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  padding: 26px 22px 20px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
  animation: modal-in 0.18s ease;
}

.modal-icon {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  margin: 0 auto 14px;
  border-radius: 15px;
  background: var(--accent-soft);
  font-size: 1.35rem;
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 1.08rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.modal-card p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.modal-card .btn {
  width: 100%;
}

.modal-card .btn + .btn {
  margin-top: 8px;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* --------------------------------------------------------------------------
   Loading / empty / error
   -------------------------------------------------------------------------- */

.loading {
  display: grid;
  place-items: center;
  gap: 14px;
  padding: 64px 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.skeleton-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.skeleton-row {
  display: flex;
  align-items: center;
  gap: 11px;
}

.sk {
  background: linear-gradient(
    90deg,
    var(--surface) 25%,
    var(--surface-3) 37%,
    var(--surface) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 7px;
}

.sk-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex: none;
}

.sk-line {
  height: 11px;
  margin-top: 9px;
}

.sk-line-sm {
  width: 38%;
  height: 9px;
  margin-top: 0;
}

.sk-line-lg {
  width: 82%;
  height: 15px;
  margin-top: 18px;
}

.sk-line-full {
  width: 100%;
}

.sk-line-half {
  width: 62%;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

.state {
  padding: 46px 22px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: rgba(20, 20, 26, 0.55);
  text-align: center;
}

.state-emoji {
  font-size: 2rem;
  line-height: 1;
  margin-bottom: 12px;
}

.state h2 {
  margin: 0 0 8px;
  font-size: 1.04rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.state p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

.state .btn + .btn {
  margin-left: 8px;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 520px) {
  .app-shell {
    padding: 16px 12px 32px;
  }

  .card {
    padding: 14px;
    border-radius: 14px;
  }

  .page-head h1 {
    font-size: 1.35rem;
  }

  .thread-card--detail .thread-title {
    font-size: 1.2rem;
  }

  .thread-body.is-clamped {
    -webkit-line-clamp: 6;
  }

  .thread-stats {
    gap: 13px;
  }

  .profile-body {
    padding: 0 16px 18px;
  }

  .profile-stats {
    gap: 18px;
  }

  .reply {
    padding: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
