/* Calcolo Mentale — stile ispirato a chip/pillole e verde lime, doppio tema giorno/notte */

:root {
  --bg: #eef1f8;
  --bg-card: #ffffff;
  --bg-soft: #f2f4fa;
  --bg-chip: #eef1f8;
  --text: #161b2e;
  --text-soft: #6b7488;
  --primary: #96d51a;
  --primary-strong: #7ab812;
  --on-primary: #16321a;
  --success: #3fae7c;
  --success-bg: #e5f6ee;
  --warning: #dd8a1e;
  --warning-bg: #fdf1de;
  --border: #e3e7f1;
  --shadow: rgba(28, 36, 62, 0.08);
  --radius: 18px;
  --radius-pill: 999px;
}

:root[data-theme="dark"] {
  --bg: #10162a;
  --bg-card: #1a2140;
  --bg-soft: #212a4d;
  --bg-chip: #212a4d;
  --text: #edf0fa;
  --text-soft: #97a2c4;
  --primary: #c6f24e;
  --primary-strong: #b3e63a;
  --on-primary: #16321a;
  --success: #5bd0a0;
  --success-bg: #17301f;
  --warning: #f0b34d;
  --warning-bg: #3a2b12;
  --border: #2b3766;
  --shadow: rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.15rem;
}

.logo-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--primary);
  font-size: 1.15rem;
}

.theme-toggle {
  border: none;
  background: var(--bg-card);
  box-shadow: 0 2px 8px var(--shadow);
  border-radius: var(--radius-pill);
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
.theme-toggle:hover { transform: scale(1.06); }
.theme-toggle:active { transform: scale(0.94); }

main#app {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 20px 40px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px var(--shadow);
  padding: 28px;
  margin-bottom: 20px;
}

.title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 6px;
}

.subtitle {
  color: var(--text-soft);
  margin: 0 0 20px;
  line-height: 1.5;
}

.menu-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.menu-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1.5px solid var(--border);
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  width: 100%;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.menu-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px var(--shadow); border-color: var(--primary); }

.menu-btn .icon {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg-chip);
  font-size: 1.4rem;
}
.menu-btn .text-col { display: flex; flex-direction: column; min-width: 0; }
.menu-btn .label { font-weight: 700; font-size: 1.02rem; }
.menu-btn .desc { color: var(--text-soft); font-size: 0.88rem; margin-top: 2px; }

.menu-btn.wide { background: transparent; border-style: dashed; }

.menu-btn-current {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, var(--bg-soft));
}
.menu-btn-current .icon { background: var(--primary); }

.menu-btn-locked {
  opacity: 0.6;
  cursor: not-allowed;
}
.menu-btn-locked:hover { transform: none; box-shadow: none; border-color: var(--border); }
.menu-btn-locked .icon { background: var(--bg-chip); }
.menu-btn-locked.radio-card::after { display: none; }
.menu-btn-locked.radio-card { padding-right: 18px; }

.tech-tab-locked {
  opacity: 0.55;
  cursor: not-allowed;
}
.tech-tab-locked:hover { background: var(--bg-chip); }

/* radio-dot per le card di livello/modalità */
.menu-btn.radio-card { position: relative; padding-right: 46px; }
.menu-btn.radio-card::after {
  content: '';
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: transparent;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.menu-btn.radio-card.menu-btn-current::after {
  border-color: var(--primary);
  background: var(--primary);
  box-shadow: inset 0 0 0 3px var(--bg-card);
}

.stats-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 18px 0 4px;
}

.stat-pill {
  background: var(--bg-chip);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font-size: 0.85rem;
  color: var(--text-soft);
}
.stat-pill strong { color: var(--text); }

.level-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-left: 5px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 20px;
}
.level-banner .emoji {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--primary);
  font-size: 1.4rem;
}
.level-banner .name { font-weight: 700; }
.level-banner .sub { font-size: 0.85rem; color: var(--text-soft); }

/* Esercizio */
.progress-track {
  height: 8px;
  background: var(--bg-soft);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-bottom: 20px;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
}

