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

:root {
  --primary: #1A3A5C;
  --accent: #F5A623;
  --bg: #F4F6F9;
  --card: #FFFFFF;
  --text: #1A1A2E;
  --muted: #6B7280;
  --border: #E5E7EB;
  --danger: #EF4444;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F172A;
    --card: #1E293B;
    --text: #F1F5F9;
    --muted: #94A3B8;
    --border: #334155;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
  }
}

/* Manual theme overrides — take precedence over system preference */
[data-theme="light"] {
  --bg: #F4F6F9;
  --card: #FFFFFF;
  --text: #1A1A2E;
  --muted: #6B7280;
  --border: #E5E7EB;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

[data-theme="dark"] {
  --bg: #0F172A;
  --card: #1E293B;
  --text: #F1F5F9;
  --muted: #94A3B8;
  --border: #334155;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Theme toggle switch */
.theme-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.theme-toggle-label {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.theme-toggle-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.theme-seg {
  display: flex;
  background: var(--border);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}
.theme-seg-btn {
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.theme-seg-btn.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  /* Use dvh first; --vh fallback is set by JS excluding safe areas */
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  /* Ensure body background bleeds into bottom safe area (kills white strip) */
  background-clip: padding-box;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, textarea { font: inherit; }

/* ===== Layout ===== */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ===== Top Nav ===== */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: #fff;
  /* iOS PWA: push content below status bar */
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: 16px;
  padding-right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(56px + env(safe-area-inset-top, 0px));
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.top-nav .logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 14px 0;
}

.top-nav .logo span { color: var(--accent); }

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

.btn-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.85);
  transition: background 0.2s;
}
.btn-icon:hover { background: rgba(255,255,255,0.15); }

/* ===== Bottom Tab Nav ===== */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  /* iOS PWA: tab buttons sit above safe area; background fills the gap */
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
  /* Force paint below home indicator so no white strip shows */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}

.bottom-nav .tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
  gap: 3px;
  color: var(--muted);
  font-size: 11px;
  transition: color 0.2s;
}

.bottom-nav .tab.active { color: var(--primary); }
.bottom-nav .tab svg { width: 22px; height: 22px; }

.bottom-nav .tab.write-tab {
  position: relative;
}
.bottom-nav .tab.write-tab .write-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(245,166,35,0.4);
  margin-top: -20px;
  color: #fff;
}

/* ===== Pages Wrap ===== */
#pages-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ===== Page Sections ===== */
.page {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: 16px;
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
}

#page-detail {
  will-change: transform;
}
.page.active { display: block; }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

/* ===== Post Card ===== */
.post-card {
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.post-card:active { transform: scale(0.99); }

.post-card .post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.post-card .post-meta { flex: 1; min-width: 0; }
.post-card .post-author { font-weight: 600; font-size: 14px; }
.post-card .post-time { font-size: 12px; color: var(--muted); margin-top: 1px; }

.post-card .post-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  line-height: 1.4;
}

.post-card .post-excerpt {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.6;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-card .post-footer {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.post-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}
.post-stat svg { width: 15px; height: 15px; }

/* ===== Post Detail ===== */
#page-detail .detail-header {
  margin-bottom: 16px;
}

#page-detail .detail-title {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.35;
  margin-bottom: 10px;
}

#page-detail .detail-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

#page-detail .detail-body {
  font-size: 16px;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
}

#page-detail .detail-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  margin: 16px -16px 0;
  padding-left: 16px;
  padding-right: 16px;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 20px;
  transition: background 0.2s, color 0.2s;
}
.action-btn:hover { background: var(--bg); }
.action-btn.liked { color: #EF4444; }
.action-btn svg { width: 15px; height: 15px; }

/* ===== Comments ===== */
.comments-section h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}

.comment-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.comment-item:last-child { border-bottom: none; }

.comment-body { flex: 1; min-width: 0; }
.comment-author { font-size: 13px; font-weight: 600; }
.comment-time { font-size: 12px; color: var(--muted); }
.comment-text { font-size: 14px; line-height: 1.6; margin-top: 4px; }

.comment-form {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  align-items: flex-end;
}

.comment-form textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  resize: none;
  background: var(--bg);
  color: var(--text);
  min-height: 44px;
  max-height: 120px;
  transition: border-color 0.2s;
}
.comment-form textarea:focus { outline: none; border-color: var(--primary); }

