:root {
  color-scheme: light;
  --page: #f3f1eb;
  --surface: #fffdf8;
  --surface-soft: #ebe8df;
  --ink: #182221;
  --muted: #63706d;
  --line: rgba(24, 34, 33, 0.12);
  --primary: #123f3b;
  --primary-ink: #f8fffd;
  --accent: #d56b45;
  --accent-soft: #f4dfd3;
  --green-soft: #dceae1;
  --green-ink: #21583e;
  --shadow: 0 12px 36px rgba(32, 42, 39, 0.08);
  --radius-lg: 26px;
  --radius-md: 18px;
  --font-size: 18px;
}

:root[data-font="xlarge"] { --font-size: 20px; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111817;
  --surface: #192220;
  --surface-soft: #222d2a;
  --ink: #eff5f2;
  --muted: #acbab5;
  --line: rgba(239, 245, 242, 0.13);
  --primary: #d9eee6;
  --primary-ink: #10201b;
  --accent: #ed9875;
  --accent-soft: #472f27;
  --green-soft: #243c31;
  --green-ink: #bfe7cf;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.2);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --page: #111817;
    --surface: #192220;
    --surface-soft: #222d2a;
    --ink: #eff5f2;
    --muted: #acbab5;
    --line: rgba(239, 245, 242, 0.13);
    --primary: #d9eee6;
    --primary-ink: #10201b;
    --accent: #ed9875;
    --accent-soft: #472f27;
    --green-soft: #243c31;
    --green-ink: #bfe7cf;
    --shadow: 0 14px 40px rgba(0, 0, 0, 0.2);
  }
}

* { box-sizing: border-box; }

html { background: var(--page); font-size: var(--font-size); scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 400;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 10px 14px;
  background: var(--surface);
  color: var(--ink);
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }

.app-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 18px calc(102px + env(safe-area-inset-bottom));
  background: var(--page);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 0 12px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 5px);
  align-items: end;
  gap: 3px;
  width: 28px;
  height: 28px;
  padding: 5px;
  border-radius: 9px;
  background: var(--primary);
}
.brand-mark span { display: block; border-radius: 3px; background: var(--primary-ink); }
.brand-mark span:nth-child(1) { height: 7px; }
.brand-mark span:nth-child(2) { height: 14px; }
.brand-mark span:nth-child(3) { height: 10px; }

.brand-copy { display: grid; line-height: 1.08; }
.brand-copy strong { font-size: 1.14rem; font-weight: 700; letter-spacing: -0.03em; }
.brand-copy small { margin-top: 4px; color: var(--muted); font-size: 0.63rem; letter-spacing: 0.02em; }

.round-button, .icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}
.round-button {
  min-width: 46px;
  height: 46px;
  padding: 0 10px;
  border-radius: 50%;
  font-weight: 700;
}
.icon-button { width: 42px; height: 42px; border-radius: 50%; font-size: 1.4rem; }

.connection-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 18px;
  color: var(--muted);
  font-size: 0.72rem;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4d966a; box-shadow: 0 0 0 4px var(--green-soft); }
.connection-line.is-stale .status-dot { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.loading-state { display: grid; min-height: 50vh; place-items: center; align-content: center; color: var(--muted); text-align: center; }
.loading-mark { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }

.section-heading { margin: 0 0 16px; font-size: 1.68rem; line-height: 1.12; letter-spacing: -0.045em; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }

.away-card {
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: var(--shadow);
}
.away-card::after {
  content: "";
  position: absolute;
  right: -35px;
  bottom: -55px;
  width: 150px;
  height: 150px;
  border: 1px solid color-mix(in srgb, var(--primary-ink) 25%, transparent);
  border-radius: 50%;
  box-shadow: 0 0 0 26px color-mix(in srgb, var(--primary-ink) 5%, transparent), 0 0 0 52px color-mix(in srgb, var(--primary-ink) 4%, transparent);
}
.away-card .eyebrow { color: color-mix(in srgb, var(--primary-ink) 72%, transparent); }
.away-card h1 { max-width: 310px; margin: 0; font-size: 1.55rem; line-height: 1.16; letter-spacing: -0.04em; }
.away-card p { position: relative; z-index: 1; max-width: 270px; margin: 12px 0 20px; color: color-mix(in srgb, var(--primary-ink) 76%, transparent); }

.quiet-button, .primary-button, .secondary-button {
  min-height: 48px;
  padding: 11px 17px;
  border-radius: 15px;
  cursor: pointer;
  font-weight: 700;
}
.quiet-button { position: relative; z-index: 1; border: 0; background: var(--primary-ink); color: var(--primary); }
.primary-button { width: 100%; border: 0; background: var(--primary); color: var(--primary-ink); }
.secondary-button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }

