:root {
  --bg: #0b0b14;
  --panel: rgba(255,255,255,0.06);
  --panel-strong: rgba(20,20,32,0.92);
  --text: #f2f2f7;
  --muted: #9a9ab0;
  --accent: #7c5cff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(600px circle at 20% 20%, rgba(124,92,255,0.18), transparent 60%),
    radial-gradient(700px circle at 80% 30%, rgba(255,92,138,0.14), transparent 60%),
    radial-gradient(600px circle at 50% 90%, rgba(92,217,255,0.12), transparent 60%);
  pointer-events: none;
}

#field {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
  backdrop-filter: blur(14px);
  background: rgba(11,11,20,0.5);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.brand {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.brand span { color: var(--muted); font-weight: 500; }

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 1;
  min-width: 0;
}

.menu-toggle {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

@media (max-width: 560px) {
  .topbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
  }
  .brand { font-size: 15px; }
  .menu-toggle { display: flex; }

  /* Controls collapse into a dropdown panel instead of eating two extra rows
     above the fold on every page load. position: fixed + its own z-index
     (well above .header-stack's) so it reliably paints on top of the thread
     tabs / pinned banner that live in the same fixed-positioned ancestor,
     instead of fighting stacking-context subtleties with position: absolute
     inside an already-fixed parent. */
  .topbar-controls {
    display: none;
    position: fixed;
    top: 58px;
    left: 14px;
    right: 14px;
    z-index: 50;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    background: var(--panel-strong);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 14px;
    padding: 12px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.45);
  }
  .topbar-controls.open { display: flex; }

  .tabs { order: 1; width: 100%; justify-content: space-between; }
  .tab { flex: 1; text-align: center; padding: 7px 6px; }

  .auto-refresh { order: 2; width: 100%; justify-content: space-between; }
  .auto-btn { flex: 1; padding: 6px 0; text-align: center; }

  .dash-link { order: 3; text-align: center; }
}

