:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --line: #e2e6ec;
  --ink: #23272f;
  --muted: #6c7480;
  --accent: #2e5fcc;
  --accent-soft: #e4ebfa;
  --good: #2f7d4f;
  --good-soft: #e1f0e7;
  --warn: #a8501a;
  --warn-soft: #fbe9dc;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1d222a;
    --line: #2c323d;
    --ink: #e8eaef;
    --muted: #9aa2af;
    --accent: #7da2f2;
    --accent-soft: #26344f;
    --good: #6cc493;
    --good-soft: #1f3a2b;
    --warn: #e09055;
    --warn-soft: #3d2a1c;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
button:disabled { opacity: .35; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- app bar ---------- */

.appbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 6px;
}
.appbar h1 { font-size: 22px; margin: 0; }
.appbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.updated { font-size: 11px; color: var(--muted); white-space: nowrap; }
.icon-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 21px; height: 21px; display: block; }
.icon-btn:active { background: var(--accent-soft); color: var(--accent); }

#refresh-btn { color: var(--accent); }
#refresh-btn.spinning { pointer-events: none; }
#refresh-btn.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  #refresh-btn.spinning svg { animation: none; opacity: .5; }
}

/* ---------- page dots (category strip) ---------- */

.pagedots {
  flex: none;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 12px 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.pagedots::-webkit-scrollbar { display: none; }
.dot {
  flex: none;
  font-size: 12.5px;
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}
.dot.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.pagedots[hidden] { display: none; }

/* ---------- bottom tab bar ---------- */

.tabbar {
  flex: none;
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--muted);
  padding: 7px 2px 6px;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 22px; height: 22px; display: block; }
.tab .tb-label { font-size: 10.5px; }
.tab.on { color: var(--accent); }
.tab.on .tb-label { font-weight: 700; }
.tab .tb-badge {
  position: absolute;
  transform: translate(13px, -3px);
  min-width: 15px;
  height: 15px;
  border-radius: 99px;
  background: var(--warn);
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
  padding: 0 3px;
}

/* ---------- horizontal pager ---------- */

.pager {
  flex: 1;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.pager::-webkit-scrollbar { display: none; }

.page {
  flex: 0 0 100%;
  width: 100%;
  position: relative;
  scroll-snap-align: start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.pull-refresh {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  left: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  transform: translateY(-48px);
  transition: transform .2s ease;
}
.pull-refresh.pulling { transition: none; }
.pull-refresh::before {
  content: '⇓';
  margin-right: 6px;
  color: var(--accent);
  font-size: 17px;
  transition: transform .2s ease;
}
.pull-refresh.ready::before { transform: rotate(180deg); }
.pull-refresh.loading::before { animation: spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  .pull-refresh { transition: none; }
  .pull-refresh.loading::before { animation: none; }
}

/* the tab bar already carries the bottom safe-area inset */
.page-inner {
  padding: 0 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform .2s ease;
}
.page.pull-refresh-active .page-inner { transition: none; }

.placeholder, .w-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 14px 6px;
  margin: 0;
}
.placeholder { padding: 40px 16px; }

/* ---------- news list ---------- */

.sortrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 0 4px;
  font-size: 12px;
  color: var(--muted);
}
.sort-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  padding: 2px 0;
}

.news-list {
  list-style: none;
  margin: 0;
  padding: 2px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.news-list.flat { border: 0; background: none; padding: 0; border-radius: 0; }

.news-item { padding: 11px 2px; border-top: 1px solid var(--line); }
.news-item:first-child { border-top: 0; }
.item-top { display: flex; align-items: flex-start; gap: 6px; }
.item-link {
  flex: 1;
  color: inherit;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  padding: 2px 0;
  -webkit-tap-highlight-color: rgba(46, 95, 204, .12);
}
.item-link:active { opacity: .55; }
/* translation failed: title stays in its original language */
.item-link.untranslated::after {
  content: 'EN';
  margin-left: 6px;
  font-size: 9.5px;
  font-weight: 700;
  color: var(--muted);
  vertical-align: 2px;
}
.thumb {
  flex: none;
  width: 76px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--accent-soft);
  margin-top: 1px;
}
.more {
  flex: none;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
}
.meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.badge {
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}
.cat-badge { background: transparent; border: 1px solid var(--line); color: var(--muted); }