.digest-card {
  margin-bottom: 26px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.digest-card h2 { margin: 0; font-size: 1.28rem; line-height: 1.2; letter-spacing: -0.025em; }
.digest-intro { margin: 8px 0 18px; color: var(--muted); font-size: 0.88rem; }
.digest-list { display: grid; gap: 14px; margin: 0; padding: 0; list-style: none; counter-reset: digest; }
.digest-list li { display: grid; grid-template-columns: 28px 1fr; gap: 9px; align-items: start; }
.digest-list li::before { counter-increment: digest; content: counter(digest, decimal-leading-zero); color: var(--accent); font-size: 0.7rem; font-weight: 700; padding-top: 4px; }

.section-tabs {
  display: flex;
  gap: 8px;
  margin: 0 -18px 20px;
  padding: 2px 18px;
  overflow-x: auto;
  scrollbar-width: none;
}
.section-tabs::-webkit-scrollbar { display: none; }
.tab-chip { flex: 0 0 auto; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--muted); cursor: pointer; }
.tab-chip.is-active { border-color: var(--primary); background: var(--primary); color: var(--primary-ink); }

.feed-head { display: flex; align-items: end; justify-content: space-between; margin: 8px 0 14px; }
.feed-head h2 { margin: 0; font-size: 1.25rem; letter-spacing: -0.03em; }
.feed-head span { color: var(--muted); font-size: 0.72rem; }
.date-divider { display: flex; gap: 12px; align-items: center; margin: 24px 0 12px; color: var(--muted); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.date-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }

