/* ============================================================
   Lezioni Private — styles.css
   Import tokens.css before this file.
   ============================================================ */

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

html { height: 100%; }
body {
  min-height: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.65;
  letter-spacing: 0.01em;
  word-spacing: 0.03em;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.view {
  min-height: 100vh;
  padding: var(--view-pad);
}

.slides-container { position: relative; }
.slide { display: flex; flex-direction: column; }

/* ============================================================
   GAME HEADER (sticky top)
   ============================================================ */
.game-header {
  position: sticky;
  top: 0;
  z-index: 300;
  background: var(--paper);
  border-bottom: var(--border-base);
  padding: 0.55rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 3px 0 rgba(26, 20, 16, 0.08);
  flex-wrap: wrap;
}
.gh-left { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.gh-avatar {
  font-size: 1.6rem;
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border: var(--border-base);
  background: var(--bg);
  box-shadow: var(--shadow-hard-sm);
  flex-shrink: 0;
  cursor: pointer;
}
.gh-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gh-level {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: var(--primary);
  text-transform: uppercase;
  font-weight: 700;
}

.gh-xp {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.gh-xp-label {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--ink-soft);
  font-weight: 600;
}
.gh-xp-bar {
  height: 10px;
  background: var(--xp-bg);
  border: 1.5px solid var(--ink);
  overflow: hidden;
  position: relative;
}
.gh-xp-fill {
  height: 100%;
  background: var(--xp-fill);
  width: 0%;
  transition: width 0.4s var(--ease);
}

.gh-stats { display: flex; gap: 0.75rem; align-items: center; }
.gh-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  padding: 4px 8px;
  background: var(--bg);
  border: 1.5px solid var(--ink);
  box-shadow: var(--shadow-hard-sm);
}
.gh-stat--streak { color: var(--streak-fire); }
.gh-stat--lives { letter-spacing: 2px; }

.gh-home {
  min-width: 44px; height: 44px;
  border: var(--border-base);
  background: var(--highlight);
  cursor: pointer;
  font-size: 1.1rem;
  box-shadow: var(--shadow-hard-sm);
}
.gh-home:hover { background: var(--primary); color: var(--paper); }

@media (max-width: 560px) {
  .game-header { padding: 0.4rem 0.6rem; gap: 0.5rem; }
  .gh-name { font-size: 0.95rem; max-width: 100px; }
  .gh-level { display: none; }
  .gh-xp { min-width: 90px; }
  .gh-stat { font-size: 0.85rem; padding: 3px 6px; }
  .gh-home { min-width: 40px; height: 40px; }
}

/* ============================================================
   TIPOGRAFIA
   ============================================================ */
h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--fs-h1);
  line-height: 1;
  letter-spacing: -0.02em;
  margin-bottom: 1rem;
  max-width: 16ch;
}
h1 .accent, h2 .accent {
  color: var(--primary);
  font-weight: 700;
}
h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-h2);
  line-height: 1.05;
  margin-bottom: 1.2rem;
  max-width: 22ch;
}
h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-h3);
  margin-bottom: 0.8rem;
}
p {
  max-width: 58ch;
  margin-bottom: 1rem;
  font-size: var(--fs-body);
}
p.big {
  font-size: var(--fs-body-big);
  max-width: 50ch;
}
p.lede {
  color: var(--ink-soft);
  font-size: var(--fs-lede);
  margin-bottom: 1.8rem;
}
strong { font-weight: 600; }
code {
  font-family: var(--font-mono);
  background: var(--ink);
  color: var(--paper);
  padding: 1px 7px;
  border-radius: var(--radius-sm);
  font-size: 0.92em;
}

.slide-label {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-mono-label);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--highlight);
  padding: 5px 12px;
  border: var(--border-thin);
  margin-bottom: 1.2rem;
  font-weight: 600;
  align-self: flex-start;
}

/* ============================================================
   HUB
   ============================================================ */
