:root {
  --bg: #fbfbf9;
  --fg: #16150f;
  --muted: #7a776c;
  --line: #e3e1d9;
  --accent: #16150f;
  --red: #c8402f;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --fg: #ecebe5;
    --muted: #8d8a80;
    --line: #2a2926;
    --accent: #ecebe5;
    --red: #e5614e;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* ── Navbar ─────────────────────────────────────────────────────────── */

.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.nav-btn {
  border: 1px solid var(--line);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.nav-btn:hover { color: var(--fg); border-color: var(--fg); }

/* ── Layout ─────────────────────────────────────────────────────────── */

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 56px 24px 80px;
}

.head { margin-bottom: 40px; }

h1 {
  font-family: var(--sans);
  font-size: clamp(26px, 5.5vw, 36px);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}

.date {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  text-transform: lowercase;
}

.section { margin-bottom: 38px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.body {
  margin: 0;
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  text-wrap: pretty;
}

.count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.3s;
}

.count.is-on { opacity: 1; }

/* ── Frases clicables ───────────────────────────────────────────────── */

.s {
  color: inherit;
  text-decoration: none;
  border-radius: 2px;
  transition: text-decoration-color 0.15s, color 0.15s;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.s:hover,
.s:focus-visible {
  text-decoration-color: var(--red);
}

.s:focus-visible { outline: none; }

/* ── Skeleton ───────────────────────────────────────────────────────── */

/* height, margin, width i delay els calcula app.js mesurant el text real. */
.sk {
  display: block;
  height: 1em;
  margin: 0.35em 0;
  border-radius: 3px;
  will-change: background-position;
  background: linear-gradient(
    90deg,
    var(--line) 0%,
    color-mix(in srgb, var(--line) 45%, var(--bg)) 50%,
    var(--line) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite ease-in-out;
}

.sk:nth-child(2) { animation-delay: 0.08s; }
.sk:nth-child(3) { animation-delay: 0.16s; }
.sk:nth-child(4) { animation-delay: 0.24s; }
.sk:nth-child(5) { animation-delay: 0.32s; }
.sk:nth-child(6) { animation-delay: 0.4s; }
.sk:nth-child(7) { animation-delay: 0.48s; }
.sk:nth-child(8) { animation-delay: 0.56s; }

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.body.is-ready {
  animation: reveal 0.4s ease;
}

@keyframes reveal { from { opacity: 0; } }

.error {
  border: 1px solid var(--line);
  border-left: 3px solid #c2410c;
  padding: 14px 16px;
  font-size: 14px;
  color: var(--muted);
}

/* ── Notícies ───────────────────────────────────────────────────────── */

.news { margin-top: 64px; }

.news-title {
  font-family: var(--sans);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 16px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
}

.tab {
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 0;
  margin-right: 18px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
}

.tab.is-active {
  color: var(--fg);
  border-bottom-color: var(--fg);
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: n;
}

.list li {
  border-top: 1px solid var(--line);
}

.list li:last-child { border-bottom: 1px solid var(--line); }

.list a {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  padding: 14px 0;
  text-decoration: none;
  transition: opacity 0.15s;
}

.list a:hover { opacity: 0.6; }

.list a::before {
  counter-increment: n;
  content: counter(n, decimal-leading-zero);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
}

.item-title {
  font-size: 15px;
  line-height: 1.45;
  text-wrap: pretty;
}

.item-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.foot {
  margin-top: 64px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.foot-fcat {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.14em;
  text-decoration-color: var(--red);
  transition: color 0.16s ease;
}

.foot-fcat:hover { color: var(--fg); }

/* ── Popup ──────────────────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 70%, #0006);
  backdrop-filter: blur(4px);
  animation: fade 0.25s ease;
}

.overlay[hidden] { display: none; }

.modal {
  position: relative;
  width: min(460px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 32px 28px 28px;
  box-shadow: 0 20px 60px #0000002e;
  animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal h2 {
  font-family: var(--sans);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}

.modal p {
  margin: 0 0 14px;
  font-size: 15px;
}

.modal .muted {
  color: var(--muted);
  font-style: italic;
}

.close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.close:hover { color: var(--fg); }

.cta {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  border: none;
  border-radius: 7px;
  background: var(--accent);
  color: var(--bg);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.cta:hover { opacity: 0.88; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── Configuració ───────────────────────────────────────────────────── */

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  width: 30px;
  height: 30px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.tones {
  border: 0;
  margin: 20px 0 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

/* Un color per opció. El rectangle sencer és el control: el radio hi és per al
   teclat i els lectors de pantalla, però no es dibuixa. */
.tone[data-tone="explicatiu"] { --tone: #e2570d; }
.tone[data-tone="proper"] { --tone: #1f8a5f; }
.tone[data-tone="afons"] { --tone: #2c62b8; }
.tone[data-tone="directe"] { --tone: #a23f8e; }

@media (prefers-color-scheme: dark) {
  .tone[data-tone="explicatiu"] { --tone: #ff8a4c; }
  .tone[data-tone="proper"] { --tone: #4bc48d; }
  .tone[data-tone="afons"] { --tone: #6ea4f5; }
  .tone[data-tone="directe"] { --tone: #dd8ccb; }
}

.tone {
  display: block;
  padding: 14px 16px;
  border-radius: 12px;
  cursor: pointer;
  background: color-mix(in srgb, var(--tone) 8%, transparent);
  /* Vora amb box-shadow: en seleccionar engreixa sense moure res de lloc. */
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 35%, transparent);
  transition: background 0.15s, box-shadow 0.15s;
}

.tone:hover {
  background: color-mix(in srgb, var(--tone) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 60%, transparent);
}

.tone:has(input:checked) {
  background: color-mix(in srgb, var(--tone) 18%, transparent);
  box-shadow: inset 0 0 0 2px var(--tone);
}

.tone:has(input:focus-visible) {
  outline: 2px solid var(--tone);
  outline-offset: 2px;
}

.tone input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.tone-name {
  display: block;
  font-weight: 600;
  font-size: 15px;
  color: var(--fg);
}

.tone:has(input:checked) .tone-name { color: var(--tone); }

.tone-desc {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-top: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .tone { transition: none; }
}
