:root {
  --bg: #faf6ef;
  --bg-alt: #f1ead9;
  --surface: #ffffff;
  --surface-2: #fbf8f2;
  --border: #e6dcc6;
  --text: #2b2620;
  --text-soft: #6b6255;
  --ink: #1f2a44;
  --accent: #a3402f;
  --accent-soft: #f2e2da;
  --good: #2f7a4f;
  --good-soft: #e3f2e6;
  --bad: #b3402e;
  --bad-soft: #fbe6e2;
  --amber: #b3781a;
  --amber-soft: #fbeed9;
  --shadow: 0 1px 2px rgba(43, 38, 32, .06), 0 8px 24px -12px rgba(43, 38, 32, .18);
  --radius: 14px;
  --radius-lg: 20px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #171512;
  --bg-alt: #1e1b17;
  --surface: #211d19;
  --surface-2: #262119;
  --border: #3a332a;
  --text: #ede6d9;
  --text-soft: #b3a794;
  --ink: #e7ecf7;
  --accent: #e07a5f;
  --accent-soft: #3a2620;
  --good: #7fd39c;
  --good-soft: #1c3226;
  --bad: #e8998a;
  --bad-soft: #3a2320;
  --amber: #e9b869;
  --amber-soft: #3a2f18;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background .2s ease, color .2s ease;
}

h1, h2, h3, h4 { font-family: var(--serif); color: var(--ink); margin: 0 0 .4em; font-weight: 600; }

a { color: inherit; }

p { line-height: 1.6; color: var(--text); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .8rem 1.5rem;
  background: rgba(250, 246, 239, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
[data-theme="dark"] .topbar { background: rgba(23, 21, 18, .88); }

.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 34px; padding: 0 .35rem; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-family: var(--mono); font-weight: 700; font-size: .72rem; letter-spacing: .03em;
}
.brand-text { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--ink); }

.topnav { display: flex; align-items: center; gap: 1.4rem; }
.topnav a { text-decoration: none; font-size: .92rem; font-weight: 600; color: var(--text-soft); }
.topnav a:hover { color: var(--accent); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  width: 36px; height: 36px; cursor: pointer; font-size: 1rem; text-decoration: none; color: var(--text);
}
.icon-btn:hover { border-color: var(--accent); }

.app { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

.footer {
  border-top: 1px solid var(--border);
  padding: 1.2rem 1.5rem 2rem;
  text-align: center;
  color: var(--text-soft);
  font-size: .82rem;
}
.footer p { margin: 0 0 .6rem; color: var(--text-soft); }
.footer-actions { display: flex; gap: 1.2rem; justify-content: center; flex-wrap: wrap; }
.link-btn {
  background: none; border: none; color: var(--text-soft); text-decoration: underline;
  cursor: pointer; font-size: .82rem; font-family: var(--sans); padding: 0;
}
.link-btn:hover { color: var(--accent); }
.link-btn.danger:hover { color: var(--bad); }
.file-label { display: inline-flex; }

/* ---------- Home ---------- */
.hero { text-align: center; margin-bottom: 2.4rem; }
.hero-kicker {
  display: block; font-family: var(--mono); font-size: .74rem; letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent); margin-bottom: .6rem; font-weight: 700;
}
.hero h1 { font-size: clamp(2rem, 4vw, 3rem); }
.hero p { max-width: 620px; margin: 0 auto; color: var(--text-soft); }

.continue-card {
  display: flex; align-items: center; justify-content: space-between; gap: 1.2rem; flex-wrap: wrap;
  border-left: 3px solid var(--accent); text-decoration: none; color: var(--text);
}
.continue-card .cc-label { font-family: var(--mono); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 700; }
.continue-card h3 { margin: .3rem 0 .2rem; font-size: 1.15rem; }
.continue-card p { margin: 0; color: var(--text-soft); font-size: .88rem; }

.episode-rail {
  display: flex; gap: 1rem; overflow-x: auto; padding: .3rem .1rem 1rem; scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.rail-card {
  flex: 0 0 230px; scroll-snap-align: start; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .5rem;
  transition: transform .15s ease, border-color .15s ease;
}
.rail-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.rail-card .rail-num { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.rail-card .rail-title { font-family: var(--serif); font-weight: 700; color: var(--ink); font-size: 1rem; line-height: 1.3; }
.rail-card .rail-focus { font-size: .8rem; color: var(--text-soft); }
.rail-card .rail-xp { margin-top: auto; font-family: var(--mono); font-size: .72rem; color: var(--text-soft); padding-top: .4rem; }

.track-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.4rem;
  margin-bottom: 2.4rem;
}

.track-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.6rem;
  box-shadow: var(--shadow);
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  transition: transform .15s ease, border-color .15s ease;
}
.track-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.track-eyebrow { font-size: .74rem; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.track-card h2 { font-size: 1.3rem; }
.track-card .desc { color: var(--text-soft); font-size: .92rem; margin: 0; }

.progress-bar {
  height: 8px; border-radius: 99px; background: var(--bg-alt); overflow: hidden; border: 1px solid var(--border);
}
.progress-bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s ease; }
.progress-meta { display: flex; justify-content: space-between; font-size: .78rem; color: var(--text-soft); }

