:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #15201e;
  --muted: #5d6b68;
  --border: #dde4e2;
  --accent: #0f766e;
  --accent-soft: #d8efec;
  --accent-text: #0b5e57;
  --danger: #b42318;
  --warning: #a15c07;
  --success: #15803d;
  --shadow: 0 1px 2px rgba(16, 24, 22, .06), 0 4px 16px rgba(16, 24, 22, .05);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1413;
    --surface: #161e1c;
    --surface-2: #1d2725;
    --text: #e7eeec;
    --muted: #9aa9a6;
    --border: #2a3633;
    --accent: #2dd4bf;
    --accent-soft: #143a35;
    --accent-text: #5eead4;
    --danger: #f97066;
    --warning: #fbbf24;
    --success: #4ade80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.7;
}

a { color: var(--accent-text); }

button, input, select { font: inherit; color: inherit; }

.container { max-width: 980px; margin: 0 auto; padding: 0 16px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 980px; margin: 0 auto; padding: 10px 16px;
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand img { border-radius: 9px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-family: "Reem Kufi", "IBM Plex Sans Arabic", sans-serif; font-size: 24px; line-height: 1.1; }
.brand-text small { color: var(--muted); font-size: 12px; }

.search input {
  width: 100%; padding: 9px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); outline: none;
}
.search input:focus { border-color: var(--accent); background: var(--surface); }

.nav { display: flex; gap: 4px; }
.nav a {
  text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; font-weight: 500;
  white-space: nowrap;
}
.nav a.active, .nav a:hover { background: var(--accent-soft); color: var(--accent-text); }

.nav .install { margin-inline-start: 6px; }

/* Bottom tab bar (phones) */
.tabbar { display: none; }

