:root {
  --bg: #1C1622;
  --bg-deep: #19131F;
  --surface: #2A2231;
  --surface-2: #332A3B;
  --border: #3A3042;
  --border-strong: #5A4A66;
  --text: #F5EEF2;
  --muted: #B9AEC0;
  --accent: #FF8A7A;
  --accent-ink: #1C1622;
  --good: #7FD1B9;
  --warn: #F2C46D;
  --paper: #F5EEF2;
  --paper-ink: #1C1622;
  --paper-muted: #4A3D55;
  --paper-line: #E3D9E6;
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: Manrope, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(40px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 28px; font-weight: 800; }
h2 { font-size: 20px; font-weight: 800; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0; }
a { color: var(--accent); }
a:hover { color: #FFB3A8; }

.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 24px 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }
.row { display: flex; gap: 10px; align-items: center; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.card.paper { background: var(--paper); color: var(--paper-ink); border-color: transparent; }
.card.paper .muted { color: var(--paper-muted); }
.card.accent { border: 2px solid var(--accent); }
.card.dashed { background: transparent; border: 1px dashed var(--border-strong); }

.btn {
  appearance: none; border: none; cursor: pointer; font: inherit; font-weight: 800; font-size: 15px;
  min-height: 52px; padding: 0 22px; border-radius: 26px;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
.btn:hover { filter: brightness(1.05); color: var(--accent-ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 600; }
.btn.dark { background: var(--paper-ink); color: var(--paper); }
.btn.small { min-height: 44px; font-size: 14px; padding: 0 16px; }
.btn.block { width: 100%; }
.btn.danger { background: transparent; color: #FF9C8F; border: 1px solid #6B3A3A; font-weight: 600; }
.linklike { background: none; border: none; color: var(--muted); font: inherit; font-size: 14px; text-decoration: underline; cursor: pointer; padding: 8px 0; min-height: 44px; }

.progress { height: 6px; border-radius: 3px; background: var(--surface); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s; }

.pill { white-space: nowrap; flex: none; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.good { background: rgba(127, 209, 185, .15); color: var(--good); }
.pill.warn { background: rgba(242, 196, 109, .15); color: var(--warn); }
.pill.accent { background: rgba(255, 138, 122, .15); color: var(--accent); }
.dot { width: 10px; height: 10px; border-radius: 5px; background: var(--border-strong); flex: none; }
.dot.good { background: var(--good); }
.dot.warn { background: var(--warn); }

/* Domande */
.question { display: flex; flex-direction: column; gap: 12px; padding: 18px; border-radius: var(--radius); background: var(--paper); color: var(--paper-ink); }
.question .qtext { font-size: 18px; font-weight: 700; line-height: 1.35; }
.question .qhint { font-size: 13px; color: var(--paper-muted); }
.scale { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.opt {
  appearance: none; font: inherit; cursor: pointer; min-height: 48px; border-radius: 14px;
  border: 1px solid #D8CCDD; background: #fff; color: var(--paper-ink); font-weight: 700; font-size: 16px; padding: 8px 12px;
}
.opt[aria-pressed="true"] { background: var(--paper-ink); color: var(--paper); border-color: var(--paper-ink); }
.scale-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--paper-muted); gap: 12px; }
.opts { display: flex; flex-direction: column; gap: 8px; }
.opts .opt { text-align: left; font-weight: 600; font-size: 15px; }
.opts-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
textarea {
  font: inherit; font-size: 16px; width: 100%; min-height: 110px; resize: vertical; padding: 12px 14px;
  border-radius: 14px; border: 1px solid #D8CCDD; background: #fff; color: var(--paper-ink);
}
input[type="text"], input[type="password"] {
  font: inherit; font-size: 16px; width: 100%; min-height: 48px; padding: 0 14px;
  border-radius: 14px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.card.paper input[type="text"] { background: #fff; color: var(--paper-ink); border-color: #D8CCDD; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.rank { display: flex; flex-direction: column; gap: 6px; }
.rank-item { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid #D8CCDD; border-radius: 14px; padding: 4px 4px 4px 14px; }
.rank-item span { flex: 1; font-weight: 600; font-size: 15px; }
.rank-item .num { flex: none; width: 22px; color: var(--paper-muted); font-weight: 800; }
.icon-btn { appearance: none; border: none; background: transparent; color: var(--paper-ink); width: 44px; height: 44px; border-radius: 12px; cursor: pointer; font-size: 18px; }
.icon-btn:disabled { opacity: .25; }

/* Tabs */
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; background: var(--bg-deep); padding: 6px; border-radius: 18px; border: 1px solid var(--border); }
.tabs button { appearance: none; border: none; font: inherit; font-size: 14px; font-weight: 700; min-height: 44px; border-radius: 13px; background: transparent; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--surface-2); color: var(--text); }

/* Percorso */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.step { display: flex; gap: 14px; }
.step .rail { display: flex; flex-direction: column; align-items: center; width: 32px; flex: none; }
.step .badge { width: 32px; height: 32px; border-radius: 16px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px; border: 1px solid var(--border-strong); color: var(--muted); }
.step.done .badge { background: var(--good); color: var(--accent-ink); border: none; }
.step.current .badge { background: var(--accent); color: var(--accent-ink); border: none; }
.step .line { width: 2px; flex: 1; min-height: 20px; background: var(--border); }
.step.done .line { background: var(--good); }
.step .body { flex: 1; padding-bottom: 20px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.step-title { font-size: 16px; font-weight: 700; }
.step:not(.current):not(.done) .step-title { color: #D9CFDE; }
ol.questions { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

/* Timer */
.timer { font-size: 56px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; text-align: center; }

.linkbox { font-size: 13px; word-break: break-all; background: var(--bg-deep); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; color: var(--muted); }
.notice { border-radius: 16px; padding: 14px 16px; background: rgba(242, 196, 109, .12); color: #F6DCA6; font-size: 14px; }
.error { border-radius: 16px; padding: 14px 16px; background: rgba(255, 138, 122, .12); color: #FFC2B9; font-size: 14px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .progress > span { transition: none; } }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--paper); color: var(--paper-ink); padding: 12px 18px; border-radius: 14px; font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 40px);
}
#toast.show { opacity: 1; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 8px; }
footer.foot { margin-top: auto; padding-top: 24px; font-size: 12px; color: var(--muted); text-align: center; }
:focus-visible { outline: 3px solid #FFB3A8; outline-offset: 2px; }
