/* ============================================
   YapApp — Mobile-first PWA Styles
   ============================================ */

:root {
  --primary: #6C5CE7;
  --primary-light: #A29BFE;
  --primary-dark: #5541D7;
  --bg: #F8F9FA;
  --surface: #FFFFFF;
  --text: #2D3436;
  --text-muted: #888;
  --border: #E9ECEF;
  --danger: #E74C3C;
  --success: #27AE60;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
}

/* ============================================
   Header
   ============================================ */

#app-header {
  display: flex;
  flex-direction: column;
  padding: 8px 16px;
  padding-top: calc(8px + var(--safe-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  overflow: visible;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}


#header-title {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}

.icon-btn:active {
  background: var(--border);
}

.icon-btn.active {
  color: var(--primary);
}

/* Back button — hidden on touch devices (swipe-right handles navigation).
   Shown on pointer-fine (desktop/trackpad) devices when not .hidden. */
.back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--primary);
  border-radius: 8px;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.back-btn:active { opacity: 0.6; }
@media (hover: hover) and (pointer: fine) {
  .back-btn:not(.hidden) { display: flex; }
}


/* ============================================
   Hamburger Menu
   ============================================ */

.hamburger-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  z-index: 200;
  overflow: hidden;
}

.hamburger-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
}

.hamburger-avatar-wrap {
  flex-shrink: 0;
}

.hamburger-display-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hamburger-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

.hamburger-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 13px 16px;
  background: transparent;
  border: none;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
}

.hamburger-item:active {
  background: var(--border);
}

