/* ============================================================
   Sense Calibrator — monochrome, light, fluid
   ============================================================ */

:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #0a0a0a;
  --ink-2: #565656;
  --ink-3: #9a9a96;
  --line: #e7e7e3;
  --line-2: #d6d6d2;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px -12px rgba(0, 0, 0, 0.08);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  /* stronger curves for enter/exit + on-screen movement */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 0 24px;
  flex: 1;
}

.hidden { display: none !important; }
.mono { font-family: var(--mono); }

/* ---------------- topbar ---------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.wordmark {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--ink);
  text-decoration: none;
}
.wordmark span {
  font-weight: 300;
  color: var(--ink-3);
  margin-left: 2px;
}

.topbar-status { display: flex; gap: 8px; align-items: center; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--surface);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  white-space: nowrap;
  transition: color 0.25s var(--ease), border-color 0.25s var(--ease),
              background 0.25s var(--ease);
}
.chip.chip-on { color: var(--ink); border-color: var(--ink); }
.chip.chip-warn { background: var(--ink); color: #fff; border-color: var(--ink); }

.gh-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  border: 1px solid var(--ink);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 0.16s var(--ease-out), box-shadow 0.16s var(--ease-out);
}
.gh-chip svg { width: 15px; height: 15px; fill: currentColor; }
.gh-chip:active { transform: scale(0.97); }
.gh-chip:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
@media (hover: hover) and (pointer: fine) {
  .gh-chip:hover { transform: translateY(-1px); box-shadow: 0 6px 20px -6px rgba(0, 0, 0, 0.35); }
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-3);
  transition: background 0.25s var(--ease);
}
.dot.on {
  background: var(--ink);
  animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(10, 10, 10, 0.25); }
  50% { box-shadow: 0 0 0 5px rgba(10, 10, 10, 0); }
}

/* ---------------- viste ---------------- */

.view { animation: viewIn 0.4s var(--ease-out); }
@keyframes viewIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- hero ---------------- */

.view-hero {
  text-align: center;
  padding: 9vh 0 6vh;
}

.view-hero h1 {
  font-size: clamp(38px, 6.5vw, 64px);
  font-weight: 750;
  letter-spacing: -0.035em;
  line-height: 1.05;
  margin: 0 0 20px;
}

.lede {
  max-width: 540px;
  margin: 0 auto 36px;
  color: var(--ink-2);
  font-size: 17px;
}

.hero-cta { margin-bottom: 12px; }

.hint {
  font-size: 12.5px;
  color: var(--ink-3);
  margin: 14px 0 0;
}

.callout {
  max-width: 480px;
  margin: 22px auto 0;
  padding: 14px 18px;
  border: 1px solid var(--ink);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
  text-align: left;
}
.callout:not(.hidden) { animation: viewIn 0.3s var(--ease-out); }

.steps-strip {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  list-style: none;
  padding: 0;
  margin: 64px 0 0;
}
.steps-strip li {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 12.5px;
  color: var(--ink-2);
}
.steps-strip b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
}

/* ---------------- faq ---------------- */

.faq {
  max-width: 560px;
  margin: 72px auto 0;
  text-align: left;
}
.faq h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 0 6px;
}
.faq details {
  border-top: 1px solid var(--line);
}
.faq details:last-child {
  border-bottom: 1px solid var(--line);
}
.faq summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  color: var(--ink-2);
  transition: color 0.18s var(--ease);
}
.faq summary:hover { color: var(--ink); }
.faq details[open] summary { color: var(--ink); }
.faq summary:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  border-radius: 4px;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: '+';
  flex-shrink: 0;
  font-size: 17px;
  font-weight: 400;
  color: var(--ink-3);
  transition: transform 0.2s var(--ease-out), color 0.18s var(--ease);
}
.faq summary:hover::after { color: var(--ink-2); }
.faq details[open] summary::after {
  content: '+';
  transform: rotate(45deg);
  color: var(--ink);
}
.faq details[open] p { animation: faqOpen 0.28s var(--ease-out); }
.faq p {
  margin: 0 0 16px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-2);
}
@keyframes faqOpen {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- bottoni ---------------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 22px;
  cursor: pointer;
  transition: transform 0.16s var(--ease-out), box-shadow 0.16s var(--ease-out),
              background 0.16s var(--ease), border-color 0.16s var(--ease),
              color 0.16s var(--ease), opacity 0.16s var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.btn-primary {
  background: var(--ink);
  color: #fff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line-2);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
}

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px -6px rgba(0, 0, 0, 0.35);
  }
  .btn-secondary:hover:not(:disabled) { border-color: var(--ink); }
  .btn-ghost:hover:not(:disabled) { color: var(--ink); }
}

