@font-face {
  font-family: "Cinzel";
  src: url("fonts/cinzel-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "IM Fell";
  src: url("fonts/imfell-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "IM Fell";
  src: url("fonts/imfell-400i.woff2") format("woff2");
  font-style: italic;
  font-display: swap;
}

:root {
  --leather: #2a1c11;
  --leather-2: #3b2717;
  --paper: #eedcb3;
  --paper-2: #e2c98f;
  --ink: #3a2714;
  --ink-soft: #6b4f2e;
  --brass: #c39443;
  --brass-hi: #f2d58e;
  --brass-lo: #6e4a1c;
  --red: #a3261c;
  --green: #2f6b4f;
  --title: "Cinzel", "Trajan Pro", Georgia, serif;
  --body: "IM Fell", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, "Roboto Mono", "DejaVu Sans Mono", Menlo, monospace;
  --nav-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; height: 100%; }

body {
  font-family: var(--body);
  color: var(--paper);
  background-color: var(--leather);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(255, 210, 140, 0.10), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 44px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 44px),
    radial-gradient(ellipse at 50% 120%, #120b05, transparent 70%);
  background-attachment: fixed;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 8px;
}
.topbar h1 {
  margin: 0;
  font-family: var(--title);
  font-size: 1.25rem;
  letter-spacing: 0.18em;
  color: var(--brass-hi);
  text-shadow: 0 1px 0 #000;
}

.badge {
  font-family: var(--title);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--brass-lo);
  color: var(--paper-2);
  background: rgba(0, 0, 0, 0.25);
}
.badge.ok { border-color: #4f9a74; color: #bfe6cc; }
.badge.weak { border-color: #b8893b; color: #f0d79c; }
.badge.bad { border-color: #a3261c; color: #f1b3aa; }

main {
  padding: 0 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  max-width: 560px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }

/* ---------- carte "pergamena" ---------- */
.card {
  color: var(--ink);
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255, 255, 255, 0.35), transparent 55%),
    radial-gradient(ellipse at 90% 100%, rgba(120, 80, 30, 0.22), transparent 60%),
    linear-gradient(160deg, var(--paper), var(--paper-2));
  border-radius: 6px;
  padding: 12px 14px;
  margin: 10px 0;
  box-shadow: 0 0 0 1px rgba(80, 50, 20, 0.5), 0 6px 16px rgba(0, 0, 0, 0.45), inset 0 0 22px rgba(110, 70, 25, 0.35);
}

.label {
  font-family: var(--title);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.mono { font-family: var(--mono); font-size: 0.86rem; }

.note {
  font-style: italic;
  color: #cdb68a;
  font-size: 0.92rem;
  text-align: center;
  margin: 10px 4px;
  line-height: 1.35;
}
.card .note { color: var(--ink-soft); }
.note.left { text-align: left; }

.section-title {
  font-family: var(--title);
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  margin: 18px 0 6px;
  color: var(--brass-hi);
}
.card .section-title { color: var(--ink); margin-top: 0; }

/* ---------- pulsanti ottone ---------- */
.btn {
  font-family: var(--title);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: #2b1a08;
  border: 1px solid #3b250c;
  border-radius: 6px;
  padding: 11px 12px;
  min-height: 44px;
  background: linear-gradient(180deg, var(--brass-hi), var(--brass) 55%, #8d6327);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5), 0 3px 8px rgba(0, 0, 0, 0.45);
  cursor: pointer;
}
.btn:active { transform: translateY(1px); filter: brightness(0.92); }
.btn.accent { background: linear-gradient(180deg, #6fb08b, var(--green) 60%, #1d4532); color: #f2ead6; border-color: #12301f; }
.btn.ghost { background: transparent; color: var(--paper-2); border-color: var(--brass-lo); box-shadow: none; }
.card .btn.ghost { color: var(--ink); border-color: var(--ink-soft); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: 0.7rem; }
.apk-link { display: block; text-align: center; text-decoration: none; line-height: 22px; }
.btn.danger { background: transparent; color: var(--red); border-color: var(--red); box-shadow: none; }

.actions { display: flex; gap: 10px; margin: 12px 0; }
.actions .btn { flex: 1; }

/* ---------- bussola ---------- */
.heading-readout { text-align: center; margin: 4px 0 6px; }
.big {
  font-family: var(--title);
  font-size: 3.1rem;
  font-weight: 700;
  color: var(--brass-hi);
  text-shadow: 0 2px 0 #000;
  font-variant-numeric: tabular-nums;
}
.dir {
  display: inline-block;
  min-width: 2.6em;
  margin-left: 8px;
  font-family: var(--title);
  font-size: 1.5rem;
  color: var(--paper-2);
  vertical-align: 0.5em;
}

.compass-wrap {
  width: min(88vw, 400px, calc(100vh - 360px));
  min-width: 240px;
  aspect-ratio: 1;
  margin: 0 auto;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.6));
}
#compass { width: 100%; height: 100%; display: block; }
#dial { will-change: transform; }
.dial-num { font-family: var(--title); font-size: 13px; fill: #4a321a; text-anchor: middle; }
.dial-card { font-family: var(--title); font-weight: 700; font-size: 26px; fill: #2b1c0f; text-anchor: middle; }
.dial-card.n { fill: var(--red); font-size: 32px; }
.dial-inter { font-family: var(--title); font-size: 14px; fill: #5b3d1e; text-anchor: middle; }

.mini-pos { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.target-info .row { display: flex; justify-content: space-between; margin: 6px 0 8px; }
.target-info strong { font-family: var(--title); }

/* ---------- livella ---------- */
.level-mode {
  text-align: center;
  font-family: var(--title);
  letter-spacing: 0.12em;
  font-size: 0.85rem;
  color: var(--paper-2);
  margin: 6px 0 12px;
}

.bullseye {
  position: relative;
  width: min(80vw, 330px);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #d9ecb9, #9fc27a 55%, #5f7f3c 100%);
  box-shadow:
    0 0 0 10px #8d6327,
    0 0 0 12px #3b250c,
    0 0 0 3px #f2d58e inset,
    0 14px 24px 12px rgba(0, 0, 0, 0.55),
    inset 0 -14px 30px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.bullseye .ring { position: absolute; border: 2px solid rgba(40, 30, 10, 0.55); border-radius: 50%; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.bullseye .r1 { width: 22%; height: 22%; }
.bullseye .r2 { width: 58%; height: 58%; border-style: dashed; border-width: 1px; }
.bullseye .cross::before, .bullseye .cross::after {
  content: ""; position: absolute; background: rgba(40, 30, 10, 0.35);
}
.bullseye .cross::before { left: 50%; top: 0; bottom: 0; width: 1px; }
.bullseye .cross::after { top: 50%; left: 0; right: 0; height: 1px; }

.bubble {
  position: absolute;
  left: 50%; top: 50%;
  width: 18%; height: 18%;
  margin: -9% 0 0 -9%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.95), rgba(255, 255, 240, 0.55) 40%, rgba(220, 240, 190, 0.25) 75%);
  box-shadow: 0 0 0 1px rgba(60, 70, 30, 0.45), 0 2px 6px rgba(0, 0, 0, 0.25);
  will-change: transform;
}
.is-level .bullseye, .is-level .tube-glass { box-shadow: 0 0 0 10px #8d6327, 0 0 0 12px #3b250c, 0 0 28px 14px rgba(120, 220, 150, 0.55); }

.tube { margin: 30px auto 10px; width: min(90vw, 380px); }
.tube-glass {
  position: relative;
  height: 74px;
  border-radius: 40px;
  background: linear-gradient(180deg, #e8f3c8, #a8c77e 50%, #6f8f45);
  box-shadow: 0 0 0 10px #8d6327, 0 0 0 12px #3b250c, 0 12px 22px 12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.tube-marks { position: absolute; inset: 0; }
.tube-marks span { position: absolute; top: 8px; bottom: 8px; width: 2px; background: rgba(40, 30, 10, 0.6); }
.tube-marks span:first-child { left: calc(50% - 34px); }
.tube-marks span:last-child { left: calc(50% + 32px); }
.tube-bubble {
  position: absolute;
  top: 12px; bottom: 12px;
  left: 50%; width: 60px; margin-left: -30px;
  border-radius: 30px;
  background: radial-gradient(ellipse at 40% 30%, rgba(255, 255, 255, 0.95), rgba(255, 255, 235, 0.5) 50%, rgba(220, 240, 190, 0.2));
  box-shadow: 0 0 0 1px rgba(60, 70, 30, 0.45);
  will-change: transform;
}

/* livella da muro col telefono sul lato lungo: tutto il pannello ruota con il telefono */
.level-stage.land {
  position: fixed;
  left: 50%;
  box-sizing: border-box;
  padding: 0 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.level-stage.land .tube { width: 100%; max-width: 560px; margin-top: 22px; }
.level-stage.land .level-hint { display: none; }

.level-readout, .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.grid { margin-top: 0; }
.level-readout .card, .grid .card { margin: 0; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.big2 { font-family: var(--title); font-weight: 700; font-size: 1.35rem; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- posizione ---------- */
.coords .coord {
  font-family: var(--title);
  font-weight: 700;
  font-size: 1.75rem;
  margin: 0 0 6px;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.coords .sub { color: var(--ink-soft); margin-top: 4px; }

.waypoints { list-style: none; margin: 0; padding: 0; }
.waypoints li { display: block; }
.wp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.wp-name { font-family: var(--title); font-weight: 700; font-size: 1rem; }
.wp-dist { font-family: var(--title); font-size: 0.85rem; color: var(--ink-soft); white-space: nowrap; }
.wp-coords { margin: 2px 0 8px; color: var(--ink-soft); }
.wp-actions { display: flex; gap: 8px; }
.wp-actions .btn { flex: 1; }

/* ---------- impostazioni ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 1rem; }
.field input {
  font-family: var(--mono);
  font-size: 1.1rem;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--ink-soft);
  background: rgba(255, 255, 255, 0.45);
  color: var(--ink);
  user-select: text;
}
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 1.05rem; }
.check input { width: 22px; height: 22px; accent-color: var(--green); }

/* ---------- barra delle schede ---------- */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: linear-gradient(180deg, #3b2717, #1d130a);
  border-top: 2px solid var(--brass-lo);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.5);
  z-index: 5;
}
.tabs button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: 0;
  color: #a88b5c;
  font-family: var(--title);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  cursor: pointer;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.tabs button.active { color: var(--brass-hi); }
.tabs button.active svg { filter: drop-shadow(0 0 4px rgba(242, 213, 142, 0.6)); }

/* ---------- schermata iniziale ---------- */
.start {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: rgba(18, 11, 5, 0.86);
  z-index: 20;
}
.start-card {
  max-width: 380px;
  text-align: center;
  color: var(--ink);
  padding: 26px 22px;
  border-radius: 8px;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(255, 255, 255, 0.35), transparent 55%),
    linear-gradient(160deg, var(--paper), var(--paper-2));
  box-shadow: 0 0 0 2px #6e4a1c, 0 20px 40px rgba(0, 0, 0, 0.7), inset 0 0 40px rgba(110, 70, 25, 0.4);
}
.start-card img { border-radius: 22px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); }
.start-card h2 { font-family: var(--title); letter-spacing: 0.06em; margin: 14px 0 6px; }
.start-card p { font-size: 1.05rem; line-height: 1.4; }
.big-btn { width: 100%; font-size: 0.95rem; min-height: 52px; margin-top: 6px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 6px;
  background: #1d130a;
  color: var(--paper);
  border: 1px solid var(--brass-lo);
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 640px) {
  .big { font-size: 2.4rem; }
  .compass-wrap { width: min(80vw, 300px); }
}
