:root {
  --bg: #070b1d;
  --panel: #0f1630;
  --panel-2: #141d3d;
  --line: #24305a;
  --text: #e7ecff;
  --muted: #9aa6cf;
  --accent: #8ab4ff;
  --gold: #ffcf6b;
  --ok: #5fd39a;
  --warn: #ffb35c;
  --bad: #ff7a85;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(ellipse at 20% -10%, #1b2a66 0%, transparent 55%),
              radial-gradient(ellipse at 110% 30%, #3a1d5c 0%, transparent 45%), var(--bg);
  color: var(--text); font-family: var(--font); line-height: 1.6; min-height: 100vh;
  display: flex; flex-direction: column;
}
.stars {
  position: fixed; inset: 0; pointer-events: none; z-index: -1; opacity: .7;
  background-image:
    radial-gradient(1px 1px at 10% 20%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 70%, #cfe 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 55% 35%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 75% 80%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 15%, #ffd 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 45% 90%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 65% 55%, #def 50%, transparent 51%);
  background-size: 420px 420px;
}
a { color: var(--accent); }
a:hover { color: #b9d1ff; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .9rem clamp(1rem, 4vw, 2.5rem); border-bottom: 1px solid var(--line);
  background: rgba(7, 11, 29, .75); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 10;
}
.brand { color: var(--text); text-decoration: none; white-space: nowrap; font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }
.logo { color: var(--gold); }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar nav > a { color: var(--muted); text-decoration: none; font-size: .95rem; }
.topbar nav > a:hover { color: var(--text); }
.lang { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang button { background: none; border: 0; color: var(--muted); padding: .3rem .7rem; cursor: pointer; font-weight: 600; font: inherit; font-size: .85rem; }
.lang button.active { background: var(--accent); color: #0b1026; }

main { flex: 1; width: 100%; max-width: 960px; margin: 0 auto; padding: clamp(1.2rem, 4vw, 2.5rem) clamp(1rem, 4vw, 2rem) 3rem; outline: none; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem 1rem; border-top: 1px solid var(--line); }

h1 { font-size: clamp(1.8rem, 5vw, 2.8rem); line-height: 1.15; margin: .2em 0 .4em; }
h2 { font-size: 1.45rem; margin: 1.6em 0 .5em; }
h3 { font-size: 1.1rem; margin: 1.2em 0 .4em; }
.lead { color: var(--muted); font-size: 1.1rem; max-width: 60ch; }
.eyebrow { color: var(--gold); text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--accent); background: var(--accent); color: #0b1026;
  padding: .7rem 1.2rem; border-radius: 999px; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.1); color: #0b1026; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.ghost:hover { background: rgba(138, 180, 255, .1); color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.row { display: flex; flex-wrap: wrap; gap: .7rem; align-items: center; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.3rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.feature h3 { margin-top: 0; }
.feature p { color: var(--muted); margin: 0; }

/* Quiz */
.progress { height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin: .6rem 0 1.4rem; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width .3s; }
.qmeta { display: flex; justify-content: space-between; color: var(--muted); font-size: .9rem; }
.question { font-size: 1.3rem; font-weight: 600; margin: .3rem 0 1rem; }
.options { display: grid; gap: .6rem; }
.option {
  text-align: left; background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 12px;
  padding: .85rem 1rem; font: inherit; cursor: pointer; display: flex; gap: .7rem; align-items: flex-start;
}
.option:hover { border-color: var(--accent); }
.option.selected { border-color: var(--accent); background: #1a2654; }
.option .letter { flex: none; width: 1.7rem; height: 1.7rem; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); font-weight: 700; font-size: .85rem; }
.option.selected .letter { background: var(--accent); color: #0b1026; }
.option.idk { color: var(--muted); font-style: italic; }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); display: inline-block; }
.dots i.on { background: var(--gold); }

/* Risultati */
.big-level { font-size: 3.2rem; font-weight: 800; color: var(--gold); line-height: 1; }
.bars { display: grid; gap: .7rem; }
.bar-label { display: flex; justify-content: space-between; font-size: .92rem; }
.bar { height: 10px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.review-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .6rem; }
.review-list li { border-left: 3px solid var(--line); padding: .3rem 0 .3rem .9rem; }
.review-list li.ok { border-color: var(--ok); }
.review-list li.no { border-color: var(--bad); }
.review-list .ans { color: var(--muted); font-size: .9rem; }

/* Corso */
.level-head { display: flex; align-items: baseline; gap: .8rem; margin-top: 2rem; flex-wrap: wrap; }
.level-head h2 { margin: 0; }
.level-num { font-family: var(--mono); color: var(--gold); font-weight: 700; }
.level-desc { color: var(--muted); margin: .2rem 0 .9rem; }
.modules { display: grid; gap: .8rem; }
.module-card { display: grid; grid-template-columns: auto 1fr auto; gap: 1rem; align-items: center; text-decoration: none; color: var(--text); }
.module-card:hover { border-color: var(--accent); color: var(--text); }
.module-card.dim { opacity: .65; }
.module-card .check { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: .9rem; }
.module-card .check.done { background: var(--ok); border-color: var(--ok); color: #0b1026; }
.module-card h3 { margin: 0 0 .15rem; }
.module-card p { margin: 0; color: var(--muted); font-size: .92rem; }
.module-card .meta { text-align: right; font-size: .82rem; color: var(--muted); white-space: nowrap; }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: .3rem; }
.badge.core { background: rgba(138, 180, 255, .15); color: var(--accent); }
.badge.review { background: rgba(255, 179, 92, .15); color: var(--warn); }
.badge.mastered { background: rgba(95, 211, 154, .15); color: var(--ok); }
.badge.next { background: var(--gold); color: #0b1026; }

/* Modulo */
.lesson { margin-top: 1.2rem; }
.lesson h3 { margin-top: 0; }
.lesson p { margin: .6em 0; }
.formula {
  font-family: var(--mono); background: #0a1028; border: 1px solid var(--line); border-left: 3px solid var(--gold);
  padding: .65rem .9rem; border-radius: 8px; overflow-x: auto; white-space: pre; font-size: .95rem; margin: .8rem 0;
}
/* Riquadri nelle lezioni */
.lesson p { line-height: 1.75; }
.lesson-list { margin: .6em 0; padding-left: 1.3rem; line-height: 1.7; }
.lesson-list li { margin: .3em 0; }
.lesson-sub { margin: 1.4rem 0 .3rem; font-size: 1rem; color: var(--gold); }
.box { display: flex; gap: .75rem; padding: .85rem 1rem; border-radius: 10px; margin: 1rem 0; }
.box p { margin: 0; }
.box-ico { flex: none; width: 1.7rem; height: 1.7rem; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .9rem; }
.box.example { background: rgba(138, 180, 255, .08); border: 1px solid rgba(138, 180, 255, .35); }
.box.example .box-ico { background: var(--accent); color: #0b1026; }
.box.note { background: rgba(255, 179, 92, .08); border: 1px solid rgba(255, 179, 92, .35); }
.box.note .box-ico { background: var(--warn); color: #0b1026; }
.keypoints { background: var(--panel-2); border-radius: 10px; padding: .7rem 1rem; margin-top: .8rem; }
.keypoints strong { color: var(--gold); font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; }
.keypoints ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.res-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; }
.res-list a { display: flex; gap: .6rem; align-items: center; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--text); background: var(--panel); }
.res-list a:hover { border-color: var(--accent); }
.res-list .ico { flex: none; width: 2rem; height: 2rem; border-radius: 8px; display: grid; place-items: center; font-size: .9rem; }
.ico.yt { background: #ff3b3b; color: #fff; }
.ico.doc { background: var(--panel-2); color: var(--accent); }
.res-list small { color: var(--muted); display: block; }
details { margin-top: .8rem; }
summary { cursor: pointer; color: var(--accent); }
.feedback { margin-top: .7rem; font-weight: 600; }
.feedback.ok { color: var(--ok); }
.feedback.no { color: var(--bad); }
.nav-modules { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; }
.back { color: var(--muted); text-decoration: none; font-size: .9rem; }
.back:hover { color: var(--text); }
.notice { border-left: 3px solid var(--accent); padding: .6rem 1rem; background: var(--panel); border-radius: 0 10px 10px 0; color: var(--muted); }

/* Account */
.logout-top { background: none; border: 1px solid var(--line); color: var(--muted); font: inherit; font-size: .9rem; padding: .25rem .8rem; border-radius: 999px; cursor: pointer; white-space: nowrap; }
.logout-top:hover { color: var(--text); border-color: var(--bad); }
.logout-top[hidden] { display: none; }
.topbar nav > a.account { white-space: nowrap; color: var(--text); border: 1px solid var(--line); padding: .25rem .8rem; border-radius: 999px; }
.topbar nav > a.account:hover { border-color: var(--accent); }
.auth { max-width: 420px; margin: 0 auto; }
.tabs { display: flex; gap: .3rem; background: var(--panel-2); border-radius: 999px; padding: .25rem; margin-bottom: 1.2rem; }
.tabs button { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; padding: .5rem; border-radius: 999px; cursor: pointer; }
.tabs button.active { background: var(--accent); color: #0b1026; }
.field { display: grid; gap: .3rem; margin-bottom: 1rem; }
.field label { font-size: .9rem; color: var(--muted); }
.field input { background: #0a1028; border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: .7rem .8rem; font: inherit; }
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.hint { font-size: .8rem; color: var(--muted); }
.error { color: var(--bad); font-weight: 600; min-height: 1.4em; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .8rem; }
.stat .n { font-size: 2rem; font-weight: 800; color: var(--gold); line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .85rem; }
table.history { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.history th, table.history td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); }
table.history th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.saved { color: var(--ok); font-size: .85rem; }

/* Tutor */
.tutor-btn { position: fixed; right: 1rem; bottom: 1rem; z-index: 20; border: 0; border-radius: 999px; padding: .75rem 1.1rem; background: var(--gold); color: #0b1026; font: inherit; font-weight: 700; cursor: pointer; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.tutor-btn:hover { filter: brightness(1.05); }
.tutor-btn[hidden], .tutor[hidden] { display: none; }
.tutor { position: fixed; right: 1rem; bottom: 1rem; z-index: 30; width: min(420px, calc(100vw - 2rem)); height: min(600px, calc(100vh - 6rem)); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.55); }
.tutor-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.tutor-close { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; }
.tutor-close:hover { color: var(--text); }
.tutor-log { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .7rem; }
.msg { max-width: 88%; padding: .6rem .85rem; border-radius: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #0b1026; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 4px; }
.msg.assistant ul { margin: .3rem 0; padding-left: 1.1rem; }
.msg.note { align-self: center; background: none; color: var(--muted); font-size: .85rem; text-align: center; }
.msg.err { align-self: center; color: var(--bad); font-size: .9rem; text-align: center; }
.typing { color: var(--muted); font-style: italic; }
.tutor-form { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--line); }
.tutor-form textarea { flex: 1; resize: none; background: #0a1028; border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: .55rem .7rem; font: inherit; }
.tutor-form textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.tutor-form .btn { padding: .5rem .9rem; }
.tutor-info { margin: 0; padding: 0 .9rem .7rem; font-size: .75rem; color: var(--muted); }

@media (max-width: 600px) {
  .tutor { right: 0; bottom: 0; width: 100vw; height: 85vh; border-radius: var(--radius) var(--radius) 0 0; }
  .tutor-btn span { display: none; }
  .topbar { padding: .7rem .75rem; gap: .5rem; }
  .topbar nav { gap: .4rem; }
  .brand { font-size: 1rem; }
  .topbar nav > a.account, .logout-top { padding: .2rem .55rem; font-size: .82rem; }
  .lang button { padding: .25rem .5rem; }
  .module-card { grid-template-columns: auto 1fr; }
  .module-card .meta { grid-column: 2; text-align: left; }
  .topbar nav > a:not(.account) { display: none; }
}
@media (max-width: 400px) { .brand-text { display: none; } .brand { font-size: 1.4rem; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
