/* ==========================================================================
   caccia37 — PWA partecipante
   Progettata per essere letta all'aperto, con una mano, in pieno sole:
   fondo pieno chiaro, contrasto alto, testi grandi, aree di tocco da 48 px.
   ========================================================================== */

:root {
  --c37-primary: #1B4D3E;
  --c37-accent:  #C8553D;
  --c37-bg:      #FFFFFF;
  --c37-surface: #F4F5F3;
  --c37-ink:     #14181C;
  --c37-muted:   #5A6169;
  --c37-line:    #D8DBD9;
  --c37-ok:      #0A6B3D;
  --c37-warn:    #8A6100;
  --c37-err:     #B32D2E;
  --c37-btn:     var(--c37-primary);
  --c37-btn-ink: #FFFFFF;
  --c37-radius:  12px;
  --c37-tap:     48px;
  --c37-safe-b:  env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--c37-bg);
  color: var(--c37-ink);
  font: 500 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain;
}

body { padding-bottom: calc(72px + var(--c37-safe-b)); }
#c37-app { min-height: 100vh; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 8px; }
h1 { font-size: 26px; font-weight: 800; }
h2 { font-size: 21px; font-weight: 700; }
h3 { font-size: 18px; font-weight: 700; }
p  { margin: 0 0 12px; }
a  { color: var(--c37-primary); }

.c37-screen { padding: 16px 16px 24px; max-width: 640px; margin: 0 auto; }
.c37-screen--center { min-height: 78vh; display: flex; flex-direction: column; justify-content: center; }
.c37-screen--entry { padding-top: 16px; }

/* Schermate d'ingresso (lingua, codice): più aria fra gli elementi e
   pulsanti nel giallo del progetto con testo nero, salvo colore scelto
   dall'organizzatore nella scheda Aspetto (--c37-entry-*). */
.c37-entry { padding-left: 20px; padding-right: 20px; }
.c37-entry h1 { font-size: 28px; margin: 0 0 12px; }
.c37-entry .c37-kicker { margin: 0 0 12px; }
.c37-entry .c37-help { font-size: 16px; line-height: 1.5; margin: 0 0 24px; }
.c37-entry .c37-btn { background: var(--c37-entry-btn, #F4EA64); border-color: var(--c37-entry-btn, #F4EA64); color: var(--c37-entry-ink, #14181C); padding: 16px 20px; }
.c37-entry .c37-btn--ghost { background: #fff; color: var(--c37-entry-ink, #14181C); }
.c37-entry .c37-btn--quiet { background: transparent; color: var(--c37-muted); border-color: var(--c37-line); }
.c37-entry .c37-btn + .c37-btn { margin-top: 14px; }
.c37-entry .c37-input--code { margin-top: 4px; }
.c37-entry .c37-actions { margin: 24px 0 0; }
.c37-entry .c37-error { margin: 14px 0 0; }
.c37-kicker { margin: 0 0 4px; font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--c37-primary); }

/* ------------------------------------------------------------- barra stato */

.c37-topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 16px;
  background: var(--c37-surface);
  border-bottom: 1px solid var(--c37-line);
  font-size: 14px; font-weight: 600;
}
.c37-net { display: inline-flex; align-items: center; gap: 6px; }
.c37-net__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c37-ok); flex: none; }
.c37-net--offline .c37-net__dot { background: var(--c37-warn); }
.c37-net--syncing .c37-net__dot { background: var(--c37-primary); }
.c37-topbar button { background: none; border: none; font: inherit; color: var(--c37-primary); padding: 6px; min-height: 36px; cursor: pointer; }

/* -------------------------------------------------------------- componenti */

.c37-btn {
  display: block; width: 100%;
  min-height: var(--c37-tap);
  padding: 14px 20px;
  border: 2px solid var(--c37-btn);
  border-radius: var(--c37-radius);
  background: var(--c37-btn);
  color: var(--c37-btn-ink);
  font: inherit; font-weight: 700;
  cursor: pointer;
  text-align: center; text-decoration: none;
}
.c37-btn:disabled { opacity: .45; cursor: not-allowed; }
.c37-btn--ghost { background: transparent; color: var(--c37-btn); }
.c37-btn--quiet { background: transparent; color: var(--c37-muted); border-color: var(--c37-line); }
.c37-btn + .c37-btn { margin-top: 10px; }

