/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--group-font, var(--font-base, 'Inter', system-ui, sans-serif));
  background: var(--group-bg-value, var(--bg));
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img, video { max-width: 100%; display: block; }

/* ── Utility ── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.muted { color: var(--text-muted); font-size: .875rem; }
.text-danger { color: var(--danger); }

hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Navbar ── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .875rem;
  padding: 1.25rem 1rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

/* Colorful gradient brand name */
.nav-brand {
  background: linear-gradient(135deg, #818cf8 0%, #a78bfa 40%, #f472b6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: clamp(1.75rem, 6vw, 2.5rem);
  font-weight: 900;
  letter-spacing: -.04em;
  line-height: 1;
  text-decoration: none;
  display: block;
}
.nav-brand:hover { text-decoration: none; filter: brightness(1.15); }

/* Large pill nav buttons */
.nav-links {
  display: flex;
  gap: .45rem;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

.nav-links a {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  padding: .55rem .95rem;
  border-radius: 14px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .01em;
  background: var(--bg);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  text-decoration: none;
  min-width: 56px;
  min-height: 52px;          /* comfortable touch target */
  transition: background .18s ease, color .18s ease,
              border-color .18s ease, transform .22s cubic-bezier(.34,1.56,.64,1),
              box-shadow .18s ease;
  white-space: nowrap;
  cursor: pointer;
}
.nav-icon  { font-size: 1.25rem; line-height: 1; }
.nav-label { font-size: .7rem; }

.nav-links a:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: translateY(-3px) scale(1.06);
  box-shadow: 0 6px 18px rgba(99,102,241,.35);
  text-decoration: none;
}
.nav-admin:hover {
  background: #f59e0b !important;
  border-color: #f59e0b !important;
  box-shadow: 0 6px 18px rgba(245,158,11,.35) !important;
}
.nav-logout:hover {
  background: var(--danger) !important;
  border-color: var(--danger) !important;
  box-shadow: 0 6px 18px rgba(239,68,68,.35) !important;
}

/* ── Main container ── */
.main-container { max-width: 860px; margin: 0 auto; padding: 1.5rem 1rem; }

/* ── Alerts ── */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: .9rem;
  border-left: 4px solid;
}
.alert-error   { background: rgba(239,68,68,.15);  border-color: var(--danger);  color: #fca5a5; }
.alert-success { background: rgba(34,197,94,.15);  border-color: var(--success); color: #86efac; }
.alert-info    { background: rgba(99,102,241,.15); border-color: var(--accent);  color: #a5b4fc; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: .875rem;
  cursor: pointer;
  transition: background .2s, border-color .2s;
  text-decoration: none;
}
.btn:hover { background: var(--border); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-danger  { background: var(--danger);  border-color: var(--danger);  color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }

/* ── Forms ── */
.form { display: flex; flex-direction: column; gap: .75rem; }

label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
textarea,
select {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg, var(--bg));
  color: var(--text);
  font-size: .9rem;
  font-family: inherit;
  transition: border-color .2s;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

select option { background: var(--surface); color: var(--text); }

/* ── Cards ── */
.auth-card,
.form-card,
.confirm-card {
  max-width: 440px;
  margin: 3rem auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
}
.auth-card h1, .form-card h1, .confirm-card h1 { margin-bottom: 1.25rem; font-size: 1.5rem; }
.auth-switch { text-align: center; margin-top: 1rem; font-size: .875rem; color: var(--text-muted); }

/* ── Dashboard ── */
.dashboard-layout { display: flex; flex-direction: column; gap: 1.5rem; }

.invitations-panel h2,
.groups-panel h2    { font-size: 1.25rem; font-weight: 700; margin-bottom: 1rem; }

.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }

.invitation-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: .5rem;
  font-size: .9rem;
}
.inv-actions { display: flex; gap: .5rem; }

.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

/* On wider screens keep cards pleasantly sized without stretching too wide */
@media (min-width: 600px) {
  .groups-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
}
@media (min-width: 900px) {
  .groups-grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
}

.group-card {
  position: relative;
  display: flex;
  align-items: flex-end;
  min-height: 150px;
  padding: 1.1rem 1rem;
  border-radius: 18px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
  overflow: hidden;
  /* Spring bounce on hover */
  transition: transform .32s cubic-bezier(.34,1.56,.64,1),
              box-shadow .28s ease,
              border-color .2s ease;
  will-change: transform;
}
.group-card:hover {
  transform: translateY(-8px) scale(1.04);
  box-shadow: 0 20px 48px rgba(0,0,0,.38);
  border-color: var(--accent);
  text-decoration: none;
}
.group-card:active {
  transform: translateY(-3px) scale(1.01);
  box-shadow: 0 8px 20px rgba(0,0,0,.28);
}

.group-name {
  position: relative;
  z-index: 1;
  font-size: 1rem;
  line-height: 1.3;
  word-break: break-word;
}

.badge {
  position: absolute;
  top: .65rem;
  right: .65rem;
  background: var(--accent);
  color: #fff;
  border-radius: 20px;
  padding: .15rem .55rem;
  font-size: .75rem;
  font-weight: 700;
  z-index: 1;
  box-shadow: 0 2px 8px rgba(99,102,241,.4);
}

.owner-crown {
  position: absolute;
  top: .65rem;
  left: .65rem;
  font-size: 1rem;
  opacity: .8;
  z-index: 1;
}

.group-bg-dot { position: absolute; inset: 0; opacity: .25; }

.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); }