@media (max-width: 380px) {
  .auto-refresh { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .auto-btn { padding: 5px 0; }
}

.dash-link {
  flex-shrink: 0;
  color: var(--text);
  text-decoration: none;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  white-space: nowrap;
}
.dash-link:hover { border-color: rgba(124,92,255,0.5); }

.auto-refresh {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border-radius: 999px;
  padding: 4px;
  flex-shrink: 0;
}

.auto-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 6px 9px;
  border-radius: 999px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.auto-btn.active {
  background: var(--accent);
  color: white;
}

.tabs {
  display: flex;
  gap: 6px;
  background: var(--panel);
  padding: 4px;
  border-radius: 999px;
}

.tab {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.tab.active {
  background: var(--accent);
  color: white;
}

.header-stack {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

.thread-tabs {
  display: flex;
  gap: 6px;
  padding: 8px 20px;
  overflow-x: auto;
  background: rgba(11,11,20,0.6);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.thread-tabs.hidden { display: none; }
.thread-tab {
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.1);
  background: var(--panel);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.thread-tab.active {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

.pinned-banner {
  display: flex;
  gap: 6px;
  align-items: center;
  max-width: min(560px, calc(100% - 32px));
  margin: 10px auto 0;
  background: var(--panel-strong);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 6px;
}
.pinned-banner.hidden { display: none; }

.pinned-nav {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.pinned-nav:disabled { opacity: 0.3; cursor: default; }

.pinned-body {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  min-width: 0;
  flex: 1;
  padding: 4px 8px;
  text-decoration: none;
  color: var(--text);
  border-radius: 10px;
}
.pinned-body:hover { background: rgba(255,255,255,0.05); }
.pinned-icon { font-size: 16px; flex-shrink: 0; }
.pinned-text-wrap { min-width: 0; flex: 1; }
.pinned-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 2px;
}
.pinned-count {
  text-transform: none;
  letter-spacing: normal;
  background: var(--panel);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 10px;
}
.pinned-text {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

main {
  position: relative;
  z-index: 5;
  pointer-events: none;
}

.hero {
  padding: calc(var(--header-h, 190px) + 30px) 24px 0;
  text-align: center;
}
.hero h1 {
  font-size: clamp(24px, 5vw, 42px);
  margin: 0 0 8px;
  background: linear-gradient(90deg, #fff, #b8a8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero p {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
}

/* --- floating creatures --- */
.creature {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transform: translate(-50%, -50%);
  will-change: transform;
  touch-action: manipulation;
}

.creature-blob {
  border-radius: 42% 58% 60% 40% / 45% 45% 55% 55%;
  animation: wobble 4.5s ease-in-out infinite;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: rgba(255,255,255,0.92);
  box-shadow: 0 8px 30px -6px rgba(0,0,0,0.6), inset 0 0 20px rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  transition: transform 0.15s ease, filter 0.15s ease;
  user-select: none;
  background-size: cover;
  background-position: center;
}
.creature-blob.has-avatar {
  color: transparent;
  /* Freeze the organic wobble shape once a real photo is showing — the
     border-radius keyframes constantly reshaping the crop line looked like
     a glitching funhouse mirror on an actual face, even though it reads as
     pleasantly "alive" on a plain color gradient. */
  animation: none;
  border-radius: 38%;
  background-position: center 30%;
}
.creature:hover .creature-blob,
.creature:active .creature-blob {
  transform: scale(1.12);
  filter: brightness(1.15);
}

.creature-label {
  font-size: 11px;
  color: var(--muted);
  background: rgba(0,0,0,0.4);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  backdrop-filter: blur(4px);
}

.creature-rank {
  position: absolute;
  top: -8px;
  right: -6px;
  font-size: 16px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
}

@keyframes wobble {
  0%, 100% { border-radius: 42% 58% 60% 40% / 45% 45% 55% 55%; }
  33% { border-radius: 58% 42% 45% 55% / 55% 60% 40% 45%; }
  66% { border-radius: 50% 50% 38% 62% / 40% 55% 45% 60%; }
}

/* --- tooltip --- */
.tooltip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  background: var(--panel-strong);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  transform: translate(-50%, -130%);
  transition: opacity 0.1s ease;
}
.tooltip.hidden { display: none; }

/* --- modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
}
.modal.hidden { display: none; }

@media (min-width: 640px) {
  .modal { align-items: center; }
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--panel-strong);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 28px;
  animation: slideUp 0.25s ease;
}
@media (min-width: 640px) {
  .modal-card { border-radius: 20px; }
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  background: var(--panel);
  border: none;
  color: var(--text);
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.modal-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: white;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}
.modal-avatar.has-avatar { color: transparent; }

.modal-name { font-size: 17px; font-weight: 700; }
.modal-rank { font-size: 13px; color: var(--muted); margin-top: 2px; }

.modal-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.stat-tile {
  background: var(--panel);
  border-radius: 12px;
  padding: 10px 12px;
}
.stat-tile .num { font-size: 18px; font-weight: 700; }
.stat-tile .lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }

.modal-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.badge {
  background: rgba(124,92,255,0.15);
  border: 1px solid rgba(124,92,255,0.3);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.top-message {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s ease, transform 0.15s ease;
}
.top-message:hover {
  background: rgba(255,255,255,0.1);
  transform: translateY(-1px);
}
.top-message .tm-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.top-message .tm-likes {
  color: #ff5c8a;
  font-weight: 700;
  text-transform: none;
  letter-spacing: normal;
}
.top-message .tm-text {
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.top-message .tm-link {
  font-size: 11px;
  color: var(--accent);
}

/* --- bottom fab + leaderboard --- */
.bottom-panel {
  position: fixed;
  bottom: 48px;
  left: 0; right: 0;
  z-index: 20;
  display: flex;
  justify-content: center;
}

.fab {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 30px -8px rgba(124,92,255,0.6);
  cursor: pointer;
}

.leaderboard {
  position: fixed;
  z-index: 40;
  bottom: 0; left: 0; right: 0;
  max-height: 60vh;
  background: var(--panel-strong);
  border-radius: 20px 20px 0 0;
  border: 1px solid rgba(255,255,255,0.08);
  padding: 16px 16px 24px;
  overflow-y: auto;
}
.leaderboard.hidden { display: none; }

@media (min-width: 640px) {
  .leaderboard {
    left: auto; right: 24px; bottom: 90px;
    width: 320px;
    border-radius: 16px;
  }
}

.leaderboard-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 700;
}
.leaderboard-head button {
  background: var(--panel);
  border: none;
  color: var(--text);
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
}

#lbList {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
}
.lb-row:hover { background: var(--panel); }
.lb-rank { width: 22px; text-align: center; font-size: 13px; color: var(--muted); }
.lb-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}
.lb-avatar.has-avatar { color: transparent; }
.lb-name { flex: 1; font-size: 13px; }
.lb-count { font-size: 12px; color: var(--muted); }

@media (max-width: 480px) {
  .creature-label { max-width: 80px; }
}

.footer {
  position: fixed;
  bottom: 18px;
  left: 0; right: 0;
  z-index: 15;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}
.footer a {
  color: var(--muted);
  pointer-events: auto;
  text-decoration: none;
  font-weight: 600;
}
.footer a:hover { color: var(--text); }

.gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(11,11,20,0.85);
  backdrop-filter: blur(10px);
}
.gate.hidden { display: none; }

.gate-card {
  max-width: 380px;
  text-align: center;
  background: var(--panel-strong);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 20px;
  padding: 32px 24px;
}
.gate-icon { font-size: 40px; margin-bottom: 12px; }
.gate-card h2 { margin: 0 0 10px; font-size: 20px; }
.gate-card p { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0 0 20px; }

.gate-btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: 0 10px 30px -8px rgba(124,92,255,0.6);
}

.heartbeat {
  display: inline-block;
  color: #ff5c8a;
  animation: heartbeat 1.1s ease-in-out infinite;
  transform-origin: center;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.35); }
  30% { transform: scale(1); }
  45% { transform: scale(1.2); }
  60% { transform: scale(1); }
}
