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

:root {
  --teal: #008080;
  --teal-light: #E5F2F2;
  --purple: #5B21B6;
  --purple-light: #EDE9F8;
  --bg: #F4F6FA;
  --card-bg: #FFFFFF;
  --text-primary: #39404A;
  --text-meta: #6B7280;
  --border: #E5E7EB;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
  --radius-card: 12px;
  --radius-pill: 9999px;
}

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

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

/* ── Top bar (sticky wrapper) ── */

.app-top {
  position: sticky;
  top: 0;
  z-index: 10;
}

header {
  background: var(--teal);
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 56px;
}

.header-logo {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
}

h1 {
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  flex: 1;
}

#refresh-btn {
  background: transparent;
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
  transition: background 150ms ease;
  -webkit-tap-highlight-color: transparent;
}

#refresh-btn svg {
  width: 20px;
  height: 20px;
  transition: transform 600ms ease;
}

#refresh-btn:hover,
#refresh-btn:focus-visible {
  background: rgba(255, 255, 255, 0.18);
  outline: none;
}

#refresh-btn:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

body.refreshing #refresh-btn svg {
  animation: spin 0.8s linear infinite;
}

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

/* ── Filter tabs ── */

nav {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

nav::-webkit-scrollbar {
  display: none;
}

nav button {
  background: #F3F4F6;
  border: none;
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  min-height: 44px;
  padding: 0 18px;
  white-space: nowrap;
  transition: background 150ms ease, color 150ms ease;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

nav button[aria-selected="true"] {
  background: var(--teal);
  color: #ffffff;
}

nav button:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ── Article list ── */

main {
  padding: 16px;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 32px;
}

/* ── Card ── */

.card {
  background: var(--card-bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: block;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 120ms ease, box-shadow 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

.card:active {
  transform: scale(0.985);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06);
}

.card:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.card-img-placeholder {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, var(--teal-light) 0%, var(--bg) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}

.card-body {
  padding: 12px 16px 16px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: nowrap;
}

.badge {
  border-radius: var(--radius-pill);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 3px 9px;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-f1 {
  background: var(--teal-light);
  color: var(--teal);
}

.badge-v8 {
  background: var(--purple-light);
  color: var(--purple);
}

.source {
  font-size: 0.75rem;
  color: var(--text-meta);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.time {
  font-size: 0.75rem;
  color: var(--text-meta);
  white-space: nowrap;
  margin-left: auto;
  flex-shrink: 0;
}

.card-title {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Skeleton loader ── */

.skeleton-card {
  background: var(--card-bg);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.skeleton-img {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(90deg, #E5E7EB 25%, #F3F4F6 50%, #E5E7EB 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

.skeleton-body {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, #E5E7EB 25%, #F3F4F6 50%, #E5E7EB 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Error state ── */

.error-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-meta);
}

.error-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
  display: block;
}

.error-state p {
  font-size: 0.9375rem;
  line-height: 1.5;
  margin-bottom: 24px;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.retry-btn {
  background: var(--teal);
  border: none;
  border-radius: var(--radius-pill);
  color: #ffffff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  min-height: 48px;
  padding: 0 28px;
  transition: opacity 150ms ease;
}

.retry-btn:hover {
  opacity: 0.88;
}

.retry-btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ── Empty state ── */

.empty-state {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-meta);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
  display: block;
}

.empty-state p {
  font-size: 0.9375rem;
  line-height: 1.6;
}

/* ── Reduced motion ── */

@media (prefers-reduced-motion: reduce) {
  body.refreshing #refresh-btn svg {
    animation: none;
    opacity: 0.6;
  }
  .skeleton-img,
  .skeleton-line {
    animation: none;
    background: #E5E7EB;
  }
  .card {
    transition: none;
  }
}