@media (max-width: 760px) {
  .topbar-inner { grid-template-columns: 1fr auto; padding-top: max(10px, env(safe-area-inset-top)); }
  .search { grid-column: 1 / -1; grid-row: 2; }
  .brand-text small { display: none; }
  /* On phones the page links move to the bottom bar; keep only "install" up top */
  .nav { grid-column: 2; grid-row: 1; }
  .nav a { display: none; }

  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    background: color-mix(in srgb, var(--surface) 95%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px;
    text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 500;
  }
  .tab-icon {
    width: 24px; height: 24px; fill: none; stroke: currentColor;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
  }
  .tabbar a.active .tab-icon { stroke-width: 2.2; }
  .tabbar a.active { color: var(--accent-text); }
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

.phone-grid { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.phone-grid ol { flex: 1; min-width: 240px; margin: 0; padding-inline-start: 20px; }
.phone-grid li { margin-bottom: 8px; }
.qr { width: 180px; height: 180px; background: #fff; border-radius: 12px; padding: 8px; flex: none; }
.qr svg { width: 100%; height: 100%; display: block; }
.addr { background: var(--surface-2); border-radius: 8px; padding: 4px 10px; margin-top: 4px; font-family: Consolas, monospace; font-size: 14px; word-break: break-all; }

.offline {
  background: #fff4d6; color: #6b4b00; text-align: center; padding: 8px 16px; font-size: 14px;
  border-bottom: 1px solid #f0d58a;
}
@media (prefers-color-scheme: dark) { .offline { background: #3a2f10; color: #f6d77a; border-color: #5a4a1a; } }

/* ---------- Filters ---------- */
.page-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 20px 0 8px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head .meta { color: var(--muted); font-size: 14px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0 10px; scrollbar-width: thin; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 5px 14px; cursor: pointer; white-space: nowrap; font-size: 14px;
}
.chip .count { color: var(--muted); font-size: 12px; margin-inline-start: 4px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip[aria-pressed="true"] .count { color: rgba(255,255,255,.8); }
@media (prefers-color-scheme: dark) { .chip[aria-pressed="true"] { color: #062b27; } .chip[aria-pressed="true"] .count { color: #0b3d37; } }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters select {
  padding: 7px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
}
.filters .clear { border: none; background: none; color: var(--accent-text); cursor: pointer; }

/* ---------- Story cards ---------- */
.stories { display: grid; gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.card-top { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; color: var(--muted); font-size: 13px; }
.badge {
  background: var(--accent-soft); color: var(--accent-text); border-radius: 999px; padding: 1px 10px;
  font-size: 12px; font-weight: 600;
}
.card h2 { font-size: 19px; line-height: 1.55; margin: 8px 0 6px; }
.card h2 a { color: var(--text); text-decoration: none; }
.card h2 a:hover { color: var(--accent-text); }
.card p.summary { margin: 0 0 10px; color: var(--text); opacity: .9; }
.original {
  border-inline-start: 3px solid var(--border); padding-inline-start: 12px; margin: 8px 0 10px; color: var(--muted);
  font-size: 14px;
}
.original strong { color: var(--text); font-weight: 600; display: block; }

.card-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: 5px 12px; cursor: pointer; font-size: 14px; text-decoration: none; color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062b27; } }
.btn.fav[aria-pressed="true"] { color: #b7791f; border-color: #e9c46a; background: color-mix(in srgb, #f4d35e 18%, var(--surface)); }
.btn:disabled { opacity: .6; cursor: progress; }

.related { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 10px; }
.related summary { cursor: pointer; color: var(--accent-text); font-weight: 600; font-size: 14px; }
.related ul { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.related li { font-size: 14px; }
.related li .src { color: var(--muted); font-size: 12px; display: block; }

.more { display: flex; justify-content: center; margin: 20px 0; }

/* ---------- Article page ---------- */
.article { margin-top: 20px; }
.article h1 { font-size: 26px; line-height: 1.5; margin: 10px 0; }
.article .lead { font-size: 18px; }
.back { display: inline-block; margin-top: 16px; text-decoration: none; }

/* ---------- Tables / forms ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel h2 { margin: 0 0 10px; font-size: 18px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: none; }
.list .sub { color: var(--muted); font-size: 13px; }
.err { color: var(--danger); font-size: 13px; }
.ok { color: var(--success); }
.warn { color: var(--warning); }

.switch { position: relative; width: 44px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { inset-inline-start: 23px; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.form input, .form select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.form .full { grid-column: 1 / -1; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 12px; box-shadow: var(--shadow); z-index: 20; max-width: calc(100% - 32px);
}

.footer { color: var(--muted); font-size: 13px; text-align: center; padding-top: 24px; padding-bottom: 32px; }

[dir="ltr"] { text-align: left; }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* ---------- Breaking news ---------- */
.breaking {
  display: flex; align-items: center; gap: 12px; margin-top: 16px; padding: 10px 14px;
  background: #fff1f1; border: 1px solid #f5c2c2; border-inline-start: 5px solid #d92d20; border-radius: 12px;
}
.breaking-label {
  background: #d92d20; color: #fff; font-weight: 700; border-radius: 8px; padding: 2px 12px; flex: none;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .65; } }
@media (prefers-reduced-motion: reduce) { .breaking-label { animation: none; } }
.breaking-items { flex: 1; min-width: 0; }
.breaking-item { display: block; color: #7a1a12; font-weight: 600; text-decoration: none; line-height: 1.5; }
.breaking-item:hover { text-decoration: underline; }
.breaking-meta { display: block; font-weight: 400; font-size: 12px; color: #a3483f; }
.breaking-count { background: #fde2e1; color: #b42318; border-radius: 999px; padding: 0 8px; font-size: 12px; flex: none; }
.badge.breaking-badge { background: #d92d20; color: #fff; }
@media (prefers-color-scheme: dark) {
  .breaking { background: #3a1513; border-color: #6b2620; }
  .breaking-item { color: #ffd2cc; }
  .breaking-meta { color: #f4a49b; }
  .breaking-count { background: #6b2620; color: #ffd2cc; }
}

/* ---------- Story images ---------- */
.card .thumb, .article .hero { display: block; overflow: hidden; border-radius: 10px; background: var(--surface-2); }
.card .thumb img, .article .hero img { width: 100%; height: 100%; object-fit: cover; display: block; }
.article .hero { aspect-ratio: 16 / 9; margin-bottom: 12px; }
/* Computer: photo beside the text */
@media (min-width: 761px) {
  .card.has-image { display: grid; grid-template-columns: 1fr 220px; column-gap: 18px; }
  .card.has-image > .thumb { grid-column: 2; grid-row: 1 / span 4; aspect-ratio: 4 / 3; align-self: start; }
  .card.has-image > :not(.thumb) { grid-column: 1; }
}
/* Phone: wide photo on top of the card */
@media (max-width: 760px) {
  .card .thumb { aspect-ratio: 16 / 9; margin: -16px -18px 12px; border-radius: var(--radius) var(--radius) 0 0; }
}

/* ---------- Breaking-news preferences ---------- */
.breaking-gear { border: none; background: transparent; color: #b42318; cursor: pointer; padding: 4px; border-radius: 8px; flex: none; display: grid; }
.breaking-gear:hover { background: #fde2e1; }
.breaking-filter { display: block; font-size: 12px; color: #a3483f; margin-top: 2px; }
.breaking-settings { margin-top: 10px; }
.breaking-settings fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 0 0 12px; padding: 10px 12px; }
.breaking-settings legend { font-weight: 600; padding: 0 6px; }
.breaking-settings label { display: block; padding: 3px 0; cursor: pointer; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 2px 12px; }
.sources-list { max-height: 260px; overflow-y: auto; margin-top: 8px; }
.source-filter { width: 100%; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
@media (prefers-color-scheme: dark) {
  .breaking-gear { color: #ffb4a9; }
  .breaking-gear:hover { background: #6b2620; }
  .breaking-filter { color: #f4a49b; }
}

/* ---------- Comprehensive summary ---------- */
.detail h2 { display: flex; align-items: center; gap: 8px; }
.detail h2::before { content: ""; width: 6px; height: 22px; border-radius: 3px; background: linear-gradient(#ffc145, #ff6b4a); }
.detail-title { font-size: 16px; margin: 14px 0 6px; color: var(--accent-text); }
.detail-points { margin: 0; padding-inline-start: 22px; }
.detail-points li { margin-bottom: 6px; line-height: 1.8; }
.detail-wait { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.detail-wait .sub { flex-basis: 100%; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