.hamburger-sign-out {
  color: var(--danger, #e74c3c);
}

/* ============================================
   Avatars
   ============================================ */

.avatar-small {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-large {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  color: white;
  font-weight: 700;
  font-size: 14px;
}

.avatar-large.avatar-placeholder {
  font-size: 32px;
}

/* ============================================
   Layout helpers
   ============================================ */

.hidden { display: none !important; }

.page-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  gap: 16px;
  text-align: center;
  min-height: 50vh;
}

.error-state-msg {
  font-weight: 600;
  color: var(--text);
}

.page-pad {
  padding: 16px;
}

.text-muted { color: var(--text-muted); }
.text-small { font-size: 13px; }
.subtitle { color: var(--text-muted); font-size: 15px; }

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-small {
  padding: 8px 16px;
  font-size: 14px;
}

.btn-google {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* ============================================
   Landing
   ============================================ */

.landing-logo {
  width: 80px;
  height: 80px;
  border-radius: 20px;
  background: var(--primary);
  color: white;
  font-size: 40px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   Auth Form (landing page)
   ============================================ */

.auth-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.auth-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-full {
  width: 100%;
}

.auth-switch {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.auth-switch a {
  color: var(--primary);
  text-decoration: none;
}

.auth-error {
  text-align: center;
  font-size: 13px;
  color: var(--danger);
  padding: 8px;
  border-radius: var(--radius-sm);
  background: rgba(231, 76, 60, 0.08);
}

/* ============================================
   Forms
   ============================================ */

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}

.form-input {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  background: var(--surface);
  resize: none;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus {
  border-color: var(--primary);
}

/* ============================================
   Topic list
   ============================================ */

.topic-list {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.topic-card {
  display: flex;
  flex-direction: column;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.topic-card-main {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topic-card-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
  text-decoration: none;
}

.topic-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.topic-card-thumb-empty {
  background: var(--border);
}

.topic-card-title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.topic-card-title {
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-challenge-note {
  font-size: 12px;
  color: var(--primary, #3b82f6);
  font-weight: 500;
  display: block;
}

.topic-challenge-note .chal-status,
.topic-challenge-note .chal-title {
  display: block;
}

.chal-title {
  color: #f59e0b;
  font-weight: 600;
}

.new-posts-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  height: 22px;
  border-radius: 11px;
  flex-shrink: 0;
  white-space: nowrap;
}

.topic-card-actions {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 10px;
  margin-top: 10px;
  border-top: 1px solid var(--border);
}

.topic-action-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
  line-height: 1.4;
}

.topic-action-btn:active {
  opacity: 0.6;
}

.topic-action-btn.active {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(108, 92, 231, 0.08);
}

.topic-action-add {
  border-color: var(--success);
  color: var(--success);
}

.drag-handle {
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  color: var(--text-muted);
  cursor: grab;
  padding: 4px 2px;
  flex-shrink: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.topic-list.edit-feeds-mode .drag-handle {
  display: flex;
}

.topic-list.edit-feeds-mode .topic-card-actions {
  display: flex;
}

.topic-list.edit-feeds-mode .new-posts-badge {
  display: none;
}

.topic-card.dragging {
  opacity: 0.4;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}

/* ============================================
   FAB (floating action button)
   ============================================ */

.fab {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 28px;
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.3);
  transition: transform 0.15s;
  z-index: 50;
}

.fab:active { transform: scale(0.9); }

/* ============================================
   Topic view / Posts
   ============================================ */

.topic-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topic-desc-bar {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-muted);
}

.ptr-indicator {
  height: 0;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.ptr-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  opacity: 0.35;
  transition: opacity 0.15s;
}

.ptr-indicator.ptr-ready .ptr-spinner {
  opacity: 1;
}

.ptr-indicator.ptr-loading .ptr-spinner {
  opacity: 1;
  animation: spin 0.6s linear infinite;
}

.posts-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 140px;
}

.post-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

@keyframes post-highlight-fade {
  0%   { box-shadow: 0 0 0 3px var(--primary); }
  100% { box-shadow: var(--shadow); }
}

.post-card.post-highlight {
  animation: post-highlight-fade 2s ease-out forwards;
}

.badge-new {
  display: inline-flex;
  align-items: center;
  background: var(--primary);
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 8px;
  flex-shrink: 0;
  margin-bottom: 4px;
}

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

.post-author {
  font-size: 14px;
  font-weight: 600;
}

.post-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

.post-body {
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}

.post-photo-wrap {
  margin: 8px -14px;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--bg-secondary, #f5f5f5);
}

.post-photo {
  width: 100%;
  height: 100%;
  display: block;
  max-height: 500px;
  object-fit: contain;
}

.post-location {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.post-location::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5'%3E%3Cpath d='M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z'/%3E%3Ccircle cx='12' cy='10' r='3'/%3E%3C/svg%3E") no-repeat center;
}

/* ============================================
   Reactions
   ============================================ */

.reaction-bar {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.reaction-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 15px;
  cursor: pointer;
  transition: all 0.15s;
  min-height: 32px;
}

.reaction-btn:active { transform: scale(0.92); }

.reaction-btn.active {
  border-color: var(--primary-light);
  background: rgba(108, 92, 231, 0.08);
}

.reaction-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.reaction-btn--hidden { display: none; }
.reaction-bar.expanded .reaction-btn--hidden { display: inline-flex; }

.btn-react-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px dashed var(--border);
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-react-add:hover,
.reaction-bar.expanded .btn-react-add {
  border-color: var(--primary);
  border-style: solid;
  color: var(--primary);
}

/* ============================================
   Replies
   ============================================ */

.replies-section {
  margin-top: 8px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reply {
  padding-top: 8px;
}

.reply .post-header {
  margin-bottom: 4px;
}

.reply .avatar-small {
  width: 24px;
  height: 24px;
}

.reply-media .post-photo-wrap {
  display: inline-block;
}

.reply-media img,
.reply-media video {
  max-width: 180px;
  max-height: 180px;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
}

#media-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

#media-lightbox img,
#media-lightbox video {
  max-width: 95vw;
  max-height: 90vh;
  border-radius: 6px;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px 8px;
}

.lightbox-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 4px;
  border-radius: 2px;
}

.btn-reply {
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  background: none;
  border: 1px solid var(--primary);
  color: var(--primary);
  margin-left: auto;
  margin-top: 6px;
}

.btn-reply:hover {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.post-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  position: relative;
}

.post-footer-actions {
  display: flex;
  align-items: center;
}

/* ⋯ overflow menu */
.btn-post-menu {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  padding: 0 4px;
  letter-spacing: 1px;
  line-height: 1;
  border-radius: 4px;
}
.btn-post-menu:hover { color: var(--text); background: var(--bg); }

.post-actions-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 100;
  min-width: 140px;
  overflow: hidden;
}

.post-action-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
.post-action-item:hover { background: var(--bg); }
.post-action-item.btn-delete-post { color: var(--danger); }

/* Reply delete ✕ icon */
.btn-delete-icon {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  opacity: 0.45;
  padding: 2px 4px;
  line-height: 1;
}
.btn-delete-icon:hover { color: var(--danger); opacity: 1; }

.crosspost-origin-badge {
  display: inline-block;
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 8px;
}

.crosspost-topic-list {
  list-style: none;
  margin: 0;
  padding: 0 0 env(safe-area-inset-bottom);
}
.crosspost-topic-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.crosspost-topic-item.crosspost-linked { opacity: 0.55; }
.crosspost-topic-title { flex: 1; font-size: 15px; }
.crosspost-check { font-size: 13px; color: var(--text-muted); }

/* ============================================
   Post form
   ============================================ */

.post-form--hidden { display: none; }

.btn-fab-post {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 32px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  z-index: 89;
}
.btn-fab-post.hidden { display: none; }
.btn-fab-post:active { transform: scale(0.94); }

.btn-form-dismiss {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 20px;
  padding: 0 6px;
  margin-right: auto;
  line-height: 1;
}
.btn-form-dismiss:hover { color: var(--text); }

.post-form-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  padding-bottom: calc(10px + var(--safe-bottom));
  z-index: 90;
}

.post-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.post-form-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.post-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
}

