:root {
  --bg-base: #111315;
  --bg-surface: #1a1e21;
  --bg-surface-elevated: #22272b;
  --bg-surface-hover: #293036;
  --bg-input: #14171a;
  --border-subtle: #2b3238;
  --border-strong: #3d464f;
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent: #1bb76e;
  --accent-hover: #169b5d;
  --accent-subtle: rgba(27, 183, 110, 0.12);
  --accent-glow: rgba(27, 183, 110, 0.25);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --max-width: 1200px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(17, 19, 21, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 20px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: -0.5px;
}

.logo-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  margin-left: 2px;
}

.header-search {
  flex: 1;
  max-width: 360px;
  display: flex;
  align-items: center;
  position: relative;
}

.header-search input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 8px 36px 8px 14px;
  border-radius: var(--radius-full);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.header-search input:focus {
  border-color: var(--accent);
}

.header-search button {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link {
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link:hover, .nav-link.active {
  color: var(--text-primary);
  background: var(--bg-surface-elevated);
}

.nav-link.active {
  color: var(--accent);
}

.btn-upload-nav {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background-color 0.2s, transform 0.1s;
}

.btn-upload-nav:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

/* User Menu Dropdown */
.user-menu-root {
  position: relative;
}

.user-avatar-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 4px 10px 4px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
}

.user-avatar-btn img {
  width: 26px;
  height: 26px;
  border-radius: var(--radius-full);
  background: #000;
}

.user-avatar-btn .msg-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: var(--radius-full);
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  display: none;
  flex-direction: column;
  z-index: 200;
}

.dropdown-panel.show {
  display: flex;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--text-secondary);
  font-size: 14px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.dropdown-item:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

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

/* Main Layout */
.main-content {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 16px 64px 16px;
}

/* Explore Hero & Quick Upload Invitation */
.hero-upload-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  margin-bottom: 32px;
  position: relative;
  overflow: hidden;
}

.hero-dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 28px 20px;
  cursor: pointer;
  background: rgba(20, 23, 26, 0.4);
  transition: all 0.2s;
}

.hero-dropzone:hover, .hero-dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.hero-dropzone i {
  font-size: 36px;
  color: var(--accent);
  margin-bottom: 12px;
}

.hero-dropzone h2 {
  margin: 0 0 6px 0;
  font-size: 20px;
  font-weight: 700;
}

.hero-dropzone p {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

/* Filter / Tabs Bar */
.feed-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.tabs-group {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 4px;
  gap: 2px;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* Natural media sizes; enhanced to compact rows by gallery-layout.js. */
.gallery-grid {
  --gallery-gap: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: var(--gallery-gap);
  align-items: start;
  width: 100%;
}

.gallery-grid.is-masonry {
  grid-auto-rows: 4px;
  row-gap: 0;
  /* Normal placement preserves feed and keyboard order; do not use dense. */
}

.gallery-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
  position: relative;
}

.gallery-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.gallery-media-wrap {
  width: 100%;
  background: #0a0b0d;
  display: block;
  overflow: hidden;
  position: relative;
}

.gallery-media-wrap img, .gallery-media-wrap video {
  width: 100%;
  height: auto;
  display: block;
}

.gallery-video-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

.gallery-card-meta {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.meta-score {
  color: var(--accent);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 4px;
}

.meta-views {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Post View Page */
.post-view-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 960px;
  margin: 0 auto 32px auto;
  box-shadow: var(--shadow-md);
}

.post-media-container {
  background: #08090a;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 75vh;
  margin-bottom: 20px;
}

.post-media-container img, .post-media-container video {
  display: block;
  height: auto;
  max-width: 100%;
  max-height: 75vh;
  object-fit: contain;
}

.post-author-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.post-author {
  display: flex;
  align-items: center;
  gap: 12px;
}

.post-author img {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: 2px solid var(--accent);
  background: #000;
}

.post-author-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.post-date {
  font-size: 13px;
  color: var(--text-muted);
}

.post-description {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  margin-bottom: 20px;
  white-space: pre-wrap;
  word-break: break-word;
}

.tag-link {
  color: var(--accent);
  font-weight: 600;
}

.tag-link:hover {
  text-decoration: underline;
}

/* Post Actions Toolbar */
.post-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border-subtle);
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.vote-box {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 2px 6px;
}

.vote-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-full);
  transition: all 0.15s;
}

.vote-btn:hover {
  color: var(--text-primary);
}

