:root {
  --ink: #14130f;
  --ink-2: #1c1b15;
  --panel: #211f18;
  --panel-2: #2a271e;
  --line: #3a362a;
  --cream: #f2ead9;
  --cream-dim: #b8b09a;
  --amber: #e8b04a;
  --amber-deep: #c8881f;
  --green: #7fb069;
  --red: #d96b5b;
  --radius: 14px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.7);
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-ui: 'Hanken Grotesk', system-ui, sans-serif;
  --font-read: 'Newsreader', Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  color: var(--cream);
  background:
    radial-gradient(1200px 800px at 80% -10%, rgba(232, 176, 74, 0.10), transparent 60%),
    radial-gradient(900px 700px at -10% 110%, rgba(127, 176, 105, 0.07), transparent 55%),
    var(--ink);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* grana sottile sopra tutto */
.grain {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* motivo a mattoni decorativo */
.brick-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.05;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 88px 30px;
  -webkit-mask-image: radial-gradient(circle at 50% 35%, black, transparent 80%);
  mask-image: radial-gradient(circle at 50% 35%, black, transparent 80%);
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

a { color: var(--amber); }

/* ---------- layout ---------- */
.wrap {
  position: relative; z-index: 1; max-width: 1080px; margin: 0 auto;
  padding: 0 20px;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 0; border-bottom: 1px solid var(--line); margin-bottom: 32px;
  flex-wrap: wrap; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
  width: 40px; height: 40px; border-radius: 11px;
  background: linear-gradient(150deg, var(--amber), var(--amber-deep));
  display: grid; place-items: center; color: #19160d; font-weight: 800;
  box-shadow: 0 6px 18px -6px rgba(232, 176, 74, 0.6);
}
.brand h1 {
  font-family: var(--font-display); font-weight: 800; font-size: 21px;
  letter-spacing: -0.02em;
}
.brand h1 span { color: var(--amber); }
.brand small { display: block; color: var(--cream-dim); font-weight: 500; font-size: 12px; letter-spacing: 0.02em; }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.badge {
  font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.badge.free { background: #322d20; color: var(--cream-dim); border: 1px solid var(--line); }
.badge.premium { background: linear-gradient(120deg, var(--amber), var(--amber-deep)); color: #1a1509; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--cream);
  padding: 11px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
  transition: transform 0.12s ease, background 0.18s ease, border-color 0.18s ease;
}
.btn:hover { transform: translateY(-1px); border-color: var(--amber); }
.btn.primary {
  background: linear-gradient(120deg, var(--amber), var(--amber-deep));
  color: #1a1509; border: none; box-shadow: 0 10px 24px -10px rgba(232, 176, 74, 0.7);
}
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #4a322c; background: transparent; }
.btn.danger:hover { border-color: var(--red); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.block { width: 100%; justify-content: center; }

/* ---------- auth ---------- */
.auth-shell { min-height: 90vh; display: grid; place-items: center; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px; padding: 38px 34px;
  box-shadow: var(--shadow);
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.auth-card .lead { font-family: var(--font-display); font-size: 28px; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 6px; }
.auth-card p.sub { color: var(--cream-dim); margin-bottom: 26px; font-size: 14px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--cream-dim); margin-bottom: 7px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--ink-2); border: 1px solid var(--line);
  color: var(--cream); padding: 12px 14px; border-radius: 10px; font-size: 15px;
  transition: border-color 0.15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--amber); }
.field textarea { resize: vertical; min-height: 80px; }

.switch { text-align: center; margin-top: 18px; font-size: 14px; color: var(--cream-dim); }
.switch button { background: none; border: none; color: var(--amber); font-weight: 700; font-size: 14px; }

.error-msg {
  background: #3a241f; border: 1px solid #5a352c; color: #f0c4b8;
  padding: 10px 13px; border-radius: 9px; font-size: 14px; margin-bottom: 16px;
}

/* ---------- stats strip ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 30px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px;
}
.stat .num { font-family: var(--font-display); font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.stat .lbl { color: var(--cream-dim); font-size: 13px; margin-top: 2px; }
.stat.accent .num { color: var(--amber); }

/* ---------- section head ---------- */
.sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sec-head h2 { font-family: var(--font-display); font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }

/* ---------- content cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; position: relative; overflow: hidden;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
}
.card.locked::before { background: linear-gradient(var(--amber), var(--amber-deep)); }
.card.open::before { background: var(--green); }

.card .card-top { display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.card h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; padding-left: 4px; }
.lock-ico { font-size: 18px; }

.meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 14px; padding-left: 4px; }
.tag {
  font-size: 11.5px; font-weight: 600; padding: 4px 9px; border-radius: 7px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--cream-dim);
  letter-spacing: 0.02em;
}
.tag.diff-facile { color: var(--green); }
.tag.diff-medio { color: var(--amber); }
.tag.diff-massimo { color: var(--red); }

.locked-note { padding-left: 4px; color: var(--cream-dim); font-size: 14px; margin-bottom: 16px; }
.reveal {
  padding-left: 4px; font-size: 15px; color: var(--cream);
  background: var(--ink-2); border: 1px dashed var(--line); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 14px; word-break: break-word; white-space: pre-wrap;
}
.reveal a { word-break: break-all; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; padding-left: 4px; }
.timer { font-size: 12.5px; color: var(--green); font-weight: 600; }

/* empty state */
.empty {
  text-align: center; padding: 50px 20px; color: var(--cream-dim);
  border: 1px dashed var(--line); border-radius: var(--radius); background: var(--panel);
}
.empty .big { font-size: 40px; margin-bottom: 10px; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 1000; background: rgba(8, 8, 6, 0.78);
  backdrop-filter: blur(6px); display: grid; place-items: center; padding: 20px;
  animation: fade 0.25s ease both;
}
.modal {
  width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 30px; box-shadow: var(--shadow);
  animation: rise 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.modal h2 { font-family: var(--font-display); font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }
.modal .modal-sub { color: var(--cream-dim); font-size: 14px; margin-bottom: 22px; }
.modal-close { float: right; background: none; border: none; color: var(--cream-dim); font-size: 26px; line-height: 1; }

/* reading passage */
.passage {
  font-family: var(--font-read); font-size: 18px; line-height: 1.7;
  background: var(--ink-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px 24px; margin-bottom: 24px;
}
.passage h4 { font-family: var(--font-display); font-size: 18px; margin-bottom: 10px; color: var(--amber); }

/* questions */
.question { margin-bottom: 22px; }
.question .q-text { font-weight: 600; font-size: 16px; margin-bottom: 12px; }
.opts { display: grid; gap: 9px; }
.opt {
  display: flex; align-items: center; gap: 11px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--ink-2);
  cursor: pointer; transition: border-color 0.14s ease, background 0.14s ease;
  font-size: 15px;
}
.opt:hover { border-color: var(--amber); }
.opt.sel { border-color: var(--amber); background: rgba(232, 176, 74, 0.1); }
.opt.correct { border-color: var(--green); background: rgba(127, 176, 105, 0.14); }
.opt.wrong { border-color: var(--red); background: rgba(217, 107, 91, 0.14); }
.opt .dot {
  width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line);
  flex-shrink: 0; display: grid; place-items: center;
}
.opt.sel .dot { border-color: var(--amber); }
.opt.sel .dot::after { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }

/* result banner */
.result {
  text-align: center; padding: 16px; border-radius: 12px; margin-bottom: 20px; font-weight: 600;
}
.result.pass { background: rgba(127, 176, 105, 0.15); border: 1px solid var(--green); color: var(--green); }
.result.fail { background: rgba(217, 107, 91, 0.13); border: 1px solid var(--red); color: var(--red); }
.result .score { font-family: var(--font-display); font-size: 32px; font-weight: 800; display: block; }

/* upgrade modal */
.price-card { text-align: center; }
.price-card .price { font-family: var(--font-display); font-size: 46px; font-weight: 800; letter-spacing: -0.03em; }
.price-card .price span { font-size: 16px; color: var(--cream-dim); font-weight: 500; }
.perks { list-style: none; text-align: left; margin: 22px auto; max-width: 320px; display: grid; gap: 11px; }
.perks li { display: flex; gap: 10px; font-size: 15px; }
.perks li::before { content: '✦'; color: var(--amber); }

footer {
  text-align: center; color: var(--cream-dim); font-size: 13px;
  padding: 40px 0 30px; margin-top: 40px; border-top: 1px solid var(--line);
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--amber); color: var(--cream);
  padding: 13px 20px; border-radius: 11px; z-index: 2000; box-shadow: var(--shadow);
  font-weight: 600; font-size: 14px; animation: rise 0.3s ease both;
}

.spinner {
  width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.3);
  border-top-color: var(--cream); border-radius: 50%; display: inline-block;
  animation: spin 0.7s linear infinite; vertical-align: -3px;
}

@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr; }
  .auth-card { padding: 30px 24px; }
}
