/* Layout: la tuta da gara. Tre fasce (nuoto, bici, corsa) in testa e sui pettorali; un grande conto alla rovescia, la stagione a mesi, le gare come pettorali che si aprono. */
:root {
  color-scheme: light;
  --bg: #e9f5ef;
  --surface: #ffffff;
  --ink: #0b2a2a;
  --on-ink: #ffffff;
  --muted: #4d6b67;
  --line: #c9e0d6;
  --soft: #d9ede4;
  --accent: #1769e0;
  --swim: #1769e0;
  --bike: #ff6a1a;
  --run: #14a36e;
  --ok: #0b7a52;
  --ok-bg: #cfeede;
  --bad: #b3261e;
  --bad-bg: #fde3e0;
  --f-display: 'Big Shoulders Display', 'Arial Narrow', 'Helvetica Neue', sans-serif;
  --f-body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #07191a;
    --surface: #0f2a2b;
    --ink: #e6f6f1;
    --on-ink: #06201f;
    --muted: #8fb0aa;
    --line: #1d4141;
    --soft: #133637;
    --accent: #6aa9ff;
    --swim: #5aa0ff;
    --bike: #ff8a4d;
    --run: #44d9a0;
    --ok: #7fe0ae;
    --ok-bg: #12372a;
    --bad: #ff9d93;
    --bad-bg: #40201d;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
img { max-width: 100%; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Fascia tri-colore */
.triband { display: grid; grid-template-rows: repeat(3, 6px); }
.triband i:nth-child(1), .sheet-band i:nth-child(1) { background: var(--swim); }
.triband i:nth-child(2), .sheet-band i:nth-child(2) { background: var(--bike); }
.triband i:nth-child(3), .sheet-band i:nth-child(3) { background: var(--run); }

.wrap {
  max-width: 920px;
  margin: 0 auto;
  padding-block: 28px 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.view { display: flex; flex-direction: column; gap: 22px; }

.mega {
  font-family: var(--f-display);
  font-weight: 900;
  text-transform: uppercase;
  font-size: clamp(34px, 8vw, 58px);
  line-height: 0.95;
  letter-spacing: -0.005em;
  margin: 0;
}
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.who { margin: -8px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }

/* Bottoni */
.btn {
  min-height: 44px;
  padding: 0 20px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 0.15s, background-color 0.15s, color 0.15s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.primary { background: var(--ink); color: var(--on-ink); }
.btn.inv { background: var(--on-ink); color: var(--ink); border-color: var(--on-ink); }
.btn[disabled] { opacity: 0.55; cursor: default; transform: none; }
.btn.ghost { border-color: transparent; color: var(--muted); min-height: 40px; padding: 0 12px; font-weight: 600; }
.btn.ghost:hover { color: var(--ink); background: var(--soft); }
.btn.icon { font-size: 28px; line-height: 1; padding: 0 12px; }
.btn.danger-arm { color: var(--bad); background: var(--bad-bg); }
.link { background: none; border: 0; padding: 6px 0; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* Conto alla rovescia */
.hero {
  position: relative;
  overflow: hidden;
  background: var(--ink);
  color: var(--on-ink);
  border-radius: 20px;
  padding: 26px 24px 30px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 28px;
  align-items: center;
  animation: rise 0.55s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.hero[role="button"] { cursor: pointer; transition: transform 0.2s; }
.hero[role="button"]:hover { transform: translateY(-2px); }
.hero.empty { display: block; }
.hero-stripes { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; display: flex; }
.hero-stripes i { flex: 1; }
.sw { background: var(--swim); } .bk { background: var(--bike); } .rn { background: var(--run); }
.count { display: flex; flex-direction: column; align-items: flex-start; line-height: 0.85; }
.count .num { font-family: var(--f-display); font-weight: 900; font-size: clamp(96px, 26vw, 168px); font-variant-numeric: tabular-nums; }
.count .num.word { font-size: clamp(54px, 15vw, 92px); text-transform: uppercase; }
.count .unit { font-family: var(--f-display); font-weight: 700; font-size: 26px; text-transform: uppercase; letter-spacing: 0.08em; margin-top: 6px; opacity: 0.8; }
.hero-body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.eyebrow { margin: 0; font-size: 12px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.7; }
.hero-title { font-family: var(--f-display); font-weight: 800; text-transform: uppercase; font-size: clamp(30px, 6vw, 46px); line-height: 0.95; overflow-wrap: anywhere; }
.hero-sub { margin: 0; opacity: 0.8; max-width: 52ch; }
.hero-meta { margin: 0; opacity: 0.85; }
.hero .legs { margin-top: 4px; }
.hero .btn { align-self: flex-start; margin-top: 8px; }
.hero-sum { margin: 6px 0 0; font-size: 14px; opacity: 0.7; font-variant-numeric: tabular-nums; }
@media (max-width: 560px) { .hero { grid-template-columns: 1fr; padding: 22px 18px 28px; } }

/* Stagione */
.season { display: flex; flex-direction: column; gap: 8px; }
.months { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x proximity; padding: 4px 2px 10px; scrollbar-width: thin; }
.m {
  flex: 0 0 66px; scroll-snap-align: start; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px 12px; border: 1.5px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink);
  cursor: pointer; transition: transform 0.15s, background-color 0.15s, border-color 0.15s;
}
.m:hover { transform: translateY(-2px); border-color: var(--ink); }
.m .mn { font-family: var(--f-display); font-weight: 800; font-size: 22px; letter-spacing: 0.05em; text-transform: uppercase; line-height: 1; }
.m .yr { font-size: 11px; color: var(--muted); height: 13px; font-variant-numeric: tabular-nums; }
.m .dots { display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start; gap: 4px; min-height: 24px; max-width: 46px; }
.m .more-n { font-size: 11px; font-weight: 700; line-height: 10px; }
.m.now { border: 2.5px solid var(--ink); }
.m[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.m[aria-pressed="true"] .yr { color: inherit; opacity: 0.7; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.full { background: currentColor; }
.dot.ring { border: 2px solid currentColor; }
.dot.dim { background: currentColor; opacity: 0.35; }
.dot.skip { border: 2px dashed currentColor; opacity: 0.45; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; color: var(--muted); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Filtri */
.controls { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.seg { display: inline-flex; border: 2px solid var(--ink); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 16px; border-radius: 999px; font-weight: 700; cursor: pointer; min-height: 38px; transition: background-color 0.15s, color 0.15s; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.tabs { display: flex; gap: 18px; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 0; font-weight: 700; color: var(--muted); cursor: pointer; min-height: 40px; }
.tabs button[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs .n { margin-left: 5px; font-variant-numeric: tabular-nums; font-weight: 500; opacity: 0.8; }
.row input[type="search"] { flex: 1 1 220px; }
.row select { flex: 0 1 220px; }
.chips { gap: 8px; }
.chip-btn { border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; font-weight: 600; cursor: pointer; min-height: 36px; transition: background-color 0.15s, color 0.15s, border-color 0.15s; }
.chip-btn:hover { border-color: var(--ink); }
.chip-btn[aria-pressed="true"], .month-chip { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }

input[type="text"], input[type="search"], input[type="date"], input[type="number"], input[type="url"],
input[type="email"], input[type="password"], select, textarea {
  width: 100%; min-height: 44px; padding: 9px 12px; border: 2px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink); transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; }
textarea { min-height: 84px; resize: vertical; }

/* Moduli e schede */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.card h2, .sheet-head h2 { font-family: var(--f-display); font-weight: 800; font-size: 32px; text-transform: uppercase; line-height: 1; margin: 0; }
.auth { max-width: 460px; margin: 0 auto; width: 100%; }
.auth .lead { margin: 0; color: var(--muted); }
.auth-msg { margin: 0; font-size: 14px; color: var(--bad); min-height: 20px; }
.auth-msg.info { color: var(--ok); }
.auth-links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field label, .legend-t { font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }
.field label { display: flex; align-items: center; gap: 6px; }
.sq { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.sq.swim { background: var(--swim); } .sq.bike { background: var(--bike); } .sq.run { background: var(--run); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.form-msg { color: var(--bad); font-size: 14px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.dist { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 6px; }

/* Scheda di inserimento */
dialog {
  border: 0; padding: 0; width: calc(100% - 24px); max-width: 660px; max-height: calc(100dvh - 32px);
  border-radius: 20px; background: var(--surface); color: var(--ink); overflow: auto;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.6);
}
dialog[open] { animation: pop 0.25s cubic-bezier(0.2, 0.8, 0.2, 1); }
dialog::backdrop { background: rgba(8, 10, 24, 0.6); backdrop-filter: blur(3px); }
.sheet-band { display: grid; grid-template-rows: repeat(3, 5px); }
#form { padding: 16px 22px 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.fgrid .full { grid-column: 1 / -1; }
.form-actions.sticky { position: sticky; bottom: 0; background: var(--surface); padding: 14px 0 18px; margin-top: 16px; border-top: 1px solid var(--line); }
@media (max-width: 640px) {
  dialog { width: 100%; max-width: none; margin: auto 0 0; border-radius: 22px 22px 0 0; max-height: 94dvh; }
  dialog[open] { animation: sheet 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); }
  #form { padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px)); }
  .form-actions.sticky { padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px)); }
}

/* Elenco */
.month { font-family: var(--f-display); font-weight: 800; font-size: 28px; letter-spacing: 0.04em; text-transform: uppercase; margin: 22px 0 10px; display: flex; align-items: baseline; gap: 12px; }
.month small { font-family: var(--f-body); font-size: 14px; font-weight: 600; letter-spacing: 0; color: var(--muted); }
.group { display: flex; flex-direction: column; gap: 10px; }
.race {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 16px; overflow: hidden;
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.2, 1) both; animation-delay: calc(var(--i, 0) * 45ms);
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
}
.race:hover { transform: translateY(-2px); border-color: var(--ink); box-shadow: 0 12px 28px -16px rgba(14, 18, 38, 0.45); }
.race.past { opacity: 0.86; }
.race-head {
  display: grid; grid-template-columns: 88px minmax(0, 1fr) auto; gap: 16px; align-items: stretch; width: 100%;
  padding: 0 18px 0 0; border: 0; background: none; text-align: left; cursor: pointer; color: inherit;
}
.bib {
  position: relative; min-height: 104px; background: var(--ink); color: var(--on-ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px 0 14px;
}
.race.past .bib { background: var(--muted); }
.bib .d { font-family: var(--f-display); font-weight: 900; font-size: 50px; line-height: 0.9; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bib .d.rg { font-size: 36px; }
.bib .mo { margin-top: 5px; font-size: 12px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; opacity: 0.85; }
.hole { position: absolute; top: 9px; width: 8px; height: 8px; border-radius: 50%; background: var(--surface); }
.hole.l { left: 9px; } .hole.r { right: 9px; }
.stripe { position: absolute; left: 0; right: 0; bottom: 0; height: 7px; display: flex; }
.stripe i { flex: 1; }
.info { display: flex; flex-direction: column; justify-content: center; gap: 6px; min-width: 0; padding: 14px 0; }
.name { font-family: var(--f-display); font-weight: 800; font-size: 30px; line-height: 0.95; text-transform: uppercase; overflow-wrap: anywhere; }
.line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; color: var(--muted); font-size: 14px; }
.tag { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 3px 9px; border-radius: 6px; background: var(--soft); color: var(--ink); white-space: nowrap; }
.when-left { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.badge { font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; padding: 3px 10px; border-radius: 999px; background: var(--soft); color: var(--ink); white-space: nowrap; }
.badge.st-iscritto { background: var(--ok-bg); color: var(--ok); }
.badge.st-saltato { background: var(--bad-bg); color: var(--bad); }
.badge.st-concluso { color: var(--muted); }
.legs { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; }
.leg { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.leg b { font-weight: 700; font-variant-numeric: tabular-nums; }
.leg .l { opacity: 0.7; }
.chev { align-self: center; width: 11px; height: 11px; border-right: 3px solid var(--muted); border-bottom: 3px solid var(--muted); transform: rotate(45deg); transition: transform 0.25s; margin-bottom: 4px; }
.race.open .chev { transform: rotate(225deg); margin-bottom: -4px; }

.more { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.3s ease; }
.race.open .more { grid-template-rows: 1fr; }
.more-in { overflow: hidden; min-height: 0; visibility: hidden; padding-left: 104px; padding-right: 18px; transition: visibility 0s linear 0.3s; }
.race.open .more-in { visibility: visible; transition-delay: 0s; }
.more-pad { padding: 2px 0 18px; display: flex; flex-direction: column; gap: 14px; border-top: 1px dashed var(--line); padding-top: 14px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 18px; margin: 0; }
.facts dt { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.facts dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.facts a { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-actions select { width: auto; min-height: 40px; padding: 6px 12px; font-weight: 600; flex: 0 0 auto; }

.note-small { color: var(--muted); font-size: 14px; margin: 0; }
.empty-list { background: var(--surface); border: 2px dashed var(--line); border-radius: 16px; padding: 28px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-list h2 { font-family: var(--f-display); font-weight: 800; font-size: 30px; text-transform: uppercase; margin: 0; }
.empty-list p { margin: 0; color: var(--muted); max-width: 46ch; }

/* Pulsante flottante e avvisi */
.toast {
  position: fixed; z-index: 20; left: 50%; top: max(14px, env(safe-area-inset-top, 0px));
  width: max-content; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: var(--ink); color: var(--on-ink);
  font-weight: 600; font-size: 14px; opacity: 0; transform: translate(-50%, -8px); pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .race-head { grid-template-columns: 70px minmax(0, 1fr) auto; gap: 12px; padding-right: 14px; }
  .bib { min-height: 96px; }
  .bib .d { font-size: 40px; } .bib .d.rg { font-size: 29px; }
  .name { font-size: 25px; }
  .more-in { padding-left: 82px; padding-right: 14px; }
  .dist { gap: 8px; }
}

@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes sheet { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
