:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e3e1dc;
  --text: #23211d;
  --muted: #6b6862;
  --accent: #b5502a;
  --accent-soft: #fbf0ec;
  --ok: #2f6f4f;
  --ok-soft: #eef6f1;
  --err: #a3312a;
  --err-soft: #fbeceb;
  --code-bg: #1f1e1b;
  --code-text: #e8e5df;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* ---------- navigazione ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.25rem;
  padding: 0.75rem 1.5rem;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 650; letter-spacing: -0.01em; margin-right: auto; }
.topbar a { color: var(--muted); text-decoration: none; font-size: 0.92rem; padding: 0.3rem 0.6rem; border-radius: 6px; }
.topbar a:hover { color: var(--text); background: var(--bg); }
.topbar a.active { color: var(--accent); background: var(--accent-soft); }

/* ---------- layout ---------- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }
.narrow { max-width: 620px; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; }
.course { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 3rem; align-items: start; }
@media (max-width: 860px) { .course { grid-template-columns: 1fr; gap: 1.5rem; } .toc { position: static !important; } }

.toc { position: sticky; top: 5rem; font-size: 0.87rem; }
.toc ol { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.toc li { margin: 0.15rem 0; }
.toc a { display: block; color: var(--muted); text-decoration: none; padding: 0.25rem 0.5rem; border-left: 2px solid var(--border); }
.toc a:hover { color: var(--text); border-left-color: var(--accent); background: var(--surface); }

/* ---------- testo ---------- */
h1 { font-size: 2.1rem; line-height: 1.2; letter-spacing: -0.025em; margin: 0 0 0.5rem; }
h2 { font-size: 1.35rem; letter-spacing: -0.015em; margin: 3rem 0 0.75rem; padding-top: 0.5rem; scroll-margin-top: 5rem; }
h3 { font-size: 1.02rem; margin: 1.75rem 0 0.5rem; }
.lead { font-size: 1.1rem; color: var(--muted); margin: 0 0 2rem; }
.step-no {
  display: inline-block; font-family: var(--mono); font-size: 0.72rem;
  color: var(--accent); background: var(--accent-soft);
  padding: 0.1rem 0.45rem; border-radius: 4px; margin-right: 0.5rem; vertical-align: 0.15em;
}
p { margin: 0.75rem 0; }
ul, ol { padding-left: 1.3rem; }
li { margin: 0.3rem 0; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.88em; background: #edeae4; padding: 0.1em 0.35em; border-radius: 4px; }
pre {
  background: var(--code-bg); color: var(--code-text);
  padding: 1.1rem 1.2rem; border-radius: var(--radius);
  overflow-x: auto; font-family: var(--mono); font-size: 0.83rem; line-height: 1.6;
  margin: 1rem 0;
}
pre code { background: none; padding: 0; font-size: inherit; color: inherit; }
pre .c { color: #8a8578; font-style: italic; }   /* commento */
pre .k { color: #d99a6c; }                        /* keyword */
pre .s { color: #97b98a; }                        /* stringa */
pre .n { color: #7fa8c9; }                        /* numero */
.filename {
  font-family: var(--mono); font-size: 0.74rem; color: var(--muted);
  background: #edeae4; border: 1px solid var(--border); border-bottom: none;
  padding: 0.35rem 0.75rem; border-radius: 6px 6px 0 0; display: inline-block; margin-bottom: -1rem; position: relative;
}
.filename + pre { border-top-left-radius: 0; }

/* ---------- riquadri ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; margin: 1.25rem 0; }
.note, .warn, .ok-box {
  border-left: 3px solid; border-radius: 0 8px 8px 0;
  padding: 0.85rem 1.1rem; margin: 1.25rem 0; font-size: 0.94rem;
}
.note { border-color: var(--accent); background: var(--accent-soft); }
.warn { border-color: #c08a2e; background: #fdf5e6; }
.ok-box { border-color: var(--ok); background: var(--ok-soft); }
.note strong, .warn strong, .ok-box strong { display: block; margin-bottom: 0.2rem; }

table { width: 100%; border-collapse: collapse; margin: 1.25rem 0; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- form ---------- */
label { display: block; font-size: 0.85rem; font-weight: 600; margin: 1rem 0 0.35rem; }
input[type=text] {
  width: 100%; padding: 0.7rem 0.85rem; font-size: 1rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
  font-family: inherit;
}
input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input.code-input { font-family: var(--mono); font-size: 1.7rem; letter-spacing: 0.35em; text-align: center; padding: 0.6rem; }
button {
  font: inherit; font-weight: 600; font-size: 0.95rem;
  padding: 0.7rem 1.3rem; border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: #fff; cursor: pointer; margin-top: 1.1rem;
}
button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
button.ghost:hover { color: var(--text); background: var(--surface); filter: none; }
button.small { font-size: 0.82rem; padding: 0.35rem 0.7rem; margin-top: 0; }

.msg { padding: 0.8rem 1rem; border-radius: 8px; margin: 1.1rem 0; font-size: 0.93rem; display: none; }
.msg.show { display: block; }
.msg.ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #cfe3d7; }
.msg.err { background: var(--err-soft); color: var(--err); border: 1px solid #f0d2d0; }

/* ---------- elementi specifici ---------- */
.qr { text-align: center; padding: 1.25rem; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.qr img { display: block; margin: 0 auto; }
.secret-manual {
  font-family: var(--mono); font-size: 1rem; letter-spacing: 0.08em; word-break: break-all;
  background: #edeae4; padding: 0.7rem 0.85rem; border-radius: 8px; text-align: center;
}
.countdown { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); }
.bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 0.35rem; }
.bar > div { height: 100%; background: var(--accent); transition: width 1s linear; }
.stepper { display: flex; gap: 0.5rem; font-size: 0.8rem; color: var(--muted); margin-bottom: 1.5rem; }
.stepper span { padding: 0.2rem 0.6rem; border-radius: 20px; background: var(--surface); border: 1px solid var(--border); }
.stepper span.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.hidden { display: none; }
.kv { font-family: var(--mono); font-size: 0.8rem; }
.kv div { display: flex; gap: 0.75rem; padding: 0.3rem 0; border-bottom: 1px solid var(--border); }
.kv b { min-width: 130px; color: var(--muted); font-weight: 500; }
.kv span { word-break: break-all; }
.muted { color: var(--muted); font-size: 0.88rem; }
.userlist { font-size: 0.88rem; }
.userlist div { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.userlist .u { font-family: var(--mono); flex: 1; }
.badge { font-size: 0.72rem; padding: 0.1rem 0.45rem; border-radius: 4px; background: var(--ok-soft); color: var(--ok); }
.badge.pending { background: #fdf5e6; color: #8a6318; }
