/*
 * Elif Moments — X dark mode
 * ---------------------------
 * z-index scheme:
 *   1–100   regular content
 *   500     floating non-critical UI
 *   9000    chaos layer (flying cats, drifting memes, injections)
 *   9500    gate overlay (always on top, even over chaos)
 */

:root {
  --bg: #000000;
  --bg-soft: #16181c;
  --bg-elev: #1c1f23;
  --ink: #e7e9ea;
  --ink-soft: #71767b;
  --ink-faint: #3a3d42;
  --line: #2f3336;
  --terracotta: #e8866d;
  --terracotta-hi: #f49a7f;

  --chaos-olive: #a7b77f;
  --chaos-saffron: #efc055;
  --chaos-peach: #f2c3a8;

  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.4), 0 18px 44px rgba(0, 0, 0, 0.45);

  /* X uses Chirp on web, SF Pro on Apple apps. system-ui resolves to SF Pro on macOS/iOS. */
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  font-size: 15px;
  line-height: 1.5;
}

/* Subtle warm glow behind content */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 60% 40% at 0% 0%, rgba(232, 134, 109, 0.05) 0%, transparent 55%),
    radial-gradient(ellipse 55% 45% at 100% 100%, rgba(232, 134, 109, 0.04) 0%, transparent 55%),
    var(--bg);
  pointer-events: none;
}

/* Film grain overlay */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.95  0 0 0 0 0.92  0 0 0 0 0.87  0 0 0 0.06 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
}

.hidden { display: none !important; }

/* ─────────────── Gate ─────────────── */
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  z-index: 9500;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.gate-card {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  width: min(100%, 380px);
  text-align: center;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--line);
}

.gate-title {
  font-family: var(--sans);
  font-size: 28px;
  font-weight: 800;
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.gate-bio {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--terracotta);
  margin: 6px 0 24px;
  font-weight: 400;
}

#gate-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#gate-input {
  font-family: inherit;
  font-size: 16px;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  outline: none;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  -webkit-appearance: none;
  appearance: none;
}
#gate-input::placeholder { color: var(--ink-soft); }
#gate-input:focus { border-color: var(--terracotta); }

#gate-form button {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 13px 16px;
  border-radius: 999px;
  border: none;
  background: var(--ink);
  color: var(--bg);
  cursor: pointer;
  transition: background 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
#gate-form button:hover { background: #fff; }
#gate-form button:active { transform: scale(0.98); }

.gate-error {
  min-height: 18px;
  margin: 12px 0 0;
  color: var(--terracotta-hi);
  font-size: 14px;
  font-weight: 400;
}

/* ─────────────── App ─────────────── */
.app {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 0 max(96px, env(safe-area-inset-bottom));
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  min-height: 100dvh;
}

/* ─────────────── Profile (X-style) ─────────────── */
.profile-banner {
  width: 100%;
  height: 180px;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(232, 134, 109, 0.55) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(239, 192, 85, 0.4) 0%, transparent 55%),
    linear-gradient(135deg, #2a1812 0%, #3a1f18 40%, #4a261c 100%);
}

.profile-row {
  position: relative;
  padding: 12px 16px 0;
  min-height: 70px;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
}