.hub-header {
  margin-bottom: 2.5rem;
  max-width: 900px;
}
.hub-kicker {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-bottom: 1.2rem;
  font-weight: 600;
}
.hub-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3rem, 7vw, 5.5rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}
.hub-title .accent { color: var(--primary); }
.hub-subtitle {
  font-size: clamp(1.1rem, 1.6vw, 1.35rem);
  color: var(--ink-soft);
  max-width: 50ch;
}
.modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.3rem;
  max-width: 1200px;
}
.module-card {
  background: var(--paper);
  border: var(--border-thick);
  padding: 1.8rem 1.8rem 1.6rem;
  cursor: pointer;
  box-shadow: var(--shadow-hard);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
  display: flex;
  flex-direction: column;
  min-height: 260px;
}
.module-card:hover {
  transform: translate(-3px, -3px);
  box-shadow: var(--shadow-hard-lg);
}
.module-card:active {
  transform: translate(2px, 2px);
  box-shadow: 4px 4px 0 var(--ink);
}
.module-card:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}
.mod-icon { font-size: 2.5rem; line-height: 1; margin-bottom: 1rem; }
.mod-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 0.4rem;
  text-transform: uppercase;
}
.mod-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.55rem;
  line-height: 1.1;
  margin-bottom: 0.6rem;
}
.mod-desc {
  font-size: 0.95rem;
  color: var(--ink-soft);
  line-height: 1.55;
  margin-bottom: auto;
  padding-bottom: 1rem;
}
.mod-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 1rem;
  border-top: 1px dashed var(--ink-soft);
  font-size: 0.82rem;
}
.mod-count { font-family: var(--font-mono); color: var(--ink-soft); }
.mod-cta { font-weight: 600; color: var(--primary); }
.mod-progress {
  margin-top: 0.7rem;
  height: 6px;
  background: var(--xp-bg);
  border: 1.5px solid var(--ink);
  overflow: hidden;
}
.mod-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.4s var(--ease);
}
.module-card.is-completed { background: color-mix(in srgb, var(--success) 8%, var(--paper)); }
.module-card.is-completed .mod-cta { color: var(--success); }

/* ============================================================
   NAV BAR moduli
   ============================================================ */
.main-nav {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--paper);
  border: var(--border-base);
  padding: 0.4rem 0.5rem;
  box-shadow: 4px 4px 0 var(--ink);
  z-index: 200;
}
.main-nav button {
  min-width: var(--touch-min);
  height: var(--touch-min);
  border: var(--border-base);
  background: var(--bg);
  cursor: pointer;
  font-size: 1.15rem;
  font-weight: 600;
  font-family: var(--font-body);
  padding: 0 10px;
}
.main-nav button:hover:not(:disabled) {
  background: var(--primary);
  color: var(--paper);
}
.main-nav button:disabled { opacity: 0.3; cursor: not-allowed; }
.main-nav .home-btn { background: var(--highlight); font-size: 1rem; }
.nav-counter {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  min-width: 68px;
  text-align: center;
}
.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 4px;
  background: var(--primary);
  width: 0;
  transition: width 0.3s ease;
  z-index: 310;
}

/* ============================================================
   XLGRID (dal v5)
   ============================================================ */