.post-input:focus {
  border-color: var(--primary);
}

.photo-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
}

.post-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

/* Photo preview */
.photo-preview-item {
  position: relative;
  display: inline-block;
}

.photo-preview-item img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.photo-remove-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: white;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  cursor: pointer;
  color: var(--text-muted);
  flex-shrink: 0;
}

.attach-wrap {
  position: relative;
  flex-shrink: 0;
}

.attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  cursor: pointer;
  color: var(--text-muted);
}

.video-preview {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.post-video-wrap {
  margin: 8px -14px;
  position: relative;
}

.post-video {
  width: 100%;
  display: block;
  max-height: 500px;
  background: #000;
  cursor: pointer;
}

.video-anim-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.post-video-wrap:not(.video-not-started) .video-anim-preview {
  display: none;
}

.video-play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: rgba(0,0,0,0.15);
}

.video-play-overlay-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.video-play-overlay:hover .video-play-overlay-btn {
  background: rgba(0,0,0,0.75);
}

.video-play-overlay-btn svg {
  margin-left: 4px;
}

.video-not-started .video-controls {
  display: none;
}

.post-video-wrap:not(.video-not-started) .video-play-overlay {
  display: none;
}

.video-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.55));
  pointer-events: none;
}

.video-controls > * {
  pointer-events: auto;
}

.video-play-btn,
.video-fs-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  line-height: 1;
  padding: 2px;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0.9;
}

.video-progress {
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,0.35);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
}

.video-progress-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: #fff;
  border-radius: 2px;
  pointer-events: none;
}

.post-video-processing {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Reply indicator */
#reply-indicator {
  font-size: 13px;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.reply-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border-left: 3px solid var(--primary);
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--text-secondary, var(--text-muted));
}

.reply-preview-photo {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.reply-preview-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}

.cancel-reply {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Sign in prompt */
.sign-in-prompt {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-bottom));
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 14px;
  color: var(--text-muted);
}

/* ============================================
   Profile page
   ============================================ */

.profile-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding-top: 40px;
}

.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.profile-card h2 {
  font-size: 22px;
}

/* ============================================
   Toast
   ============================================ */

