:root {
  color-scheme: light;
  --bg: #f8f7f3;
  --card: #fffefa;
  --ink: #20252e;
  --muted: #5d6877;
  --faint: #9aa3b2;
  --line: rgba(45, 49, 55, 0.08);
  --soft: #eeece7;
  --accent: #e5a900;
  --orange: #f47721;
  --section-active-bg: #050505;
  --section-active-ink: #ffffff;
  --shadow: 0 1px 2px rgba(30, 35, 40, 0.06), 0 0 0 1px rgba(30, 35, 40, 0.025);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0d0c;
  --card: #171514;
  --ink: #f1f1ef;
  --muted: #d3d0cb;
  --faint: #aaa59d;
  --line: rgba(255, 255, 255, 0.07);
  --soft: #2a2826;
  --accent: #f0bd22;
  --section-active-bg: #f0bd22;
  --section-active-ink: #171514;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  transition: background-color 220ms ease, color 220ms ease;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.utility-bar {
  position: fixed;
  z-index: 10;
  top: 19px;
  right: 20px;
  display: flex;
  gap: 8px;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 50%;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.icon-button:hover { background: var(--soft); color: var(--accent); transform: translateY(-1px); }
.icon-button svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sun-icon { color: var(--accent); }
.moon-icon { display: none; color: var(--accent); }
[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

main {
  min-height: 100vh;
  padding: 57px 24px 48px;
}

.hero { text-align: center; }
.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 3.05vw, 2.55rem);
  line-height: 1.2;
  font-weight: 760;
}
.hero h1 span { color: var(--accent); }
.hero > p { margin: 13px 0 31px; color: var(--muted); font-size: 1rem; }

.section-switch { display: flex; justify-content: center; gap: 34px; }
.section-button {
  border: 0;
  border-radius: 7px;
  padding: 10px 19px;
  color: var(--ink);
  background: var(--soft);
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}
.section-button:hover { transform: translateY(-1px); }
.section-button.active { color: var(--section-active-ink); background: var(--section-active-bg); }

.content { width: min(100%, 960px); margin: 31px auto 0; }
.feed-tabs { display: flex; justify-content: center; gap: 36px; }
.feed-tabs[hidden] { display: none !important; }
.feed-tab {
  position: relative;
  border: 0;
  background: none;
  padding: 5px 0 11px;
  color: var(--faint);
  font-size: .9rem;
  cursor: pointer;
  transition: color 160ms ease;
}
.feed-tab:hover, .feed-tab.active { color: var(--accent); }
.feed-tab.active::after {
  content: "";
  position: absolute;
  left: 50%; bottom: 3px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: currentColor;
  transform: translateX(-50%);
}

.status-row {
  min-height: 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  margin-top: 0;
  padding: 0 4px;
}

.refresh-button {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 8px;
  border: 0; background: transparent;
  color: var(--faint); font-size: .72rem;
  cursor: pointer; border-radius: 5px;
}
.refresh-button:hover { color: var(--accent); background: var(--soft); }
.refresh-button:disabled { opacity: .5; cursor: wait; }
.refresh-button svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.refresh-button.spinning svg { animation: spin .8s linear infinite; }
.ai-status { margin-right: auto; color: var(--muted); font-size: .72rem; }
.ai-status.error { color: var(--orange); }
#summaryRetryButton[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.story-list { display: grid; gap: 14px; }
.skeleton-card {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 12px;
  min-height: 142px;
  padding: 16px 17px;
  border-radius: 9px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.skeleton-card > div { padding-top: 2px; }
.skeleton-score, .skeleton-line {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 5px;
  background: var(--soft);
}
.skeleton-score { width: 18px; height: 32px; margin: 3px auto; }
.skeleton-line { width: 100%; height: 11px; margin-top: 12px; }
.skeleton-title { width: 52%; height: 16px; margin-top: 0; }
.skeleton-meta { width: 28%; height: 10px; margin-top: 10px; }
.skeleton-short { width: 72%; }
.skeleton-score::after, .skeleton-line::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .48), transparent);
  animation: shimmer 1.4s infinite;
}
.load-more-wrap {
  position: fixed;
  z-index: 12;
  right: 24px;
  bottom: 24px;
  display: flex;
  justify-content: center;
  padding: 0;
}
.load-more-wrap[hidden] { display: none; }
.load-more-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 17px;
  border: 0;
  border-radius: 999px;
  background: #11100f;
  color: #fff;
  font-size: .78rem;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(23, 20, 15, .2);
  transition: color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .load-more-button:hover:not(:disabled) { color: #f3c12c; transform: translateY(-2px); box-shadow: 0 14px 35px rgba(23, 20, 15, .27); }
}
.load-more-button:disabled { cursor: wait; opacity: .58; }
.load-more-button svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.load-more-button.loading svg { animation: load-bob .75s ease-in-out infinite alternate; }
@keyframes load-bob { to { transform: translateY(3px); } }
.story-card {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 12px;
  padding: 16px 17px;
  background: var(--card);
  border-radius: 9px;
  box-shadow: var(--shadow);
  animation: card-in 360ms both;
}
/* Restored lists (back/forward) appear in place instead of replaying the
   arrival animation, which read as a flash when coming back from a detail page. */