.xlgrid {
  display: inline-block;
  background: var(--paper);
  border: var(--border-thick);
  box-shadow: var(--shadow-hard);
  margin: 0.8rem 0;
  font-family: var(--font-mono);
  max-width: 100%;
  overflow-x: auto;
}
.xlgrid-fbar {
  display: flex;
  align-items: center;
  background: var(--bg-dark);
  border-bottom: var(--border-base);
  padding: 8px 14px;
  gap: 12px;
  min-height: 38px;
}
.xlgrid-fbar .fx-label {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--ink-soft);
  padding-right: 12px;
  border-right: 1.5px solid var(--ink-soft);
  font-size: 1.15rem;
}
.xlgrid table { border-collapse: collapse; }
.xlgrid th, .xlgrid td {
  border: 1px solid #B8A688;
  padding: 0.65rem 1rem;
  text-align: center;
  min-width: 72px;
  font-size: 1rem;
  font-weight: 500;
  font-family: var(--font-mono);
}
.xlgrid th {
  background: var(--bg-dark);
  font-family: var(--font-body);
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
}
.xlgrid th.rownum { min-width: 38px; width: 38px; font-size: 0.9rem; }
.xlgrid th.col-highlight { background: var(--primary); color: var(--paper); }
.xlgrid tr.row-highlight th.rownum { background: var(--accent); color: var(--ink); }
.xlgrid td.col-tinted { background: var(--col-tint); }
.xlgrid td.row-tinted { background: var(--row-tint); }
.xlgrid td.col-tinted.row-tinted {
  background: var(--highlight);
  box-shadow: inset 0 0 0 2.5px var(--primary);
  font-weight: 700;
  color: var(--primary-dark);
}
.xlgrid td.active-cell {
  background: var(--highlight);
  box-shadow: inset 0 0 0 2.5px var(--primary);
  font-weight: 700;
  color: var(--primary-dark);
}
.xlgrid td.result-cell {
  background: #D8E8CC;
  font-weight: 700;
  color: var(--success);
}
.xlgrid td.empty { color: var(--ink-soft); opacity: 0.35; }
.xlgrid.clickable td { cursor: pointer; transition: background 0.15s; min-height: var(--touch-min); }
.xlgrid.clickable td:hover { background: var(--highlight); }
.xlgrid td.click-correct {
  background: var(--success) !important;
  color: var(--paper);
}
.xlgrid td.click-wrong {
  background: var(--error) !important;
  color: var(--paper);
}

/* ============================================================
   QUIZ / PROMPT / CARDS
   ============================================================ */
.prompt-card {
  background: var(--paper);
  border: var(--border-thick);
  padding: 1.2rem 1.5rem;
  box-shadow: 5px 5px 0 var(--accent);
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 700px;
  margin-bottom: 1rem;
}
.prompt-card .prompt-icon { font-size: 1.8rem; }
.prompt-card .prompt-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
}
.prompt-card .prompt-text .target {
  background: var(--highlight);
  padding: 2px 10px;
  border: var(--border-base);
  font-family: var(--font-mono);
  margin: 0 2px;
}
.prompt-feedback {
  display: none;
  margin-top: 0.8rem;
  padding: 0.9rem 1.2rem;
  border: var(--border-base);
  font-weight: 600;
}
.prompt-feedback.show { display: block; }
.prompt-feedback.right { background: var(--success); color: var(--paper); }
.prompt-feedback.wrong { background: var(--error); color: var(--paper); }

.quiz { max-width: 800px; margin: 0.8rem 0; }
.quiz-question {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.15rem, 2vw, 1.5rem);
  margin-bottom: 1.3rem;
  background: var(--paper);
  padding: 1.2rem 1.4rem;
  border: var(--border-base);
  border-left: 10px solid var(--accent);
}
.quiz-options { display: flex; flex-direction: column; gap: 0.7rem; }
.quiz-option {
  background: var(--paper);
  border: var(--border-base);
  padding: 0.95rem 1.3rem;
  text-align: left;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 1.02rem;
  font-weight: 500;
  box-shadow: 2px 2px 0 var(--ink);
  line-height: 1.4;
  transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
  min-height: var(--touch-min);
}
.quiz-option.mono { font-family: var(--font-mono); font-size: 0.95rem; }
.quiz-option:hover:not(.answered) {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 var(--ink);
  background: var(--highlight);
}
.quiz-option .letter {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: var(--border-base);
  border-radius: 50%;
  text-align: center;
  line-height: 24px;
  font-weight: 700;
  margin-right: 0.8rem;
  font-size: 0.9rem;
  background: var(--bg);
  vertical-align: middle;
}
.quiz-option.correct { background: var(--success); color: var(--paper); }
.quiz-option.correct .letter { background: var(--paper); color: var(--success); }
.quiz-option.wrong { background: var(--error); color: var(--paper); }
.quiz-option.wrong .letter { background: var(--paper); color: var(--error); }
.quiz-option.dim { opacity: 0.55; }
.quiz-feedback {
  margin-top: 1.2rem;
  padding: 1.1rem 1.3rem;
  border: var(--border-base);
  background: var(--highlight);
  display: none;
}
.quiz-feedback.show { display: block; }
.quiz-feedback h4 { font-family: var(--font-display); font-size: 1.25rem; margin-bottom: 0.4rem; }
.quiz-feedback.right h4 { color: var(--success); }
.quiz-feedback.wrong-fb h4 { color: var(--error); }
.quiz-feedback p { margin: 0; font-size: 1rem; max-width: none; }

