:root {
  --olive: #3e4a2b;
  --olive-dark: #232a17;
  --olive-mid: #566638;
  --khaki: #c9b98a;
  --paper: #efe6c8;
  --paper-dark: #e0d4ac;
  --ink: #1f1d17;
  --muted: #5d5840;
  --red: #9b1c1c;
  --red-dark: #701212;
  --green: #2f6b2f;
  --gold: #b8913b;
  --stencil: Impact, "Arial Narrow Bold", "Franklin Gothic Heavy", "Arial Black", sans-serif;
  --type: "Courier New", Courier, "Liberation Mono", monospace;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

html { background: var(--olive-dark); }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.5;
  background:
    repeating-linear-gradient(135deg, rgba(255,255,255,.025) 0 2px, transparent 2px 14px),
    radial-gradient(ellipse at top, #34401f 0%, var(--olive-dark) 70%);
}

/* ---------- Barra superiore ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  background: #171c0f;
  border-bottom: 3px solid var(--gold);
  color: var(--paper);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .star { color: var(--gold); font-size: 26px; line-height: 1; }
.brand-text { font-family: var(--stencil); font-size: 22px; letter-spacing: 3px; text-transform: uppercase; }
.brand-text small { font-family: var(--type); font-size: 13px; letter-spacing: 2px; color: var(--khaki); margin-left: 8px; }
.userbar { display: flex; align-items: center; gap: 12px; font-family: var(--type); font-size: 14px; }
#username { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wrap { width: 100%; max-width: 760px; margin: 0 auto; padding: 28px 16px 40px; flex: 1; }
.foot { text-align: center; padding: 16px; font-family: var(--type); font-size: 12px; color: var(--khaki); opacity: .8; }
.loading { color: var(--paper); font-family: var(--type); text-align: center; }

/* ---------- Carta / schede ---------- */
.card {
  position: relative;
  background:
    linear-gradient(180deg, rgba(255,255,255,.35), transparent 40%),
    var(--paper);
  border: 3px solid var(--ink);
  border-radius: 4px;
  padding: 26px 26px 28px;
  box-shadow: 0 0 0 5px var(--olive-mid), 0 14px 30px rgba(0,0,0,.45);
}
.card::before {
  content: "";
  position: absolute; inset: 7px;
  border: 1.5px dashed rgba(31,29,23,.35);
  pointer-events: none;
}
.card > * { position: relative; }
.card + .card { margin-top: 28px; }

h1, h2, h3 { font-family: var(--stencil); font-weight: normal; letter-spacing: 2px; text-transform: uppercase; margin: 0 0 12px; color: var(--olive-dark); }
h1 { font-size: 34px; }
h2 { font-size: 26px; }
h3 { font-size: 19px; }
.kicker { font-family: var(--type); font-size: 13px; letter-spacing: 3px; text-transform: uppercase; color: var(--red); margin: 0 0 6px; }
.lead { margin: 0 0 18px; color: var(--muted); }

/* ---------- Form ---------- */
.tabs { display: flex; margin: -26px -26px 22px; border-bottom: 3px solid var(--ink); }
.tab {
  flex: 1; padding: 12px 8px; background: var(--paper-dark); border: 0; cursor: pointer;
  font-family: var(--stencil); font-size: 18px; letter-spacing: 2px; text-transform: uppercase; color: var(--muted);
}
.tab + .tab { border-left: 3px solid var(--ink); }
.tab[aria-selected="true"] { background: var(--olive); color: var(--paper); }

form { display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { display: grid; gap: 4px; font-family: var(--type); font-size: 13px; letter-spacing: 1px; text-transform: uppercase; color: var(--olive-dark); }
input[type="text"], input[type="email"], input[type="password"] {
  width: 100%; padding: 11px 12px; font: inherit; font-size: 17px; text-transform: none; letter-spacing: normal;
  color: var(--ink); background: #fbf7e6; border: 2px solid var(--ink); border-radius: 2px;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.hint { font-family: var(--type); font-size: 12px; color: var(--muted); text-transform: none; letter-spacing: 0; }
.code-input { text-align: center; font-family: var(--type) !important; font-size: 30px !important; letter-spacing: 12px !important; max-width: 280px; margin: 0 auto; }

.msg { margin: 0; padding: 10px 12px; font-family: var(--type); font-size: 14px; border-left: 5px solid; }
.msg.error { background: #f3d6d0; border-color: var(--red); color: var(--red-dark); }
.msg.info { background: #e3e8cf; border-color: var(--olive); color: var(--olive-dark); }

/* ---------- Pulsanti ---------- */
.btn {
  display: inline-block; padding: 13px 22px; cursor: pointer; text-align: center; text-decoration: none;
  font-family: var(--stencil); font-size: 19px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--paper); background: var(--olive); border: 3px solid var(--ink); border-radius: 3px;
  box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { background: var(--olive-mid); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn[disabled] { opacity: .55; cursor: wait; }
.btn-red { background: var(--red); }
.btn-red:hover { background: #b32424; }
.btn-ghost { background: transparent; color: var(--paper); border-color: var(--khaki); box-shadow: none; }
.btn-ghost:hover { background: rgba(255,255,255,.1); }
.btn-small { padding: 5px 12px; font-size: 14px; border-width: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-top: 8px; }

/* ---------- 2FA ---------- */
.steps { margin: 0 0 18px; padding-left: 22px; }
.steps li { margin-bottom: 6px; }
.qr-box { display: grid; justify-items: center; gap: 10px; margin: 6px 0 18px; }
.qr-box img { width: 220px; height: 220px; border: 3px solid var(--ink); background: #fff; image-rendering: pixelated; }
.secret { font-family: var(--type); font-size: 15px; letter-spacing: 2px; background: #fbf7e6; border: 2px dashed var(--ink); padding: 6px 10px; word-break: break-all; text-align: center; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--olive-dark); text-decoration: underline; cursor: pointer; }

/* ---------- Dashboard ---------- */
.rules { list-style: none; padding: 0; margin: 0 0 22px; display: grid; gap: 8px; }
.rules li { display: flex; gap: 12px; align-items: baseline; }
.rules .tag { flex: none; min-width: 74px; font-family: var(--stencil); letter-spacing: 1px; text-align: center; padding: 1px 8px; background: var(--olive); color: var(--paper); }
.history-wrap { overflow-x: auto; }
table.history { width: 100%; border-collapse: collapse; font-family: var(--type); font-size: 14px; }
table.history th, table.history td { padding: 8px 6px; border-bottom: 1px solid rgba(31,29,23,.25); text-align: left; }
table.history th { text-transform: uppercase; letter-spacing: 1px; font-size: 12px; color: var(--muted); }
.badge { display: inline-block; padding: 1px 8px; font-weight: bold; border: 2px solid; transform: rotate(-3deg); }
.badge.ok { color: var(--green); border-color: var(--green); }
.badge.ko { color: var(--red); border-color: var(--red); }
.empty { font-family: var(--type); color: var(--muted); margin: 0; }

/* ---------- Quiz ---------- */
.quiz-head { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--type); text-transform: uppercase; letter-spacing: 2px; font-size: 14px; margin-bottom: 8px; }
.progress { height: 8px; background: var(--paper-dark); border: 2px solid var(--ink); margin-bottom: 18px; }
.progress > i { display: block; height: 100%; background: var(--olive); }

.timer { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.timer-num { flex: none; width: 58px; text-align: center; font-family: var(--stencil); font-size: 40px; line-height: 1; color: var(--olive-dark); }
.timer-track { flex: 1; height: 20px; background: var(--paper-dark); border: 3px solid var(--ink); }
.timer-fill { height: 100%; width: 100%; background: var(--olive); }
.timer.danger .timer-num { color: var(--red); animation: pulse .5s infinite alternate; }
.timer.danger .timer-fill { background: var(--red); }
@keyframes pulse { to { transform: scale(1.18); } }

.question { font-family: var(--serif); font-weight: bold; text-transform: none; letter-spacing: 0; font-size: 23px; line-height: 1.35; margin: 0 0 20px; min-height: 90px; color: var(--ink); }
.options { display: grid; gap: 12px; grid-template-columns: 1fr; }
.option {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; text-align: left; cursor: pointer;
  font: inherit; font-size: 18px; color: var(--ink); background: #fbf7e6;
  border: 3px solid var(--ink); border-radius: 3px; box-shadow: 0 3px 0 var(--ink);
  transition: background .12s, transform .08s;
}
.option .letter { flex: none; width: 34px; height: 34px; display: grid; place-items: center; font-family: var(--stencil); font-size: 20px; background: var(--olive); color: var(--paper); }
.option:hover:not([disabled]) { background: #f1e9c4; transform: translateY(-1px); }
.option[disabled] { cursor: default; }
.option.picked { border-color: var(--olive-dark); background: #dfe5c6; }
.option.right { background: #cfe5c4; border-color: var(--green); }
.option.right .letter { background: var(--green); }
.option.wrong { background: #f0cbc4; border-color: var(--red); }
.option.wrong .letter { background: var(--red); }
.feedback { min-height: 28px; margin: 16px 0 0; text-align: center; font-family: var(--stencil); font-size: 22px; letter-spacing: 2px; text-transform: uppercase; }
.feedback.right { color: var(--green); }
.feedback.wrong { color: var(--red); }
.kbd-hint { margin: 14px 0 0; text-align: center; font-family: var(--type); font-size: 12px; color: var(--muted); }

/* ---------- Risultato ---------- */
.result { text-align: center; }
.score { font-family: var(--stencil); font-size: 64px; letter-spacing: 3px; margin: 4px 0; line-height: 1.1; }
.verdict { font-family: var(--stencil); font-size: 44px; letter-spacing: 6px; text-transform: uppercase; margin: 8px 0 6px; }
.verdict.pass { color: var(--green); border: 6px double var(--green); display: inline-block; padding: 2px 22px; transform: rotate(-4deg); animation: stamp .45s ease-out; }
.verdict.fail { color: var(--red); }
@keyframes stamp { from { transform: rotate(-4deg) scale(2.2); opacity: 0; } to { transform: rotate(-4deg) scale(1); opacity: 1; } }

.skull { width: min(300px, 70vw); height: auto; margin: 6px auto 0; display: block; animation: skull-in .7s ease-out, shake 1.6s .7s ease-in-out 2; }
.skull .bo-out { fill: var(--ink); stroke: var(--ink); stroke-width: 8; stroke-linejoin: round; }
.skull .bo-in { fill: #efe6c8; }
.skull .cranium { fill: #f4ecd0; stroke: var(--ink); stroke-width: 5; stroke-linejoin: round; }
.skull .hole { fill: var(--ink); }
.skull .glow { fill: var(--red); opacity: .85; }
.skull .teeth rect { fill: #f4ecd0; stroke: var(--ink); stroke-width: 3; }
.skull .crack { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
@keyframes skull-in { from { transform: scale(.3) rotate(-20deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake { 0%,100% { transform: none; } 20% { transform: rotate(-4deg); } 40% { transform: rotate(4deg); } 60% { transform: rotate(-3deg); } 80% { transform: rotate(3deg); } }

@media (min-width: 700px) {
  .options { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .card { padding: 20px 16px 22px; }
  .tabs { margin: -20px -16px 18px; }
  .row2 { grid-template-columns: 1fr; }
  h1 { font-size: 28px; }
  .question { font-size: 19px; min-height: 0; }
  .brand-text { font-size: 17px; letter-spacing: 2px; white-space: nowrap; }
  .brand-text small { display: none; }
  .topbar { padding: 10px 12px; }
  .userbar { gap: 8px; min-width: 0; }
  #username { max-width: 18vw; min-width: 0; }
  .btn-small { padding: 4px 9px; font-size: 13px; }
  table.history { font-size: 12.5px; }
  table.history th, table.history td { padding: 8px 4px; }
  .badge { font-size: 11px; padding: 0 5px; }
  .quiz-head span:last-child { display: none; }
  .score { font-size: 52px; }
  .verdict { font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Pagina check.php ---------- */
table.chk { width: 100%; border-collapse: collapse; font-family: var(--type); font-size: 14px; }
table.chk td { padding: 6px 10px; border-bottom: 1px solid rgba(31,29,23,.25); text-align: left; }
.chk .ok { color: var(--green); font-weight: bold; }
.chk .ko { color: var(--red); font-weight: bold; }
.chk .warn { color: #8a6d00; font-weight: bold; }
.mt { margin-top: 18px; }