.btn-lg { font-size: 16px; padding: 14px 34px; }
.btn-sm { font-size: 12.5px; padding: 7px 16px; }

/* ---------------- card ---------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 18px;
}

#view-device { padding: 28px 0 40px; }

/* device card */

.device-card {
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
}
.device-id h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.device-sub {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--ink-3);
  font-family: var(--mono);
}
.device-info {
  display: flex;
  gap: 26px;
  flex-wrap: wrap;
  margin: 0;
  flex: 1;
}
.device-info div { min-width: 90px; }
.device-info dt {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-3);
  font-weight: 600;
}
.device-info dd {
  margin: 3px 0 0;
  font-size: 13.5px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}
.device-actions { display: flex; gap: 4px; }

/* drift card */

.drift-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.drift-head h3 { margin: 0; font-size: 15px; }
.drift-status { margin: 0; color: var(--ink-2); font-size: 14px; }
.drift-card[data-state="testing"] .drift-status { color: var(--ink); }
.drift-card[data-state="testing"] #btn-retest { visibility: hidden; }

/* sticks */

.grid-sticks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 640px) { .grid-sticks { grid-template-columns: 1fr; } }

.stick-card {
  text-align: center;
  margin-bottom: 18px;
}
.stick-card h3 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  font-weight: 700;
}
.stick-card canvas {
  width: min(240px, 70vw);
  height: auto;
  aspect-ratio: 1;
}

.readout {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-3);
}
.readout b {
  font-family: var(--mono);
  font-weight: 500;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.verdict {
  display: inline-block;
  margin-top: 14px;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  animation: viewIn 0.3s var(--ease-out);
}
.verdict.v-ok { border-color: var(--ink); color: var(--ink); }
.verdict.v-mild { border: 2px solid var(--ink); color: var(--ink); }
.verdict.v-bad { background: var(--ink); border-color: var(--ink); color: #fff; }

/* actions */

.actions-card { padding: 8px 24px; }
.action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 17px 0;
}
.action + .action { border-top: 1px solid var(--line); }
.action h4 { margin: 0 0 3px; font-size: 15px; }
.action p { margin: 0; font-size: 13px; color: var(--ink-2); max-width: 520px; }
.action .btn { flex-shrink: 0; min-width: 92px; }

/* banner non salvato */

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  padding: 18px 24px;
  margin-bottom: 18px;
  animation: bannerIn 0.36s var(--ease-out);
}
@keyframes bannerIn {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to { opacity: 1; transform: none; }
}
.banner b { display: block; font-size: 14.5px; }
.banner span { font-size: 13px; opacity: 0.75; }
.banner .btn-primary {
  background: #fff;
  color: var(--ink);
  flex-shrink: 0;
}

/* log */

.log-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 18px;
}
.log-panel summary {
  padding: 11px 18px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  cursor: pointer;
  user-select: none;
  transition: color 0.18s var(--ease);
}
.log-panel summary:hover { color: var(--ink-2); }
.log-panel summary:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: -2px;
  border-radius: var(--radius-sm);
}
.log-panel pre {
  margin: 0;
  padding: 4px 18px 14px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
  color: var(--ink-2);
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}

/* ---------------- progress ---------------- */

.progress {
  height: 5px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
  margin: 14px 0;
}
.progress i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--ink);
  transition: width 0.3s var(--ease-out);
}

/* ---------------- modali ---------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(247, 247, 245, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fadeIn 0.2s var(--ease-out);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-panel {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 70px -20px rgba(0, 0, 0, 0.25);
  padding: 28px 30px;
  /* modals stay centered: transform-origin center is correct here */
  animation: panelIn 0.28s var(--ease-out);
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
.modal-narrow { max-width: 460px; }

.modal-panel h3 {
  margin: 0 0 12px;
  font-size: 19px;
  letter-spacing: -0.01em;
}
.modal-panel p { color: var(--ink-2); font-size: 14.5px; margin: 0 0 12px; }
.modal-panel p b { color: var(--ink); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

/* wizard */

.wizard-dots {
  display: flex;
  gap: 7px;
  margin: 0 0 18px;
}
.wizard-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line-2);
  transition: background 0.3s var(--ease), transform 0.3s var(--ease-out);
}
.wizard-dots i.done { background: var(--ink-3); }
.wizard-dots i.active { background: var(--ink); transform: scale(1.35); }

