:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #1d2b2a;
  --muted: #5d6d6b;
  --line: #e3ddd2;
  --brand: #0f766e;
  --brand-dark: #0b5953;
  --hot: #c0392b;
  --warm: #e67e22;
  --cool: #1f9d8a;
  --green: #2e7d32;
  --radius: 16px;
  --tabs-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  height: 100dvh;
  background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #f59e0b; outline-offset: 2px; }

/* Header */
.top {
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: linear-gradient(135deg, #0f766e 0%, #0b5953 100%);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 12px; }
.mark { width: 38px; height: 38px; flex: none; filter: drop-shadow(0 2px 4px rgba(0,0,0,.25)); }
.brand h1 { margin: 0; font-size: 1.2rem; letter-spacing: .01em; line-height: 1.15; }
.brand p { margin: 0; font-size: .8rem; opacity: .85; }

.demo {
  background: #fff4d6; color: #7a4b00; border-bottom: 1px solid #f1d58a;
  padding: 6px 16px; font-size: .82rem; text-align: center;
}

/* Layout viste */
main { position: relative; flex: 1; min-height: 0; }
.view { position: absolute; inset: 0; display: none; }
.view.active { display: block; }
.view.scroll { overflow-y: auto; padding: 14px 14px 24px; -webkit-overflow-scrolling: touch; }

/* Mappa */
#map { position: absolute; inset: 0; background: #e8e4da; }
.controls {
  position: absolute; z-index: 500; top: 10px; left: 10px; right: 10px;
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: none;
}
.controls::-webkit-scrollbar { display: none; }
.select select, .chip {
  height: 38px; border-radius: 19px; border: 1px solid var(--line);
  background: rgba(255,255,255,.96); box-shadow: 0 2px 8px rgba(0,0,0,.15);
  padding: 0 14px; white-space: nowrap; font-size: .9rem;
}
.select select { appearance: none; -webkit-appearance: none; padding-right: 14px; }
.chip { display: inline-flex; align-items: center; gap: 7px; flex: none; }
.chip:not(.on) { opacity: .6; background: rgba(255,255,255,.8); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot.hot { background: linear-gradient(135deg, #fd8d3c, #bd0026); }
.dot.cool { background: linear-gradient(135deg, #7fcdbb, #0c7c59); }
.dot.pts { background: #fff; border: 3px solid #555; }

.legend {
  position: absolute; z-index: 500; left: 10px; bottom: 14px;
  background: rgba(255,255,255,.94); border-radius: 12px; padding: 8px 12px;
  font-size: .76rem; color: var(--muted); box-shadow: 0 2px 8px rgba(0,0,0,.15);
  display: grid; gap: 3px; pointer-events: none;
}
.legend .dot { width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; }
.legend .count { color: var(--ink); font-weight: 600; margin-top: 2px; }

.pick {
  position: absolute; z-index: 600; left: 10px; right: 10px; top: 58px;
  background: #1d2b2a; color: #fff; border-radius: 14px; padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.pick button { background: #fff; color: #1d2b2a; border: 0; border-radius: 10px; padding: 6px 12px; font-weight: 600; }
.leaflet-container { font-family: inherit; }
.leaflet-control-zoom { margin-bottom: 18px !important; margin-right: 10px !important; }

/* Popup */
.pop { min-width: 150px; max-width: 220px; }
.pop strong { display: block; margin-bottom: 2px; }
.pop .meta { color: var(--muted); font-size: .8rem; }
.pop .txt { margin-top: 4px; word-wrap: break-word; }

/* Card e form */
.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  margin: 0 auto 14px; max-width: 640px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 18px rgba(33,52,50,.06);
}
.card h2 { margin: 0 0 4px; font-size: 1.15rem; }
.card p { margin: 8px 0; }
.hint { color: var(--muted); font-size: .9rem; }
.hint.small { font-size: .8rem; }

.cats { border: 0; margin: 14px 0 6px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cat {
  position: relative; display: grid; gap: 1px; padding: 12px;
  border: 2px solid var(--line); border-radius: 14px; background: #fcfbf8; cursor: pointer;
  min-height: 98px; align-content: start;
}
.cat input { position: absolute; opacity: 0; pointer-events: none; }
.cat .emo { font-size: 1.5rem; line-height: 1.2; }
.cat b { font-size: 1rem; }
.cat small { color: var(--muted); font-size: .78rem; line-height: 1.25; }
.cat:has(input:checked) { border-color: var(--brand); background: #e9f6f4; box-shadow: 0 0 0 3px rgba(15,118,110,.18); }
.cat[data-cat="molto_caldo"]:has(input:checked) { border-color: var(--hot); background: #fdecea; box-shadow: 0 0 0 3px rgba(192,57,43,.18); }
.cat[data-cat="caldo"]:has(input:checked) { border-color: var(--warm); background: #fff1e3; box-shadow: 0 0 0 3px rgba(230,126,34,.2); }
.cat:has(input:focus-visible) { outline: 3px solid #f59e0b; outline-offset: 2px; }

.field { display: block; margin-top: 16px; position: relative; }
.lbl { display: block; font-weight: 600; margin-bottom: 6px; font-size: .92rem; }
.lbl em { font-weight: 400; color: var(--muted); font-style: normal; }
input[type=text], textarea {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 11px 12px; background: #fcfbf8;
}
input[type=text]:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
textarea { resize: vertical; }
.counter { position: absolute; right: 10px; bottom: 8px; font-size: .72rem; color: var(--muted); }

.pos { background: #f1ede5; border-radius: 12px; padding: 10px 12px; font-size: .92rem; margin-bottom: 8px; }
.pos.ok { background: #e3f4ef; color: #0b5953; }
.pos.err { background: #fdecea; color: #922b21; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 1.5px solid transparent; border-radius: 14px; padding: 12px 16px;
  font-weight: 600; min-height: 46px;
}
.btn.primary { width: 100%; margin-top: 14px; background: var(--brand); color: #fff; font-size: 1.05rem; }
.btn.primary:active { background: var(--brand-dark); }
.btn.primary:disabled { opacity: .55; }
.btn.ghost { background: #fff; border-color: var(--line); flex: 1; min-width: 150px; }
.btn.ghost:active { background: #f1ede5; }

/* Dati */
.catcards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.cc { border-radius: 14px; padding: 12px; border: 1.5px solid var(--line); background: #fcfbf8; }
.cc .n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.cc .l { font-size: .85rem; font-weight: 600; }
.cc .t { font-size: .75rem; color: var(--muted); margin-top: 2px; }
.cc.molto_caldo { border-color: #efb8b1; background: #fdf1ef; }
.cc.caldo { border-color: #f4cfa5; background: #fff6ec; }
.cc.fresco { border-color: #a9dcd3; background: #eef9f7; }
.cc.verde { border-color: #b4d8b6; background: #f0f8f0; }

.zones { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.zones li button {
  width: 100%; text-align: left; border: 1.5px solid var(--line); background: #fcfbf8;
  border-radius: 12px; padding: 10px 12px; display: flex; gap: 12px; align-items: center;
}
.zones .rank { font-weight: 700; color: var(--hot); width: 22px; flex: none; }
.zones .name { font-weight: 600; display: block; }
.zones .sub { font-size: .8rem; color: var(--muted); }
.empty { color: var(--muted); font-size: .9rem; padding: 6px 0; }

.bars { display: grid; gap: 10px; margin-top: 10px; }
.bar { display: grid; grid-template-columns: 96px 1fr 34px; gap: 10px; align-items: center; font-size: .88rem; }
.bar .track { height: 14px; background: #f1ede5; border-radius: 7px; overflow: hidden; }
.bar .fill { height: 100%; background: linear-gradient(90deg, #fd8d3c, #bd0026); border-radius: 7px; min-width: 2px; }
.bar .v { text-align: right; font-weight: 600; }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabs-h) + var(--safe-b) + 14px);
  background: #1d2b2a; color: #fff; padding: 11px 16px; border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.3); z-index: 2000; max-width: calc(100% - 28px);
  text-align: center; font-size: .92rem;
}

/* Tab bar */
.tabs {
  display: flex; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; border: 0; background: none; display: grid; place-items: center; align-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; font-weight: 600;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--brand); }

@media (min-width: 760px) {
  .view.scroll { padding-top: 22px; }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: pop .2s ease-out; }
  @keyframes pop { from { opacity: 0; transform: translate(-50%, 8px); } }
}

/* Intro video */
.intro {
  position: fixed; inset: 0; z-index: 5000; background: #06201f;
  display: grid; place-items: center; transition: opacity .35s ease;
}
.intro.out { opacity: 0; pointer-events: none; }
.intro video { width: 100%; height: 100%; object-fit: cover; background: #06201f; }
@media (min-width: 760px) { .intro video { object-fit: contain; } }
.intro-btn {
  position: absolute; bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  border: 1px solid rgba(246,243,238,.45); background: rgba(6,32,31,.55); color: #f6f3ee;
  border-radius: 22px; padding: 9px 16px; font-weight: 600; font-size: .9rem;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.intro-btn.left { left: 16px; }
.intro-btn.right { right: 16px; }
.intro.done .intro-btn { display: none; }
.intro.done { cursor: pointer; }
.intro-play {
  display: none; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  border: 2px solid rgba(246,243,238,.85); background: rgba(6,32,31,.7); color: #f6f3ee;
  border-radius: 40px; padding: 16px 26px; font-weight: 700; font-size: 1.05rem;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.intro.needtap .intro-play { display: block; }