/* ---------- widgets ---------- */

.widget {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px 12px;
}
.w-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.w-btns { display: flex; align-items: center; gap: 4px; }
.w-place {
  max-width: 112px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.w-locate {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  padding: 4px;
  background: none;
  color: var(--accent);
}
.w-locate:active { background: var(--accent-soft); }
.w-locate svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}
.w-locate svg .fill { fill: currentColor; stroke: none; }
.w-locate.spinning svg { animation: spin .8s linear infinite; }
.w-btn {
  border: 1px solid var(--line);
  background: none;
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 8px;
  padding: 3px 8px;
}

.add-dashed {
  width: 100%;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  background: none;
  color: var(--muted);
  font-size: 13px;
  padding: 12px;
}

/* weather */
.weather-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.wx-icon { font-size: 24px; line-height: 1; }
.temp { font-size: 30px; font-weight: 800; line-height: 1.1; }
.cond { font-size: 13px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.bad { background: var(--warn-soft); color: var(--warn); }

.week {
  display: flex;
  gap: 4px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.week::-webkit-scrollbar { display: none; }
.wday {
  flex: 1 0 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}
.wday.today .wd-name { color: var(--accent); font-weight: 700; }
.wd-name { font-size: 11px; color: var(--muted); }
.wd-icon { font-size: 17px; line-height: 1; }
.wd-max { font-size: 13px; font-weight: 700; }
.wd-min { font-size: 12px; color: var(--muted); }

/* links */
.linkgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.linkitem {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  color: var(--muted);
}
.linkitem .ic {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  font-weight: 700;
}
.linkitem .lb { font-size: 10.5px; text-align: center; }

/* ---------- tracker / scrap ---------- */

.segrow { display: flex; gap: 6px; padding: 2px 0; }
.seg {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  padding: 5px 4px;
}
.seg.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }

.tk-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 12px;
}
.tk-top { display: flex; align-items: flex-start; gap: 6px; }
.tk-name {
  flex: 1;
  border: 0;
  background: none;
  color: inherit;
  font-size: 15px;
  font-weight: 700;
  text-align: left;
  padding: 0;
  line-height: 1.35;
}
.tk-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted);
}
.tk-kw { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.tk-kw .kw {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--line);
  color: var(--muted);
}

/* timeline inside the tracker panel: one card per day, strung on a rail */
.tl { display: flex; flex-direction: column; }
.tl-day { display: flex; gap: 9px; }
.tl-rail { flex: none; width: 14px; display: flex; flex-direction: column; align-items: center; }
.tl-dot {
  width: 11px;
  height: 11px;
  border-radius: 99px;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1.5px var(--accent);
  margin-top: 15px;
  flex: none;
}
/* a day several outlets covered reads as a bigger event */
.tl-dot.big {
  width: 15px;
  height: 15px;
  margin-top: 13px;
  background: var(--warn);
  box-shadow: 0 0 0 1.5px var(--warn);
}
.tl-line { flex: 1; width: 2.5px; background: var(--accent); opacity: .3; border-radius: 2px; }
.tl-body { flex: 1; min-width: 0; padding-bottom: 10px; }

