*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0a;
  --surface: #1a1a1a;
  --surface2: #252525;
  --border: #333;
  --primary: #e1306c;
  --primary-dark: #c0274f;
  --success: #2ea44f;
  --text: #f0f0f0;
  --muted: #777;
  --radius: 12px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding: 2rem 1rem;
}

.container {
  max-width: 860px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 2.5rem;
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #e1306c, #f77737);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  color: var(--muted);
  margin-top: 0.4rem;
  font-size: 0.95rem;
}

/* ── Input ── */
.input-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.input-row {
  display: flex;
  gap: 0.75rem;
}

input[type="url"] {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
input[type="url"]:focus { border-color: var(--primary); }
input[type="url"]::placeholder { color: var(--muted); }

.btn {
  padding: 0.65rem 1.4rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-dark); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { background: #26903f; }

.error-msg {
  margin-top: 0.75rem;
  color: #f85149;
  font-size: 0.88rem;
}

/* ── Loading ── */
.loading {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Result ── */
.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.meta-user {
  font-weight: 700;
  font-size: 1rem;
}
.meta-user::before { content: "@"; color: var(--muted); }

.meta-badge {
  font-size: 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.15rem 0.65rem;
  color: var(--muted);
}

.meta-caption {
  color: #aaa;
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
  white-space: pre-wrap;
  max-height: 4.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* ── Media Grid ── */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.media-card {
  background: var(--surface2);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.media-card img,
.media-card video {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.media-card .card-footer {
  padding: 0.6rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.media-card .card-label { font-size: 0.78rem; color: var(--muted); }

.card-dl-btn {
  font-size: 0.8rem;
  padding: 0.3rem 0.7rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.card-dl-btn:hover { background: var(--primary); border-color: var(--primary); }

/* ── Action bar ── */
.action-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.count-label { font-size: 0.85rem; color: var(--muted); }

/* ── Utility ── */
.hidden { display: none !important; }

@media (max-width: 480px) {
  .input-row { flex-direction: column; }
  .media-grid { grid-template-columns: 1fr 1fr; }
}