/* ===== Write Page ===== */
#page-write .write-form { padding-top: 8px; }

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 16px;
  background: var(--card);
  color: var(--text);
  transition: border-color 0.2s;
}
.form-group input:focus,
.form-group textarea:focus { outline: none; border-color: var(--primary); }

.form-group textarea { resize: vertical; min-height: 200px; line-height: 1.7; }

.draft-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

.write-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.write-actions .btn {
  flex: 1;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-full { width: 100%; }

/* ===== Auth Pages ===== */
.auth-wrap {
  max-width: 400px;
  margin: 40px auto;
  padding: 0 16px;
  /* Extra top padding since bottom-nav is hidden on auth pages */
}

body.auth-page {
  padding-bottom: 0;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}
.auth-logo h1 { font-size: 28px; font-weight: 800; color: var(--primary); }
.auth-logo h1 span { color: var(--accent); }
.auth-logo p { color: var(--muted); margin-top: 6px; font-size: 14px; }

.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}

.auth-card h2 { font-size: 20px; font-weight: 700; margin-bottom: 20px; }

.auth-footer {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  color: var(--muted);
}
.auth-footer a { color: var(--primary); font-weight: 600; }

/* ===== Profile Page ===== */
/* ===== Me Page ===== */
.me-profile-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  margin-top: 8px;
}
.me-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
}
.me-avatar {
  width: 60px; height: 60px;
  border-radius: 50%;
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.me-avatar-edit {
  position: absolute;
  bottom: 0; right: 0;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--card);
}
.me-profile-info { flex: 1; min-width: 0; }
.me-profile-name { font-size: 17px; font-weight: 700; color: var(--text); }
.me-profile-account { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-edit-btn { flex-shrink: 0; }

/* Role badges — shared */
.role-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  vertical-align: middle;
  flex-shrink: 0;
}
.role-badge-super {
  background: linear-gradient(135deg, #1A3A5C, #2563EB);
  color: #fff;
}
.role-badge-cohort {
  background: linear-gradient(135deg, #065f46, #059669);
  color: #fff;
}

/* Avatar role ring */
.avatar-ring-super .me-avatar {
  outline: 3px solid #2563EB;
  outline-offset: 2px;
}
.avatar-ring-cohort .me-avatar {
  outline: 3px solid #059669;
  outline-offset: 2px;
}

.me-stats-card {
  display: flex;
  align-items: center;
  padding: 0;
  overflow: hidden;
}
.me-stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 8px;
  gap: 3px;
  cursor: default;
}
.me-stat-notif { cursor: pointer; color: var(--muted); }
.me-stat-notif:active { background: var(--bg); }
.me-stat-num { font-size: 20px; font-weight: 800; color: var(--primary); line-height: 1; }
.me-stat-label { font-size: 11px; color: var(--muted); }
.me-stat-divider { width: 1px; height: 32px; background: var(--border); flex-shrink: 0; }

.me-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0 8px;
}
.me-section-title { font-size: 15px; font-weight: 700; color: var(--text); }
.me-section-count { font-size: 13px; color: var(--muted); }

.me-settings-card {
  padding: 0;
  overflow: hidden;
}
.me-settings-card .theme-toggle-row {
  padding: 14px 16px;
  border-top: none;
  margin: 0;
}
.me-settings-divider {
  height: 1px;
  background: var(--border);
  margin: 0 16px;
}
.me-settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  transition: background 0.15s;
}
.me-settings-row:active { background: var(--bg); }
.me-settings-row span { flex: 1; }
.me-settings-arrow { color: var(--muted); }
.me-logout-row { color: var(--danger); }
.me-logout-row svg { stroke: var(--danger); }

/* Admin Guide Page */
.guide-item { display: flex; align-items: flex-start; gap: 12px; padding: 2px 0; }
.guide-icon { font-size: 20px; flex-shrink: 0; width: 28px; text-align: center; margin-top: 1px; }
.guide-step { display: flex; align-items: flex-start; gap: 12px; padding: 2px 0; }
.guide-step-num {
  flex-shrink: 0;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.guide-title { font-size: 14px; font-weight: 700; margin-bottom: 3px; }
.guide-desc { font-size: 13px; color: var(--muted); line-height: 1.6; }
.guide-divider { height: 1px; background: var(--border); margin: 12px 0; }

/* Keep old styles for other pages that may reference them */
.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 0 16px;
}
.profile-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  font-size: 24px;
  font-weight: 800;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.profile-info h2 { font-size: 20px; font-weight: 700; }
