:root {
  --accent: #c9a227;
  --bg: #14161a;
  --card: #1e2127;
  --fg: #e8e6df;
  --muted: #8d8f96;
  --line: #2c3038;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f4ee;
  --card: #ffffff;
  --fg: #1c1d20;
  --muted: #6b6d73;
  --line: #d9d5c9;
  color-scheme: light;
}
:root[data-private] {
  --accent: #a78bfa;
  --bg: #171226;
  --card: #211a36;
  --fg: #ece8f7;
  --muted: #9a92b3;
  --line: #35294f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--fg);
  font: 16px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }

header { display: flex; align-items: center; gap: 8px; height: 56px; max-width: 640px; margin: 0 auto; }
.chip { padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #171226; font-weight: 600; }
.chip.quiet { border: 0; color: var(--muted); padding: 6px 4px; font-size: 13px; }
.icon { margin-left: auto; width: 44px; height: 44px; border-radius: 12px; font-size: 20px; }

main { max-width: 640px; margin: 0 auto; }
.santuario { display: block; width: min(100%, 460px); height: auto; aspect-ratio: 160 / 111; margin: 1vh auto 20px; filter: drop-shadow(0 16px 20px #0009); }

#search {
  display: flex; align-items: center; height: 52px; padding: 0 6px 0 20px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card);
}
#search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
#search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none; }
#search button { flex: none; width: 42px; height: 42px; border-radius: 50%; color: var(--accent); display: grid; place-items: center; }
#search button:active { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.primary { height: 50px; padding: 0 20px; border-radius: 999px; background: var(--accent); color: #14161a; font-weight: 600; }
.note { margin: 14px 0 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; color: var(--muted); font-size: 13.5px; }

section { margin-top: 30px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
h2 { margin: 0; font-size: 15px; font-weight: 600; }
.link { color: var(--accent); font-size: 14px; padding: 6px 0 6px 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; border-radius: 14px; min-width: 0; }
.tile:active { background: var(--card); }
.tile .badge {
  width: 48px; height: 48px; border-radius: 14px; background: var(--card); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 20px; font-weight: 600; color: var(--accent); text-transform: uppercase;
}
.tile .name { width: 100%; font-size: 12.5px; text-align: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tile .remove {
  position: absolute; top: 2px; right: 8px; width: 24px; height: 24px; border-radius: 50%;
  background: #e06a5a; color: #fff; font-size: 12px; line-height: 24px;
}

.list { display: flex; flex-direction: column; }
.row { display: block; width: 100%; text-align: left; padding: 11px 12px; border-radius: 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.row:active { background: var(--card); }
.row small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

dialog {
  width: min(92vw, 420px); padding: 20px; border: 1px solid var(--line); border-radius: 18px;
  background: var(--bg); color: var(--fg);
}
dialog::backdrop { background: #000a; }
dialog h2 { font-size: 18px; margin-bottom: 16px; }
dialog label { display: block; margin-bottom: 14px; color: var(--muted); font-size: 13px; }
dialog input[type="text"], dialog select {
  display: block; width: 100%; height: 44px; margin-top: 6px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--fg); outline: none;
}
dialog input[type="color"] { display: block; width: 64px; height: 40px; margin-top: 6px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: none; }
dialog button { display: block; width: 100%; height: 46px; margin-top: 10px; border-radius: 999px; border: 1px solid var(--line); }
dialog button.primary { border: 0; }
.danger { color: #e06a5a; }
.error { color: #e06a5a; font-size: 13px; margin: -6px 0 8px; }

/* il + della tessera «aggiungi» è disegnato: al centro preciso del quadrato */
.tile .badge svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; display: block; }
