:root {
  --text: #111827;
  --muted: rgba(17, 24, 39, 0.78);
  --border: rgba(0, 0, 0, 0.12);
  --nav: rgba(255, 255, 255, 0.90);
  --shadow: rgba(0, 0, 0, 0.10);
  --card: rgba(255, 255, 255, 0.94);
  --topbar-offset: 96px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  background: #ffffff;
  position: relative;
  isolation: isolate;
}

/* subtle light background */
.bg-fixed {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 20% 10%, rgba(255, 200, 60, 0.18), transparent 60%),
    radial-gradient(900px 500px at 90% 30%, rgba(120, 160, 255, 0.18), transparent 62%),
    linear-gradient(180deg, #ffffff, #f8fafc);
  pointer-events: none;
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 22px 72px;
}

/* topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  /* make it feel like a real header bar */
  margin: 0 -22px 18px;
  padding: 14px 22px;
  background: var(--nav);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);

  /* keep it clean and readable */
  border-left: 0;
  border-right: 0;
  border-top: 0;
  border-radius: 0;
  box-shadow: none;
}

/* Ensure anchored headings (Art. X) are visible below the sticky topbar */
h2[id] {
  scroll-margin-top: var(--topbar-offset);
}

/* Optional: subtle highlight when navigating from the index */
h2[id]:target {
  background: rgba(0, 0, 0, 0.03);
  border-radius: 10px;
  padding: 6px 10px;
  margin-left: -10px;
  margin-right: -10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-weight: 900;
  letter-spacing: -0.2px;
}

.topbtn {
  margin-left: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.04);
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  line-height: 1;
  font-size: 14px;
  white-space: nowrap;
}

/* Train icon inside Regolamento button */
.topbtn .icon-train {
  display: inline-block;
  margin-right: 6px;
  font-size: 16px;
  line-height: 1;
  transform: translateY(1px);
}

.topbtn .btn-label {
  display: inline-block;
}

.topbtn:hover {
  background: rgba(0, 0, 0, 0.06);
}

.topbtn.is-active {
  background: rgba(0, 0, 0, 0.08);
  border-color: rgba(0, 0, 0, 0.18);
}

.brand .topbtn:first-of-type {
  margin-left: 0;
}

.dot {
  opacity: 0.6;
}

/* main card */
.section {
  margin-top: 22px;
  padding: 36px 46px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 14px 46px var(--shadow);
}

h1 {
  margin: 0 0 14px;
  font-size: clamp(30px, 4vw, 46px);
  letter-spacing: -0.7px;
  line-height: 1.12;
}

/* --- Improved vertical rhythm and spacing --- */
p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.75;
}

h2 {
  margin: 42px 0 14px;
  font-size: 22px;
  letter-spacing: -0.2px;
  line-height: 1.28;
}

h3 {
  margin: 26px 0 12px;
  font-size: 18px;
  letter-spacing: -0.15px;
  line-height: 1.3;
}

.sep {
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.12);
  margin: 28px 0 22px;
}

/* index */
.toc {
  margin-top: 18px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.03);
  border-radius: 14px;
  padding: 16px;
}

.toc-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 900;
}

.toc-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 26px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.toc a {
  color: #1f4aa8;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.toc a:hover {
  color: #163a84;
}

/* lists */
.bullets {
  margin: 16px 0 22px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 14px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.65;
}

.bullets li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.bullets .icon {
  flex: 0 0 24px;
  width: 24px;
  opacity: 0.9;
  line-height: 1.2;
}

/* allow the text column to shrink properly on iOS */
.bullets li > :last-child {
  flex: 1 1 auto;
  min-width: 0;
}

.ordered {
  margin: 16px 0 22px;
  color: var(--muted);
  line-height: 1.7;
  padding-left: 22px;
}

details {
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.03);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 14px 0 18px;
}

summary {
  cursor: pointer;
  font-weight: 900;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px;
}

summary::-webkit-details-marker { display: none; }

.note {
  font-size: 14px;
  opacity: 0.95;
  margin: 12px 0 0;
  color: rgba(17, 24, 39, 0.74);
  line-height: 1.6;
}

/* Visually hidden (keeps elements in DOM for JS) */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.03);
  margin: 14px 0 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th, td {
  text-align: left;
  padding: 14px 14px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.10);
  vertical-align: top;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