/* ── Group view ── */
.group-layout { display: flex; flex-direction: column; gap: 1rem; }

.group-header {
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.group-title { font-size: 1.5rem; margin-bottom: .25rem; }
.group-desc  { color: var(--text-muted); font-size: .875rem; margin-bottom: .75rem; }
.group-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Post composer ── */
.post-composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}
.post-composer textarea {
  min-height: 80px;
  resize: vertical;
  margin-bottom: .5rem;
}
.composer-media {
  display: flex;
  gap: .5rem;
  margin-bottom: .5rem;
  flex-wrap: wrap;
}
.composer-media input { flex: 1; min-width: 200px; }
.file-upload-label {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
  font-size: .875rem;
  cursor: pointer;
  white-space: nowrap;
}
.file-upload-label:hover { background: var(--border); }

/* ── Posts feed ── */
.posts-feed { display: flex; flex-direction: column; gap: .75rem; }

.post {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  overflow: hidden;
}

.post-body { margin-bottom: .5rem; }

.post-text { line-height: 1.65; word-break: break-word; }

.post-image {
  max-width: 100%;
  max-height: 500px;
  object-fit: contain;
  border-radius: 8px;
  margin-top: .5rem;
}

.post-video, .post-audio { margin-top: .5rem; border-radius: 8px; }
.post-video { max-width: 100%; }
.post-audio { width: 100%; }

.post-link {
  display: inline-block;
  word-break: break-all;
  color: var(--accent);
}

/* ── Embeds — mobile-first, aspect-ratio based ── */

/*
 * 16:9 landscape (YouTube, Vimeo, Facebook video, Dailymotion, Twitch)
 * Mobile: full post width.  Desktop: capped so height stays ≤ ~360px.
 */
.embed-wrapper {
  width: 100%;
  max-width: 640px;   /* at 640px wide → 360px tall (16:9) */
  margin: .5rem auto 0;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}
.embed-wrapper iframe {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: none;
}

/*
 * 9:16 portrait (YouTube Shorts)
 * Width is capped at 260px → height ≈ 462px.
 * On narrow phones the width shrinks and height follows proportionally.
 */