/* ============================================
   App Overlay Banner
   ============================================ */

#app-overlay-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 500;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 12px 16px;
  padding-top: calc(12px + var(--safe-top));
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  animation: slideDown 0.25s ease;
}

#app-overlay-banner.hidden { display: none; }

#app-overlay-banner .overlay-msg { flex: 1; }

#app-overlay-banner .overlay-dismiss {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

@keyframes slideDown {
  from { transform: translateY(-100%); }
  to   { transform: translateY(0); }
}

/* Push page content down when banner is visible */
body.has-overlay #nav { top: var(--overlay-height, 48px); }
body.has-overlay #content { padding-top: calc(var(--header-height, 56px) + var(--overlay-height, 48px)); }

.toast {
  --toast-slide: 16px;
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(var(--toast-slide));
  background: var(--primary);
  color: #fff;
  padding: 14px 22px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 500;
  max-width: min(320px, calc(100vw - 32px));
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-note {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 5px;
}

/* ============================================
   Spinner
   ============================================ */

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.posts-sentinel {
  height: 1px;
}
.posts-sentinel.loading {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   Scrollbar (subtle)
   ============================================ */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ============================================
   Main content area
   ============================================ */

#app-content {
  flex: 1;
  overflow-y: auto;
}

/* ============================================
   Photo Search Modal
   ============================================ */

.ps-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: var(--safe-bottom);
}

.ps-modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.ps-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--border);
}

.ps-title {
  font-size: 17px;
  font-weight: 700;
}

.ps-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--border);
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.ps-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ps-hint {
  font-size: 14px;
  color: var(--text-muted);
}

.ps-upload-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  transition: background 0.15s;
}

.ps-upload-btn:active {
  background: rgba(108, 92, 231, 0.06);
}

.ps-preview {
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.ps-preview-img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
  border-radius: var(--radius-sm);
}

.ps-status {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 0;
}

.ps-result {
  margin-top: 4px;
}

/* Found state */
.ps-found {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ps-found-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--success);
}

.ps-pct {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 13px;
}

.ps-match-photo {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.ps-match-meta {
  font-size: 13px;
  color: var(--text-muted);
}

.ps-more-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* No match state */
.ps-no-match {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 0;
  text-align: center;
}

.ps-no-match-msg {
  font-size: 15px;
  font-weight: 600;
}

.ps-no-match-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

/* Error */
.ps-error {
  font-size: 14px;
  color: var(--danger);
  text-align: center;
  padding: 8px;
  background: rgba(231, 76, 60, 0.08);
  border-radius: var(--radius-sm);
}

/* Post highlight on scroll-to */
@keyframes ps-pulse {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 0 0 3px var(--primary-light); }
}

.ps-highlight {
  animation: ps-pulse 0.6s ease 2;
}

/* ============================================
   Settings section (profile page)
   ============================================ */

.settings-section {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.threshold-slider {
  width: 100%;
  margin-top: 6px;
  accent-color: var(--primary);
}

/* ============================================
   Topic behavior config (new-topic form)
   ============================================ */

.behavior-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
}

.behavior-toggle-icon {
  font-size: 12px;
}

.behavior-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.behavior-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.behavior-group-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.behavior-options {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.behavior-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

.behavior-options input[type="radio"] {
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
}

/* ============================================
   Rating slider input (post form)
   ============================================ */

.rating-input {
  padding: 6px 0 2px;
}

.rating-readout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 6px;
}

.rating-face {
  font-size: 28px;
  line-height: 1;
  transition: filter 0.15s;
}

.rating-num {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 28px;
  text-align: center;
}

