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

:root {
  --bg-primary: #15202b;
  --bg-secondary: #192734;
  --bg-card: #1e2a38;
  --text-primary: #fff;
  --text-secondary: #8899a6;
  --accent: #1da1f2;
  --border: #38444d;
  --img-border: #333;
}

/* Light theme */
@media (prefers-color-scheme: light) {
  :root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f8fa;
    --bg-card: #ffffff;
    --text-primary: #0f1419;
    --text-secondary: #536471;
    --accent: #1da1f2;
    --border: #eff3f4;
    --img-border: #e0e0e0;
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-top {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-left h1 {
  font-size: 20px;
  color: var(--text-primary);
  margin: 0;
}

.header-search input {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  width: 200px;
}

.header-search input::placeholder {
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  gap: 8px;
}

.btn-primary, .btn-secondary {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: opacity 0.2s;
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-primary:hover, .btn-secondary:hover {
  opacity: 0.9;
}

.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 40px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  position: sticky;
  top: 0;
  background: var(--bg-primary);
  z-index: 50;
  padding: 12px 0;
}

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  position: sticky;
  top: 60px;
  background: var(--bg-primary);
  z-index: 50;
  padding: 8px 0;
}

.category-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn {
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.filter-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.filter-count {
  background: rgba(255,255,255,0.25);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
  margin-left: 2px;
}

.tweet-count {
  color: var(--text-secondary);
  font-size: 14px;
  white-space: nowrap;
}

/* Regular Grid Layout - CSS Grid 2 columns, horizontal first */
.tweets-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

@media (max-width: 900px) {
  .tweets-grid {
    grid-template-columns: repeat(1, 1fr);
  }
}

.tweet-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border);
}

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

.author-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

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

.author-name {
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.author-handle {
  color: var(--text-secondary);
  font-size: 14px;
}

.tweet-time {
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.tweet-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  display: inline-block;
}

.tweet-text {
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 10px;
  word-break: break-word;
}

.tweet-text p {
  margin: 0 0 8px 0;
}

.tweet-text p:last-child {
  margin-bottom: 0;
}

.tweet-text ul, .tweet-text ol {
  margin: 6px 0;
  padding-left: 20px;
}

.tweet-text li {
  margin-bottom: 4px;
}

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

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

.show-more-btn {
  color: var(--accent);
  cursor: pointer;
  font-weight: 500;
  margin-left: 4px;
}

.show-more-btn:hover {
  text-decoration: underline;
}

.tweet-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.tweet-badges .badge {
  background: var(--bg-secondary);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.tweet-badges .badge:hover {
  opacity: 0.8;
}

/* Quote tweet - embedded style */
.quoted-tweet {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.quoted-tweet-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.quoted-tweet-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.quoted-tweet-author {
  font-weight: 600;
  color: var(--text-primary);
}

.quoted-tweet-handle {
  color: var(--text-secondary);
}

.quoted-tweet-text {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.4;
}

/* Media grid - 2 columns for photos */
.tweet-media {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

/* Photos grid - auto-fit with max 300px per image */
.tweet-media.cols-1 { grid-template-columns: minmax(0, 300px); }
.tweet-media.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tweet-media.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tweet-media.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tweet-media.cols-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tweet-media.cols-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* Images - fit in cell, max width 300px */
.tweet-media img {
  width: 100%;
  max-width: 300px;
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  background: #000;
  cursor: pointer;
  display: block;
  margin: 0 auto;
  border: 1px solid var(--img-border);
}

.tweet-media video {
  width: 100%;
  height: auto;
  max-height: 400px;
  object-fit: contain;
  border-radius: 6px;
  background: transparent;
}

/* Portrait videos - maintain aspect ratio */
.tweet-media video.portrait {
  width: auto;
  height: auto;
  aspect-ratio: auto;
}

.tweet-media img:hover {
  opacity: 0.95;
}

/* Plyr video customization */
.video-wrapper {
  border-radius: 8px;
  overflow: hidden;
  background: #2a2a2a;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 150px;
}

.video-wrapper.portrait {
  width: auto;
  height: auto;
  flex-shrink: 0;
}

.video-wrapper video {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
}

.video-local-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.7);
  color: #1da1f2;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  z-index: 5;
}

.tweet-videos {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tweet-videos .video-wrapper {
  width: 100%;
}

.tweet-videos .video-wrapper.portrait {
  width: auto;
  max-width: 300px;
}

.remote-video-link {
  position: relative;
  display: block;
  width: 100%;
  overflow: hidden;
  border-radius: 8px;
  background: #111;
  color: white;
  text-decoration: none;
}

.remote-video-link.portrait {
  max-width: 300px;
}

.remote-video-link img,
.remote-video-placeholder {
  display: block;
  width: 100%;
  min-height: 150px;
  object-fit: cover;
  background: #222;
}

.remote-video-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
}

.remote-video-play {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(0,0,0,0.68);
  font-size: 18px;
  line-height: 1;
}

.remote-video-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(0,0,0,0.72);
  color: white;
  font-size: 12px;
}

/* Plyr overrides */
.plyr--video .plyr__control.plyr__tab-focus,
.plyr--video .plyr__control:hover,
.plyr--video .plyr__control[aria-expanded=true] {
  background: var(--accent);
}

.plyr--full-ui input[type=range] {
  color: var(--accent);
}

.tweet-actions {
  display: flex;
  gap: 12px;
}

.action-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
}

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

.loading, .error-state, .empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

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

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

.hidden {
  display: none !important;
}

.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.lightbox img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  color: white;
  font-size: 32px;
  cursor: pointer;
}

.footer {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 14px;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* Help page */
.help-content {
  max-width: 800px;
}

.help-section {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.help-section h2 {
  color: var(--text-primary);
  margin-bottom: 16px;
  font-size: 18px;
}

.help-section ul {
  list-style: none;
  padding: 0;
}

.help-section li {
  padding: 8px 0;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

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

.help-section li strong {
  color: var(--text-primary);
}

.load-more-btn {
  display: block;
  width: 100%;
  max-width: 600px;
  margin: 24px auto;
  padding: 14px 24px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}
.load-more-btn:hover:not(:disabled) {
  background: var(--bg-tertiary);
}
.load-more-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Account Switcher */
.account-switcher {
  position: relative;
}

.account-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
}

.account-btn:hover {
  border-color: var(--accent);
}

.dropdown-arrow {
  font-size: 10px;
  opacity: 0.6;
}

.account-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  z-index: 100;
  overflow: hidden;
}

.account-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}

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

.account-item.active {
  color: var(--accent);
  font-weight: 600;
}

.mock-badge {
  background: rgba(255,200,0,0.2);
  color: #f0b90b;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
}