.story-list.no-entrance .story-card { animation: none; }
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } }

.score { display: flex; flex-direction: column; align-items: center; padding-top: 2px; font-size: .73rem; font-weight: 700; color: var(--muted); }
.upvote { width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid var(--orange); margin-bottom: 2px; }
.story-content { min-width: 0; }
.story-image {
  float: right;
  width: 154px;
  height: 82px;
  margin: 0 0 8px 18px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--soft);
}
.story-title {
  display: block;
  color: var(--ink);
  font-weight: 690;
  font-size: 1rem;
  line-height: 1.45;
  text-decoration: none;
  transition: color 160ms ease;
}
.story-title:hover { color: var(--accent); }
.story-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; margin-top: 4px; color: var(--faint); font-size: .72rem; }
.author { padding: 2px 7px; border-radius: 5px; background: var(--soft); color: var(--ink); font-weight: 650; }
.meta-item { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: none; }
.meta-item:hover { color: var(--accent); }
.meta-item svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.summary { margin: 10px 0 0; color: var(--muted); font-size: .875rem; line-height: 1.52; }
.story-summary-link { display: block; color: inherit; text-decoration: none; border-radius: 5px; }
.story-summary-link:hover .summary { color: var(--ink); }
.story-summary-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.story-summary-link.return-focus:focus { outline: none; }
.quote { margin: 7px 0 0; color: var(--ink); font-size: .86rem; font-style: italic; }
.ai-shimmer { position: relative; overflow: hidden; color: transparent; border-radius: 4px; background: var(--soft); user-select: none; }
.ai-shimmer::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent); animation: shimmer 1.5s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

.toast {
  position: fixed; z-index: 20; left: 50%; bottom: 28px;
  padding: 9px 14px; border-radius: 8px;
  background: var(--ink); color: var(--bg); font-size: .8rem;
  transform: translate(-50%, 18px); opacity: 0; pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .utility-bar { display: none; }
  main { padding: 38px 13px 35px; }
  .hero h1 { font-size: 1.62rem; }
  .hero > p { margin: 8px 0 20px; font-size: .84rem; }
  .section-switch { gap: 18px; }
  .section-button { padding: 7px 12px; font-size: .83rem; }
  .content { margin-top: 20px; }
  .feed-tabs { gap: 25px; }
  .feed-tab { font-size: .75rem; }
  .status-row { min-height: 30px; margin-top: 4px; }
  .story-list { gap: 11px; }
  .skeleton-card { grid-template-columns: 23px minmax(0, 1fr); gap: 8px; min-height: 126px; padding: 12px 10px; }
  .load-more-wrap { right: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(50%); }
  .load-more-button { padding: 9px 18px; white-space: nowrap; }
  .story-card { grid-template-columns: 23px minmax(0, 1fr); gap: 8px; padding: 12px 10px; border-radius: 8px; }
  .score { font-size: .66rem; }
  .upvote { border-left-width: 5px; border-right-width: 5px; border-bottom-width: 8px; }
  .story-image { width: 96px; height: 72px; margin-left: 10px; }
  .story-title { font-size: .86rem; line-height: 1.4; }
  .story-meta { gap: 6px; font-size: .65rem; }
  .summary, .quote { font-size: .75rem; line-height: 1.5; }
  .summary { margin-top: 7px; }
  .quote { margin-top: 5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
