:root {
  --bg: #f2f2f7;
  --bg-elevated: #ffffff;
  --bg-secondary: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #6e6e73;
  --text-tertiary: #aeaeb2;
  --accent: #007aff;
  --accent-soft: #e8f1ff;
  --green: #34c759;
  --border: #e5e5ea;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 8px rgba(0, 0, 0, 0.04);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --text: #f2f2f7;
    --text-secondary: #98989d;
    --text-tertiary: #636366;
    --accent: #0a84ff;
    --accent-soft: #0a2c4e;
    --green: #30d158;
    --border: #38383a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 8px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.view { flex: 1; display: flex; flex-direction: column; padding: 20px; }
.view[hidden] { display: none; }

/* ---------- HOME ---------- */

.home-header { text-align: center; margin: 32px 0 28px; }
.home-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 6px;
  letter-spacing: -0.03em;
}
.tagline { color: var(--text-secondary); font-size: 0.9rem; margin: 0; line-height: 1.4; }

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  flex: 1;
}

.level-card {
  background: var(--bg-elevated);
  border: none;
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  color: var(--text);
  cursor: pointer;
  min-height: 116px;
  justify-content: space-between;
  transition: transform 0.15s ease;
}
.level-card:active { transform: scale(0.97); }

.level-code {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.level-label { font-size: 0.95rem; font-weight: 600; text-align: left; }
.level-progress { font-size: 0.75rem; color: var(--text-secondary); text-align: left; margin-top: -6px; }

/* ---------- SUB HEADER (lezioni / player) ---------- */

.sub-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.sub-header h2 {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
  text-align: center;
}

.btn-back {
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border: none;
  color: var(--accent);
  font-size: 1.15rem;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.btn-back:active { transform: scale(0.94); }

/* ---------- LESSON LIST ---------- */

.lesson-list { display: flex; flex-direction: column; gap: 10px; }

.lesson-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border: none;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.lesson-row:active { transform: scale(0.985); }
.lesson-row.lesson-locked { opacity: 0.4; cursor: default; }

.lesson-num {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.lesson-locked .lesson-num { background: var(--text-tertiary); }

.lesson-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.lesson-theme { font-size: 0.95rem; font-weight: 500; }
.lesson-count { font-size: 0.78rem; color: var(--text-secondary); }
.lesson-lock { font-size: 1rem; color: var(--text-tertiary); }

/* ---------- PLAYER ---------- */

.player-stage { flex: 1; display: flex; flex-direction: column; }

.player-card {
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border: none;
  border-radius: var(--radius-lg);
  padding: 36px 26px;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  min-height: 320px;
}

.step-label {
  color: var(--accent);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  min-height: 1.2em;
}

.step-it { font-size: 1.4rem; font-weight: 500; color: var(--text-secondary); min-height: 1.6em; }
.step-en { font-size: 1.9rem; font-weight: 700; color: var(--text); letter-spacing: -0.02em; min-height: 1.8em; }
.step-note {
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 34ch;
  min-height: 1.2em;
  line-height: 1.45;
}

.recall-ring { position: relative; width: 64px; height: 64px; margin-top: 8px; }
.recall-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.recall-track { fill: none; stroke: var(--border); stroke-width: 4; }
.recall-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.05s linear;
}
.recall-count {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 24px;
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width 0.2s; }
.progress-label { text-align: center; color: var(--text-tertiary); font-size: 0.75rem; margin-top: 8px; }

.player-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 28px 0 8px;
}

.btn-icon {
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border: none;
  color: var(--text);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-lg { width: 52px; height: 52px; font-size: 1.15rem; color: var(--text-secondary); }
.btn-xl {
  width: 72px;
  height: 72px;
  font-size: 1.6rem;
  background: var(--accent);
  color: #fff;
  border: none;
  box-shadow: 0 4px 14px rgba(0, 122, 255, 0.35);
}
.btn-icon:active { transform: scale(0.93); }

/* ---------- DONE ---------- */

.view-done { align-items: center; justify-content: center; }
.done-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.done-emoji {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; font-weight: 700;
  margin-bottom: 6px;
}
.done-card h2 { margin: 4px 0; font-size: 1.3rem; font-weight: 700; }
.done-card p { color: var(--text-secondary); margin: 0 0 16px; font-size: 0.92rem; }

/* ---------- BUTTONS ---------- */

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 26px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { opacity: 0.85; }
.btn-ghost { background: var(--bg-elevated); color: var(--accent); box-shadow: var(--shadow); }
.btn-ghost:active { transform: scale(0.97); }

/* ---------- SETTINGS DIALOG ---------- */

.settings-dialog {
  border: none;
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 26px;
  width: min(360px, 90vw);
  box-shadow: var(--shadow);
}
.settings-dialog::backdrop { background: rgba(0,0,0,0.35); backdrop-filter: blur(4px); }
.settings-dialog h3 { margin-top: 0; font-size: 1.1rem; font-weight: 700; }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.settings-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0 16px;
}
.settings-subtitle { margin: 0 0 6px; font-size: 0.92rem; font-weight: 600; }
.settings-hint { color: var(--text-secondary); font-size: 0.78rem; margin: 0 0 14px; line-height: 1.4; }
.settings-backup-row { display: flex; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.settings-backup-row .btn { flex: 1; padding: 10px 14px; font-size: 0.85rem; box-shadow: none; border: 1px solid var(--border); }

.home-footer { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 20px; }

.settings-row select {
  background: var(--bg);
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 0.85rem;
  max-width: 55%;
}

@media (min-width: 600px) {
  .app { max-width: 480px; margin: 0 auto; }
}
