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

:root {
  --bg: #ffffff;
  --bg-secondary: #f5f5f7;
  --text: #1a1a1a;
  --text-secondary: #666;
  --text-tertiary: #999;
  --border: #f0f0f0;
  --accent: #1a1a1a;
  --cat-politics: #e74c3c;
  --cat-tech: #8b5cf6;
  --cat-business: #2563eb;
  --cat-world: #059669;
  --cat-japan: #dc2626;
  --cat-australia: #d97706;
  --cat-digital: #0891b2;
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --bg-secondary: #1c1c1e;
    --text: #f5f5f7;
    --text-secondary: #a1a1a6;
    --text-tertiary: #636366;
    --border: #2c2c2e;
    --accent: #f5f5f7;
  }
}

:root[data-theme="dark"] {
  --bg: #000000;
  --bg-secondary: #1c1c1e;
  --text: #f5f5f7;
  --text-secondary: #a1a1a6;
  --text-tertiary: #636366;
  --border: #2c2c2e;
  --accent: #f5f5f7;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* --- Login --- */
.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
}

.login-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.login-icon { margin-bottom: 1.25rem; }

.login-card h1 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.25rem;
}

.login-sub {
  color: var(--text-tertiary);
  font-size: 0.9375rem;
  margin-bottom: 2rem;
}

.login-card input {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  background: var(--bg-secondary);
  color: var(--text);
  margin-bottom: 0.75rem;
  outline: none;
  transition: border-color 0.2s;
}

.login-card input:focus { border-color: var(--text-tertiary); }

.login-card button {
  width: 100%;
  padding: 0.875rem;
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
}

.error { color: #e74c3c; font-size: 0.875rem; margin-top: 0.5rem; }

/* --- App shell --- */
#app {
  max-width: 640px;
  margin: 0 auto;
}

.view { min-height: 100vh; min-height: 100dvh; }

/* --- Top bar --- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
}

.app-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.top-bar-actions { display: flex; gap: 0.25rem; }

.top-icon {
  background: none;
  border: none;
  color: var(--text);
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
}

.top-icon:active { background: var(--bg-secondary); }

/* --- Search bar --- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0 1.25rem 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
}

.search-bar input {
  flex: 1;
  border: none;
  background: none;
  font-size: 0.9375rem;
  font-family: var(--font);
  color: var(--text);
  outline: none;
}

.search-bar input::placeholder { color: var(--text-tertiary); }

/* --- Trending section --- */
.trending-section {
  margin-bottom: 1.5rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  margin-bottom: 0.75rem;
}

.section-header h2 {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.trending-arrows {
  display: flex;
  gap: 0.375rem;
}

.arrow-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.arrow-btn:active { background: var(--bg-secondary); }

.trending-scroll {
  display: flex;
  gap: 0.875rem;
  padding: 0 1.25rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.trending-scroll::-webkit-scrollbar { display: none; }

/* --- Trending card --- */
.trend-card {
  flex: 0 0 280px;
  scroll-snap-align: start;
  cursor: pointer;
}

.trend-card .trend-img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
  background: var(--bg-secondary);
}

.trend-card .trend-img-placeholder {
  width: 100%;
  height: 180px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #333 0%, #555 100%);
  display: flex;
  align-items: flex-end;
  padding: 1rem;
}

.trend-card .trend-body {
  padding: 0.625rem 0.125rem;
}

.trend-card .trend-title {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.25rem;
}

.trend-card .trend-meta {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.trend-card .trend-source {
  color: var(--text-secondary);
}

.trend-card .read-link {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.375rem;
}

/* --- Category tabs --- */
.category-nav {
  display: flex;
  gap: 0;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  margin-bottom: 0;
}

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

.cat-tab {
  flex-shrink: 0;
  padding: 0.75rem 0;
  margin-right: 1.5rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-tertiary);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.cat-tab:hover { color: var(--text-secondary); }

.cat-tab.active {
  color: var(--text);
  border-bottom-color: var(--text);
  font-weight: 600;
}

/* --- Category colors --- */
.cat-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.cat-label[data-cat="world"] { color: var(--cat-world); }
.cat-label[data-cat="ai-tech"] { color: var(--cat-tech); }
.cat-label[data-cat="business"] { color: var(--cat-business); }
.cat-label[data-cat="japan"] { color: var(--cat-japan); }
.cat-label[data-cat="australia"] { color: var(--cat-australia); }
.cat-label[data-cat="digital"] { color: var(--cat-digital); }

/* --- Article list --- */
.article-list {
  padding: 0;
}

.article-row {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.article-row:active { background: var(--bg-secondary); }

.article-row-text {
  flex: 1;
  min-width: 0;
}

.article-row-text .cat-label {
  margin-bottom: 0.25rem;
  display: block;
}

.article-row-text h3 {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.35;
  margin-bottom: 0.375rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-row-text .row-meta {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.article-row-text .row-source {
  color: var(--text-secondary);
}

.article-row-img {
  width: 100px;
  height: 80px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-secondary);
}

.article-row-img-placeholder {
  width: 100px;
  height: 80px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

/* --- Article detail --- */
#view-detail {
  padding-bottom: 2rem;
}

.detail-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.detail-back-btn {
  background: none;
  border: none;
  color: var(--text);
  padding: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.detail-actions { display: flex; gap: 0.25rem; }

.detail-content {
  padding: 0;
}

.detail-hero-img {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  display: block;
}

.detail-hero-caption {
  padding: 0.5rem 1.25rem;
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-style: italic;
}

.detail-body {
  padding: 1rem 1.25rem 2rem;
}

.detail-body h1 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
}

.detail-meta-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-tertiary);
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.detail-meta-row .source-name {
  color: var(--cat-business);
  font-weight: 600;
}

.detail-meta-row .dot { color: var(--text-tertiary); }

/* Key Points box */
.key-points {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
}

.key-points h3 {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--cat-business);
  margin-bottom: 0.625rem;
}

.key-points ul {
  list-style: none;
  padding: 0;
}

.key-points li {
  position: relative;
  padding-left: 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--text);
}

.key-points li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.5rem;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--cat-business);
}

.detail-full-text {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  line-height: 1.8;
  color: var(--text);
  margin-bottom: 1.5rem;
}

.detail-source-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.75rem 1.25rem;
  background: var(--accent);
  color: var(--bg);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  transition: opacity 0.2s;
}

.detail-source-btn:active { opacity: 0.8; }

.detail-video { margin-bottom: 1.25rem; border-radius: var(--radius-sm); overflow: hidden; }
.detail-video iframe { width: 100%; aspect-ratio: 16/9; border: none; }

/* --- Last updated --- */
.last-updated {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.75rem;
  color: var(--text-tertiary);
}

/* --- Loading & empty --- */
.loading {
  text-align: center;
  padding: 3rem 1rem;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}

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

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-tertiary);
}


/* --- Responsive --- */
@media (min-width: 641px) {
  .trending-scroll { gap: 1rem; }
  .trend-card { flex: 0 0 320px; }
}