.profile-info p { font-size: 14px; color: var(--muted); margin-top: 2px; }
.profile-stats {
  display: flex;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.stat-item { flex: 1; text-align: center; position: relative; }
.stat-item + .stat-item::before {
  content: ''; position: absolute; left: 0; top: 20%; bottom: 20%;
  width: 1px; background: var(--border);
}
.stat-item .num { font-size: 22px; font-weight: 800; color: var(--primary); }
.stat-item .label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-item:has(.notif-stat-btn) { display: flex; align-items: center; justify-content: center; }
.notif-stat-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 10px; border-radius: 10px; color: var(--muted);
  position: relative; transition: background 0.15s;
}
.notif-stat-btn:active { background: var(--bg); }
.notif-stat-btn span {
  font-size: 11px;
  color: var(--danger);
  font-weight: 700;
  min-height: 14px;
}

/* ===== Landing Page ===== */
.landing {
  padding: 40px 0 48px;
}
.landing .share-card {
  margin-top: 10px;
  width: 100%;
  box-sizing: border-box;
}

.landing-hero {
  text-align: center;
  padding: 32px 20px 36px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.landing-logo {
  font-size: 36px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.landing-logo span { color: var(--accent); }

.landing-tagline {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

.landing-desc {
  font-size: 15px;
  color: var(--text);
  line-height: 1.7;
  margin-bottom: 28px;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.landing-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-landing {
  padding: 12px 28px;
  font-size: 16px;
  border-radius: 24px;
}

.landing-features {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.landing-feature {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.landing-feature-icon {
  font-size: 28px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 12px;
  flex-shrink: 0;
}

.landing-feature-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.landing-feature-text strong { font-size: 15px; font-weight: 700; }
.landing-feature-text span { font-size: 13px; color: var(--muted); }

/* ===== Landing Guide ===== */
.landing-guide {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 16px;
  margin-top: 10px;
}
.landing-guide-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
}
.landing-guide-steps {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.landing-guide-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.landing-guide-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.landing-guide-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.landing-guide-text strong { font-size: 14px; font-weight: 700; }
.landing-guide-text span { font-size: 13px; color: var(--muted); line-height: 1.5; }
.landing-guide-note {
  margin-top: 16px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ===== Share Card Modal ===== */
.share-card-modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  z-index: 300;
  width: min(340px, calc(100vw - 40px));
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.share-card-modal.open {
  display: block;
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}
.share-card-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  z-index: 1;
}
.share-card {
  background: linear-gradient(145deg, #1A3A5C 0%, #0f2744 100%);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.share-card-header {
  text-align: center;
  margin-bottom: 22px;
}
.share-card-logo {
  font-size: 32px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.share-card-logo span { color: #F5A623; }
.share-card-tagline {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.share-card-desc {
  font-size: 14px;
  color: rgba(255,255,255,0.85);
  line-height: 1.5;
}
.share-card-qr {
  background: #fff;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.share-card-qr img {
  width: 180px;
  height: 180px;
  display: block;
}
.share-card-url {
  font-size: 15px;
  font-weight: 700;
  color: #F5A623;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.share-card-cta {
  font-size: 13px;
  color: rgba(255,255,255,0.7);
  text-align: center;
  line-height: 1.5;
  padding: 10px 16px;
  background: rgba(255,255,255,0.08);
  border-radius: 10px;
  width: 100%;
}
/* ===== Cohort Invite Card ===== */
.cohort-invite-name {
  font-size: 15px;
  font-weight: 700;
  color: rgba(255,255,255,0.9);
  margin-top: 6px;
  letter-spacing: 0.3px;
}
.cohort-invite-code-section {
  background: rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 12px 24px;
  text-align: center;
  margin: 4px 0 12px;
  width: 100%;
  box-sizing: border-box;
}
.cohort-invite-code-label {
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.cohort-invite-code-value {
  font-size: 30px;
  font-weight: 900;
  color: #F5A623;
  letter-spacing: 5px;
  font-family: 'Courier New', monospace;
}

/* ===== Likers Row ===== */
.likers-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.likers-avatars { display: flex; }
.likers-avatars .lk-av {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 2px solid var(--card);
  margin-right: -6px;
  font-size: 10px; font-weight: 700; color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.likers-avatars .lk-av img { width: 100%; height: 100%; object-fit: cover; }
.likers-avatars .lk-av:last-child { margin-right: 0; }

/* ===== Avatar Upload ===== */
.avatar-wrap {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.avatar-wrap .avatar-edit-overlay {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s;
}
.avatar-wrap:hover .avatar-edit-overlay,
.avatar-wrap:active .avatar-edit-overlay { opacity: 1; }
.avatar-wrap .avatar-edit-overlay svg { color: #fff; }
.avatar img, .profile-avatar img {
  width: 100%; height: 100%;
  object-fit: cover; border-radius: 50%;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state svg { width: 56px; height: 56px; opacity: 0.3; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ===== Loading ===== */
.loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Like feedback ===== */
.like-particle {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  color: #EF4444;
  transform: translate(-50%, -50%);
  animation: like-burst 0.55s cubic-bezier(.2,.8,.3,1) forwards;
  user-select: none;
}
@keyframes like-burst {
  0%   { transform: translate(-50%,-50%) scale(0.2); opacity: 1; }
  40%  { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.1); opacity: 0; }
}

.like-pop {
  animation: like-pop 0.35s cubic-bezier(.3,1.6,.4,1) forwards;
}
@keyframes like-pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.45); }
  100% { transform: scale(1); }
}

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1A1A2E;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Draft Banner ===== */
.draft-banner {
  background: #FEF3C7;
  border: 1px solid #F59E0B;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  color: #92400E;
}

/* ===== Back Button ===== */
.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,0.85);
  font-size: 15px;
}

/* ===== Delete button in post ===== */
.post-admin-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}

.post-more-wrap {
  position: relative;
}

.post-more-btn {
  letter-spacing: 2px;
  padding: 5px 10px;
}

.post-more-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  min-width: 100px;
  z-index: 100;
  overflow: hidden;
}
.post-more-menu.open { display: block; }

.post-more-item {
  display: block;
  width: 100%;
  padding: 11px 16px;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
}
.post-more-item:active { background: var(--bg); }
.post-more-item.danger { color: var(--danger); }

/* ===== Misc ===== */
.text-muted { color: var(--muted); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

.delete-comment-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: auto;
}
.delete-comment-btn:hover { color: var(--danger); background: #FEE2E2; }

/* ===== Announcement Bar ===== */
#announce-bar {
  padding: 8px 16px 0;
}
.announce-inner {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  overflow: hidden;
  transition: opacity 0.15s;
}
.announce-inner:active { opacity: 0.75; }
.announce-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
}
.announce-divider {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}
.announce-viewport {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-width: 0;
  height: 20px;
}
.announce-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  line-height: 20px;
}
.announce-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.announce-arrow {
  background: var(--border);
  color: var(--muted);
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.announce-arrow:active { background: var(--primary); color: #fff; }
.announce-pager {
  font-size: 11px;
  color: var(--muted);
  min-width: 26px;
  text-align: center;
}

/* ===== Back to top ===== */
#back-to-top {
  position: fixed;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 16px);
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--card);
  border: 1.5px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
#back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
#back-to-top:active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ===== Pin badge on post cards ===== */
.pin-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(245,166,35,0.12);
  border-radius: 6px;
  padding: 2px 6px;
  margin-left: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ===== Image attachments in write form ===== */
.attach-hint {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
  margin-left: 4px;
}
.write-images-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.write-img-thumb {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}
.write-img-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.write-img-thumb .img-uploading {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
.write-img-thumb .img-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  border: none;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.attach-btn:active { border-color: var(--primary); color: var(--primary); }

/* ===== Post images in detail/feed ===== */
.post-images {
  display: grid;
  gap: 4px;
  margin-top: 12px;
  border-radius: var(--radius);
  overflow: hidden;
}
.post-images.count-1 { grid-template-columns: 1fr; }
.post-images.count-2 { grid-template-columns: 1fr 1fr; }
.post-images.count-3 { grid-template-columns: 1fr 1fr 1fr; }
.post-images.count-4 { grid-template-columns: 1fr 1fr; }
.post-images.count-many { grid-template-columns: 1fr 1fr 1fr; }
.post-images img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: opacity 0.15s;
}
.post-images img:active { opacity: 0.8; }
.post-images.count-1 img { aspect-ratio: 16/9; max-height: 280px; }

/* Thumbnail strip in feed card */
.post-thumb-strip {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  margin: 6px 0 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.post-thumb-strip::-webkit-scrollbar { display: none; }
.post-thumb-strip img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  cursor: pointer;
}

/* Lightbox */
#img-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}
#img-lightbox.open { display: flex; }
#img-lightbox img {
  max-width: 96vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}
#img-lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* ===== Pin options in write form ===== */
.pin-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0 4px;
  cursor: pointer;
}
.pin-check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}
.pin-check-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.pin-date-input {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
}
.pin-date-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== Filter Bar ===== */
#filter-bar {
  padding: 10px 0 6px;
}
.filter-chips-row {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}

/* Author chip button */
.filter-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color 0.15s, background 0.15s;
  outline: none;
}
.filter-chip.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}
.filter-chip .chip-avatar {
  width: 20px; height: 20px;
  border-radius: 50%;
  font-size: 10px; font-weight: 700; color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.filter-chip .chip-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Native select styled as filter chip */
.filter-select {
  appearance: auto;
  -webkit-appearance: auto;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}
.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}
.filter-select.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.filter-clear-chip {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #FEE2E2;
  color: var(--danger);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Author search */
.author-search-wrap {
  padding: 4px 0 12px;
}
.author-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 14px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.author-search-input:focus { border-color: var(--primary); }

/* Author picker list */
.author-picker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 55vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

/* Prevent scroll bleed-through on the mask */
.sheet-mask {
  touch-action: none;
}

.author-picker-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.author-picker-item:active { background: var(--bg); }
.author-picker-item.selected { background: var(--bg); }
.author-picker-item.selected .author-picker-name { color: var(--primary); font-weight: 700; }

.author-picker-name { font-size: 15px; font-weight: 500; flex: 1; }

.author-picker-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.author-picker-item.selected .author-picker-check {
  background: var(--primary);
  border-color: var(--primary);
}
.author-picker-item.selected .author-picker-check::after {
  content: '';
  width: 5px; height: 9px;
  border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(45deg) translateY(-1px);
  display: block;
}


/* ===== Pull to Refresh ===== */
#pull-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  transition: height 0.2s ease;
}
#pull-indicator.visible { height: 48px; }