.wizard-body {
  display: flex;
  gap: 24px;
  align-items: center;
  min-height: 120px;
}
.wizard-diagram {
  width: 110px;
  flex-shrink: 0;
  color: var(--ink);
}
.wizard-diagram #wizard-line,
.wizard-diagram #wizard-target { transition: x 0.45s var(--ease-in-out), y 0.45s var(--ease-in-out),
                                            cx 0.45s var(--ease-in-out), cy 0.45s var(--ease-in-out); }
#wizard-msg { margin: 0; }

.wizard-live {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.wizard-live figure { margin: 0; text-align: center; }
.wizard-live canvas { width: 110px; height: auto; aspect-ratio: 1; }
.wizard-live figcaption {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}

/* range */

.range-minmax {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  margin: 4px 0 8px;
}
.range-minmax .edge-ok { color: var(--ink); font-weight: 700; }
.range-hint { font-size: 12px; }

.range-dials {
  display: flex;
  justify-content: center;
  gap: 26px;
  margin: 18px 0 8px;
}
.range-dials canvas {
  width: min(200px, 38vw);
  height: auto;
  aspect-ratio: 1;
}
.range-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-2);
}
#range-pct { font-weight: 700; color: var(--ink); }
#range-vals { font-variant-numeric: tabular-nums; }

/* telemetria opt-in */

.telemetry-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--ink-3);
  cursor: pointer;
  line-height: 1.45;
}
.telemetry-label input[type="checkbox"] {
  margin: 1px 0 0;
  flex-shrink: 0;
  accent-color: var(--ink);
  width: 13px;
  height: 13px;
  cursor: pointer;
}

/* ---------------- toast ---------------- */

.toasts {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  font-weight: 500;
  padding: 11px 20px;
  border-radius: 999px;
  box-shadow: 0 10px 30px -8px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.32s var(--ease-out);
  max-width: min(520px, 86vw);
  text-align: center;
}
/* exit stays under the 350ms JS removal delay; same direction as enter */
.toast.out { animation: toastOut 0.24s var(--ease-out) forwards; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes toastOut {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(10px) scale(0.97); }
}

/* ---------------- footer ---------------- */

.footer {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 26px 24px 34px;
  font-size: 12px;
  color: var(--ink-3);
}
.footer a {
  color: var(--ink-2);
  transition: color 0.18s var(--ease);
}
.footer a:hover { color: var(--ink); }
.footer a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------- test di precisione (gioco) ---------------- */

.modal-wide { max-width: 680px; }

.game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.game-head h3 { margin: 0; }

.game-instr {
  min-height: 1.5em;
  margin: 0 0 14px;
}

.game-dials {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 36px;
  margin: 6px 0 4px;
}
.game-dials figure { margin: 0; text-align: center; }
.game-dials canvas {
  width: min(220px, 38vw);
  height: auto;
  aspect-ratio: 1;
}
.game-dials figcaption {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}

/* countdown 3-2-1 centrato tra i due quadranti */
.game-countdown {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 64px;
  font-weight: 750;
  letter-spacing: -0.04em;
  color: var(--ink);
  pointer-events: none;
  animation: countPop 0.3s var(--ease-out);
}
@keyframes countPop {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.game-trials {
  margin: 14px 0 0;
  padding-left: 20px;
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.8;
}
.game-trials b { color: var(--ink); }

/* report */

.game-report { animation: viewIn 0.4s var(--ease-out); }

.game-overall {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
}
.game-overall-num {
  font-size: 64px;
  font-weight: 750;
  letter-spacing: -0.04em;
  line-height: 1;
}
.game-overall-cap {
  font-size: 14px;
  color: var(--ink-3);
}
.game-verdict {
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  margin: 8px 0 4px;
}
.game-compare {
  text-align: center;
  font-size: 13px;
  color: var(--ink-2);
  margin: 0 0 16px;
}
.game-delta { font-weight: 700; color: var(--ink); }

.game-breakdown {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 540px) { .game-breakdown { grid-template-columns: 1fr; } }

.game-stick-col {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.game-stick-col h4 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  font-weight: 700;
}
.game-score-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink-2);
  padding: 4px 0;
}
.game-score-row + .game-score-row { border-top: 1px solid var(--line); }
.game-score-row b {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.game-formula {
  margin: 16px 0 0;
  font-size: 11.5px;
  color: var(--ink-3);
  text-align: center;
}