.quiz-variant.hidden-variant { display: none; }

.try-another {
  display: none;
  margin-top: 1rem;
  background: var(--accent);
  color: var(--ink);
  border: var(--border-base);
  padding: 0.7rem 1.2rem;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.98rem;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}
.try-another.show { display: inline-block; }
.try-another:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--ink);
}
.try-another:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: 3px 3px 0 var(--ink); }

/* ============================================================
   DEMO BOX / CODE DISPLAY / COMPARE / STEPS
   ============================================================ */
.demo-box {
  background: var(--paper);
  border: var(--border-thick);
  padding: 1.5rem 1.8rem;
  box-shadow: 6px 6px 0 var(--primary);
  max-width: 720px;
  margin: 1rem 0;
}
.demo-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.demo-row label { font-weight: 600; min-width: 120px; font-size: 1.05rem; }
.demo-row input[type="range"] {
  flex: 1;
  min-width: 180px;
  accent-color: var(--primary);
  height: 6px;
}
.demo-row .val {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.8rem;
  color: var(--primary);
  min-width: 56px;
  text-align: center;
  background: var(--highlight);
  border: var(--border-base);
  padding: 0.1rem 0.5rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  max-width: 1100px;
  margin: 1rem 0;
}
.info-card {
  background: var(--paper);
  border: var(--border-base);
  padding: 1.1rem 1.3rem;
  box-shadow: 4px 4px 0 var(--ink);
}
.info-card .ic-icon { font-size: 1.6rem; margin-bottom: 0.4rem; }
.info-card h4 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  margin-bottom: 0.3rem;
  color: var(--primary);
}
.info-card p { font-size: 0.92rem; color: var(--ink-soft); margin: 0; line-height: 1.5; }