.stat-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 2rem; }
.stat-pill {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px;
  padding: .4rem 1rem; font-size: .82rem; color: var(--text-soft);
}
.stat-pill b { color: var(--ink); }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 2rem 0 1rem; }
.section-title h3 { margin: 0; font-size: 1.05rem; color: var(--text-soft); text-transform: uppercase; letter-spacing: .05em; font-family: var(--sans); font-weight: 700; }

/* ---------- Breadcrumb ---------- */
.crumbs { font-size: .84rem; color: var(--text-soft); margin-bottom: 1.2rem; }
.crumbs a { text-decoration: none; color: var(--text-soft); }
.crumbs a:hover { color: var(--accent); }

/* ---------- Track view ---------- */
.track-head { margin-bottom: 1.4rem; }
.track-head h1 { margin-bottom: .3rem; }
.filter-bar { display: flex; gap: .6rem; margin: 1.2rem 0; flex-wrap: wrap; }
.filter-bar input[type="search"] {
  flex: 1; min-width: 200px; padding: .55rem .8rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-family: var(--sans); font-size: .9rem;
}
.filter-bar select {
  padding: .55rem .8rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-family: var(--sans); font-size: .9rem;
}

.npr-panel { padding: 1.2rem 1.4rem; }
.npr-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.npr-panel-head h3 { margin: 0; }
.npr-controls { display: flex; align-items: center; gap: .5rem; }
.npr-controls select {
  padding: .4rem .6rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-family: var(--sans); font-size: .84rem;
}
.npr-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.npr-list li { display: flex; align-items: baseline; justify-content: space-between; gap: .8rem; border-bottom: 1px dashed var(--border); padding-bottom: .5rem; }
.npr-list li:last-child { border-bottom: none; padding-bottom: 0; }
.npr-list a { text-decoration: none; color: var(--ink); font-size: .9rem; font-weight: 600; }
.npr-list a:hover { color: var(--accent); text-decoration: underline; }
.npr-date { font-size: .76rem; color: var(--text-soft); white-space: nowrap; flex-shrink: 0; }
.npr-status { color: var(--text-soft); font-size: .86rem; margin: 0; }
.npr-disclaimer { color: var(--text-soft); font-size: .74rem; margin: .9rem 0 0; }

.group-block { margin-bottom: 1.6rem; }
.group-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .5rem .2rem; border-bottom: 1px solid var(--border); margin-bottom: .5rem;
}
.group-head h4 { margin: 0; font-size: .98rem; color: var(--ink); }
.group-head .progress-bar { width: 110px; }

.unit-list { display: flex; flex-direction: column; gap: .5rem; }
.unit-row {
  display: flex; align-items: center; gap: .8rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: .7rem .9rem; text-decoration: none; color: var(--text);
  transition: border-color .15s ease, background .15s ease;
}
.unit-row:hover { border-color: var(--accent); background: var(--surface-2); }
.unit-row .num { font-family: var(--serif); font-weight: 700; color: var(--text-soft); width: 2rem; flex-shrink: 0; }
.unit-row .title { flex: 1; font-size: .93rem; }
.unit-row .title small { display: block; color: var(--text-soft); font-weight: 400; font-size: .78rem; margin-top: .1rem; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; background: var(--border); }
.status-dot.done { background: var(--good); }
.status-dot.progress { background: var(--amber); }
.badge-soon {
  font-size: .72rem; color: var(--text-soft); background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: 99px; padding: .15rem .6rem; flex-shrink: 0;
}

/* ---------- Unit view ---------- */
.unit-header { margin-bottom: 1.4rem; }
.unit-kicker { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 700; }
.unit-header h1 { font-size: clamp(1.4rem, 2.6vw, 1.9rem); margin-top: .25rem; }
.unit-meta { display: flex; gap: .8rem; flex-wrap: wrap; color: var(--text-soft); font-size: .84rem; margin-top: .4rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 1.4rem 1.6rem; margin-bottom: 1.2rem; box-shadow: var(--shadow);
}
.card h3 { font-size: 1rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); font-family: var(--sans); font-weight: 700; margin-bottom: .8rem; }

.key-points { margin: 0; padding-left: 1.2rem; }
.key-points li { margin-bottom: .4rem; color: var(--text); }

.example-list { display: flex; flex-direction: column; gap: .6rem; }
.example-item { border-left: 3px solid var(--accent); padding: .2rem .9rem; }
.example-item .en { font-weight: 600; color: var(--ink); }
.example-item .it { color: var(--text-soft); font-size: .88rem; }

.exercise {
  border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.1rem; margin-bottom: 1rem; background: var(--surface-2);
}
.exercise .ex-kicker { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-soft); margin-bottom: .4rem; }
.exercise .prompt { font-weight: 600; margin-bottom: .7rem; color: var(--text); }

.mcq-options { display: flex; flex-direction: column; gap: .5rem; }
.mcq-option {
  display: block; width: 100%; text-align: left; padding: .55rem .8rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-family: var(--sans); font-size: .9rem;
}
.mcq-option:hover { border-color: var(--accent); }
.mcq-option.correct { background: var(--good-soft); border-color: var(--good); }
.mcq-option.incorrect { background: var(--bad-soft); border-color: var(--bad); }
.mcq-option[disabled] { cursor: default; }

