/* ---- Theme tokens -------------------------------------------------------- */
:root {
  --max: 720px;
  --radius: 14px;
  --gap: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  /* Claude-style warm accent — shared by both themes */
  --accent-grad: linear-gradient(135deg, #ff9a52 0%, #e8825a 45%, #d97757 100%);
  --accent-glow: 0 6px 18px rgba(217, 119, 87, .42);
  --sa-l: env(safe-area-inset-left);
  --sa-r: env(safe-area-inset-right);
}
html[data-theme="dark"] {
  --bg: #0d1014;
  --bg-elev: #161b22;
  --bg-hover: #1d242e;
  --border: #262d36;
  --text: #e7ecf1;
  --text-dim: #9aa6b2;
  --text-faint: #6b7682;
  --accent: #f0935f;
  --pill: #1f2730;
  --shadow: 0 1px 0 rgba(255,255,255,.02), 0 6px 18px rgba(0,0,0,.35);
}
html[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-elev: #ffffff;
  --bg-hover: #f0f3f7;
  --border: #e3e7ec;
  --text: #17202a;
  --text-dim: #5a6573;
  --text-faint: #8a95a3;
  --accent: #c75f3b;
  --pill: #f1ece8;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.06);
}

* { box-sizing: border-box; }
/* `display:flex/block` on a section beats the UA [hidden] rule, so force it. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
html {
  /* don't let iOS bump font sizes on rotation */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* kill the grey flash on tap, allow smooth momentum scroll */
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
/* roomier, finger-friendly tap targets on touch devices */
button, .tab, .chip, .icon-btn { touch-action: manipulation; }

/* ---- Top bar ------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 12px max(16px, var(--sa-r)) 12px max(16px, var(--sa-l));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand .globe { font-size: 22px; }
.brand h1 {
  font-family: "Iowan Old Style", Georgia, "Times New Roman", serif;
  font-size: 21px; font-weight: 700; margin: 0; letter-spacing: -.01em;
}
.actions { display: flex; align-items: center; gap: 8px; }
.updated { font-size: 12px; color: var(--text-faint); white-space: nowrap; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px; height: 40px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s, color .15s, transform .1s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.spin svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* theme icon swap */
html[data-theme="dark"] #theme .ic-sun { display: none; }
html[data-theme="light"] #theme .ic-moon { display: none; }

/* ---- View tabs ----------------------------------------------------------- */
.tabs {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 max(12px, var(--sa-r)) 10px max(12px, var(--sa-l));
  display: flex;
  gap: 8px;
}
.tab {
  flex: 0 0 auto;
  padding: 9px 17px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--accent-glow);
}

/* ---- Search -------------------------------------------------------------- */
.searchrow {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 max(12px, var(--sa-r)) 10px max(12px, var(--sa-l));
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
.searchrow svg {
  position: absolute;
  left: calc(max(12px, var(--sa-l)) + 13px);
  color: var(--text-faint);
  pointer-events: none;
}
.searchrow input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
}
.searchrow input::placeholder { color: var(--text-faint); }
.searchrow input:focus { outline: none; border-color: var(--accent); }

/* ---- Filter bar ---------------------------------------------------------- */
.filters {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 max(12px, var(--sa-r)) 12px max(12px, var(--sa-l));
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--pill);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { color: var(--text); }
.chip.active {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--accent-glow);
}