.question-box {
  text-align: center;
  padding: 30px 10px;
}

.question-text {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 24px;
}

.answer-form {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.answer-input {
  font-size: 1.4rem;
  padding: 12px 16px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 140px;
  text-align: center;
  font-family: inherit;
}
.answer-input:focus {
  outline: none;
  border-color: var(--primary);
}

.btn {
  border: none;
  border-radius: var(--radius-pill);
  padding: 13px 24px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 14px var(--shadow); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-secondary { background: var(--bg-soft); color: var(--text); border: 1.5px solid var(--border); }
.btn-ghost { background: transparent; color: var(--text-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.feedback {
  margin-top: 20px;
  padding: 14px 18px;
  border-radius: 14px;
  font-weight: 600;
  min-height: 24px;
}
.feedback.correct { background: var(--success-bg); color: var(--success); }
.feedback.wrong { background: var(--warning-bg); color: var(--warning); }

.actions-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
  flex-wrap: wrap;
}

/* Riepilogo */
.summary-score {
  text-align: center;
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--primary-strong);
  margin: 6px 0 4px;
}
.summary-note {
  text-align: center;
  color: var(--text-soft);
  margin-bottom: 20px;
}

/* Tecniche */
.tech-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.tech-tab {
  border: 1.5px solid var(--border);
  background: var(--bg-chip);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.tech-tab.active {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary);
}

.example-box {
  background: var(--bg-soft);
  border-radius: 14px;
  padding: 16px 18px;
  margin: 14px 0;
  font-size: 1.05rem;
}
.example-box .step {
  margin: 4px 0;
}

.platoon-grid {
  display: inline-grid;
  gap: 4px;
  margin: 14px auto;
}
.platoon-cell {
  width: 20px;
  height: 20px;
  background: var(--primary);
  border-radius: 5px;
}
.platoon-wrap {
  text-align: center;
  margin: 16px 0;
}
.platoon-caption {
  color: var(--text-soft);
  font-size: 0.85rem;
  margin-top: 8px;
}

/* Visualizzazione animata: sassolini -> rettangolo (plotone) */
.pebble-anim-wrap { text-align: center; margin: 20px 0; }
.pebble-anim-stage {
  position: relative;
  margin: 6px auto 14px;
}
.anim-dot {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--warning);
  transition: transform 0.7s cubic-bezier(0.5, 0.05, 0.2, 1),
              border-radius 0.7s ease, background 0.5s ease;
}
.pebble-anim-stage.as-rect .anim-dot {
  border-radius: 6px;
  background: var(--primary);
}
.anim-plus {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--text-soft);
  transition: opacity 0.4s ease;
  pointer-events: none;
}
.pebble-anim-stage.as-rect .anim-plus { opacity: 0; }
.anim-btn { margin-top: 2px; }

/* Tavola pitagorica */
.tbl-scroll {
  overflow-x: auto;
  margin: 16px 0;
  -webkit-overflow-scrolling: touch;
}
.tbl-tabelline {
  border-collapse: collapse;
  margin: 0 auto;
  font-size: 0.85rem;
}
.tbl-tabelline th,
.tbl-tabelline td {
  width: 34px;
  height: 34px;
  text-align: center;
  border: 1px solid var(--border);
  padding: 0;
}
.tbl-tabelline thead th,
.tbl-tabelline tbody th {
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
}
.tbl-tabelline th.corner { background: var(--primary-strong); }
.tbl-tabelline td {
  background: var(--bg-card);
  color: var(--text);
}
.tbl-tabelline td.mirror {
  background: var(--bg-soft);
  color: var(--text-soft);
}
.tbl-tabelline td.diag {
  background: color-mix(in srgb, var(--primary) 30%, var(--bg-card));
  font-weight: 700;
}

.review-banner {
  background: var(--warning-bg);
  color: var(--warning);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 16px;
  font-weight: 600;
}

footer.app-footer {
  text-align: center;
  color: var(--text-soft);
  font-size: 0.8rem;
  padding: 10px 20px 24px;
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
.pop { animation: pop 0.25s ease; }