.tl-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 9px 12px 11px;
}
.tl-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 7px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.tl-date {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.tl-dow { font-size: 11.5px; color: var(--muted); }
.tl-count { font-size: 11px; color: var(--muted); margin-left: auto; }

.tl-links { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.tl-links li { display: flex; align-items: flex-start; gap: 6px; }
.tl-links a {
  flex: 1;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}
.tl-links a:active { opacity: .55; }
.tl-src { display: block; font-size: 11.5px; font-weight: 400; color: var(--muted); margin-top: 2px; }

/* hand-written entry: an event with no article behind it */
.tl-note { flex: 1; min-width: 0; }
.tl-note .nt {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tl-note .nb {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--good);
  background: var(--good-soft);
  border-radius: 99px;
  padding: 1px 7px;
  margin-top: 4px;
}
.tl-x {
  flex: none;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  padding: 2px 3px;
}

/* ---------- settings / editor rows ---------- */

.set-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px 12px;
  margin-bottom: 10px;
}
.set-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.set-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 0;
  border-top: 1px solid var(--line);
}
.set-row:first-of-type { border-top: 0; }
.set-label { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.set-label input { width: 18px; height: 18px; accent-color: var(--accent); }

.set-choice { align-items: flex-start; gap: 9px; padding: 8px 0; }
.set-choice input { flex: none; width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }
.choice-tx { display: flex; flex-direction: column; gap: 2px; }
.choice-label { font-size: 14px; }
.choice-hint { font-size: 11.5px; color: var(--muted); line-height: 1.4; }

/* source blocking: dashed tiles, struck through when blocked */
.src-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.src-chip {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font-size: 12.5px;
  padding: 5px 10px;
  line-height: 1.3;
}
.src-chip.blocked {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  text-decoration-color: var(--warn);
  color: var(--muted);
  border-style: solid;
  border-color: var(--warn-soft);
  background: var(--warn-soft);
}

.set-title.mt { margin-top: 12px; }

.fam-chip {
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 12px;
}
.fam-chip.blocked {
  background: var(--warn-soft);
  border-color: var(--warn);
  color: var(--warn);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
}
.fam-chip.partial {
  border-style: dashed;
  border-color: var(--warn);
  color: var(--warn);
}

.chipbox { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.x-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  padding: 3px 6px 3px 10px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
}
.x-chip .x { border: 0; background: none; color: inherit; font-size: 11px; padding: 0 2px; }

.add-form { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
/* iOS Safari zooms the page in when a focused field is under 16px and never
   zooms back out, so every text control stays at 16px on touch screens. */
.in {
  flex: 1;
  min-width: 130px;
  font: inherit;
  font-size: 16px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  color: var(--ink);
}
@media (pointer: fine) {
  .in { font-size: 13px; }
}
textarea.in { width: 100%; resize: vertical; line-height: 1.45; }
.primary {
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
}

.edit-list { display: flex; flex-direction: column; gap: 8px; }
.edit-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
}
.edit-row .tx { flex: 1; min-width: 0; }
.edit-row .nm { font-size: 14px; font-weight: 600; }
.edit-row .url {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- overlay: sheet + panel ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 50;
}
.sheet {
  width: 100%;
  max-width: 430px;
  background: var(--surface);
  border-radius: 14px;
  overflow: hidden;
}
.s-title {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}
.s-item {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  padding: 13px 10px;
}
.s-item:last-child { border-bottom: 0; }
.s-cancel { color: var(--muted); }
.s-item.danger { color: var(--warn); }

/* a confirmation raised from inside a panel has to sit above it */
.sheet-backdrop.stacked { z-index: 80; }

/* in-app article viewer (standalone mode only) */
.reader {
  position: fixed;
  inset: 0;
  background: var(--surface);
  z-index: 70;
  display: flex;
  flex-direction: column;
}
.reader-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.reader-back {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
  padding: 2px 0;
}
.reader-src {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-open {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 9px;
}
.reader-frame { flex: 1; width: 100%; border: 0; background: var(--surface); }
.reader-hint {
  display: none;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  text-align: center;
  border-top: 1px solid var(--line);
}
.reader-hint.on { display: block; }
.reader-hint p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }

.panel {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.panel-done { border: 0; background: none; color: var(--accent); font-size: 15px; font-weight: 700; }
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px calc(20px + env(safe-area-inset-bottom));
}