.answer-row { display: flex; gap: .6rem; flex-wrap: wrap; }
.answer-row input[type="text"] {
  flex: 1; min-width: 180px; padding: .55rem .8rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-family: var(--sans); font-size: .9rem;
}
.answer-row textarea {
  width: 100%; min-height: 70px; padding: .6rem .8rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-family: var(--sans); font-size: .9rem; resize: vertical;
}
.btn {
  padding: .55rem 1rem; border-radius: 10px; border: 1px solid var(--ink); background: var(--ink); color: var(--bg);
  cursor: pointer; font-family: var(--sans); font-size: .86rem; font-weight: 600;
}
.btn:hover { opacity: .88; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { border-color: var(--accent); color: var(--accent); }

.feedback { margin-top: .7rem; padding: .6rem .8rem; border-radius: 10px; font-size: .88rem; display: none; }
.feedback.show { display: block; }
.feedback.correct { background: var(--good-soft); color: var(--good); }
.feedback.incorrect { background: var(--bad-soft); color: var(--bad); }
.feedback.info { background: var(--amber-soft); color: var(--amber); }

.unit-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 1.6rem; flex-wrap: wrap; gap: 1rem; }
.mark-done { display: flex; align-items: center; gap: .6rem; }

/* ---------- Episode / Journey / Profile / Settings ---------- */
.episode-card .title small { display: block; margin-top: .15rem; }
.episode-card .num {
  width: 2.1rem; height: 2.1rem; display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); border-radius: 8px; font-family: var(--mono);
  font-size: .78rem; font-weight: 700; transition: background .15s ease, color .15s ease;
}
.episode-card:hover .num { background: var(--accent); color: var(--bg); }

.xp-ring-wrap { display: flex; align-items: center; gap: 1.4rem; flex-wrap: wrap; }
.xp-ring { flex-shrink: 0; }
.xp-ring-track { stroke: var(--border); }
.xp-ring-fill { stroke: var(--accent); transition: stroke-dashoffset .5s ease; }
.xp-ring text { font-family: var(--mono); fill: var(--ink); }
.xp-ring-value { font-size: 22px; font-weight: 700; }
.xp-ring-label { font-size: 10px; fill: var(--text-soft); letter-spacing: .05em; }
.xp-ring-meta { font-family: var(--mono); font-size: .84rem; color: var(--text-soft); }
.xp-ring-meta b { color: var(--ink); font-size: 1rem; }
.level-tag {
  font-family: var(--serif); font-weight: 700; color: var(--text-soft); font-size: .74rem;
  flex-shrink: 0; width: 3.4rem;
}

.checklist { display: flex; flex-direction: column; gap: .6rem; }
.checklist-item { display: flex; align-items: center; gap: .6rem; font-size: .92rem; cursor: pointer; }
.checklist-item.disabled { cursor: default; color: var(--text-soft); }
.checklist-item input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.checklist-item small { color: var(--text-soft); }

.achievement-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem;
}
.achievement-card {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem;
  background: var(--surface-2); opacity: .55;
}
.achievement-card.unlocked { opacity: 1; background: var(--surface); border-color: var(--accent); box-shadow: var(--shadow); }
.achievement-title { font-family: var(--serif); font-weight: 700; color: var(--ink); margin-bottom: .3rem; }
.achievement-desc { font-size: .84rem; color: var(--text-soft); margin-bottom: .6rem; }
.achievement-status { font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.achievement-card:not(.unlocked) .achievement-status { color: var(--text-soft); }

.prompt-kind-row { display: flex; gap: .5rem; flex-wrap: wrap; margin: .8rem 0; }
.prompt-kind-btn.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
#prompt-preview { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; }

.settings-row { margin-bottom: 1.1rem; }
.settings-row:last-child { margin-bottom: 0; }
.settings-row label { display: block; font-weight: 600; margin-bottom: .4rem; color: var(--ink); }

.empty-state {
  text-align: center; padding: 3rem 1.5rem; color: var(--text-soft);
}
.empty-state h2 { color: var(--ink); }

.soon-card { text-align: center; padding: 2.4rem 1.4rem; }
.soon-card .badge-soon { display: inline-block; margin-bottom: .8rem; }

.toast {
  position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%) translateY(120%);
  background: var(--ink); color: var(--bg); padding: .7rem 1.2rem; border-radius: 10px; font-size: .86rem;
  box-shadow: var(--shadow); transition: transform .25s ease; z-index: 50;
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .topbar { padding: .7rem 1rem; }
  .topnav { gap: .8rem; }
  .topnav a { font-size: .8rem; }
  .app { padding: 1.4rem 1rem 3rem; }
}

/* ---------- Cross-device sync ---------- */
.sync-code {
  font-family: var(--mono); font-size: .92rem; letter-spacing: .04em; padding: .45rem .7rem; border-radius: 8px;
  background: var(--accent-soft); color: var(--ink); word-break: break-all;
}