.code-display {
  background: var(--ink);
  color: var(--paper);
  padding: 1.2rem 1.5rem;
  font-family: var(--font-mono);
  font-size: clamp(0.95rem, 1.4vw, 1.15rem);
  line-height: 1.5;
  border: var(--border-base);
  box-shadow: 6px 6px 0 var(--primary);
  margin: 0.8rem 0;
  max-width: 800px;
  font-weight: 500;
}
.code-display .fn { color: #FFB86C; font-weight: 700; }
.code-display .c { color: #8BE9FD; }
.code-display .t { color: #50FA7B; }
.code-display .f { color: #FF79C6; }

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  max-width: 900px;
  margin: 1rem 0;
}
.compare-side {
  padding: 1.2rem 1.3rem;
  border: var(--border-base);
  box-shadow: 4px 4px 0 var(--ink);
}
.compare-side.bad { background: #F2D0CE; }
.compare-side.good { background: #D8E8CC; }
.compare-side .label {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.compare-side.bad .label { color: var(--error); }
.compare-side.good .label { color: var(--success); }
.compare-side .formula {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 600;
  background: var(--ink);
  color: var(--paper);
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.6rem;
}
.compare-side .explanation { font-size: 0.95rem; }

.module-cover {
  padding: 4vh 0;
  position: relative;
}
.cover-number {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(5rem, 14vw, 14rem);
  line-height: 0.8;
  color: var(--primary);
  opacity: 0.13;
  position: absolute;
  right: 3vw;
  top: 0;
  user-select: none;
  pointer-events: none;
}
.cover-kicker {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 1.2rem;
  font-weight: 700;
}
.cover-note {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  color: var(--ink-soft);
  max-width: 30ch;
  line-height: 1.3;
  margin-top: 0.5rem;
}

.steps {
  list-style: none;
  counter-reset: step;
  padding: 0;
  margin: 1rem 0;
  max-width: 700px;
}
.steps li {
  counter-increment: step;
  position: relative;
  padding: 0.7rem 0 0.7rem 3rem;
  border-bottom: 1px dashed var(--ink-soft);
  font-size: 1.02rem;
}
.steps li:last-child { border-bottom: none; }
.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0.5rem;
  width: 2rem;
  height: 2rem;
  background: var(--primary);
  color: var(--paper);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.1rem;
  line-height: 2rem;
  text-align: center;
  border-radius: 50%;
}

.hint { color: var(--ink-soft); font-size: 0.98rem; margin-top: 0.4rem; }

.end-of-module {
  background: var(--paper);
  border: var(--border-thick);
  box-shadow: 6px 6px 0 var(--accent);
  padding: 2rem 2.2rem;
  max-width: 640px;
  margin-top: 1.5rem;
}
.end-of-module h3 { font-size: 1.5rem; margin-bottom: 0.8rem; }
.end-of-module .actions {
  display: flex;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-top: 1.3rem;
}
.action-btn {
  background: var(--primary);
  color: var(--paper);
  border: var(--border-base);
  padding: 0.7rem 1.3rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 1rem;
  box-shadow: 3px 3px 0 var(--ink);
  transition: all var(--t-fast);
  min-height: var(--touch-min);
}
.action-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--ink);
}
.action-btn.secondary { background: var(--paper); color: var(--ink); }

@media (max-width: 900px) {
  .compare { grid-template-columns: 1fr; }
}

/* ============================================================
   SANDBOX
   ============================================================ */
.sandbox {
  background: var(--paper);
  border: var(--border-thick);
  box-shadow: 6px 6px 0 var(--primary);
  padding: 1.5rem 1.8rem;
  max-width: 760px;
  margin: 1rem 0;
}
.sandbox-input-wrap { margin-top: 1.2rem; }
.sandbox-input-wrap label {
  font-weight: 600;
  display: block;
  margin-bottom: 0.5rem;
  font-size: 1.05rem;
}
.sandbox-inputs { display: flex; gap: 0.6rem; align-items: stretch; flex-wrap: wrap; }
.sandbox-inputs input {
  flex: 1;
  min-width: 240px;
  padding: 0.8rem 1rem;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 600;
  border: var(--border-thick);
  background: var(--bg);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  min-height: var(--touch-min);
}
.sandbox-inputs input:focus {
  outline: none;
  box-shadow: 3px 3px 0 var(--primary);
  background: var(--highlight);
}
.sandbox-inputs button {
  padding: 0.8rem 1.4rem;
  background: var(--primary);
  color: var(--paper);
  font-weight: 700;
  border: var(--border-thick);
  font-family: var(--font-body);
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  min-height: var(--touch-min);
}
.sandbox-inputs button:hover {
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 var(--ink);
}
.sandbox td.sandbox-output {
  background: var(--highlight);
  box-shadow: inset 0 0 0 2.5px var(--primary);
  font-weight: 700;
  color: var(--primary-dark);
  min-width: 90px;
}
.sandbox td.sandbox-output.has-value {
  background: #D8E8CC;
  box-shadow: inset 0 0 0 2.5px var(--success);
  color: var(--success);
}
.sandbox td.sandbox-output.has-error {
  background: #F2D0CE;
  box-shadow: inset 0 0 0 2.5px var(--error);
  color: var(--error);
  font-family: var(--font-body);
  font-size: 0.8rem;
}
.sandbox-result {
  margin-top: 0.9rem;
  padding: 0.9rem 1.1rem;
  font-size: 1rem;
  border: var(--border-base);
  display: none;
  line-height: 1.5;
}
.sandbox-result.show { display: block; }
.sandbox-result.success { background: #D8E8CC; color: var(--success); }
.sandbox-result.error { background: #F2D0CE; color: var(--error); }
.sandbox-result code { background: var(--ink); color: var(--paper); padding: 1px 6px; }
.sandbox-suggestions { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px dashed var(--ink-soft); }
.suggestions-grid { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.6rem; }
.chip {
  background: var(--paper);
  border: var(--border-base);
  padding: 0.4rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  transition: all var(--t-fast);
  color: var(--ink);
  min-height: 36px;
}
.chip:hover {
  background: var(--highlight);
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--ink);
}
.xlgrid td.cell-input-wrap { padding: 0; min-width: 130px; }
.xlgrid td.cell-input-wrap input.cell-input {
  width: 100%;
  border: none;
  background: var(--highlight);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  padding: 0.65rem 1rem;
  text-align: center;
  color: var(--primary-dark);
  box-shadow: inset 0 0 0 2.5px var(--primary);
}
.xlgrid td.cell-input-wrap input.cell-input:focus {
  outline: none;
  background: var(--paper);
  box-shadow: inset 0 0 0 3px var(--primary);
}

/* ============================================================
   TOAST (XP, Level up, Badge)
   ============================================================ */
.toast-host {
  position: fixed;
  top: 80px;
  right: 16px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--paper);
  border: var(--border-thick);
  box-shadow: var(--shadow-hard);
  padding: 0.7rem 1rem;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  pointer-events: auto;
  animation: toastIn 0.35s var(--ease);
  max-width: 320px;
}
.toast--xp { background: var(--highlight); }
.toast--level { background: var(--accent); }
.toast--badge { background: var(--success); color: var(--paper); }
.toast--streak { background: var(--streak-fire); color: var(--paper); }
.toast--life-lost { background: var(--error); color: var(--paper); }
.toast-icon { font-size: 1.3rem; }

@keyframes toastIn {
  from { transform: translate(20px, -10px); opacity: 0; }
  to { transform: translate(0, 0); opacity: 1; }
}
@keyframes toastOut {
  to { transform: translate(20px, -10px); opacity: 0; }
}
.toast.leaving { animation: toastOut 0.25s var(--ease) forwards; }

/* ============================================================
   OVERLAY (vite finite)
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 20, 16, 0.65);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.overlay-card {
  background: var(--paper);
  border: var(--border-thick);
  box-shadow: var(--shadow-hard);
  padding: 2rem 2.2rem;
  max-width: 420px;
  text-align: center;
}
.overlay-card h3 { font-family: var(--font-display); font-size: 1.6rem; margin-bottom: 0.8rem; }
.overlay-card p { margin: 0 auto 1.2rem; }

/* ============================================================
   ACCESSIBILITÀ
   ============================================================ */
*:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 3px;
}
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 560px) {
  .view { padding: 3vh 4vw 16vh; }
  h1 { max-width: 100%; }
  .hub-title { font-size: clamp(2.2rem, 10vw, 3.2rem); }
  .modules-grid { grid-template-columns: 1fr; }
  .demo-row label { min-width: 100%; }
  .main-nav { bottom: max(12px, env(safe-area-inset-bottom)); padding: 0.3rem; gap: 0.3rem; }
  .main-nav button { min-width: 42px; height: 42px; font-size: 1rem; padding: 0 6px; }
  .xlgrid { display: block; overflow-x: auto; white-space: nowrap; }
  .xlgrid table { min-width: max-content; }
}
