:root {
  --bg: #ffffff;
  --bg2: #f5f5f5;
  --bg3: #ececec;
  --surface: #ffffff;
  --border: rgba(0,0,0,0.1);
  --border2: rgba(0,0,0,0.06);
  --text: #111111;
  --text2: #555555;
  --text3: #888888;
  --accent: #e8392a;
  --accent2: #ff5240;
  --header-bg: rgba(255,255,255,0.92);
  --shadow: 0 1px 12px rgba(0,0,0,0.08);
  --card-hover: rgba(0,0,0,0.03);
  --font: 'Be Vietnam Pro', sans-serif;
  --mono: 'Space Mono', monospace;
  --radius: 14px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg2: #141414;
  --bg3: #1e1e1e;
  --surface: #181818;
  --border: rgba(255,255,255,0.1);
  --border2: rgba(255,255,255,0.05);
  --text: #f0f0f0;
  --text2: #a0a0a0;
  --text3: #666666;
  --header-bg: rgba(10,10,10,0.92);
  --shadow: 0 1px 20px rgba(0,0,0,0.4);
  --card-hover: rgba(255,255,255,0.03);
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background 0.3s, color 0.3s;
}

/* VIEWS */
.view {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
.view.active { display: flex; }

/* HEADER */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border2);
  padding: env(safe-area-inset-top, 0) 0 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 8px;
}

.logo {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
}
.logo-vie { color: var(--accent); }
.logo-news { color: var(--text); }
.logo-24 {
  font-size: 11px;
  color: var(--text3);
  vertical-align: super;
  margin-left: 3px;
  font-weight: 400;
}

.header-sub {
  font-size: 11px;
  color: var(--text3);
  padding: 0 16px 10px;
  letter-spacing: 0.3px;
}

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

.icon-btn {
  width: 36px; height: 36px;
  border: none;
  background: var(--bg3);
  color: var(--text2);
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.15s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { transform: scale(0.92); background: var(--border); }
.icon-btn svg { flex-shrink: 0; }

.back-btn {
  display: flex; align-items: center; gap: 6px;
  border: none; background: none; cursor: pointer;
  color: var(--accent);
  font-family: var(--font);
  font-size: 15px; font-weight: 600;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s;
}
.back-btn:active { opacity: 0.7; }
.back-btn svg { flex-shrink: 0; }

.source-title-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 16px 6px;
}
.source-badge {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 9px; font-weight: 700;
  color: #fff; flex-shrink: 0;
  letter-spacing: 0.3px;
}
.source-title {
  font-size: 20px; font-weight: 800;
  color: var(--text); letter-spacing: -0.5px;
}

/* CATEGORY TABS */
.category-tabs {
  display: flex; gap: 6px;
  padding: 6px 16px 12px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text2);
  font-family: var(--font); font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tab-btn:not(.active):active { background: var(--bg3); }

/* HOME GRID */
.home-grid-wrap {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sources-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.source-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  aspect-ratio: 1;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
}
.source-card:active {
  transform: scale(0.96);
  box-shadow: none;
}

.card-top {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 8px;
  padding: 20px 12px 12px;
}

.card-logo-circle {
  width: 56px; height: 56px;
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono);
  font-size: 12px; font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.card-name {
  font-size: 13px; font-weight: 700;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
}

.card-bottom {
  padding: 8px 12px 12px;
  display: flex; align-items: center; justify-content: space-between;
}

.card-count {
  font-size: 11px; color: var(--text3);
  font-family: var(--mono);
}

.card-arrow {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
  color: var(--text3);
}

.card-bar {
  height: 3px;
  width: 100%;
  position: absolute;
  top: 0; left: 0;
  border-radius: 0;
}

/* NEWS LIST */
.news-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 env(safe-area-inset-bottom, 16px);
}

.news-item {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border2);
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  color: inherit;
}
.news-item:active { background: var(--card-hover); }

.news-thumb {
  width: 90px; height: 68px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--bg3);
}

.news-thumb-placeholder {
  width: 90px; height: 68px;
  border-radius: var(--radius-sm);
  background: var(--bg3);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text3);
  font-size: 22px;
}

.news-content { flex: 1; min-width: 0; }

.news-category {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--accent);
  margin-bottom: 4px;
}

.news-title {
  font-size: 14px; font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
}

.news-time {
  font-size: 11px; color: var(--text3);
  font-family: var(--mono);
}

/* ARTICLE VIEW */
.article-frame-wrap {
  flex: 1;
  position: relative;
  display: flex; flex-direction: column;
}

.article-loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  background: var(--bg);
  z-index: 10;
  transition: opacity 0.3s;
  font-size: 14px; color: var(--text3);
}
.article-loading.hidden { opacity: 0; pointer-events: none; }

.article-frame {
  flex: 1;
  border: none;
  width: 100%;
  min-height: 0;
  background: var(--bg);
}

/* LOADING & SPINNER */
.grid-loading {
  grid-column: 1/-1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text3);
  font-size: 14px;
}

.spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* SKELETON */
.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--bg2) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* EMPTY / ERROR */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 20px; gap: 12px;
  color: var(--text3); text-align: center;
}
.empty-state svg { opacity: 0.3; }
.empty-state p { font-size: 14px; line-height: 1.5; }
.retry-btn {
  margin-top: 8px;
  padding: 10px 24px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--accent); font-family: var(--font);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
}

/* TRANSITIONS */
.view { animation: fadeIn 0.22s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* SCROLLBAR */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* SAFE AREA */
.news-header { padding-bottom: 0; }
.home-grid-wrap { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0)); }
