/* ========================================
   SkySearch - Modern Bluesky Search UI
   ======================================== */

:root {
  /* Colors - Light */
  --bg-primary: #f0f4f8;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-focus: #818cf8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --header-bg: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-focus: #818cf8;
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-light: rgba(99, 102, 241, 0.15);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
  --header-bg: rgba(15, 23, 42, 0.85);
}

/* ========== Reset & Base ========== */
[hidden] { display: none !important; }

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* ========== Hamburger ========== */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  flex-shrink: 0;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: all 0.25s;
}

.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ========== Mobile Menu ========== */
.mobile-menu {
  display: none;
  flex-direction: column;
  position: fixed;
  top: 57px;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  z-index: 99;
  padding: 8px 0;
  transform: translateY(-8px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s, opacity 0.2s;
}

.mobile-menu.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.mobile-menu a {
  display: block;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
}

.mobile-menu a:hover { background: var(--bg-input); }

.mobile-menu-lang {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.mobile-lang-btn {
  padding: 4px 14px !important;
  border-radius: 4px;
  font-size: 0.8rem !important;
  font-weight: 600 !important;
  border: 1.5px solid var(--border);
  color: var(--text-muted) !important;
}

.mobile-lang-btn.active {
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  color: #fff !important;
}

.mobile-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 98;
}

.mobile-menu-overlay.open { display: block; }

/* ========== Header ========== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.25rem;
}

.logo-icon {
  color: var(--accent);
}

.theme-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.theme-toggle:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

[data-theme="dark"] .icon-sun { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
.icon-sun { display: none; }
.icon-moon { display: block; }

/* ========== Main ========== */
.main {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

/* ========== Hero ========== */
.hero {
  text-align: center;
  padding: 48px 0 32px;
}

.hero-title {
  font-size: 2rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.3;
}

.hero-sub {
  color: var(--text-secondary);
  margin-top: 8px;
  font-size: 0.95rem;
}

/* ========== Search Form ========== */
.search-section {
  margin-bottom: 32px;
}

.search-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
}

.form-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.form-row:last-of-type {
  margin-bottom: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-group.flex-1 {
  flex: 1;
}

.field-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.search-cond-summary {
  max-width: 760px;
  margin: 0 auto 8px;
  padding: 0 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.label-required {
  font-size: 0.7rem;
  font-weight: 500;
  color: #f43f5e;
  margin-left: 4px;
}

.label-optional {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 4px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.input-with-prefix {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s;
}

.input-with-prefix:focus-within {
  border-color: var(--border-focus);
}

.input-prefix {
  padding: 0 0 0 12px;
  color: var(--text-muted);
  font-weight: 500;
  user-select: none;
}

.input-with-prefix input {
  border: none;
  background: none;
  padding: 10px 12px 10px 4px;
  flex: 1;
  min-width: 0;
}

.input-with-prefix input:focus {
  outline: none;
}

input, select {
  font-family: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  transition: border-color 0.2s;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  -webkit-appearance: none;
  min-height: 44px;
}

input[type="date"] {
  min-height: 44px;
  line-height: 1.2;
}

.flatpickr-wrapper {
  display: block !important;
  width: 100% !important;
}

.flatpickr-input {
  width: 100% !important;
  box-sizing: border-box !important;
  min-height: 44px !important;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--border-focus);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* Checkbox */
.form-check-group {
  justify-content: flex-end;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  user-select: none;
  padding-top: 8px;
}

.checkbox-label input[type="checkbox"] {
  display: none;
}

.checkbox-custom {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.checkbox-label input:checked + .checkbox-custom {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox-label input:checked + .checkbox-custom::after {
  content: '';
  width: 6px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* Search Button */
.btn-search {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  color: white;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-search:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
}

.btn-search:active {
  transform: translateY(0);
}

.btn-search:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ========== Profile Card ========== */
.profile-section {
  margin-bottom: 24px;
}

.profile-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.profile-banner {
  height: 120px;
  background: var(--accent-gradient);
  background-size: cover;
  background-position: center;
}

.profile-body {
  padding: 0 20px 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--bg-card);
  margin-top: -36px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-input);
}

.profile-info {
  padding-top: 8px;
  min-width: 0;
}

.profile-name {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
}

.profile-handle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.profile-link {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--accent);
  text-decoration: none;
}
.profile-link:hover {
  text-decoration: underline;
}

.profile-bio {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.5;
  word-break: break-word;
}

.profile-stats {
  display: flex;
  gap: 16px;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.profile-stats strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* ========== Results ========== */
.results-section {
  margin-bottom: 24px;
}

.results-count {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ========== Post Card ========== */
.posts-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.post-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: box-shadow 0.2s, transform 0.15s;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.post-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.post-card--sensitive > *:not(.sensitive-overlay) {
  filter: blur(20px);
  pointer-events: none;
  user-select: none;
}

.sensitive-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(0,0,0,0.08);
  backdrop-filter: blur(2px);
  z-index: 2;
  text-align: center;
  padding: 16px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.sensitive-overlay p { margin: 0; font-weight: 500; }

.btn-reveal {
  padding: 6px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

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

.post-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-input);
}

.post-author {
  min-width: 0;
  flex: 1;
}

.post-author-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-author-handle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.post-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.post-text {
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 10px;
}

.post-text a {
  color: var(--accent);
  text-decoration: none;
}

.post-text a:hover {
  text-decoration: underline;
}

/* Post Images */
.post-images {
  display: grid;
  gap: 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 10px;
}

.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; }
.post-images.count-4 { grid-template-columns: 1fr 1fr; }

.post-images img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  cursor: pointer;
  transition: opacity 0.2s;
}

.post-images img:hover {
  opacity: 0.9;
}

.post-images.count-1 img {
  height: 300px;
}

/* Video Thumbnail */
.post-video-thumb {
  display: block;
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 10px;
  text-decoration: none;
}

.post-video-thumb img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  display: block;
}

.video-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  transition: background 0.2s;
}

.post-video-thumb:hover .video-play-icon {
  background: rgba(0, 0, 0, 0.5);
}

.video-play-icon svg {
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

/* External Link Embed */
.post-embed-link {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  margin-bottom: 10px;
  transition: background 0.2s;
}

.post-embed-link:hover {
  background: var(--bg-input);
}

.post-embed-thumb {
  width: 120px;
  height: 90px;
  object-fit: cover;
  flex-shrink: 0;
}

.post-embed-info {
  padding: 10px 12px;
  min-width: 0;
}

.post-embed-title {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.post-embed-domain {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Post Stats */
.post-stats {
  display: flex;
  gap: 20px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.post-stat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.post-stat svg {
  flex-shrink: 0;
}

.post-stat.likes { color: #f43f5e; }
.post-stat.reposts { color: #22c55e; }

.post-link {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

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

/* ========== Search History ========== */
.search-history {
  margin-top: 16px;
  margin-bottom: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

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

.history-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.history-clear {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}

.history-clear:hover {
  color: #f43f5e;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.history-chip:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.history-chip-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
  transition: color 0.2s;
}

.history-chip-remove:hover {
  color: #f43f5e;
}

.history-show-more {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  padding: 6px 0;
  margin-top: 4px;
  font-weight: 500;
  transition: opacity 0.2s;
  width: 100%;
  text-align: center;
}

.history-show-more:hover {
  opacity: 0.7;
}

/* ========== Statistics ========== */
.stats-section {
  margin-bottom: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* ========== Results Header ========== */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

/* ========== Sort Pills ========== */
.sort-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.sort-pill {
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.sort-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.sort-pill:hover:not(.active) {
  border-color: var(--accent);
  color: var(--accent);
}

/* ========== Load More ========== */
.load-more-wrap {
  text-align: center;
  margin-top: 20px;
}

.btn-load-more {
  padding: 12px 32px;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-load-more:hover {
  background: var(--accent);
  color: white;
}

.btn-load-more:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== States ========== */
.loading-overlay {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

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

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 12px;
  opacity: 0.5;
}

.error-state {
  text-align: center;
  padding: 40px 20px;
}

.error-message {
  background: #fef2f2;
  color: #dc2626;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 480px;
  text-align: left;
  line-height: 1.5;
}

.error-message::before {
  content: '';
  display: inline-block;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23dc2626' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E");
  background-size: contain;
}

[data-theme="dark"] .error-message {
  background: rgba(220, 38, 38, 0.15);
  color: #fca5a5;
}

[data-theme="dark"] .error-message::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fca5a5' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E");
}

/* ========== Footer ========== */
.footer {
  text-align: center;
  padding: 24px 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

/* ========== Image Modal ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  animation: fadeIn 0.2s ease;
}

.modal-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ========== Responsive ========== */
.sp-only {
  display: none;
}

@media (max-width: 640px) {
  .sp-only {
    display: inline;
  }

  .hero {
    padding: 32px 0 24px;
  }

  .hero-title {
    font-size: 1.5rem;
  }

  .search-form {
    padding: 16px;
  }

  .form-row {
    flex-direction: column;
    gap: 12px;
  }

  .form-group.flex-1 {
    flex: none;
    width: 100%;
  }

  .form-group input,
  .form-group select,
  .form-group .flatpickr-wrapper,
  .form-group .flatpickr-input {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0;
    box-sizing: border-box !important;
  }

  .search-form {
    overflow: hidden;
  }

  .profile-body {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .profile-avatar {
    margin-top: -40px;
  }

  .profile-stats {
    justify-content: center;
  }

  .post-images img {
    height: 160px;
  }

  .post-images.count-1 img {
    height: 220px;
  }

  .post-embed-link {
    flex-direction: column;
  }

  .post-embed-thumb {
    width: 100%;
    height: 140px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .results-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Header mobile */
  .hamburger { display: flex; }
  .header .nav { display: none; }
  .header .lang-select { display: none; }
  .mobile-menu { display: flex; }
  .logo span { font-size: 1.1rem; }

  /* Tabs mobile — horizontal scroll */
  .tab-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 16px;
    gap: 6px;
  }
  .tab-nav::-webkit-scrollbar { display: none; }
  .tab-btn {
    flex-shrink: 0;
    font-size: 0.8rem;
    padding: 8px 12px;
    gap: 5px;
    white-space: nowrap;
  }
  .tab-btn svg { width: 13px; height: 13px; }

  /* Footer mobile */
  .footer-links {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 20px;
    text-align: left;
    margin-bottom: 12px;
  }
}

/* ========== Animations ========== */
.post-card {
  animation: slideUp 0.3s ease both;
}

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

/* Staggered animation for cards */
.post-card:nth-child(1) { animation-delay: 0ms; }
.post-card:nth-child(2) { animation-delay: 40ms; }
.post-card:nth-child(3) { animation-delay: 80ms; }
.post-card:nth-child(4) { animation-delay: 120ms; }
.post-card:nth-child(5) { animation-delay: 160ms; }
.post-card:nth-child(6) { animation-delay: 200ms; }
.post-card:nth-child(7) { animation-delay: 240ms; }
.post-card:nth-child(8) { animation-delay: 280ms; }
.post-card:nth-child(9) { animation-delay: 320ms; }
.post-card:nth-child(10) { animation-delay: 360ms; }

/* ========================================
   Tab Navigation
   ======================================== */
.tab-nav {
  max-width: 760px;
  margin: 0 auto 20px;
  padding: 0 20px;
  display: flex;
  gap: 8px;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

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

.tab-btn:hover:not(.active) {
  border-color: var(--accent);
  color: var(--accent);
}

/* ========================================
   Trending Section
   ======================================== */
.trend-section {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.trend-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 0;
  gap: 12px;
  color: var(--text-secondary);
}

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

.trend-card {
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s;
  animation: slideUp 0.3s ease both;
}

.trend-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.15);
}

.trend-rank {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
  letter-spacing: 0.3px;
}

.trend-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  word-break: break-word;
}

.trend-count {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* ========================================
   Analytics Section
   ======================================== */
.analytics-section {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 40px;
}

.analytics-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 24px;
}

.analytics-form .form-group {
  flex: 1;
}

.analytics-form .btn-search {
  width: auto;
  flex-shrink: 0;
  padding: 14px 24px;
}

.analytics-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 0;
  gap: 12px;
  color: var(--text-secondary);
}

.analytics-error {
  background: #fef2f2;
  color: #dc2626;
  border: 1.5px solid #fecaca;
  border-radius: var(--radius-md);
  padding: 14px 18px;
  font-size: 0.9rem;
  margin-bottom: 16px;
}

[data-theme="dark"] .analytics-error {
  background: rgba(220, 38, 38, 0.12);
  border-color: rgba(220, 38, 38, 0.3);
  color: #f87171;
}

.analytics-results .stats-grid {
  margin-bottom: 20px;
}

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-card {
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}

.chart-row .chart-card {
  margin-bottom: 0;
}

.chart-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0 0 14px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.top-posts-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top-post-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.top-post-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.top-post-rank {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-post-content {
  flex: 1;
  min-width: 0;
}

.top-post-text {
  font-size: 0.875rem;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.top-post-likes {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.top-post-likes svg {
  vertical-align: -2px;
  margin-right: 3px;
}

.top-post-link {
  font-size: 0.78rem;
  color: var(--accent);
  text-decoration: none;
  margin-left: 8px;
}

.top-post-link:hover {
  text-decoration: underline;
}

@media (max-width: 560px) {
  .analytics-form {
    flex-direction: column;
    align-items: stretch;
  }

  .chart-row {
    grid-template-columns: 1fr;
  }
}

/* ========================================
   Flatpickr Theme Override
   ======================================== */
.flatpickr-calendar {
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-family: inherit;
}

.flatpickr-months .flatpickr-month,
.flatpickr-weekdays,
span.flatpickr-weekday {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
  background: transparent;
  color: var(--text-primary);
  font-weight: 600;
}

.flatpickr-day {
  color: var(--text-primary);
  border-radius: var(--radius-sm);
}

.flatpickr-day:hover,
.flatpickr-day.prevMonthDay:hover,
.flatpickr-day.nextMonthDay:hover {
  background: var(--accent-light);
  border-color: transparent;
}

.flatpickr-day.selected,
.flatpickr-day.selected:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.flatpickr-day.today {
  border-color: var(--accent);
}

.flatpickr-day.today:hover {
  background: var(--accent);
  color: #fff;
}

.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay {
  color: var(--text-muted);
}

.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
  fill: var(--text-secondary);
}

.flatpickr-months .flatpickr-prev-month:hover svg,
.flatpickr-months .flatpickr-next-month:hover svg {
  fill: var(--accent);
}

[data-theme="dark"] .flatpickr-calendar {
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