.news-list { display: grid; gap: 15px; }
.news-card {
  width: 100%;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.card-media, .article-media {
  position: relative;
  overflow: hidden;
  background: var(--surface-soft);
}
.card-media { height: 184px; }
.article-media { height: 260px; margin: 0 -18px 24px; }
.card-media img, .article-media img { position: absolute; z-index: 2; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.media-art { position: absolute; inset: 0; }
.media-art::before, .media-art::after { content: ""; position: absolute; border-radius: 50%; }
.media-art::before { width: 230px; height: 230px; right: -54px; top: -70px; background: rgba(255,255,255,.17); }
.media-art::after { width: 110px; height: 110px; left: 22px; bottom: -38px; border: 1px solid rgba(255,255,255,.38); box-shadow: 0 0 0 24px rgba(255,255,255,.08); }
.media-art.diplomacy { background: linear-gradient(135deg, #354d52, #937d65); }
.media-art.russia { background: linear-gradient(135deg, #5a6670, #879387); }
.media-art.economy { background: linear-gradient(135deg, #344d45, #9a8d60); }
.media-art.world { background: linear-gradient(135deg, #45526d, #7d8699); }
.media-art.siberia { background: linear-gradient(135deg, #315b55, #9aa989); }
.media-art.altai { background: linear-gradient(135deg, #496a60, #b49a78); }
.media-symbol { position: absolute; z-index: 2; right: 18px; bottom: 14px; color: rgba(255,255,255,.86); font-size: 0.68rem; letter-spacing: .08em; text-transform: uppercase; }
.card-badge { position: absolute; z-index: 3; top: 14px; left: 14px; padding: 6px 10px; border-radius: 99px; background: rgba(255,253,248,.92); color: #17312d; font-size: 0.66rem; font-weight: 800; }

.card-body { padding: 18px 18px 20px; }
.card-meta, .article-meta { display: flex; flex-wrap: wrap; gap: 7px 10px; align-items: center; margin-bottom: 8px; color: var(--muted); font-size: 0.68rem; }
.category { color: var(--accent); font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.news-card h3 { margin: 0 0 10px; font-size: 1.12rem; line-height: 1.25; letter-spacing: -0.025em; }
.news-card p { margin: 0; color: var(--muted); font-size: 0.86rem; line-height: 1.5; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  bottom: 0;
  left: 50%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: min(100%, 480px);
  padding: 9px 10px max(9px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(22px);
  transform: translateX(-50%);
}
.nav-item { display: grid; justify-items: center; gap: 3px; min-height: 54px; padding: 6px 2px; border: 0; border-radius: 14px; background: transparent; color: var(--muted); cursor: pointer; font-size: 0.58rem; }
.nav-item svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item.is-active { background: var(--surface-soft); color: var(--primary); }

.article-view { padding-bottom: 20px; }
.article-back { display: inline-flex; align-items: center; gap: 6px; margin: 2px 0 16px; padding: 8px 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.article-view h1 { margin: 0 0 16px; font-size: 1.72rem; line-height: 1.12; letter-spacing: -0.045em; }
.article-lead { margin: 0 0 24px; color: var(--muted); font-size: 1rem; line-height: 1.58; }
.article-body p { margin: 0 0 18px; }
.info-block { margin: 22px 0; padding: 18px; border-radius: var(--radius-md); background: var(--surface-soft); }
.info-block.is-context { border-left: 4px solid var(--primary); }
.info-block.is-meaning { border-left: 4px solid var(--accent); }
.info-block.is-assessment { border: 1px dashed var(--line); background: transparent; }
.info-block h2 { margin: 0 0 8px; font-size: 1rem; }
.info-block p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.change-block { margin-bottom: 22px; padding: 18px; border-radius: var(--radius-md); background: var(--green-soft); color: var(--green-ink); }
.change-block .eyebrow { color: inherit; }
.change-block p { margin: 0; }
.story-history { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--line); }
.photo-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 22px 0; }
.photo-gallery img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 14px; background: var(--surface-soft); }
.story-history summary { cursor: pointer; font-weight: 700; }
.history-item { margin: 15px 0 0; padding-left: 15px; border-left: 2px solid var(--line); }
.history-item time { color: var(--muted); font-size: 0.68rem; }
.history-item h3 { margin: 4px 0 6px; font-size: .95rem; }
.history-item p { margin: 0; color: var(--muted); font-size: .82rem; }

.settings-dialog { width: min(calc(100% - 28px), 430px); padding: 0; border: 0; border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); box-shadow: 0 24px 80px rgba(0,0,0,.3); }
.settings-dialog::backdrop { background: rgba(9, 18, 16, .55); backdrop-filter: blur(4px); }
.settings-dialog form { padding: 22px; }
.dialog-head { display: flex; align-items: start; justify-content: space-between; margin-bottom: 18px; }
.dialog-head h2 { margin: 0; font-size: 1.35rem; }
.settings-dialog fieldset { margin: 0 0 18px; padding: 0; border: 0; }
.settings-dialog legend { margin-bottom: 9px; font-weight: 700; }
.choice-row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 9px 12px; border-top: 1px solid var(--line); cursor: pointer; }
.choice-row input { width: 20px; height: 20px; accent-color: var(--primary); }

.error-card { margin-top: 32px; padding: 24px; border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); text-align: center; }
.error-card h1 { margin: 0 0 10px; font-size: 1.35rem; }
.error-card p { color: var(--muted); }

@media (min-width: 600px) {
  body { padding: 22px 0; }
  .app-shell { min-height: calc(100vh - 44px); border-radius: 32px; box-shadow: 0 20px 80px rgba(32,42,39,.14); }
  .topbar { border-radius: 32px 32px 0 0; }
  .bottom-nav { bottom: 18px; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
}