th {
  font-size: 13px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  opacity: 0.85;
}

/* Prize stack (Divisione premi) */

.prize-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Prizes table: allow headers to wrap cleanly */
.table-prizes {
  table-layout: auto;
}

.table-prizes th,
.table-prizes td {
  word-break: normal;
  overflow-wrap: normal;
}

.table-prizes th {
  white-space: normal;
  line-height: 1.25;
  letter-spacing: 0;
}

/* buttons */
.btn-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 18px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.04);
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn:hover {
  background: rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

/* footer */
.footer {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: rgba(17, 24, 39, 0.60);
}

/* Dedicated view toggling (Regolamento vs Classifica) */
#classifica-page { display: none; }

.view-classifica #regolamento { display: none; }
.view-classifica #classifica-page { display: block; }

/* readable line length */
.section p,
.section ul,
.section ol {
  max-width: 880px;
}

@media (max-width: 600px) {
  .wrap { padding: 18px 14px 56px; }
  .section { padding: 26px 20px; }
  .toc-list { grid-template-columns: 1fr; gap: 10px; }
  .btn { width: 100%; }

  /* Topbar layout and transition on mobile */
  .topbar {
    margin: 0 -14px 14px;
    padding: 12px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    transition: transform 0.28s ease;
    will-change: transform;
  }

  .topbar.topbar-hidden {
    transform: translateY(-110%);
  }

  .brand {
    width: 100%;
    gap: 8px;
  }

  /* Nav buttons: first full width, next two half width */
  .brand .topbtn {
    margin-left: 0;
    padding: 10px 10px;
    font-size: 13px;
    white-space: normal;
    text-align: center;
    flex: 1 1 auto;
    border-radius: 14px;
  }

  .topbtn .icon-train {
    font-size: 15px;
    margin-right: 6px;
  }

  .brand .topbtn#nav-regolamento {
    flex: 1 1 100%;
  }

  .brand .topbtn#nav-andata,
  .brand .topbtn#nav-ritorno {
    flex: 1 1 calc(50% - 8px);
  }

  /* Table: fit screen (no horizontal scroll) */
  .table-wrap {
    overflow-x: hidden;
  }

  .table-wrap table th,
  .table-wrap table td {
    padding: 10px 10px;
    font-size: 14px;
  }

  /* Mobile: compact table headers (no wrap for PACCHETTO) */
  th {
    font-size: 12px;
    white-space: nowrap;
    word-break: keep-all;
  }

  /* Override nowrap headers ONLY for the prizes table */
  .table-prizes th {
    white-space: normal;
    font-size: 11px;
    line-height: 1.2;
    padding: 10px 8px;
  }

  .table-prizes td {
    padding: 12px 10px;
  }

  .table-prizes th:nth-child(1),
  .table-prizes td:nth-child(1) { width: 32%; }

  .table-prizes th:nth-child(2),
  .table-prizes td:nth-child(2) { width: 28%; }

  .table-prizes th:nth-child(3),
  .table-prizes td:nth-child(3) { width: 40%; }

  /* Make prize stacks tighter on mobile and avoid messy wrapping */
  .table-prizes td {
    overflow-wrap: normal;
    word-break: normal;
  }

  .table-prizes th {
    overflow-wrap: normal;
    word-break: keep-all;
    hyphens: auto;
  }

  .prize-stack {
    gap: 4px;
  }

  /* Leaderboard columns sizing */
  #lb-table th:nth-child(1),
  #lb-table td:nth-child(1) { width: 12%; text-align: center; }

  #lb-table th:nth-child(2),
  #lb-table td:nth-child(2) { width: 44%; }

  #lb-table th:nth-child(3),
  #lb-table td:nth-child(3) { width: 18%; text-align: center; }

  #lb-table th:nth-child(4),
  #lb-table td:nth-child(4) { width: 26%; text-align: center; }

  /* Classifica title a misura iPhone */
  #classifica-page h1 {
    font-size: 34px;
    line-height: 1.1;
  }

  /* Mobile: bullet list readability (fix iOS overlap) */
  .bullets li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
  }

  .bullets .icon {
    flex: 0 0 24px;
    width: 24px;
  }

  /* Keep “1ª giornata di Serie A” on one line without overlapping */
  .bullets li strong {
    white-space: nowrap;
    font-size: 0.98em;
  }
}