.pull-ring {
  flex-shrink: 0;
  transform: rotate(-90deg);
}
.pull-ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 2.5;
}
.pull-ring-fg {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 56.55; /* 2π×9 */
  stroke-dashoffset: 56.55;
  transition: stroke-dashoffset 0.1s linear;
}
#pull-indicator.refreshing .pull-ring {
  animation: spin 0.7s linear infinite;
}
#pull-indicator.refreshing .pull-ring-fg {
  stroke-dashoffset: 0;
  transition: none;
}

#notif-badge {
  position: absolute;
  top: 4px; right: calc(50% - 18px);
  min-width: 16px; height: 16px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 8px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ===== Draft Card ===== */
.draft-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.15s;
}
.draft-card:active { transform: scale(0.99); }
.draft-card-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: #FEF3C7;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
}
.draft-card-body { flex: 1; min-width: 0; }
.draft-card-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.draft-card-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.draft-card-del {
  padding: 6px;
  color: var(--muted);
  border-radius: 6px;
  flex-shrink: 0;
}
.draft-card-del:hover { color: var(--danger); background: #FEE2E2; }

/* ===== Notification Items ===== */
.notif-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: transparent; }
.notif-unread-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
  margin-top: 6px;
}
.notif-unread-dot.read { background: transparent; }
.notif-body { flex: 1; min-width: 0; }
.notif-text { font-size: 14px; line-height: 1.5; }
.notif-text strong { font-weight: 700; }
.notif-post-title {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notif-time { font-size: 12px; color: var(--muted); margin-top: 3px; }


.sheet-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
}
.sheet-mask.open { display: block; }

.edit-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 201;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(24px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-width: 680px;
  margin: 0 auto;
}
.edit-sheet.open { transform: translateY(0); }

.edit-sheet-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.edit-sheet-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
}

.edit-avatar-area {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  background: var(--bg);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.edit-avatar-area:active { background: var(--border); }

.edit-sheet-avatar {
  width: 64px; height: 64px;
  font-size: 24px; font-weight: 800;
  flex-shrink: 0;
}

.edit-avatar-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.edit-avatar-action {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
}
.edit-avatar-hint {
  font-size: 12px;
  color: var(--muted);
}

/* ===== Cohort Chips ===== */
/* ===== Admin Tabs ===== */
.admin-tabs {
  display: flex;
  gap: 0;
  background: var(--bg);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.admin-tab {
  flex: 1;
  padding: 9px 0;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
  -webkit-tap-highlight-color: transparent;
}
.admin-tab.active {
  background: var(--card);
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.10);
}
.admin-tab:not(.active):hover {
  color: var(--text);
  background: rgba(0,0,0,0.04);
}

.cohort-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cohort-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.cohort-chip:active {
  opacity: 0.75;
}
