/* ==========================================================================
   Loop Network: styles (mobile-first)
   ========================================================================== */

@font-face {
  font-family: 'IRANSansDN';
  src: url('../fonts/IRANSansDN-Light.ttf') format('truetype');
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IRANSansDN';
  src: url('../fonts/IRANSansDN-Regular.ttf') format('truetype');
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IRANSansDN';
  src: url('../fonts/IRANSansDN-Bold.ttf') format('truetype');
  font-weight: 600 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --blue-50: #EEF4FF;
  --blue-100: #E0EBFF;
  --blue-200: #C7DAFE;
  --blue-500: #0055FF;
  --blue-600: #0047D6;
  --blue-700: #0038A8;
  --blue-900: #001952;

  --ink: #0f172a;
  --text: #334155;
  --muted: #64748b;
  --subtle: #94a3b8;
  --line: #e2e8f0;
  --line-soft: #f1f5f9;
  --surface: #ffffff;
  --bg: #f4f7fb;

  --green-50: #ecfdf5;
  --green-200: #a7f3d0;
  --green-600: #059669;
  --green-700: #047857;

  --radius-sm: 12px;
  --radius: 18px;
  --radius-lg: 24px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 2px 8px -2px rgba(0, 85, 255, .05);
  --shadow-md: 0 12px 28px -8px rgba(0, 85, 255, .18), 0 4px 10px rgba(15, 23, 42, .04);
  --shadow-sheet: 0 -16px 48px rgba(15, 23, 42, .18);

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --gutter: 16px;
  --font: 'IRANSansDN', Tahoma, system-ui, -apple-system, sans-serif;
}

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

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 140px; }
html.is-locked { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(to right, rgba(0, 85, 255, .035) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0, 85, 255, .035) 1px, transparent 1px);
  background-size: 36px 36px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

