:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #121826;
  --bg-card: rgba(22, 30, 46, 0.75);
  --bg-card-hover: rgba(28, 38, 58, 0.9);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(29, 155, 240, 0.5);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-color: #1d9bf0;
  --accent-hover: #1a8cd8;
  --accent-gradient: linear-gradient(135deg, #1d9bf0 0%, #00ba7c 100%);
  --success-color: #00ba7c;
  --danger-color: #f43f5e;
  --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-glow: 0 0 30px rgba(29, 155, 240, 0.12);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Subtle background glow effect */
.bg-glow {
  position: absolute;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 700px;
  height: 380px;
  background: radial-gradient(circle, rgba(29, 155, 240, 0.14) 0%, rgba(0, 186, 124, 0.05) 50%, transparent 80%);
  filter: blur(70px);
  pointer-events: none;
  z-index: 0;
}

.container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
  position: relative;
  z-index: 1;
}

@media (min-width: 640px) {
  .container {
    padding: 0 24px;
  }
}

/* Navbar with iOS Safe Area support */
.navbar {
  border-bottom: 1px solid var(--border-color);
  background: rgba(10, 14, 23, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: env(safe-area-inset-top);
}

.nav-content {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  height: 56px;
}

@media (min-width: 640px) {
  .nav-content {
    height: 62px;
  }
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.x-icon {
  color: var(--text-primary);
  flex-shrink: 0;
}

/* Main Content */
.main-content {
  flex: 1;
  padding-top: 28px;
  padding-bottom: 48px;
}

@media (min-width: 640px) {
  .main-content {
    padding-top: 48px;
    padding-bottom: 64px;
  }
}

.hero-section {
  text-align: center;
}

.headline {
  font-size: clamp(1.65rem, 5.5vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
  line-height: 1.25;
}

.gradient-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: clamp(0.92rem, 3.2vw, 1.05rem);
  color: var(--text-secondary);
  max-width: 580px;
  margin: 0 auto 24px auto;
  line-height: 1.5;
  padding: 0 4px;
}

@media (min-width: 640px) {
  .subtitle {
    margin-bottom: 32px;
  }
}

/* URL Form */
.url-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 640px;
  margin: 0 auto 24px auto;
}

@media (min-width: 640px) {
  .url-form {
    flex-direction: row;
    gap: 12px;
  }
}

.input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.input-wrapper input {
  width: 100%;
  height: 52px;
  padding: 0 76px 0 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px; /* Must be at least 16px to prevent iOS Safari auto-zoom */
  font-family: inherit;
  transition: all 0.2s ease;
  outline: none;
  -webkit-appearance: none;
}

@media (min-width: 640px) {
  .input-wrapper input {
    height: 56px;
    padding: 0 85px 0 46px;
  }
}

.input-wrapper input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(29, 155, 240, 0.2);
}

.paste-btn {
  position: absolute;
  right: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
}

.paste-btn:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.96);
}

.submit-btn {
  height: 52px;
  width: 100%;
  padding: 0 24px;
  background: var(--accent-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
  box-shadow: 0 4px 15px rgba(29, 155, 240, 0.3);
}

@media (min-width: 640px) {
  .submit-btn {
    width: auto;
    height: 56px;
    padding: 0 28px;
  }
}

.submit-btn:hover {
  box-shadow: 0 6px 20px rgba(29, 155, 240, 0.4);
}

.submit-btn:active {
  transform: scale(0.98);
}

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

/* Status / Loader Card */
.status-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 16px;
  max-width: 640px;
  margin: 0 auto;
  border-radius: var(--radius-md);
  background: rgba(29, 155, 240, 0.08);
  border: 1px solid rgba(29, 155, 240, 0.2);
  color: var(--accent-color);
  font-size: 0.92rem;
  font-weight: 500;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(29, 155, 240, 0.3);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* Error Card */
.error-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
  border-radius: var(--radius-md);
  background: rgba(244, 63, 94, 0.08);
  border: 1px solid rgba(244, 63, 94, 0.25);
  text-align: left;
}

.error-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.error-details h4 {
  color: var(--danger-color);
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.error-details p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Result Card */
.result-card {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-glow);
  text-align: left;
  animation: fadeIn 0.3s ease-out forwards;
}

@media (min-width: 640px) {
  .result-card {
    padding: 24px;
  }
}

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

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

.author-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  object-fit: cover;
  flex-shrink: 0;
}

.author-name-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 2px;
}

.author-name {
  font-weight: 700;
  font-size: 0.95rem;
}

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

.tweet-caption {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-word;
}

.media-container {
  margin-bottom: 18px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #000;
  max-height: 340px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

@media (min-width: 640px) {
  .media-container {
    max-height: 400px;
  }
}

.preview-wrapper {
  position: relative;
  width: 100%;
  max-height: 340px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}

@media (min-width: 640px) {
  .preview-wrapper {
    max-height: 400px;
  }
}

.video-thumbnail {
  max-width: 100%;
  max-height: 340px;
  object-fit: contain;
  display: block;
}

@media (min-width: 640px) {
  .video-thumbnail {
    max-height: 400px;
  }
}

.play-overlay {
  position: absolute;
  width: 56px;
  height: 56px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: transform 0.2s ease;
}

.play-overlay:active {
  transform: scale(0.92);
}

.play-overlay svg {
  margin-left: 3px;
  width: 28px;
  height: 28px;
}

.video-player {
  width: 100%;
  max-height: 340px;
  background: #000;
  border-radius: var(--radius-md);
  outline: none;
}

@media (min-width: 640px) {
  .video-player {
    max-height: 400px;
  }
}

/* Broadcast / Space Replay Card */
.broadcast-card {
  margin-bottom: 20px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(244, 63, 94, 0.08);
  border: 1px solid rgba(244, 63, 94, 0.25);
}

.broadcast-badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 700;
  color: #f43f5e;
  margin-bottom: 6px;
}

.broadcast-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  line-height: 1.45;
}

.cmd-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

@media (min-width: 480px) {
  .cmd-box {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
  }
}

.cmd-box code {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  color: #38bdf8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.copy-cmd-btn {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.copy-cmd-btn:active {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(0.97);
}

.quality-heading {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.video-options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 520px) {
  .video-options-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  }
}

.dl-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  touch-action: manipulation;
  transition: all 0.2s ease;
  cursor: pointer;
  min-height: 54px; /* Ideal iOS thumb target size */
}

.dl-button:active {
  transform: scale(0.98);
  background: var(--bg-card-hover);
}

@media (hover: hover) {
  .dl-button:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }
}

.dl-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dl-quality {
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.hd-tag {
  background: rgba(0, 186, 124, 0.15);
  color: var(--success-color);
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 800;
}

.dl-bitrate {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.dl-icon {
  color: var(--accent-color);
  flex-shrink: 0;
}

/* Footer with iOS safe area inset bottom */
.footer {
  border-top: 1px solid var(--border-color);
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom)) 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: auto;
}

.hidden {
  display: none !important;
}