.profile-avatar {
  position: absolute;
  left: 16px;
  top: -66px;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: 4px solid var(--bg);
  background: var(--terracotta);
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.profile-mark {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 700;
  font-size: 72px;
  line-height: 1;
  color: var(--bg);
  padding-bottom: 6px; /* optical centering */
}

.profile-edit {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.profile-edit:hover { background: rgba(231, 233, 234, 0.08); border-color: #40454b; }
.profile-edit:active { transform: scale(0.98); }

.profile-info {
  padding: 12px 16px 12px;
}

.profile-name {
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.profile-handle {
  font-size: 15px;
  color: var(--ink-soft);
  margin: 2px 0 0;
  font-weight: 400;
}

.profile-bio {
  font-size: 15px;
  color: var(--ink);
  margin: 12px 0 0;
  font-weight: 400;
  line-height: 1.4;
}

.profile-joined {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 12px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.profile-icon {
  flex-shrink: 0;
  opacity: 0.85;
}

.profile-stats {
  font-size: 14px;
  color: var(--ink-soft);
  margin: 12px 0 0;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.profile-stats strong {
  color: var(--ink);
  font-weight: 700;
  margin-right: 2px;
}
.profile-stats span:hover .profile-stat-label { text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.profile-tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  margin-top: 16px;
}
.profile-tab {
  flex: 1;
  padding: 16px 0;
  background: transparent;
  border: none;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  position: relative;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.profile-tab:hover:not(:disabled) { background: rgba(231, 233, 234, 0.05); color: var(--ink); }
.profile-tab.active {
  color: var(--ink);
  font-weight: 700;
}
.profile-tab.active::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 56px;
  height: 4px;
  border-radius: 999px;
  background: var(--terracotta);
}
.profile-tab:disabled { color: var(--ink-faint); cursor: default; }

/* ─────────────── Feed ─────────────── */
.feed {
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

.moment {
  padding: 16px 0 14px;
  border-bottom: 1px solid var(--line);
  animation: rise 0.5s ease both;
  transition: background-color 0.15s;
}
.moment:last-child { border-bottom: none; }

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

.moment-head {
  font-size: 14.5px;
  color: var(--ink-soft);
  margin-bottom: 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  font-feature-settings: "tnum";
}

.moment-handle {
  color: var(--terracotta);
  font-weight: 600;
  cursor: default;
  word-break: break-all;
}
.moment-handle:hover { color: var(--terracotta-hi); text-decoration: underline; text-underline-offset: 3px; }

.moment-head .dot { color: var(--ink-soft); }

.moment-time, .moment-loc { color: var(--ink-soft); }

.moment-loc-wrap {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.moment-text {
  font-size: 15.5px;
  line-height: 1.45;
  color: var(--ink);
  margin: 0 0 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.moment-media {
  margin-top: 4px;
}

/* ─────────────── Carousel ─────────────── */
.carousel {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  aspect-ratio: 1 / 1;
  touch-action: pan-y;
}

.carousel-track {
  display: flex;
  height: 100%;
  width: 100%;
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.3, 1);
  will-change: transform;
}

.carousel-slide {
  flex: 0 0 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.carousel-slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.carousel-slide.placeholder {
  background: linear-gradient(135deg, #3a2620 0%, var(--terracotta) 100%);
}

.carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0 0 3px;
  opacity: 0;
  transition: opacity 0.2s, background 0.15s;
  z-index: 2;
  -webkit-tap-highlight-color: transparent;
  font-family: var(--sans);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.carousel-prev { left: 10px; }
.carousel-next { right: 10px; }

.carousel:hover .carousel-nav { opacity: 1; }
.carousel-nav:hover { background: rgba(0, 0, 0, 0.85); }
.carousel-nav:disabled { opacity: 0 !important; cursor: default; }

.carousel-dots {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
  z-index: 2;
}

.carousel-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.carousel-dot.active { background: #fff; transform: scale(1.2); }

@media (hover: none) {
  .carousel-nav { display: none; }
}

/* ─────────────── Empty / Footer ─────────────── */
.empty {
  font-family: var(--sans);
  font-size: 15.5px;
  color: var(--ink-soft);
  padding: 60px 16px;
  margin: 0;
  line-height: 1.5;
  text-align: left;
}

.app-footer {
  margin: 40px 16px 0;
  padding-top: 20px;
  color: var(--ink-soft);
  font-size: 13px;
  border-top: 1px solid var(--line);
  letter-spacing: 0.01em;
}

/* ─────────────── Chaos Layer ─────────────── */
#chaos-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  overflow: hidden;
}

.chaos-cat {
  position: absolute;
  font-size: 42px;
  line-height: 1;
  will-change: transform;
  filter: drop-shadow(0 0 12px rgba(232, 134, 109, 0.25));
  animation: chaos-cat-drift 14s linear forwards;
}

@keyframes chaos-cat-drift {
  0%   { transform: translate3d(calc(100vw + 80px), 0, 0) rotate(-4deg); }
  25%  { transform: translate3d(calc(75vw), -18px, 0) rotate(2deg); }
  50%  { transform: translate3d(calc(50vw), 8px, 0) rotate(-3deg); }
  75%  { transform: translate3d(calc(25vw), -10px, 0) rotate(1deg); }
  100% { transform: translate3d(-80px, 0, 0) rotate(-5deg); }
}

/* ─────────────── Reduced motion ─────────────── */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  .chaos-cat { display: none !important; }
  .moment { animation: none; }
}

/* ─────────────── Small screens ─────────────── */
@media (max-width: 640px) {
  .app { border-left: none; border-right: none; padding: 0 0 max(80px, env(safe-area-inset-bottom)); }
}
@media (max-width: 520px) {
  .profile-banner { height: 140px; }
  .profile-avatar { width: 104px; height: 104px; top: -54px; border-width: 3px; }
  .profile-mark { font-size: 58px; padding-bottom: 4px; }
  .profile-name { font-size: 19px; }
  .moment { padding: 14px 0 12px; }
  .moment-head { font-size: 14px; }
  .moment-text { font-size: 15px; }
  .chaos-cat { font-size: 36px; }
}