.vote-btn.active-up {
  color: var(--accent);
}

.vote-btn.active-down {
  color: var(--danger);
}

.vote-score {
  font-size: 14px;
  font-weight: 700;
  padding: 0 4px;
  min-width: 24px;
  text-align: center;
}

.btn-action {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-action:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-strong);
}

.btn-action.active {
  background: var(--accent-subtle);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-action.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-action.primary:hover {
  background: var(--accent-hover);
}

/* Reactions popover/drawer */
.reactions-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 16px 0;
  padding: 8px 12px;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-full);
  width: fit-content;
}

.reaction-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  transition: transform 0.1s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.reaction-btn:hover {
  transform: scale(1.2);
}

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

/* One React control; the emoji choices open above it. */
.react-wrap {
  position: relative;
  display: inline-flex;
}

.react-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  display: flex;
  gap: 2px;
  padding: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  z-index: 40;
}

.react-menu[hidden] {
  display: none;
}

.react-menu .reaction-btn {
  padding: 6px 10px;
}

@media (max-width: 480px) {
  .react-menu {
    left: auto;
    right: 0;
  }
}

/* Comments */
.comments-container {
  max-width: 960px;
  margin: 0 auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.comments-container h3 {
  margin: 0 0 16px 0;
  font-size: 18px;
  font-weight: 700;
}

.comment-form textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  min-height: 70px;
  margin-bottom: 10px;
  outline: none;
}

.comment-form textarea:focus {
  border-color: var(--accent);
}

.comment-card {
  padding: 12px 14px;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
}

.comment-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 13px;
}

.comment-author-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--accent);
}

.comment-author-info img {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #000;
}

.comment-time {
  color: var(--text-muted);
  font-size: 12px;
}

.comment-body {
  font-size: 14px;
  color: var(--text-primary);
  white-space: pre-wrap;
  line-height: 1.5;
}

/* Modal Framework */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-overlay.open {
  display: flex;
}

.modal-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

/* Upload Queue Items */
.upload-queue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.queue-thumb-card {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #0a0b0d;
  aspect-ratio: 1;
  border: 1px solid var(--border-subtle);
}

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

.queue-remove-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.7);
  border: none;
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.queue-remove-btn:hover {
  background: var(--danger);
}

/* Progress bar */
.upload-progress-wrap {
  margin-top: 16px;
  display: none;
}

.progress-bar-track {
  width: 100%;
  height: 8px;
  background: var(--bg-input);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}

/* Success sharing modal */
.share-links-box {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  margin: 16px 0;
}

.share-link-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.share-link-row:last-child {
  margin-bottom: 0;
}

.share-link-input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  font-family: monospace;
}

/* Visible action failures (vote/save/react) */
.action-toast-host {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1500;
  width: min(420px, calc(100% - 24px));
  pointer-events: none;
}

.action-toast {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--danger);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .site-header {
    height: auto;
    padding: 8px 14px;
  }
  /* Let the bar wrap instead of forcing a wider-than-screen row. */
  .header-container {
    flex-wrap: wrap;
    gap: 8px 10px;
    min-width: 0;
  }
  /* Search keeps a full reachable row rather than a cut-off input. */
  .header-search {
    order: 10;
    flex: 1 0 100%;
    max-width: none;
  }
  .header-nav {
    margin-left: auto;
    gap: 4px;
  }
  .nav-link {
    padding: 8px 10px;
  }
  .nav-text {
    display: none;
  }
  .gallery-grid {
    --gallery-gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(min(160px, 100%), 1fr));
  }
  .post-view-card {
    padding: 16px;
  }
  .post-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Narrow phones: keep Explore, Following, Random, Upload and profile reachable
   within 320px instead of overflowing sideways. */
@media (max-width: 480px) {
  .site-header {
    padding: 8px 10px;
  }
  .header-nav {
    gap: 2px;
  }
  .nav-link {
    padding: 8px;
  }
  .logo {
    font-size: 17px;
    gap: 6px;
  }
  .logo-badge {
    display: none;
  }
  /* Icon-only upload button; aria-label keeps the name for assistive tech. */
  .btn-upload-nav {
    padding: 9px 11px;
  }
  .btn-upload-nav span {
    display: none;
  }
  .user-avatar-btn {
    padding: 4px;
  }
  .main-content {
    padding: 16px 12px 48px;
  }
  .post-view-card,
  .comments-container {
    padding: 14px;
  }
}
