:root {
  --bg: #f5f4f0;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6a6f76;
  --line: #e4e2dc;
  --chip: #ebe9e3;
  --chip-on: #1f2328;
  --chip-on-text: #ffffff;
  --critical: #d92d36;
  --important: #d97706;
  --worth: #2f6fdb;
  --other: #8b9097;
  --accent-soft: #fdecec;
  --shadow: 0 1px 2px rgba(31, 35, 40, 0.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141518;
    --card: #1d1f23;
    --text: #e8e9eb;
    --muted: #9aa0a6;
    --line: #2c2f35;
    --chip: #262930;
    --chip-on: #e8e9eb;
    --chip-on-text: #141518;
    --critical: #ff5b61;
    --important: #f5a524;
    --worth: #6ea2ff;
    --other: #7d838b;
    --accent-soft: #3a1d1f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC",
        "Microsoft JhengHei", system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button { font: inherit; color: inherit; cursor: pointer; }

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
}
.bar, .windows, #list, .status, .message { max-width: 720px; margin-left: auto; margin-right: auto; }
@media (min-width: 752px) { .cats { max-width: 720px; margin-left: auto; margin-right: auto; padding: 0; } }
.bar { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 20px; margin: 0; letter-spacing: 0.02em; }
.icon-btn {
  border: 0; background: var(--chip); border-radius: 999px;
  width: 36px; height: 36px; font-size: 18px; line-height: 36px;
}
.icon-btn.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.windows { display: flex; gap: 8px; margin-top: 10px; }
.windows button {
  border: 0; background: var(--chip); border-radius: 999px; padding: 6px 14px; font-size: 14px;
}
.windows button.on { background: var(--chip-on); color: var(--chip-on-text); font-weight: 600; }
.cats {
  display: flex; gap: 6px; margin: 8px -16px 0; padding: 0 16px 2px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.cats::-webkit-scrollbar { display: none; }
.cats button {
  flex: none; border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 3px 10px; font-size: 13px; white-space: nowrap;
}
.cats button.on { background: var(--chip-on); color: var(--chip-on-text); border-color: var(--chip-on); }
.cats .n { margin-left: 5px; opacity: 0.6; font-variant-numeric: tabular-nums; }
.status { margin-top: 8px; margin-bottom: 0; font-size: 12px; color: var(--muted); min-height: 1em; }
.status span + span::before { content: "｜"; }
.status .warn { color: var(--critical); }
.sections { display: none; }

#list { padding: 4px 16px 0; }
.section {
  font-size: 13px; font-weight: 700; color: var(--muted);
  margin: 22px 2px 8px; letter-spacing: 0.04em;
  display: flex; align-items: center; gap: 8px;
}
.section::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.section { scroll-margin-top: 130px; }
.section.critical { color: var(--critical); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 14px 10px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.card.critical { border-color: var(--critical); box-shadow: 0 0 0 1px var(--critical) inset; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.score {
  font-weight: 700; font-variant-numeric: tabular-nums; color: #fff;
  border-radius: 7px; padding: 1px 7px; font-size: 13px;
}
.tier-critical .score { background: var(--critical); }
.tier-important .score { background: var(--important); }
.tier-worth .score { background: var(--worth); }
.tier-other .score { background: var(--other); }
.tag { border-radius: 6px; padding: 0 6px; font-size: 12px; font-weight: 600; }
.tag.new { background: var(--worth); color: #fff; }
.tag.urgent { border: 1px solid var(--critical); color: var(--critical); }
.tag.rules { border: 1px solid var(--other); }

.headline { font-size: 17px; line-height: 1.45; margin: 8px 0 4px; font-weight: 650; }
.card { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.card:active { opacity: 0.85; }
.card:focus-visible { outline: 2px solid var(--worth); outline-offset: 2px; }
.summary { margin: 0 0 6px; }
.why, .rel { margin: 0 0 4px; font-size: 14px; color: var(--muted); }
.why b, .rel b { color: var(--text); font-weight: 600; margin-right: 4px; }
.src { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

.fb { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.fb button {
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 4px 10px; font-size: 13px; min-height: 32px;
}
.fb button.on { background: var(--chip-on); color: var(--chip-on-text); border-color: var(--chip-on); }

.card.compact { padding: 10px 14px; }
.card.compact .headline { font-size: 15px; font-weight: 550; margin: 6px 0 0; }
.fb.mini { margin: 0 0 0 auto; gap: 4px; }
.fb.mini button { min-height: 28px; min-width: 36px; padding: 0 8px; font-size: 13px; }

.sentinel { height: 1px; }
.message { text-align: center; color: var(--muted); font-size: 14px; padding: 24px 16px 40px; }

/* Detail view: full screen on a phone, a side panel on a desktop. */
body.noscroll { overflow: hidden; }
.detail { position: fixed; inset: 0; z-index: 50; }
.detail[hidden] { display: none; }
.detail-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); }
.detail-panel {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); padding: 0 16px calc(env(safe-area-inset-bottom) + 40px);
}
.detail-top {
  position: sticky; top: 0; z-index: 1; margin: 0 -16px; padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.back { border: 0; background: var(--chip); border-radius: 999px; padding: 6px 14px; font-size: 14px; }
#detail-body { max-width: 720px; margin: 0 auto; }
.d-headline { font-size: 22px; line-height: 1.4; margin: 10px 0 8px; }
.d-lead { font-size: 17px; margin: 0 0 4px; }
.d-section h3 { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 0.04em; margin: 24px 0 8px; }
.d-section p { margin: 0; }
.d-points { margin: 0; padding-left: 1.2em; }
.d-points li { margin-bottom: 8px; }
.d-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 20px; }
.d-actions .fb { margin-top: 0; }
.btn-primary {
  background: var(--chip-on); color: var(--chip-on-text); text-decoration: none; font-weight: 600;
  border-radius: 999px; padding: 6px 16px; font-size: 14px; min-height: 32px; display: inline-flex; align-items: center;
}
.breakdown { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; max-width: 360px; }
.breakdown b { font-variant-numeric: tabular-nums; text-align: right; }
.breakdown span:nth-last-child(2), .breakdown b:last-child { border-top: 1px solid var(--line); padding-top: 4px; }
.dims {
  display: grid; grid-template-columns: 5em 1fr 1.5em; gap: 6px 10px; align-items: center;
  font-size: 13.5px; margin-top: 14px; max-width: 420px;
}
.dims .meter { display: block; height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.dims .meter i { display: block; height: 100%; background: var(--worth); border-radius: 4px; }
.dims .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.d-note { font-size: 12.5px; color: var(--muted); margin-top: 10px !important; }
.reports { list-style: none; margin: 0; padding: 0; }
.reports li { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.reports li:last-child { border-bottom: 0; }
.reports .r-meta { font-size: 12.5px; color: var(--muted); }
.reports .r-meta b { color: var(--text); font-weight: 600; }
.reports a { color: inherit; }

/* Desktop: a fixed sidebar with the controls, stories in as many columns as fit. */
@media (min-width: 1024px) {
  body { display: grid; grid-template-columns: 260px minmax(0, 1fr); }
  .top {
    height: 100vh; overflow-y: auto; padding: 28px 20px;
    border-bottom: 0; border-right: 1px solid var(--line);
  }
  .bar, .windows, .status { max-width: none; }
  h1 { font-size: 22px; }
  .windows { flex-wrap: wrap; margin-top: 18px; }
  .cats { flex-wrap: wrap; overflow: visible; max-width: none; margin: 14px 0 0; padding: 0; }
  .status { margin-top: 14px; line-height: 1.7; }
  .status span { display: block; }
  .status span + span::before { content: none; }
  .sections { display: flex; flex-direction: column; gap: 2px; margin-top: 22px; }
  .sections button {
    display: flex; justify-content: space-between; border: 0; background: transparent;
    border-radius: 8px; padding: 8px 10px; font-size: 14px; text-align: left;
  }
  .sections button:hover { background: var(--chip); }
  .sections button.critical { color: var(--critical); font-weight: 600; }
  .sections .count { color: var(--muted); font-variant-numeric: tabular-nums; }
  .content { padding: 8px 32px 0; min-width: 0; }
  #list {
    max-width: 1240px; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); gap: 14px; align-items: start;
  }
  #list .section { grid-column: 1 / -1; margin: 22px 2px -4px; scroll-margin-top: 16px; }
  .card { margin-bottom: 0; }
  .message { max-width: 1240px; }
  .card:hover { border-color: color-mix(in srgb, var(--muted) 45%, var(--line)); }
  .card:active { opacity: 1; }
  .fb button:hover, .icon-btn:hover, .windows button:not(.on):hover { filter: brightness(0.95); }
}

@media (min-width: 1024px) {
  .detail-panel {
    left: auto; width: min(640px, 100vw); padding: 0 28px 40px;
    border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(0, 0, 0, 0.12);
  }
  .detail-top { margin: 0 -28px; padding: 16px 28px 10px; }
}
