:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --text: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --accent: #ff6b18;
  --accent-soft: #fff0e6;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgb(0 0 0 / 10%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214;
    --surface: #1c1d20;
    --surface-2: #242529;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --line: #36373b;
    --accent-soft: #3a2418;
    --shadow: 0 18px 50px rgb(0 0 0 / 35%);
  }
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}
button, select, input { font: inherit; }

.app-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px clamp(16px, 3vw, 36px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; min-width: 0; gap: 12px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--accent-soft); font-size: 22px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(18px, 2vw, 24px); line-height: 1.2; }
.brand p { max-width: min(70vw, 780px); margin-top: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; flex: none; }
.button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.button:hover:not(:disabled) { border-color: var(--accent); }
.button:disabled { opacity: .4; cursor: not-allowed; }
.button.primary { border-color: var(--accent); background: var(--accent); color: white; }
.button.danger { color: var(--danger); }
.button.icon { width: 38px; padding-inline: 0; }

.controlbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 230px)) minmax(220px, 1fr);
  align-items: end;
  gap: 12px;
  padding: 12px clamp(16px, 3vw, 36px);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 32px 9px 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(255 107 24 / 12%); }
input[type="number"], input[type="password"] {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
input[type="number"]:focus, input[type="password"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(255 107 24 / 12%); }
.progress-block { align-self: center; min-width: 0; }
.progress-block span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.activity-track { height: 5px; overflow: hidden; border-radius: 99px; background: var(--line); }
#activity-bar { width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ff9a3d, var(--accent)); transition: width .25s ease; }
#activity-bar.indeterminate { width: 35%; animation: activity 1.2s ease-in-out infinite alternate; }
@keyframes activity { from { transform: translateX(-20%); } to { transform: translateX(230%); } }

.content { min-height: 0; overflow: auto; padding: clamp(14px, 2.5vw, 32px) clamp(16px, 3vw, 36px) 40px; }
.empty { display: grid; place-items: center; min-height: 45vh; color: var(--muted); text-align: center; }
.keyword-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.keyword {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px 13px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 3px 10px rgb(0 0 0 / 3%);
}
.keyword:hover { border-color: var(--accent); transform: translateY(-1px); }
.keyword-count { color: var(--muted); font-size: 12px; }

.article-list { display: grid; gap: 8px; }
.article {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 10px;
  background: var(--surface);
}
.article.no-time { grid-template-columns: minmax(0, 1fr); }
.article time { display: block; color: var(--muted); font-size: 11px; line-height: 1.45; white-space: nowrap; }
.article a { color: var(--text); line-height: 1.55; text-decoration: none; overflow-wrap: anywhere; }
.article a:hover { color: var(--accent); text-decoration: underline; }
.article-list.compact {
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.article-list.compact .article {
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px;
  border: 0;
  border-radius: 0;
  padding: 6px 10px;
  background: transparent;
}
.article-list.compact .article + .article { border-top: 1px solid var(--line); }
.article-list.compact .article.no-time { grid-template-columns: minmax(0, 1fr); }
.article-list.compact .article time { font-size: 10px; line-height: 1.4; }
.article-list.compact .article a { font-size: 13px; line-height: 1.4; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 18px; }
.page-info { min-width: 76px; color: var(--muted); font-size: 12px; text-align: center; }

.settings-panel { position: fixed; inset: 0; z-index: 20; padding: 18px; background: rgb(0 0 0 / 35%); }
.settings-card { width: min(420px, 100%); max-height: calc(100dvh - 36px); margin: min(10vh, 36px) auto 0; overflow: auto; border: 1px solid var(--line); border-radius: 16px; padding: 18px; background: var(--surface); box-shadow: var(--shadow); }
.settings-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.settings-title h2 { font-size: 18px; }
.settings-section-title { margin: 0 0 14px; font-size: 15px; }
.settings-card > label + label { margin-top: 14px; }
.check-row { display: flex; grid-template: none; align-items: center; gap: 9px; color: var(--text); }
.check-row input { width: 17px; height: 17px; accent-color: var(--accent); }
.settings-card p { margin-top: 18px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.admin-settings { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.admin-settings h3 { margin: 0 0 14px; font-size: 15px; }
.admin-settings h4 { margin: 0 0 12px; color: var(--muted); font-size: 12px; font-weight: 600; }
.admin-settings > label + label { margin-top: 12px; }
.admin-settings .button { width: 100%; margin-top: 14px; }
.admin-settings .admin-message { min-height: 19px; margin-top: 8px; color: var(--accent); }
.admin-action-panel { z-index: 30; }
.action-card { width: min(380px, 100%); }
.action-description { margin-bottom: 16px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.action-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.action-buttons .button { width: 100%; }

@media (max-width: 820px) {
  .topbar { align-items: flex-start; padding: 12px; }
  .brand-mark { display: none; }
  .button { padding: 7px 9px; }
  .controlbar { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 10px 12px; }
  .progress-block { grid-column: 1 / -1; }
  .content { padding: 12px 12px 28px; }
}

@media (max-width: 520px) {
  .topbar { gap: 8px; }
  .brand p { max-width: 48vw; }
  .top-actions { gap: 5px; }
  .button.primary, .button.danger { font-size: 12px; }
  .controlbar { gap: 7px; }
  .controlbar label span { display: none; }
  .controlbar select { padding: 8px 25px 8px 7px; font-size: 12px; }
  .keyword-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .article { grid-template-columns: max-content minmax(0, 1fr); gap: 6px; padding: 7px 8px; }
  .article time { display: block; font-size: 10px; }
  .article-list.compact .article { grid-template-columns: max-content minmax(0, 1fr); gap: 5px; padding: 4px 6px; }
  .article-list.compact .article.no-time { grid-template-columns: minmax(0, 1fr); }
  .article-list.compact .article time { display: block; }
  .pagination { flex-wrap: wrap; }
}