.c37-input, .c37-textarea, .c37-select {
  width: 100%; min-height: var(--c37-tap);
  padding: 12px 14px;
  border: 2px solid var(--c37-line); border-radius: var(--c37-radius);
  background: #fff; color: var(--c37-ink);
  font: inherit;
}
.c37-input:focus, .c37-textarea:focus, .c37-select:focus,
.c37-btn:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--c37-accent); outline-offset: 2px;
}
.c37-input--code { font-size: 30px; font-weight: 800; letter-spacing: .28em; text-align: center; text-transform: uppercase; }

.c37-label { display: block; font-weight: 700; margin: 16px 0 6px; }
.c37-help  { color: var(--c37-muted); font-size: 14px; margin: 6px 0 0; }
.c37-error { color: var(--c37-err); font-weight: 600; margin: 8px 0 0; }

.c37-card { border: 1px solid var(--c37-line); border-radius: var(--c37-radius); padding: 16px; background: #fff; margin-bottom: 12px; }
.c37-card--flat { background: var(--c37-surface); border: none; }

.c37-check { display: flex; gap: 12px; align-items: flex-start; margin: 12px 0; }
.c37-check input { width: 24px; height: 24px; margin-top: 2px; flex: none; }

/* ------------------------------------------------------------ progressione */

.c37-hero { background: var(--c37-primary); color: #fff; padding: 20px 16px; }
.c37-hero h2 { margin: 0; }
.c37-hero__score { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.c37-bar { height: 10px; border-radius: 999px; background: rgba(255,255,255,.28); overflow: hidden; margin: 10px 0 6px; }
.c37-bar__fill { height: 100%; background: #fff; border-radius: 999px; transition: width .3s; }
.c37-hero__meta { display: flex; justify-content: space-between; font-size: 14px; opacity: .92; }

/* ------------------------------------------------------------------ tappe */

.c37-stagelist { list-style: none; margin: 0; padding: 0; }
.c37-stageitem {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 64px;
  padding: 12px 14px; margin-bottom: 8px;
  border: 2px solid var(--c37-line); border-radius: var(--c37-radius);
  background: #fff; font: inherit; text-align: left; cursor: pointer;
}
.c37-stageitem[disabled] { cursor: default; opacity: .7; background: var(--c37-surface); }
.c37-stageitem__num { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--c37-surface); font-weight: 800; flex: none; }
.c37-stageitem--done { border-color: var(--c37-ok); }
.c37-stageitem--done .c37-stageitem__num { background: var(--c37-ok); color: #fff; }
.c37-stageitem--open { border-color: var(--c37-primary); border-width: 3px; }
.c37-stageitem--open .c37-stageitem__num { background: var(--c37-primary); color: #fff; }
.c37-stageitem__body { flex: 1; min-width: 0; }
.c37-stageitem__title { font-weight: 700; display: block; }
.c37-stageitem__state { font-size: 14px; color: var(--c37-muted); }

.c37-clue { font-size: 19px; line-height: 1.55; background: var(--c37-surface); border-left: 4px solid var(--c37-primary); padding: 16px; border-radius: 0 var(--c37-radius) var(--c37-radius) 0; }
.c37-stagemeta { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: var(--c37-muted); margin: 12px 0; }

.c37-choice { display: block; width: 100%; min-height: var(--c37-tap); padding: 14px; margin-bottom: 8px; border: 2px solid var(--c37-line); border-radius: var(--c37-radius); background: #fff; font: inherit; text-align: left; cursor: pointer; }
.c37-choice[aria-pressed="true"] { border-color: var(--c37-primary); border-width: 3px; background: var(--c37-surface); }

/* ------------------------------------------------------------------ esito */

.c37-result { text-align: center; padding: 32px 16px; }
.c37-result__icon { font-size: 56px; line-height: 1; margin-bottom: 12px; }
.c37-result--ok    { color: var(--c37-ok); }
.c37-result--ko    { color: var(--c37-err); }
.c37-result--wait  { color: var(--c37-warn); }
.c37-result p { color: var(--c37-ink); }

/* ------------------------------------------------------------- classifica */

.c37-rank { list-style: none; margin: 0; padding: 0; }
.c37-rank li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--c37-line); }
.c37-rank li.is-me { background: var(--c37-surface); font-weight: 700; border-radius: var(--c37-radius); }
.c37-rank__pos { width: 32px; font-weight: 800; font-variant-numeric: tabular-nums; }
.c37-rank__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c37-rank__score { font-variant-numeric: tabular-nums; font-weight: 700; }

/* ------------------------------------------------------------- notifiche */

.c37-notif { border-left: 4px solid var(--c37-primary); padding: 12px 14px; background: var(--c37-surface); border-radius: 0 var(--c37-radius) var(--c37-radius) 0; margin-bottom: 8px; }
.c37-notif--unread { border-left-color: var(--c37-accent); }
.c37-notif--safety { border-left-color: var(--c37-err); background: #fdf0f0; }
.c37-notif time { display: block; font-size: 13px; color: var(--c37-muted); margin-top: 4px; }

/* ---------------------------------------------------------- coda di invio */

.c37-queue-item { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--c37-line); }
.c37-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--c37-surface); }
.c37-pill--pending { background: #fdf0d5; color: var(--c37-warn); }
.c37-pill--done { background: #d1f0dd; color: var(--c37-ok); }
.c37-pill--failed { background: #fbe2e2; color: var(--c37-err); }

/* ------------------------------------------------------ navigazione basso */

.c37-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-top: 1px solid var(--c37-line);
  padding-bottom: var(--c37-safe-b);
}
.c37-tabbar button {
  min-height: 60px; border: none; background: none; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--c37-muted); cursor: pointer; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.c37-tabbar button[aria-current="page"] { color: var(--c37-primary); }
.c37-tabbar .c37-dot { display: inline-block; min-width: 18px; height: 18px; border-radius: 999px; background: var(--c37-accent); color: #fff; font-size: 11px; line-height: 18px; }

/* ------------------------------------------------------------- overlay */

.c37-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20,24,28,.94); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px; text-align: center;
}
.c37-overlay h2 { color: #fff; }
.c37-overlay p { color: rgba(255,255,255,.85); max-width: 40ch; }

.c37-map { height: 260px; border-radius: var(--c37-radius); overflow: hidden; border: 1px solid var(--c37-line); background: var(--c37-surface); display: grid; place-items: center; color: var(--c37-muted); font-size: 14px; }

.c37-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

/* ------------------------------------------------------ atterraggio evento */

.c37-cover { width: 100%; aspect-ratio: 16 / 9; max-height: 42vh; object-fit: cover; display: block; background: var(--c37-surface); }
/* Su schermo largo la copertina resta nella colonna dell'app: a tutta
   larghezza occupava l'intera prima schermata e sembrava di essere già
   dentro la caccia. */
@media (min-width: 700px) {
  .c37-cover:not(.c37-cover--logo) { max-width: 640px; margin: 16px auto 0; border-radius: var(--c37-radius); max-height: 320px; }
}
.c37-cover--logo { aspect-ratio: auto; max-height: 120px; width: auto; max-width: 60%; margin: 28px auto 0; object-fit: contain; background: transparent; }
.c37-langbar { display: flex; justify-content: flex-end; gap: 6px; padding: 10px 16px 0; }
.c37-langbar button { min-height: 36px; padding: 4px 12px; border: 2px solid var(--c37-line); border-radius: 999px; background: #fff; font: inherit; font-size: 14px; font-weight: 700; color: var(--c37-muted); cursor: pointer; }
.c37-langbar button[aria-pressed="true"] { border-color: var(--c37-primary); color: var(--c37-primary); }
.c37-partners { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 16px 28px; padding: 24px 16px 8px; border-top: 1px solid var(--c37-line); margin-top: 24px; }
.c37-partners img { height: 40px; width: auto; max-width: 140px; object-fit: contain; }
.c37-footnote { text-align: center; font-size: 13px; color: var(--c37-muted); padding: 0 16px 16px; }
.c37-hintimg { width: 100%; border-radius: var(--c37-radius); margin-top: 8px; display: block; }

/* ---------------------------------------------------- scanner QR interno */
.c37-scan { position: fixed; inset: 0; z-index: 80; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 0 16px calc(24px + var(--c37-safe-b)); }
.c37-scan__video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.c37-scan__frame { position: absolute; top: 50%; left: 50%; width: min(70vw, 320px); aspect-ratio: 1; transform: translate(-50%, -60%); border: 3px solid #F4EA64; border-radius: 18px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); }
.c37-scan__help { position: relative; color: #fff; text-align: center; font-weight: 600; margin: 0 0 12px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.c37-scan .c37-btn--quiet { position: relative; background: #fff; color: var(--c37-ink); border-color: #fff; max-width: 320px; }
