:root {
  --bg: #f6f3ee; --surface: #ffffff; --ink: #1d2420; --muted: #66706a; --line: #e2ddd4;
  --accent: #1f6f5c; --accent-ink: #ffffff; --warn: #b4531f; --shadow: 0 6px 24px rgba(20, 30, 25, .16);
  --map-bg: #e9e5dd;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141815; --surface: #1e2420; --ink: #eef1ee; --muted: #9aa49e; --line: #2e3631;
    --accent: #4cc19f; --accent-ink: #0d1a15; --warn: #f08a52; --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    --map-bg: #0f120f; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.15; margin: 0 0 .4rem; letter-spacing: -.01em; }
p { margin: 0 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: .75rem 1rem;
  background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 46px;
  box-shadow: inset 0 0 0 1px var(--line);
}
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
button.ghost { background: transparent; box-shadow: none; color: var(--accent); }
button.danger { color: var(--warn); }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password] {
  font: inherit; width: 100%; padding: .75rem .9rem; border-radius: 12px; min-height: 48px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
input:focus-visible, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
label { display: block; font-weight: 600; margin: 0 0 .35rem; }
.field { margin-bottom: 1rem; }
.error { color: var(--warn); font-weight: 600; min-height: 1.4em; }

/* pagine semplici */
.page { max-width: 520px; margin: 0 auto; padding: 32px 16px 48px; }
.card { background: var(--surface); border-radius: 18px; padding: 20px; box-shadow: inset 0 0 0 1px var(--line); margin-bottom: 16px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }
.linkbox { word-break: break-all; font-family: ui-monospace, Menlo, monospace; font-size: .85rem; background: var(--bg); padding: .7rem; border-radius: 10px; margin-bottom: .8rem; }
.preview { max-width: 100%; max-height: 240px; display: block; margin: .6rem 0 0; border-radius: 10px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-top: 1px solid var(--line); }

/* app mappa */
body.app { overflow: hidden; overscroll-behavior: none; position: fixed; inset: 0; }
#viewport { position: fixed; inset: 0; background: var(--map-bg); touch-action: none; overflow: hidden; user-select: none; -webkit-user-select: none; }
#viewport.picking { cursor: crosshair; }
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#stage img { display: block; pointer-events: none; -webkit-user-drag: none; }

.dot { position: absolute; width: 0; height: 0; transition: left .9s ease, top .9s ease; }
.dot .acc { position: absolute; border-radius: 50%; transform: translate(-50%, -50%); background: color-mix(in srgb, var(--c) 18%, transparent); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); pointer-events: none; }
.dot .mk { position: absolute; left: 0; top: 0; transform: scale(var(--inv, 1)); transform-origin: 0 0; }
.dot .pin {
  position: absolute; left: -15px; top: -15px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--c); color: #fff; font-weight: 700; font-size: 14px; display: grid; place-items: center;
  border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.dot.me .pin { box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 40%, transparent), 0 2px 8px rgba(0,0,0,.35); }
.dot .lbl {
  position: absolute; top: 18px; left: 0; transform: translateX(-50%); white-space: nowrap;
  background: var(--surface); color: var(--ink); font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.dot .lbl small { font-weight: 500; color: var(--muted); }
.dot.stale .pin { opacity: .65; }
.dot.old .pin { opacity: .4; filter: grayscale(.6); }
.dot.old .lbl small { color: var(--warn); }
.cp { position: absolute; width: 0; height: 0; }
.cp .mk { position: absolute; transform: scale(var(--inv, 1)); transform-origin: 0 0; }
.cp .mk span { position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border: 2px dashed var(--ink); border-radius: 4px; transform: rotate(45deg); }

.topbar {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: linear-gradient(var(--bg) 55%, transparent); pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.topbar h1 { font-size: 1.05rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar button { min-height: 40px; padding: .45rem .8rem; font-size: .9rem; box-shadow: var(--shadow); }

.toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; gap: 8px; justify-content: center;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px);
}
.toolbar button { box-shadow: var(--shadow); flex: 1; max-width: 170px; }

.banner {
  position: fixed; left: 12px; right: 12px; z-index: 6; top: calc(env(safe-area-inset-top) + 62px);
  background: var(--ink); color: var(--bg); border-radius: 14px; padding: 10px 12px; display: flex; gap: 10px; align-items: center;
  box-shadow: var(--shadow); font-size: .95rem; max-width: 560px; margin: 0 auto;
}
.banner span { flex: 1; }
.banner button { min-height: 36px; padding: .35rem .75rem; background: transparent; color: var(--bg); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bg) 40%, transparent); }
[hidden] { display: none !important; }

.sheet-back { position: fixed; inset: 0; z-index: 9; background: rgba(0,0,0,.35); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface); color: var(--ink);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px);
  max-height: 80vh; overflow: auto; box-shadow: var(--shadow); max-width: 600px; margin: 0 auto;
}
.sheet h2 { margin: 0 0 .5rem; font-size: 1.2rem; }
.sheet .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.member { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); width: 100%; background: none; box-shadow: none; border-radius: 0; text-align: left; justify-content: flex-start; font-weight: 500; }
.member .sw { width: 22px; height: 22px; border-radius: 50%; background: var(--c); flex: none; }
.member .who { flex: 1; min-width: 0; }
.member .who b { display: block; }
.member .who small { color: var(--muted); }
.steps { margin: 0 0 .6rem; padding-left: 1.2rem; }
.steps li { margin-bottom: .3rem; }
.gpsq { font-weight: 600; }
.gpsq.good { color: var(--accent); }
.gpsq.bad { color: var(--warn); }
.center-msg { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; text-align: center; color: var(--muted); }
.sheet details { border-radius: 12px; background: color-mix(in srgb, var(--ink) 5%, transparent); padding: 8px 12px; margin: 8px 0; }
.sheet details summary { font-weight: 600; cursor: pointer; }