h1, h2, h3, p { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
svg { flex-shrink: 0; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: 3px solid var(--blue-200); outline-offset: 2px; }

.container {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* Stroke icons */
.search-icon, .search-clear svg, .view-btn svg, .icon-btn svg, .action svg, .card-arrow, .peer-arrow {
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* --------------------------------------------------------------------------
   Hero
   -------------------------------------------------------------------------- */
.hero { padding-top: 20px; padding-bottom: 18px; }

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 14px;
  display: grid; place-items: center; font-size: 20px;
  background: var(--blue-500);
  box-shadow: 0 8px 18px -6px rgba(0, 85, 255, .5);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.3; }
.brand-kicker { font-size: 11px; font-weight: 700; color: var(--blue-500); letter-spacing: .02em; }
.brand-name { font-size: 14px; font-weight: 700; color: var(--ink); }

.hero-title {
  font-size: clamp(26px, 7.5vw, 46px);
  line-height: 1.35;
  font-weight: 900;
  color: var(--ink);
  margin-bottom: 10px;
}
.hero-lead { font-size: 14.5px; color: var(--muted); max-width: 640px; }
.hero-lead strong { color: var(--blue-600); }

.hero-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
  padding: 5px 12px; border-radius: 999px;
}
.badge-blue { color: var(--blue-600); background: var(--blue-50); border-color: var(--blue-200); }

/* --------------------------------------------------------------------------
   Sticky toolbar: search, view toggle, chips
   -------------------------------------------------------------------------- */
.toolbar {
  position: sticky; top: 0; z-index: 30;
  padding: 10px 0 2px;
  background: rgba(244, 247, 251, .86);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
.toolbar.is-stuck { border-bottom-color: var(--line); box-shadow: 0 6px 20px -12px rgba(15, 23, 42, .18); }

.toolbar-row { display: flex; gap: 8px; align-items: stretch; }

.search {
  position: relative; flex: 1; min-width: 0;
  display: flex; align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: border-color .2s, box-shadow .2s;
}
.search:focus-within { border-color: var(--blue-500); box-shadow: 0 0 0 4px var(--blue-100); }
.search-icon { width: 19px; height: 19px; color: var(--subtle); margin-inline-start: 14px; }
.search input {
  flex: 1; min-width: 0; height: 46px;
  border: 0; outline: 0; background: transparent;
  padding: 0 10px; font-size: 14px; font-weight: 500;
}
.search input::placeholder { color: var(--subtle); font-weight: 400; }
.search input::-webkit-search-cancel-button { display: none; }
.search-clear {
  width: 32px; height: 32px; margin-inline-end: 7px; border-radius: 50%;
  display: grid; place-items: center; color: var(--subtle);
}
.search-clear:hover { background: var(--line-soft); color: var(--text); }
.search-clear svg { width: 16px; height: 16px; }

.view-toggle {
  display: flex; padding: 4px; gap: 2px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.view-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 42px; padding: 0 10px; border-radius: 13px;
  font-size: 13px; font-weight: 700; color: var(--muted);
  transition: background .2s, color .2s;
}
.view-btn svg { width: 18px; height: 18px; }
.view-btn span { display: none; }
.view-btn.is-active { background: var(--blue-500); color: #fff; }

.chips {
  display: flex; gap: 8px;
  overflow-x: auto; overscroll-behavior-x: contain;
  scrollbar-width: none;
  margin-inline: calc(var(--gutter) * -1);
  padding: 10px var(--gutter) 10px;
  scroll-padding-inline: var(--gutter);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  transition: background .2s, color .2s, border-color .2s;
}
.chip:hover { border-color: var(--blue-200); }
.chip-count {
  font-size: 10.5px; min-width: 20px; padding: 0 6px; line-height: 18px;
  border-radius: 999px; background: var(--line-soft); color: var(--muted); text-align: center;
}
.chip.is-active { background: var(--blue-500); border-color: var(--blue-500); color: #fff; box-shadow: 0 6px 14px -6px rgba(0, 85, 255, .55); }
.chip.is-active .chip-count { background: rgba(255, 255, 255, .22); color: #fff; }

/* --------------------------------------------------------------------------
   Cards (list view)
   -------------------------------------------------------------------------- */
.main { padding-top: 14px; padding-bottom: calc(48px + env(safe-area-inset-bottom)); }

.cards { display: grid; grid-template-columns: 1fr; gap: 12px; }

.card {
  display: flex; flex-direction: column; gap: 12px;
  width: 100%; text-align: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform .2s var(--ease-out), box-shadow .2s, border-color .2s;
  animation: cardIn .4s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 25ms);
}
.card:active { transform: scale(.985); }
@media (hover: hover) {
  .card:hover { border-color: var(--blue-500); box-shadow: var(--shadow-md); transform: translateY(-2px); }
  .card:hover .card-name { color: var(--blue-600); }
  .card:hover .card-arrow { transform: translateX(-3px); }
}
@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } }

.card-head { display: flex; align-items: center; gap: 12px; }
.card-who { display: block; min-width: 0; flex: 1; }
.card-name, .card-title, .node-name { display: block; }
.card-name {
  font-size: 15.5px; font-weight: 800; color: var(--ink); line-height: 1.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color .2s;
}
.card-title {
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-arrow { width: 20px; height: 20px; color: var(--blue-500); transition: transform .2s; }

.card-intro {
  font-size: 13px; color: var(--text); line-height: 1.85;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font-size: 11.5px; font-weight: 700; line-height: 1.6;
  color: var(--blue-600); background: var(--blue-50);
  padding: 3px 10px; border-radius: 9px;
}
.tag-more { color: var(--muted); background: var(--line-soft); }

/* --------------------------------------------------------------------------
   Avatar
   -------------------------------------------------------------------------- */
.avatar {
  position: relative; flex-shrink: 0;
  display: grid; place-items: center;
  width: 52px; height: 52px; border-radius: 16px; overflow: hidden;
  color: #fff; font-weight: 800; font-size: 15px; letter-spacing: .02em;
  background: linear-gradient(135deg, var(--c1, #2563eb), var(--c2, #4338ca));
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, .3);
  user-select: none;
}
.avatar img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; opacity: 0; transition: opacity .3s;
}
.avatar img.is-loaded { opacity: 1; }
.avatar-lg { width: 96px; height: 96px; border-radius: 28px; font-size: 28px; border: 4px solid #fff; box-shadow: 0 14px 30px -10px rgba(0, 85, 255, .4); }
.avatar-sm { width: 38px; height: 38px; border-radius: 12px; font-size: 12px; }
.avatar-node { width: 50px; height: 50px; border-radius: 16px; font-size: 14px; }

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */
.empty { text-align: center; padding: 56px 16px; }
.empty-icon { font-size: 40px; margin-bottom: 8px; }
.empty-title { font-size: 17px; font-weight: 800; color: var(--ink); }
.empty-text { font-size: 13.5px; color: var(--muted); margin: 4px 0 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 14px;
  font-size: 14px; font-weight: 800;
  transition: background .2s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-soft { background: var(--blue-50); color: var(--blue-600); }
.btn-soft:hover { background: var(--blue-100); }

/* --------------------------------------------------------------------------
   Network view
   -------------------------------------------------------------------------- */
.network-hint {
  font-size: 12.5px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px;
}
.legend { display: inline-block; width: 18px; height: 0; vertical-align: middle; margin: 0 2px; border-top: 2px solid var(--blue-500); }
.legend-dashed { border-top-style: dashed; border-color: #f59e0b; }

.network { position: relative; width: 100%; }
.network-edges { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }

.edge {
  fill: none; stroke: var(--blue-500); stroke-width: 1.6; stroke-linecap: round;
  opacity: .22; transition: opacity .25s, stroke-width .25s;
}
.edge.is-cross { stroke: #f59e0b; stroke-dasharray: 5 5; opacity: .45; }
.edge.is-dim { opacity: .05; }
.edge.is-hot { opacity: .95; stroke-width: 3; }

.node {
  position: absolute; z-index: 2;
  width: 92px; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px 8px;
  text-align: center;
  background: rgba(255, 255, 255, .9);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  transition: transform .3s var(--ease-out), opacity .25s, filter .25s, border-color .2s, box-shadow .2s;
}
.node-name {
  width: 100%; font-size: 11px; font-weight: 800; color: var(--ink); line-height: 1.5;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 2px;
}
.node-title { display: none; }
.node.is-dim { opacity: .2; filter: grayscale(.85); }
.node.is-hot { z-index: 3; border-color: var(--blue-500); box-shadow: var(--shadow-md); transform: translate(-50%, -50%) scale(1.08); }
.node:active { transform: translate(-50%, -50%) scale(.96); }

/* --------------------------------------------------------------------------
   Bottom sheet
   -------------------------------------------------------------------------- */
.sheet-root { position: fixed; inset: 0; z-index: 100; }

.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .3s ease;
}

.sheet {
  --drag: 0px;
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: column;
  max-height: 92vh; max-height: 92dvh;
  background: var(--surface);
  border-radius: 28px 28px 0 0;
  box-shadow: var(--shadow-sheet);
  transform: translateY(100%);
  transition: transform .42s var(--ease-out);
  outline: none;
  overflow: hidden;
}
.sheet-root.is-open .sheet-backdrop { opacity: 1; }
.sheet-root.is-open .sheet { transform: translateY(var(--drag)); }
.sheet.is-dragging { transition: none; }

.sheet-grab {
  position: relative; flex-shrink: 0;
  height: 36px; display: grid; place-items: center;
  touch-action: none; cursor: grab;
}
.sheet-handle { width: 44px; height: 5px; border-radius: 99px; background: #cbd5e1; }
.sheet-close {
  position: absolute; top: 10px; left: 12px;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--muted); background: var(--line-soft);
  transition: background .2s, color .2s;
}
.icon-btn:hover { background: var(--line); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

.sheet-body {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
  padding: 6px 20px 20px;
}

/* Profile content */
.profile-head { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 4px 0 22px; }
.profile-head .avatar-lg { margin-bottom: 12px; }
.profile-cat {
  font-size: 11.5px; font-weight: 700; color: var(--blue-600);
  background: var(--blue-50); border: 1px solid var(--blue-200);
  padding: 2px 12px; border-radius: 999px; margin-bottom: 8px;
}
.profile-name { font-size: 22px; font-weight: 900; color: var(--ink); line-height: 1.5; }
.profile-title { font-size: 13.5px; font-weight: 700; color: var(--muted); }

/* Thread: the line and dots that link the sections */
.thread { position: relative; padding-inline-start: 26px; }
.thread::before {
  content: ''; position: absolute; top: 10px; bottom: 16px; inset-inline-start: 6px;
  width: 2px; border-radius: 2px;
  background: linear-gradient(to bottom, var(--blue-500), rgba(0, 85, 255, .08));
}
.thread-item { position: relative; padding-bottom: 22px; }
.thread-item::before {
  content: ''; position: absolute; top: 7px; inset-inline-start: -24px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--blue-500);
  box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--blue-50);
}
.thread-label { font-size: 12px; font-weight: 700; color: var(--subtle); margin-bottom: 8px; }

.story {
  font-size: 14px; line-height: 2; color: var(--text);
  background: #f8fafc; border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 14px 16px;
}
.topics .tag { font-size: 12.5px; padding: 5px 12px; border-radius: 11px; border: 1px solid var(--blue-100); }

.quote {
  position: relative;
  font-size: 14px; font-weight: 700; line-height: 1.95; color: var(--ink);
  background: rgba(238, 244, 255, .7); border: 1px solid var(--blue-100);
  border-radius: var(--radius); padding: 14px 16px;
}
.quote-empty { font-weight: 400; font-size: 13px; color: var(--muted); background: #f8fafc; border-color: var(--line-soft); }

.peers { display: flex; flex-direction: column; gap: 8px; }
.peer {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: start;
  padding: 8px 10px; border-radius: 16px;
  border: 1px solid var(--line-soft);
  transition: border-color .2s, background .2s;
}
.peer:hover { border-color: var(--blue-200); background: rgba(238, 244, 255, .5); }
.peer-who { min-width: 0; flex: 1; line-height: 1.5; }
.peer-name { display: block; font-size: 13px; font-weight: 800; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-title { display: block; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-arrow { width: 16px; height: 16px; color: var(--subtle); }

/* Sticky action bar */
.sheet-actions {
  flex-shrink: 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  border-top: 1px solid var(--line-soft);
}
.actions-hint { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 10px; }
.actions-row { display: flex; gap: 8px; }
.action {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 50px; min-width: 50px; padding: 0 14px;
  border-radius: 16px; border: 1px solid var(--line);
  font-size: 14px; font-weight: 800; color: var(--text); background: var(--surface);
  text-decoration: none;
  transition: background .2s, transform .1s, border-color .2s;
}
.action:active { transform: scale(.96); }
.action:hover { background: #f8fafc; }
.action svg { width: 21px; height: 21px; }
.action-primary {
  flex: 1;
  background: var(--green-600); border-color: var(--green-600); color: #fff;
  box-shadow: 0 10px 22px -10px rgba(5, 150, 105, .7);
}
.action-primary:hover { background: var(--green-700); }

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
.toast {
  position: fixed; z-index: 200; left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  max-width: calc(100% - 32px);
  padding: 11px 18px; border-radius: 16px;
  background: var(--ink); color: #fff;
  font-size: 13.5px; font-weight: 700;
  box-shadow: 0 14px 32px rgba(15, 23, 42, .28);
  transform: translate(-50%, 90px); opacity: 0; pointer-events: none;
  transition: transform .3s var(--ease-out), opacity .25s;
}
.toast.is-show { transform: translate(-50%, 0); opacity: 1; }
.toast-dot { width: 9px; height: 9px; border-radius: 50%; background: #34d399; flex-shrink: 0; }

/* --------------------------------------------------------------------------
   ≥ 640px
   -------------------------------------------------------------------------- */
@media (min-width: 640px) {
  :root { --gutter: 24px; }

  .hero { padding-top: 32px; padding-bottom: 24px; }
  .hero-lead { font-size: 16px; }

  .view-btn span { display: inline; }
  .view-btn { padding: 0 14px; }
  .search input { height: 50px; font-size: 15px; }

  .chips { flex-wrap: wrap; overflow: visible; margin-inline: 0; padding-inline: 0; }

  .cards { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .card { padding: 18px; }
  .card-intro { -webkit-line-clamp: 3; }

  .node { width: 112px; }
  .node-title {
    display: block; width: 100%; font-size: 10px; color: var(--muted); line-height: 1.5;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px;
  }
  .avatar-node { width: 56px; height: 56px; border-radius: 18px; }

  /* Sheet: a centered card that still slides up from the bottom */
  .sheet {
    left: 0; right: 0; bottom: 16px;
    width: min(520px, calc(100% - 32px));
    margin-inline: auto;
    max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px);
    border-radius: 28px;
    transform: translateY(calc(100% + 24px));
  }
  .sheet-body { padding: 6px 28px 24px; }
  .sheet-actions { padding: 14px 20px 16px; }
}

/* --------------------------------------------------------------------------
   ≥ 1024px
   -------------------------------------------------------------------------- */
@media (min-width: 1024px) {
  .cards { grid-template-columns: repeat(3, 1fr); gap: 18px; }
  .hero-title { margin-top: 8px; }
}

@media (hover: hover) {
  .node:hover { border-color: var(--blue-500); box-shadow: var(--shadow-md); }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}