/* ---- Feed ---------------------------------------------------------------- */
.feed {
  max-width: var(--max);
  margin: 0 auto;
  padding: 16px max(12px, var(--sa-r)) 8px max(12px, var(--sa-l));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-main {
  display: block;
  padding: 15px 16px;
  color: inherit;
  text-decoration: none;
}
.card-main:hover { background: var(--bg-hover); }

.meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.source {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .01em;
}
.dot { color: var(--text-faint); font-size: 11px; }
.time { font-size: 12px; color: var(--text-faint); }
.badge {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--pill);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.headline {
  /* taglio editoriale: serif per i titoli, come un quotidiano */
  font-family: "Iowan Old Style", Georgia, "Times New Roman", serif;
  font-size: 18.5px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -.005em;
  margin: 0 0 6px;
}
.fresh {
  width: 7px; height: 7px; border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34,197,94,.7);
  flex: 0 0 auto;
}
.summary {
  font-size: 14px;
  color: var(--text-dim);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* expandable source list */
.expand {
  border-top: 1px solid var(--border);
}
.expand summary {
  list-style: none;
  cursor: pointer;
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 7px;
  user-select: none;
}
.expand summary::-webkit-details-marker { display: none; }
.expand summary .chev {
  transition: transform .2s;
  color: var(--text-faint);
}
.expand[open] summary .chev { transform: rotate(90deg); }
.expand summary:hover { color: var(--text); }

.srclist { padding: 2px 8px 10px; }
.srclink {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 9px 8px;
  border-radius: 9px;
  color: inherit;
  text-decoration: none;
}
.srclink:hover { background: var(--bg-hover); }
.srclink .s-name { font-size: 13px; font-weight: 700; color: var(--accent); flex: 0 0 auto; min-width: 92px; }
.srclink .s-title { font-size: 13px; color: var(--text-dim); flex: 1; min-width: 0; }
.srclink .s-time { font-size: 11px; color: var(--text-faint); flex: 0 0 auto; white-space: nowrap; }

/* ---- States -------------------------------------------------------------- */
.state {
  text-align: center;
  color: var(--text-faint);
  padding: 60px 20px;
  font-size: 14px;
}
.skeleton {
  height: 116px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(100deg, var(--bg-elev) 30%, var(--bg-hover) 50%, var(--bg-elev) 70%);
  background-size: 220% 100%;
  animation: sheen 1.3s ease-in-out infinite;
}
@keyframes sheen { from { background-position: 180% 0; } to { background-position: -40% 0; } }

/* ---- Globe view ---------------------------------------------------------- */
.globe-view {
  position: relative;
  width: 100%;
  /* fill the space under the sticky header — dvh tracks Safari's shrinking bar */
  height: calc(100vh - 132px);
  height: calc(100dvh - 132px);
  min-height: 420px;
  overflow: hidden;
}
.globe-canvas { width: 100%; height: 100%; cursor: grab; }
.globe-canvas:active { cursor: grabbing; }
.globe-hint {
  position: absolute;
  left: 50%; bottom: 14px;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--text-faint);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  pointer-events: none;
  white-space: nowrap;
}

/* slide-in panel listing the news for a clicked location */
.geo-panel {
  position: absolute;
  top: 0; right: 0;
  width: min(380px, 88vw);
  height: 100%;
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  animation: slideIn .22s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.geo-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
}
.geo-panel-head h2 {
  margin: 0; font-size: 17px; font-weight: 700; flex: 1;
  letter-spacing: -.01em;
}
.geo-panel-list { overflow-y: auto; padding: 8px; flex: 1; }
.geo-item {
  display: block;
  padding: 11px 12px;
  border-radius: 10px;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.geo-item:last-child { border-bottom: none; }
.geo-item:hover { background: var(--bg-hover); }
.geo-item .gi-meta { display: flex; gap: 7px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.geo-item .gi-src { font-size: 11px; font-weight: 700; color: var(--accent); }
.geo-item .gi-time { font-size: 11px; color: var(--text-faint); }
.geo-item .gi-badge { font-size: 10px; font-weight: 700; color: var(--text-dim); background: var(--pill); border: 1px solid var(--border); padding: 2px 7px; border-radius: 999px; }
.geo-item .gi-title { font-size: 14px; font-weight: 600; line-height: 1.32; margin: 0; }

@media (max-width: 600px) {
  .globe-view { height: calc(100vh - 124px); height: calc(100dvh - 124px); }
}

.foot {
  max-width: var(--max);
  margin: 0 auto;
  padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
  text-align: center;
}
.foot p { font-size: 12px; color: var(--text-faint); margin: 0; }

@media (max-width: 480px) {
  .brand h1 { font-size: 18px; }
  .headline { font-size: 16px; }
  .srclink .s-name { min-width: 78px; }
}