.embed-portrait-outer {
  width: min(260px, 100%);
  margin: .5rem auto 0;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
.embed-portrait-outer iframe {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  border: none;
}

/*
 * TikTok (9:16 portrait, slightly wider for their UI chrome)
 * Width capped at 320px → height ≈ 568px.
 */
.embed-tiktok {
  width: min(320px, 100%);
  margin: .5rem auto 0;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
.embed-tiktok iframe {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  border: none;
}

/*
 * SoundCloud — fixed-height bar, full post width, max 640px
 */
.embed-soundcloud {
  display: block;
  width: 100%;
  max-width: 640px;
  height: 166px;
  margin: .5rem auto 0;
  border: none;
  border-radius: 10px;
}

/*
 * Spotify — track bar (80px) or album/playlist panel (232px on mobile, 352px on desktop)
 */
.embed-spotify {
  display: block;
  width: 100%;
  max-width: 640px;
  margin: .5rem auto 0;
  border: none;
  border-radius: 12px;
}

/*
 * Instagram post / reel — square-ish, max 400px wide
 */
.embed-instagram {
  display: block;
  width: min(400px, 100%);
  height: clamp(420px, 70vw, 505px);
  margin: .5rem auto 0;
  border: none;
  border-radius: 12px;
}

/*
 * Twitter/X — auto height from widget.js, max readable width
 */
.embed-tweet {
  margin: .5rem auto 0;
  max-width: min(550px, 100%);
}
.embed-tweet .twitter-tweet {
  margin: 0 !important;
}

.post-meta {
  display: flex;
  gap: .75rem;
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: .5rem;
}
.post-edited { font-style: italic; }

/* ── New post slide-in animation ── */
@keyframes postSlideIn {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.post-new {
  animation: postSlideIn .28s ease-out forwards;
}

/* ── Post hover actions (shoulder-surf protection) ── */
.post-actions {
  position: absolute;
  top: .5rem;
  right: .5rem;
  display: flex;
  gap: .25rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.post:hover .post-actions {
  opacity: 1;
  pointer-events: auto;
}
.btn-icon {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .25rem .4rem;
  font-size: .85rem;
  cursor: pointer;
  transition: background .15s;
  line-height: 1;
}
.btn-edit:hover   { background: var(--accent);  color: #fff; border-color: var(--accent); }
.btn-delete:hover { background: var(--danger);  color: #fff; border-color: var(--danger); }

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem;
  width: 100%;
  max-width: 500px;
  margin: 1rem;
}
.modal-box h3 { margin-bottom: 1rem; }
.modal-box textarea { min-height: 100px; margin-bottom: .5rem; }
.modal-actions { display: flex; gap: .5rem; margin-top: .75rem; }

/* ── Account settings ── */
.settings-layout { max-width: 600px; margin: 0 auto; }
.settings-section { padding: 1.25rem 0; }
.settings-section h2 { margin-bottom: .75rem; font-size: 1rem; }
.reveal-box {
  padding: .75rem 1rem;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: .9rem;
}

/* ── Admin ── */
.admin-layout { max-width: 100%; }
.admin-layout h1 { margin-bottom: 1rem; }
.admin-nav { display: flex; gap: .75rem; flex-wrap: wrap; margin: 1rem 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .75rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  text-align: center;
}
.stat-num   { display: block; font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-label { display: block; font-size: .8rem; color: var(--text-muted); }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
}
.admin-table th,
.admin-table td {
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
.admin-table th { background: var(--surface); font-weight: 600; }
.admin-table tr:hover td { background: rgba(255,255,255,.03); }
.row-deleted { opacity: .5; }
.badge-admin {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-size: .65rem;
  border-radius: 4px;
  padding: 1px 4px;
  vertical-align: middle;
}

.filter-form { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-form input { flex: 1; min-width: 200px; }

.pagination { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: 1rem; }
.pagination a {
  display: inline-block;
  padding: .3rem .6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .8rem;
  color: var(--text-muted);
}
.pagination a.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Reaction bar ────────────────────────────────────────────────────── */
.reaction-bar {
  display: flex;
  align-items: center;
  gap: .45rem;
  flex-wrap: wrap;
  margin-top: .65rem;
  padding-top: .6rem;
  border-top: 1px solid var(--border);
  position: relative;       /* anchor for the picker */
}

.reaction-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  flex: 1;
  min-height: 26px;         /* prevent layout jump when empty */
}

/* ── Chips ── */
.reaction-chip {
  display: inline-flex;
  align-items: center;
  gap: .22rem;
  padding: .18rem .55rem;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-size: .85rem;
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease,
              transform .18s cubic-bezier(.34,1.56,.64,1),
              box-shadow .18s ease;
  user-select: none;
  -webkit-user-select: none;
  line-height: 1;
}

/* Start hidden — animation reveals them on viewport entry */
.reaction-bar:not(.rx-visible) .reaction-chip {
  opacity: 0;
  transform: scale(0);
  transition: none;
}

.reaction-chip:hover {
  border-color: var(--accent);
  transform: scale(1.1);
  box-shadow: 0 2px 10px rgba(99,102,241,.22);
}

.reaction-mine {
  border-color: var(--accent) !important;
  background: rgba(99,102,241,.12);
  color: var(--accent);
}

.rc-emoji { line-height: 1; font-size: .9rem; }
.rc-count {
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: .8em;
  line-height: 1;
}
.reaction-mine .rc-count { color: var(--accent); }

/* ── Keyframes ── */
@keyframes rxPop {
  from { transform: scale(0) rotate(-10deg); opacity: 0; }
  to   { transform: scale(1) rotate(0deg);   opacity: 1; }
}
@keyframes rxPopIn {
  0%   { transform: scale(0) rotate(-10deg); opacity: 0; }
  65%  { transform: scale(1.2) rotate(2deg);  opacity: 1; }
  100% { transform: scale(1) rotate(0deg);    opacity: 1; }
}
@keyframes rxPulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.45); }
  100% { transform: scale(1); }
}

/* Staggered pop-in when bar first enters viewport */
.rx-visible .reaction-chip {
  animation: rxPop .42s cubic-bezier(.34,1.56,.64,1)
             calc(var(--rx-i, 0) * 65ms) backwards;
}

/* Brand-new chip (after a toggle creates it) */
.rx-popin {
  animation: rxPopIn .36s cubic-bezier(.34,1.56,.64,1) both !important;
}

/* Bounce on the chip the user just toggled */
.rx-pulse {
  animation: rxPulse .3s cubic-bezier(.34,1.56,.64,1) !important;
}

/* ── Add (＋) button ── */
.reaction-add {
  background: transparent;
  border: 1.5px dashed var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: .85rem;
  padding: .15rem .52rem;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1.6;
  transition: border-color .18s, color .18s,
              transform .22s cubic-bezier(.34,1.56,.64,1);
}
.reaction-add:hover,
.reaction-add-active {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.1) rotate(45deg);
}

/* ── Emoji picker ── */
.reaction-picker {
  position: absolute;
  bottom: calc(100% + .5rem);
  left: 0;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .45rem;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: .25rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.42);
  /* Entry animation */
  opacity: 0;
  transform: scale(.88) translateY(8px);
  transform-origin: bottom left;
  transition: opacity .16s ease, transform .2s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}
.reaction-picker.rp-open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}
.rp-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  padding: .25rem;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
  aspect-ratio: 1;
  transition: transform .15s cubic-bezier(.34,1.56,.64,1), background .1s;
}
.rp-btn:hover {
  transform: scale(1.35);
  background: rgba(128,128,128,.12);
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .navbar { padding: 1rem .75rem .75rem; gap: .65rem; }
  /* On the smallest phones pack nav icons tighter */
  .nav-links a { min-width: 48px; padding: .5rem .6rem; }
  .nav-label { display: none; }           /* icon-only below 480px */
  /* Cards fill width on very small phones */
  .groups-grid { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
  .group-card  { min-height: 120px; }
  .composer-media { flex-direction: column; }
  .composer-media input { width: 100%; }
  .admin-table { font-size: .72rem; }
}

/* Show labels again from 481 px up (default) */
@media (min-width: 481px) {
  .nav-label { display: block; }
}

/* Desktop — constrain navbar pill row so it doesn't span the full 860px awkwardly */
@media (min-width: 700px) {
  .nav-links { max-width: 700px; }
  .nav-links a { min-width: 68px; padding: .6rem 1.1rem; }
  .nav-icon  { font-size: 1.4rem; }
  .nav-label { font-size: .72rem; }
}
