/* ═══════════ LINUX DOJO — tema scuro neon ═══════════ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0b0e1a;
  --bg2: #131830;
  --card: #1a2040;
  --accent: #7c5cff;
  --accent2: #00e5a0;
  --danger: #ff4d6d;
  --gold: #ffc83d;
  --text: #eef0ff;
  --muted: #8a90b8;
  --radius: 22px;
}

html, body { height: 100%; overscroll-behavior: none; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.hidden { display: none !important; }

.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  overflow-y: auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

/* ═══════════ HOME ═══════════ */
#home { padding: 20px 18px 30px; background: radial-gradient(ellipse at top, #1a1f45 0%, var(--bg) 60%); }

.home-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.logo { font-size: 1.5rem; font-weight: 900; letter-spacing: 1px; }
.logo span { background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.streak-pill {
  background: var(--card); border: 1px solid #2a3160;
  padding: 8px 14px; border-radius: 999px; font-weight: 800; font-size: 1rem;
}
.streak-pill.hot { border-color: var(--gold); box-shadow: 0 0 18px rgba(255, 200, 61, .35); }

.level-card {
  display: flex; align-items: center; gap: 16px;
  background: linear-gradient(135deg, var(--card), #232a55);
  border: 1px solid #2a3160; border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.level-emoji { font-size: 3rem; }
.level-info { flex: 1; }
.level-name { font-weight: 800; font-size: 1.1rem; margin-bottom: 8px; }
.xp-bar { height: 10px; background: #0d1129; border-radius: 999px; overflow: hidden; }
.xp-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 999px; transition: width .6s cubic-bezier(.2, .9, .3, 1.3);
}
.xp-text { font-size: .8rem; color: var(--muted); margin-top: 6px; font-weight: 600; }

.daily-msg {
  background: rgba(124, 92, 255, .12); border: 1px dashed #4a3f9f;
  border-radius: 14px; padding: 12px 14px; font-size: .9rem;
  color: #c9c2ff; margin-bottom: 22px;
}

.section-title { font-size: 1.05rem; margin-bottom: 12px; color: var(--muted); font-weight: 700; }

.module-list { display: flex; flex-direction: column; gap: 12px; }

.module-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid #262d58;
  border-radius: var(--radius); padding: 16px;
  cursor: pointer; transition: transform .15s, border-color .15s;
  user-select: none;
}
.module-card:active { transform: scale(.97); }
.module-card.done { border-color: var(--accent2); }
.module-card.locked { opacity: .45; }
.module-icon { font-size: 2rem; width: 48px; text-align: center; }
.module-meta { flex: 1; min-width: 0; }
.module-title { font-weight: 800; font-size: 1rem; margin-bottom: 4px; }
.module-sub { font-size: .78rem; color: var(--muted); }
.module-progress { height: 6px; background: #0d1129; border-radius: 999px; margin-top: 8px; overflow: hidden; }
.module-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; }
.module-badge { font-size: 1.3rem; }

/* ═══════════ Ricerca globale ═══════════ */
.search-wrap { position: relative; margin-bottom: 14px; }
.search-input {
  width: 100%; background: var(--bg2); border: 1px solid #2a3160;
  border-radius: 14px; padding: 11px 14px 11px 40px;
  color: var(--text); font-size: .92rem; outline: none;
  transition: border-color .2s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--muted); }
body.light-theme .search-input { background: #fff; border-color: #c8ccee; }
.search-icon {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: .95rem; pointer-events: none;
}
.search-results { margin-bottom: 8px; }
.search-result {
  display: flex; flex-direction: column; gap: 2px;
  background: var(--bg2); border: 1px solid #2a3160; border-radius: 12px;
  padding: 10px 13px; margin-bottom: 6px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.search-result:hover, .search-result:active { border-color: var(--accent); background: rgba(124,92,255,.08); }
body.light-theme .search-result { background: #fff; border-color: #c8ccee; }
.sr-mod { font-size: .7rem; color: var(--muted); }
.sr-title { font-size: .88rem; font-weight: 700; }
.sr-type { display: inline-block; font-size: .65rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  border-radius: 5px; padding: 1px 6px; background: rgba(124,92,255,.15); color: var(--accent); margin-top: 2px; }
.sr-type.quiz { background: rgba(255,77,109,.12); color: var(--danger); }
.sr-type.input { background: rgba(0,229,160,.12); color: var(--accent2); }
.sr-type.mission { background: rgba(255,200,61,.15); color: var(--gold); }
.search-empty { color: var(--muted); font-size: .88rem; padding: 10px 0; text-align: center; }

/* ═══════════ Quiz drill mode ═══════════ */
.drill-kicker { color: var(--danger) !important; }
.drill-finale-tip {
  margin-top: 1rem; padding: 10px 14px;
  background: rgba(255,77,109,.07); border: 1px dashed rgba(255,77,109,.3);
  border-radius: 12px; font-size: .85rem; color: var(--danger);
}

.home-footer { text-align: center; color: #3d4470; font-size: .75rem; margin-top: 34px; }

/* mazzo ripasso errori (CP4) */
.review-deck { border-color: var(--gold) !important; background: linear-gradient(135deg, #2a2000, var(--card)) !important; }
.review-count { background: var(--gold); color: #1a1000; font-size: .82rem; font-weight: 900; padding: 4px 11px; border-radius: 999px; }
.review-ok-msg { margin-top: 10px; color: var(--accent2); font-weight: 800; font-size: .95rem; animation: slideUp .3s ease; }

/* ═══════════ FEED ═══════════ */
#feed { background: var(--bg); }

.feed-topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(to bottom, rgba(11, 14, 26, .95), transparent);
}
.btn-icon {
  background: rgba(255, 255, 255, .08); border: none; color: var(--text);
  width: 38px; height: 38px; border-radius: 50%; font-size: 1.1rem;
  cursor: pointer; flex-shrink: 0;
}
.feed-progress { flex: 1; height: 7px; background: rgba(255, 255, 255, .1); border-radius: 999px; overflow: hidden; }
.feed-progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; transition: width .3s; }
.feed-xp { font-weight: 800; font-size: .95rem; color: var(--gold); flex-shrink: 0; }

.cards {
  height: 100%; overflow-y: scroll;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
}
.cards::-webkit-scrollbar { display: none; }

.card {
  min-height: 100%; height: auto;
  scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; flex-direction: column; justify-content: center;
  padding: 80px 24px 60px;
  position: relative;
}

.card-emoji { font-size: 3.4rem; margin-bottom: 18px; animation: pop .5s cubic-bezier(.2, .9, .3, 1.4); }
.card-kicker { font-size: .75rem; font-weight: 800; letter-spacing: 2px; text-transform: uppercase; color: var(--accent2); margin-bottom: 10px; }
.card-title { font-size: 1.7rem; font-weight: 900; line-height: 1.2; margin-bottom: 16px; }
.card-text { font-size: 1.08rem; line-height: 1.65; color: #d6d9f5; }
.card-text strong { color: var(--accent2); }
.card-text code {
  background: #0d1129; padding: 2px 8px; border-radius: 8px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: .92em; color: var(--gold);
}
.analogy {
  margin-top: 18px; background: rgba(0, 229, 160, .08);
  border-left: 4px solid var(--accent2); border-radius: 0 14px 14px 0;
  padding: 14px 16px; font-size: .98rem; line-height: 1.55; color: #c4f5e4;
}
.analogy::before { content: "🐒 Per la scimmia: "; font-weight: 800; color: var(--accent2); }

/* card RIPASSO LAMPO (recap dinamico alla riapertura del modulo) */
.card.recap { background: radial-gradient(circle at 70% 12%, #142a4a 0%, var(--bg) 70%); }
.recap-list { margin-top: 18px; display: flex; flex-direction: column; gap: 8px; }
.recap-item {
  display: flex; align-items: center; gap: 10px;
  background: rgba(124, 92, 255, .10); border-left: 4px solid var(--accent);
  border-radius: 0 12px 12px 0; padding: 10px 14px;
  font-size: 1rem; font-weight: 600; color: #e6e8ff;
}
.recap-item .recap-ico { font-size: 1.2rem; flex-shrink: 0; }
.recap-more { font-size: .9rem; color: var(--muted); padding: 4px 4px 0; font-style: italic; }
.recap-btn { margin-top: 22px; }
body.light-theme .recap-item { background: rgba(124, 92, 255, .08); color: #2a2d52; }

/* card tipo FACT */
.card.fact { background: radial-gradient(circle at 30% 20%, #2b1f5e 0%, var(--bg) 70%); }
.fact-label { display: inline-block; background: var(--gold); color: #1a1400; font-weight: 900; font-size: .72rem; letter-spacing: 1.5px; padding: 5px 12px; border-radius: 999px; margin-bottom: 16px; }

/* card tipo TERMINAL */
.terminal {
  background: #0a0d18; border: 1px solid #232a55; border-radius: 16px;
  overflow: hidden; margin-top: 18px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.terminal-bar { background: #161b33; padding: 9px 14px; display: flex; gap: 7px; align-items: center; }
.dot { width: 11px; height: 11px; border-radius: 50%; }
.dot.r { background: #ff5f57; } .dot.y { background: #ffbd2e; } .dot.g { background: #28c840; }
.terminal-title { margin-left: 8px; font-size: .72rem; color: var(--muted); }
.terminal-body { padding: 16px; font-size: .88rem; line-height: 1.6; }
.term-cmd { color: var(--accent2); word-break: break-all; }
.term-cmd::before { content: "$ "; color: var(--accent); font-weight: 700; }
.term-out { color: #aab0d8; white-space: pre-wrap; word-break: break-all; margin-top: 8px; }
.term-reveal {
  margin-top: 12px; width: 100%;
  background: linear-gradient(90deg, var(--accent), #5a3fd6); color: #fff;
  border: none; border-radius: 12px; padding: 13px; font-size: .95rem; font-weight: 800;
  cursor: pointer; transition: transform .1s;
}
.term-reveal:active { transform: scale(.96); }

/* card tipo QUIZ */
.quiz-options { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.quiz-opt {
  background: var(--card); border: 2px solid #2a3160; color: var(--text);
  border-radius: 16px; padding: 15px 16px; font-size: .98rem; font-weight: 600;
  text-align: left; cursor: pointer; transition: transform .12s, border-color .15s;
  line-height: 1.4;
}
.quiz-opt:active { transform: scale(.97); }
.quiz-opt.correct { border-color: var(--accent2); background: rgba(0, 229, 160, .15); animation: pop .4s; }
.quiz-opt.wrong { border-color: var(--danger); background: rgba(255, 77, 109, .15); animation: shake .4s; }
.quiz-opt:disabled { cursor: default; }
.quiz-explain {
  margin-top: 16px; background: var(--bg2); border: 1px solid #2a3160;
  border-radius: 14px; padding: 14px 16px; font-size: .92rem; line-height: 1.55;
  color: #c9cdf0; animation: slideUp .35s ease;
}
.quiz-explain strong { color: var(--accent2); }
.quiz-result { font-weight: 900; font-size: 1.15rem; margin-top: 16px; animation: pop .4s; }
.quiz-result.ok { color: var(--accent2); }
.quiz-result.ko { color: var(--danger); }

/* card tipo INPUT (risposta scritta) */
.input-label { display: inline-block; background: var(--accent); color: #fff; font-weight: 900; font-size: .72rem; letter-spacing: 1.5px; padding: 5px 12px; border-radius: 999px; margin-bottom: 16px; }
.input-row { display: flex; gap: 10px; margin-top: 20px; }
.quiz-input {
  flex: 1; min-width: 0;
  background: #0d1129; border: 2px solid #2a3160; color: var(--gold);
  border-radius: 16px; padding: 15px 16px; font-size: 1rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  outline: none; transition: border-color .15s;
}
.quiz-input:focus { border-color: var(--accent); }
.quiz-input::placeholder { color: #4a517e; font-family: inherit; }
.quiz-input.correct { border-color: var(--accent2); background: rgba(0, 229, 160, .12); animation: pop .4s; }
.quiz-input.wrong { border-color: var(--danger); background: rgba(255, 77, 109, .12); animation: shake .4s; }
.btn-check {
  background: linear-gradient(90deg, var(--accent), #5a3fd6); color: #fff;
  border: none; border-radius: 16px; padding: 0 22px; font-size: 1.2rem; font-weight: 900;
  cursor: pointer; transition: transform .1s; flex-shrink: 0;
}
.btn-check:active { transform: scale(.94); }
.btn-check:disabled { opacity: .4; cursor: default; }
.input-answer {
  margin-top: 14px; font-size: 1rem; color: #d6d9f5; animation: slideUp .35s ease;
}
.input-answer code {
  background: #0d1129; padding: 4px 10px; border-radius: 8px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace; color: var(--accent2); font-weight: 700;
}

/* card tipo MISSION */
.card.mission { background: radial-gradient(circle at 30% 20%, #1f3828 0%, var(--bg) 70%); }
.mission-label { display: inline-block; background: linear-gradient(90deg, #ff9800, #ff6f00); color: #1a0800; font-weight: 900; font-size: .72rem; letter-spacing: 1.5px; padding: 5px 12px; border-radius: 999px; margin-bottom: 16px; }
.mission-zone { margin-top: 24px; display: flex; flex-direction: column; gap: 12px; }
.mission-solution { background: #0a0d18; border: 1px solid #232a55; border-radius: 14px; padding: 16px; font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: .86rem; color: var(--accent2); white-space: pre; word-break: break-all; overflow-x: auto; animation: slideUp .3s ease; }
.btn-solution { background: rgba(255,255,255,.07); border: 1px solid #3a4070; color: var(--text); border-radius: 14px; padding: 13px 20px; font-size: .95rem; font-weight: 700; cursor: pointer; transition: transform .1s, background .15s; text-align: center; }
.btn-solution:active { transform: scale(.97); background: rgba(255,255,255,.12); }
.btn-done { background: linear-gradient(90deg, #00c853, #00e676); color: #001a00; border: none; border-radius: 14px; padding: 16px 20px; font-size: 1rem; font-weight: 900; cursor: pointer; transition: transform .1s; }
.btn-done:active { transform: scale(.96); }
.btn-done:disabled { opacity: .5; cursor: default; transform: none; }
.btn-done.done { background: rgba(0,229,160,.15); color: var(--accent2); border: 1px solid var(--accent2); }

/* card finale modulo */
.card.finale { text-align: center; background: radial-gradient(circle at 50% 30%, #1f4536 0%, var(--bg) 75%); }
.finale .card-emoji { font-size: 5rem; }
.btn-big {
  margin-top: 26px; background: linear-gradient(90deg, var(--accent2), #00b380);
  color: #00261a; border: none; border-radius: 16px; padding: 17px 30px;
  font-size: 1.05rem; font-weight: 900; cursor: pointer;
}
.btn-big:active { transform: scale(.96); }

.swipe-hint {
  position: fixed; bottom: calc(18px + env(safe-area-inset-bottom)); left: 0; right: 0;
  text-align: center; font-size: .8rem; color: var(--muted);
  animation: bounce 1.8s infinite; pointer-events: none; z-index: 15;
}

/* ═══════════ Toast / Confetti ═══════════ */
.toast {
  position: fixed; top: calc(70px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%); z-index: 50;
  background: var(--gold); color: #1a1400; font-weight: 900;
  padding: 10px 22px; border-radius: 999px; font-size: 1rem;
  box-shadow: 0 8px 30px rgba(255, 200, 61, .4);
  animation: toastIn .3s ease, toastOut .3s ease 1.4s forwards;
  pointer-events: none;
}

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 100; }

/* ═══════════ Simulatore Esame (CP10) ═══════════ */
.exam-card { border-color: var(--gold) !important; background: linear-gradient(135deg, #2a2000, var(--card)) !important; }
.exam-kicker { color: var(--gold); }
.exam-timer-warn { color: var(--danger) !important; animation: pulse .8s infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: .5; } }

.card.exam-finale { background: radial-gradient(circle at 50% 30%, #1a1200 0%, var(--bg) 75%); }

.exam-score {
  font-size: 4.5rem; font-weight: 900; letter-spacing: -3px;
  line-height: 1; margin: .5rem 0;
  animation: pop .6s cubic-bezier(.2, .9, .3, 1.4);
}
.exam-score.pass { color: var(--accent2); text-shadow: 0 0 40px rgba(0,229,160,.5); }
.exam-score.fail { color: var(--danger); text-shadow: 0 0 40px rgba(255,77,109,.4); }
.exam-score-label { font-size: 1.1rem; font-weight: 800; margin-bottom: 1rem; }

.exam-stats {
  text-align: left; background: var(--bg2); border: 1px solid #2a3160;
  border-radius: 14px; padding: 14px 16px; margin: 1rem 0;
  font-size: .92rem; line-height: 1.9;
}
.exam-stats strong { color: var(--accent2); }

.exam-bar-wrap { margin: 1rem 0; }
.exam-bar {
  position: relative; height: 14px;
  background: #1e2340; border-radius: 999px; overflow: visible;
}
.exam-bar-fill {
  height: 100%; border-radius: 999px;
  transition: width 1.2s cubic-bezier(.2, .9, .3, 1);
}
.exam-bar-fill.pass { background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.exam-bar-fill.fail { background: linear-gradient(90deg, var(--danger), #ff9800); }
.exam-bar-threshold {
  position: absolute;
  left: 50%; top: -5px; /* (500-200)/(800-200) = 50% */
  width: 3px; height: 24px;
  background: var(--gold);
  border-radius: 2px;
  transform: translateX(-50%);
}
.exam-bar-labels {
  display: flex; justify-content: space-between;
  font-size: .75rem; color: var(--muted); margin-top: .4rem;
}

.exam-tip {
  margin-top: 1rem; padding: 12px 14px;
  background: rgba(124,92,255,.1); border: 1px dashed #4a3f9f;
  border-radius: 14px; font-size: .88rem; color: #c9c2ff;
}
.exam-loading { color: var(--muted); font-size: 1rem; padding: 1rem 0; }

/* ═══════════ Animazioni ═══════════ */
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
@keyframes toastIn { from { transform: translate(-50%, -18px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes toastOut { to { transform: translate(-50%, -18px); opacity: 0; } }

/* ═══════════ Light theme ═══════════ */
body.light-theme {
  --bg: #f4f6ff;
  --bg2: #eaecf8;
  --card: #ffffff;
  --text: #1a1d3a;
  --muted: #636888;
}
body.light-theme #home { background: radial-gradient(ellipse at top, #dfe3ff 0%, var(--bg) 60%); }
body.light-theme .level-card { background: linear-gradient(135deg, #fff, #eef0ff); border-color: #c8ccee; }
body.light-theme .module-card { background: var(--card); border-color: #c8ccee; box-shadow: 0 2px 10px rgba(0,0,0,.06); }
body.light-theme .module-card:active { background: #f0f2ff; }
body.light-theme .xp-bar, body.light-theme .module-progress { background: #d8daf0; }
body.light-theme .review-deck, body.light-theme .exam-card { background: linear-gradient(135deg, #fff8e0, #fff) !important; }
body.light-theme .card { background: linear-gradient(160deg, #fff 0%, #f4f6ff 100%); }
body.light-theme .terminal { background: #1a2040; }
body.light-theme .analogy { background: rgba(124,92,255,.08); border-color: rgba(124,92,255,.2); }
body.light-theme .exam-stats { background: #eaecf8; }
body.light-theme #cheatsheet-overlay, body.light-theme #stats-overlay { background: rgba(244,246,255,.95); }
body.light-theme .cs-body, body.light-theme .stats-body { scrollbar-color: #c8ccee transparent; }
body.light-theme .cs-item { background: #eaecf8; border-left-color: #b0b4d8; }
body.light-theme .btn-cheatsheet { background: rgba(124,92,255,.1); }

/* ═══════════ Header actions ═══════════ */
.header-actions { display: flex; align-items: center; gap: 8px; }
.btn-header-icon {
  background: var(--card); border: 1px solid #2a3160;
  color: var(--text); border-radius: 999px; padding: 8px 10px;
  font-size: .9rem; cursor: pointer; transition: background .15s;
}
.btn-header-icon:hover { background: #2a3160; }
body.light-theme .btn-header-icon { border-color: #c8ccee; }
body.light-theme .btn-header-icon:hover { background: #e0e3ff; }

/* ═══════════ Exam section (3 exam cards) ═══════════ */
.exam-section-title {
  font-size: .7rem; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); margin: 16px 0 8px 2px;
}
.exam-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.exam-row .module-card { margin-bottom: 0; }
.exam-full { margin-bottom: 12px; }
.exam-tag {
  display: inline-block; background: rgba(255,200,61,.15);
  border: 1px solid rgba(255,200,61,.4); border-radius: 6px;
  padding: 2px 7px; font-size: .68rem; font-weight: 700;
  color: var(--gold); margin-bottom: 4px;
}

/* ═══════════ Flash mode ═══════════ */
.flash-kicker { color: var(--accent2) !important; }
.flash-finale-tip {
  margin-top: 1rem; padding: 10px 14px;
  background: rgba(0,229,160,.08); border: 1px dashed rgba(0,229,160,.3);
  border-radius: 12px; font-size: .85rem; color: var(--accent2);
}

/* ═══════════ Stats modale ═══════════ */
#stats-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(11,14,26,.92); backdrop-filter: blur(8px);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}
#stats-overlay.hidden { display: none !important; }

.stats-hero {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg2); border-radius: 16px; padding: 14px 16px; margin-bottom: 16px;
}
.stats-emoji { font-size: 2.8rem; }
.stats-level { font-weight: 800; font-size: 1rem; margin-bottom: 4px; }
.stats-xp { font-size: .78rem; color: var(--muted); }

.stats-section-title {
  font-size: .68rem; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; color: var(--accent); margin: 14px 0 8px;
}
.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px;
}
.stats-kv {
  background: var(--bg2); border-radius: 12px; padding: 10px;
  text-align: center;
}
.stats-val { font-size: 1.3rem; font-weight: 800; margin-bottom: 4px; }
.stats-val.warn { color: var(--danger); }
.stats-key { font-size: .68rem; color: var(--muted); line-height: 1.3; }

.stats-mod-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg2); border-radius: 10px; padding: 8px 10px; margin-bottom: 6px;
}
.stats-mod-icon { font-size: 1.2rem; width: 28px; text-align: center; flex-shrink: 0; }
.stats-mod-info { flex: 1; min-width: 0; }
.stats-mod-name { font-size: .78rem; font-weight: 700; margin-bottom: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats-mod-bar { height: 5px; background: #0d1129; border-radius: 999px; overflow: hidden; }
body.light-theme .stats-mod-bar { background: #d8daf0; }
.stats-mod-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 999px; transition: width .8s ease; }
.stats-mod-fill.done { background: var(--accent2); }
.stats-mod-acc { font-size: .78rem; font-weight: 700; color: var(--muted); flex-shrink: 0; width: 32px; text-align: right; }

.stats-body {
  flex: 1; overflow-y: auto; padding: 20px;
  scrollbar-width: thin; scrollbar-color: #2a3160 transparent;
}

.note-pin {
  position: fixed; right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 50px; height: 50px; border-radius: 50%;
  background: rgba(255,255,255,.08); border: 1px solid #3a4070;
  color: var(--text); font-size: 1.35rem; cursor: pointer; z-index: 16;
  display: none; align-items: center; justify-content: center;
  transition: transform .12s, background .15s;
}
.note-pin.visible { display: flex; }
.note-pin:active { transform: scale(.9); }
.note-pin.has-note { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 4px rgba(124,92,255,.18); }

@media (min-width: 700px) {
  #home, .card { max-width: 520px; margin-left: auto; margin-right: auto; }
  .feed-topbar { max-width: 520px; left: 50%; transform: translateX(-50%); }
  #stats-overlay .stats-body, #cheatsheet-overlay .cs-body { max-width: 560px; margin: 0 auto; width: 100%; }
}

/* ═══════════ Cheatsheet button in module card ═══════════ */
.module-badge-area {
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0;
}
.btn-cheatsheet {
  background: rgba(124,92,255,.15); border: 1px solid #4a3f9f;
  color: var(--accent); border-radius: 8px; padding: 4px 8px;
  font-size: .75rem; cursor: pointer; white-space: nowrap;
  transition: background .15s;
}
.btn-cheatsheet:hover { background: rgba(124,92,255,.3); }
.btn-review { border-color: var(--gold) !important; color: var(--gold) !important; background: rgba(255,200,61,.12); }
.btn-review:hover { background: rgba(255,200,61,.24); }

/* ═══════════ Cheatsheet modale ═══════════ */
#cheatsheet-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(11,14,26,.92); backdrop-filter: blur(8px);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}
#cheatsheet-overlay.hidden { display: none !important; }

.cs-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid #1e2550;
  flex-shrink: 0;
}
.cs-title { flex: 1; font-size: 1.05rem; font-weight: 800; }
.cs-close {
  background: none; border: none; color: var(--muted);
  font-size: 1.4rem; cursor: pointer; padding: 4px 8px;
  border-radius: 8px; transition: color .15s;
}
.cs-close:hover { color: var(--text); }

.cs-body {
  flex: 1; overflow-y: auto; padding: 20px;
  scrollbar-width: thin; scrollbar-color: #2a3160 transparent;
}

.cs-section { margin-bottom: 20px; }
.cs-section-title {
  font-size: .72rem; font-weight: 800; letter-spacing: .12em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 10px;
  padding-left: 2px;
}
.cs-item {
  background: var(--bg2); border-radius: 10px;
  padding: 10px 13px; margin-bottom: 6px;
  font-size: .82rem; line-height: 1.55; color: var(--text);
  border-left: 3px solid #2a3160;
}
.cs-item code {
  background: #0d1129; border-radius: 5px;
  padding: 1px 5px; font-family: 'Courier New', monospace;
  font-size: .82rem; color: var(--accent2);
}

@media (min-width: 700px) {
  #cheatsheet-overlay .cs-body { max-width: 560px; margin: 0 auto; width: 100%; }
}

/* ── Profilo ── */
#profile-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(11,14,26,.92); backdrop-filter: blur(8px);
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top, 0) 0 env(safe-area-inset-bottom, 0);
}
#profile-overlay.hidden { display: none !important; }
body.light-theme #profile-overlay { background: rgba(244,246,255,.95); }
.profile-body { max-width: 480px; margin: 0 auto; width: 100%; padding: 16px; box-sizing: border-box; }
.profile-hint { color: var(--muted); line-height: 1.5; margin: 8px 0 18px; }
.profile-input {
  display: block; width: 100%; box-sizing: border-box; margin-bottom: 12px;
  padding: 14px 16px; font-size: 16px; border-radius: 14px;
  border: 1px solid var(--card); background: var(--card); color: var(--text);
}
.profile-input::placeholder { color: var(--muted); }
.profile-btn {
  width: 100%; padding: 14px; font-size: 16px; font-weight: 800;
  border: none; border-radius: 14px; cursor: pointer;
  background: var(--accent); color: #fff;
}
.profile-btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--card); margin-top: 10px; }
.profile-error { color: var(--danger); min-height: 20px; margin-top: 10px; font-size: 14px; }

/* ── Note sheet + hub ───────────────────────────────────────────────────────── */
.note-sheet { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; }
.note-sheet.hidden { display: none; }
.note-sheet-inner { width: 100%; background: var(--card); border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); animation: slideUp .25s ease; }
.note-sheet-title { font-weight: 800; font-size: .95rem; margin-bottom: 12px; color: var(--accent2); }
.note-sheet-text { width: 100%; min-height: 130px; resize: vertical; background: #0a0d18; border: 1px solid #2a3158; border-radius: 12px; color: var(--text); font: inherit; padding: 12px; }
.note-sheet-actions { display: flex; gap: 10px; margin-top: 14px; }
#notes-hub { position: fixed; inset: 0; z-index: 200; background: var(--bg); overflow-y: auto; padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom); }
.notes-hub-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 24px; }
.notes-hub-mod { font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 14px 2px 4px; }
.notes-hub-item { background: var(--card); border: 1px solid #232a55; border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.notes-hub-item .nh-card { font-weight: 700; font-size: .9rem; margin-bottom: 4px; }
.notes-hub-item .nh-text { font-size: .88rem; color: #c9cdf0; white-space: pre-wrap; }
.notes-hub-empty { color: var(--muted); text-align: center; margin-top: 40px; }
.card.recap-check { justify-content: flex-start; }
.rc-list { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; }
.rc-item { display: flex; align-items: flex-start; gap: 10px; background: #11152b; border: 1px solid #232a55; border-radius: 12px; padding: 11px 12px; cursor: pointer; }
.rc-item.checked { opacity: .55; border-color: var(--accent2); }
.rc-item input { margin-top: 3px; width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--accent2); }
.rc-ico { font-size: 1.15rem; flex-shrink: 0; }
.rc-title { font-weight: 700; font-size: .92rem; display: block; }
.rc-essence { font-size: .82rem; color: var(--muted); display: block; margin-top: 2px; }
.card.recall-card { justify-content: center; }
.recall-essence { margin-top: 16px; font-size: 1.05rem; line-height: 1.6; color: #d6d9f5; animation: slideUp .25s ease; }
.recall-actions { display: flex; gap: 10px; margin-top: 20px; }
.recall-card.recall-done { opacity: .4; }