.rating-num.negative { color: #e74c3c; }
.rating-num.positive { color: #27ae60; }

.rating-track-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rating-pole {
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.rating-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: #e0e0e0;
  outline: none;
  cursor: pointer;
}

.rating-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #888;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  transition: background 0.15s, transform 0.1s;
}

.rating-slider:active::-webkit-slider-thumb {
  transform: scale(1.15);
}

.rating-slider.negative::-webkit-slider-thumb {
  background: #e74c3c;
}

.rating-slider.positive::-webkit-slider-thumb {
  background: #27ae60;
}

.rating-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #888;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

.rating-required {
  display: block;
  font-size: 12px;
  color: var(--danger);
  margin-top: 4px;
}

.photo-required svg {
  stroke: var(--primary);
}

/* ============================================
   Post: rating display & image description
   ============================================ */

.post-rating {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.post-rating-emoji {
  font-size: 20px;
  line-height: 1;
}

.post-rating-value {
  font-size: 14px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
}

.post-rating-value.negative {
  color: #e74c3c;
  background: rgba(231, 76, 60, 0.1);
}

.post-rating-value.neutral {
  color: #888;
  background: rgba(136, 136, 136, 0.1);
}

.post-rating-value.positive {
  color: #27ae60;
  background: rgba(39, 174, 96, 0.1);
}

.translation-blocks { display: flex; flex-direction: column; gap: 6px; }
.translation-block { display: flex; align-items: baseline; gap: 6px; }
.lang-badge { font-size: 10px; font-weight: 700; letter-spacing: 0.05em; color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); border-radius: 3px; padding: 1px 4px; flex-shrink: 0; }
.translation-pending { font-size: 12px; margin-left: 4px; opacity: 0.6; }

.post-image-description {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border-left: 3px solid var(--primary-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ============================================
   Subscribe bar
   ============================================ */

.subscribe-bar {
  padding: 8px 16px 0;
}

.btn-subscribe {
  width: 100%;
}

.topic-photo-search-bar {
  display: flex;
  padding: 8px 16px 0;
}

/* ============================================
   Manage modal / bottom sheet
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  transition: background 0.3s;
  pointer-events: none;
}

.modal-overlay.open {
  background: rgba(0, 0, 0, 0.4);
  pointer-events: all;
}

.modal-sheet {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  -webkit-overflow-scrolling: touch;
}

.modal-overlay.open .modal-sheet {
  transform: translateY(0);
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
}

.modal-body {
  padding: 0 0 calc(24px + var(--safe-bottom));
}

.manage-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.manage-section:last-child {
  border-bottom: none;
}

.manage-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.manage-danger {
  background: rgba(231, 76, 60, 0.04);
}

.danger-title {
  color: var(--danger);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

/* Subscribers list */

.subscribers-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 32px;
}

.subscriber-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.subscriber-name {
  flex: 1;
  font-size: 14px;
}

.btn-remove-subscriber {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: color 0.15s;
}

.btn-remove-subscriber:hover {
  color: var(--danger);
}

.add-subscriber-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-subscriber-row .form-input {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
}

.spinner-small {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 4px auto;
}

.text-danger {
  color: var(--danger);
}

/* ============================================
   Add Yappers sheet
   ============================================ */

.yappers-topic-label {
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 16px 8px;
  border-bottom: 1px solid var(--border);
}

.yapper-list {
  list-style: none;
  padding: 0;
}

.yapper-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.yapper-item:last-child {
  border-bottom: none;
}

.yapper-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================
   YapBot Admin (Control Room)
   ============================================ */

.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
}

.admin-section h3 {
  margin: 0 0 0.75rem 0;
  font-size: 15px;
}

.person-config {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}

.person-config:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.person-config-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.person-config-header strong {
  flex: 1;
}

.config-form {
  padding-top: 0.25rem;
}

/* ============================================
   Notification History Page
   ============================================ */

.notif-history-page {
  padding: 0.5rem 0;
}

.notif-history-list {
  display: flex;
  flex-direction: column;
}

.notif-history-item {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
}

.notif-history-item:last-child {
  border-bottom: none;
}

.notif-history-item:active {
  background: var(--surface);
}

.notif-history-icon {
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 0.1rem;
}

.notif-history-body {
  flex: 1;
  min-width: 0;
}

.notif-history-title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.15rem;
}

.notif-history-preview {
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.2rem;
}

.notif-history-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

