:root {
  color-scheme: light;
  --paper: #f3f0e8;
  --paper-deep: #e9e4d8;
  --ink: #171916;
  --ink-soft: #62655d;
  --line: rgba(23, 25, 22, 0.14);
  --acid: #d8ff38;
  --acid-deep: #bfe516;
  --blue: #3157d5;
  --coral: #ef6b55;
  --surface: rgba(255, 255, 255, 0.58);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Avenir Next", Avenir, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 3%, rgba(216, 255, 56, 0.22), transparent 24rem),
    var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }

.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.045;
  z-index: 20;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.7'/%3E%3C/svg%3E");
}

.app-shell { width: min(100%, 760px); min-height: 100vh; margin: 0 auto; }

.topbar {
  height: calc(68px + var(--safe-top));
  padding: calc(14px + var(--safe-top)) 20px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(var(--paper) 70%, rgba(243, 240, 232, 0));
}

.brand {
  border: 0;
  background: transparent;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  font: 700 24px/1 var(--display);
  cursor: pointer;
}

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: var(--acid);
  font: 700 17px/1 var(--display);
  transform: rotate(-8deg);
}

.brand-dot { color: var(--blue); }

.avatar-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--coral);
  font-weight: 700;
  cursor: pointer;
}

.view { padding: 12px 20px calc(106px + var(--safe-bottom)); }

.loading-screen {
  min-height: 65vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  color: var(--ink-soft);
}

.loading-orbit {
  width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 50%;
  animation: spin 1.4s linear infinite;
}

.loading-orbit span {
  display: block;
  width: 14px;
  height: 14px;
  margin: -3px 0 0 4px;
  border-radius: 50%;
  background: var(--blue);
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.screen { animation: rise 320ms ease-out both; }
.eyebrow { font-size: 11px; line-height: 1; text-transform: uppercase; letter-spacing: 0.14em; font-weight: 800; color: var(--blue); }

h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: var(--display); letter-spacing: -0.035em; }
h1 { margin-bottom: 12px; font-size: clamp(40px, 12vw, 68px); line-height: 0.94; font-weight: 500; }
h2 { font-size: 31px; line-height: 1.02; font-weight: 500; }
h3 { font-size: 22px; line-height: 1.1; font-weight: 600; }

.hero { padding: 24px 0 30px; position: relative; }
.hero::after { content: ""; display: block; width: 68px; height: 8px; margin-top: 22px; background: var(--acid); transform: rotate(-2deg); }
.hero-copy { max-width: 36rem; margin: 0; color: var(--ink-soft); font-size: 15px; line-height: 1.55; }

.date-line { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; color: var(--ink-soft); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.11em; }
.date-line::before { content: ""; width: 22px; border-top: 1px solid currentColor; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); margin: 4px 0 34px; }
.metric { padding: 15px 12px 14px 0; border-right: 1px solid var(--line); }
.metric + .metric { padding-left: 12px; }
.metric:last-child { border-right: 0; }
.metric strong { display: block; font: 600 28px/1 var(--display); }
.metric span { display: block; margin-top: 7px; color: var(--ink-soft); font-size: 10px; line-height: 1.2; text-transform: uppercase; letter-spacing: 0.08em; }

.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin: 0 0 15px; }
.section-heading h2 { margin: 0; }
.text-button { border: 0; border-bottom: 1px solid currentColor; background: none; padding: 2px 0; color: var(--blue); font-size: 13px; font-weight: 700; cursor: pointer; }

.lesson-card {
  position: relative;
  overflow: hidden;
  min-height: 235px;
  padding: 22px;
  border: 1px solid var(--ink);
  border-radius: 3px 24px 3px 3px;
  background: var(--ink);
  color: #f7f4eb;
  box-shadow: 8px 8px 0 var(--acid);
}
.lesson-card::after { content: "↗"; position: absolute; right: 18px; top: 10px; color: var(--acid); font: 400 46px/1 var(--display); }
.lesson-card h2 { max-width: 85%; margin: 32px 0 12px; font-size: 32px; }
.lesson-card p { max-width: 32rem; color: rgba(247, 244, 235, 0.68); font-size: 14px; line-height: 1.5; }
.lesson-meta { display: flex; gap: 18px; align-items: center; font-size: 12px; color: rgba(247, 244, 235, 0.76); }
.lesson-card .primary-button { margin-top: 25px; background: var(--acid); color: var(--ink); }

.empty-lesson { padding: 28px 24px; border: 1px dashed var(--ink-soft); background: rgba(255,255,255,.22); }
.empty-lesson h3 { margin-bottom: 7px; }
.empty-lesson p { margin: 0; color: var(--ink-soft); line-height: 1.45; }

.track-list { display: grid; gap: 12px; margin-top: 40px; }
.track-card { width: 100%; padding: 18px; border: 1px solid var(--line); background: var(--surface); text-align: left; cursor: pointer; }
.track-card:hover { border-color: var(--ink); }
.track-top { display: flex; justify-content: space-between; align-items: start; gap: 15px; }
.track-card h3 { margin: 5px 0 7px; }
.track-card p { margin-bottom: 14px; color: var(--ink-soft); font-size: 13px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.status-pill { padding: 6px 8px; border-radius: 999px; background: var(--paper-deep); font-size: 9px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
.status-pill.active { background: var(--acid); }
.status-pill.generating { background: #d8e1ff; color: #2546af; }
.status-pill.failed { background: #ffe0da; color: #a3301e; }
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-rail { flex: 1; height: 4px; background: var(--paper-deep); overflow: hidden; }
.progress-rail span { display: block; height: 100%; background: var(--blue); }
.progress-row > span { font: 600 13px/1 var(--display); }

.primary-button, .secondary-button, .danger-button {
  min-height: 48px;
  border: 1px solid var(--ink);
  padding: 12px 17px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}
.primary-button { background: var(--ink); color: white; }
.primary-button:hover { background: var(--blue); }
.primary-button:disabled { opacity: .45; cursor: wait; }
.secondary-button { background: transparent; }
.danger-button { background: transparent; color: #a3301e; border-color: #a3301e; }
.full-button { width: 100%; }

.bottom-nav {
  position: fixed;
  z-index: 12;
  left: 50%;
  bottom: max(12px, var(--safe-bottom));
  transform: translateX(-50%);
  width: min(calc(100% - 28px), 520px);
  height: 66px;
  padding: 7px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid rgba(23,25,22,.8);
  border-radius: 18px;
  background: rgba(248, 246, 239, 0.9);
  backdrop-filter: blur(18px);
  box-shadow: 0 10px 35px rgba(20, 21, 19, .14);
}
.nav-item { border: 0; border-radius: 12px; background: transparent; color: var(--ink-soft); display: grid; place-items: center; align-content: center; gap: 3px; cursor: pointer; }
.nav-item svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-item span { font-size: 10px; font-weight: 700; }
.nav-item.is-active { background: var(--ink); color: var(--acid); }

.screen-header { padding: 20px 0 25px; border-bottom: 1px solid var(--ink); }
.screen-header h1 { font-size: clamp(42px, 12vw, 64px); }
.screen-header p { max-width: 36rem; margin-bottom: 0; color: var(--ink-soft); line-height: 1.5; }
.back-button { display: block; border: 0; background: none; padding: 0 0 20px; color: var(--blue); font-size: 13px; font-weight: 800; cursor: pointer; }

.route-summary { padding: 18px 0; display: flex; align-items: center; gap: 18px; }
.route-ring { --progress: 0deg; width: 64px; height: 64px; flex: 0 0 auto; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--acid-deep) var(--progress), var(--paper-deep) 0); position: relative; }
.route-ring::after { content: ""; position: absolute; inset: 7px; border-radius: inherit; background: var(--paper); }
.route-ring strong { position: relative; z-index: 1; font: 600 16px var(--display); }
.route-summary p { margin: 3px 0 0; color: var(--ink-soft); font-size: 13px; }

.roadmap-section { padding: 26px 0 8px; }
.section-index { color: var(--blue); font: italic 18px var(--display); }
.roadmap-section h2 { margin: 3px 0 7px; font-size: 28px; }
.section-copy { margin-bottom: 22px; color: var(--ink-soft); font-size: 13px; line-height: 1.5; }
.roadmap-nodes { margin-left: 11px; border-left: 1px solid var(--line); }
.roadmap-node { position: relative; width: calc(100% + 11px); margin-left: -11px; padding: 0 0 22px 42px; border: 0; background: none; text-align: left; cursor: pointer; }
.node-dot { position: absolute; left: 0; top: 0; width: 23px; height: 23px; display: grid; place-items: center; border: 1px solid var(--ink); border-radius: 50%; background: var(--paper); font-size: 11px; font-weight: 900; }
.roadmap-node.mastered .node-dot { background: var(--acid); }
.roadmap-node.skipped { opacity: .48; }
.roadmap-node.in_progress .node-dot { background: var(--blue); color: white; box-shadow: 0 0 0 5px rgba(49,87,213,.12); }
.roadmap-node strong { display: block; padding-top: 1px; font-size: 14px; }
.roadmap-node small { display: block; margin-top: 5px; color: var(--ink-soft); font-size: 11px; }

.lesson-page .screen-header { border: 0; }
.lesson-page h1 { font-size: clamp(38px, 11vw, 60px); }
.lesson-intro { margin: 0 -20px; padding: 22px 20px; background: var(--acid); }
.lesson-intro p { margin: 0; line-height: 1.55; }
.lesson-section { padding: 30px 0; border-bottom: 1px solid var(--line); }
.lesson-section > h2 { display: flex; gap: 12px; align-items: baseline; }
.lesson-section > h2 span { color: var(--blue); font: italic 15px var(--display); }
.theory-block { font-size: 15px; line-height: 1.65; }
.theory-block + .theory-block { margin-top: 18px; }
.theory-block.bullets { white-space: pre-line; padding-left: 18px; border-left: 3px solid var(--acid-deep); }
pre { margin: 18px -4px 0; padding: 18px; overflow-x: auto; border-radius: 3px; background: #20231f; color: #eff6d0; font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; }
.numbered-list { list-style: none; padding: 0; counter-reset: item; }
.numbered-list li { counter-increment: item; display: grid; grid-template-columns: 26px 1fr; gap: 10px; margin: 13px 0; line-height: 1.5; }
.numbered-list li::before { content: counter(item, decimal-leading-zero); color: var(--blue); font: italic 13px var(--display); }

.quiz-item { padding: 20px 0; border-top: 1px solid var(--line); }
.quiz-item:first-of-type { border-top: 0; }
.quiz-item h3 { font-family: var(--sans); font-size: 15px; letter-spacing: 0; line-height: 1.4; }
.quiz-option { width: 100%; min-height: 46px; margin-top: 8px; padding: 10px 13px; display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); background: rgba(255,255,255,.32); text-align: left; cursor: pointer; }
.quiz-option span { width: 22px; height: 22px; flex: 0 0 auto; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; font-size: 10px; }
.quiz-option.selected { border-color: var(--blue); background: #e3e8ff; }
.quiz-option.correct { border-color: #367527; background: #e6f5d9; }
.quiz-option.wrong { border-color: #b44532; background: #ffe3dc; }
.quiz-explanation { margin: 9px 0 0; color: var(--ink-soft); font-size: 12px; line-height: 1.45; }
.lesson-actions { display: grid; gap: 10px; padding-top: 28px; }

.settings-block { padding: 26px 0; border-bottom: 1px solid var(--line); }
.settings-block h2 { margin-bottom: 8px; }
.settings-block > p { color: var(--ink-soft); font-size: 13px; line-height: 1.5; }
label { display: grid; gap: 8px; font-size: 12px; font-weight: 800; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 0; background: rgba(255,255,255,.5); color: var(--ink); padding: 13px; outline: none; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(49,87,213,.12); }
.inline-setting { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.inline-setting input { min-width: 120px; }
.focus-tags { display: flex; gap: 7px; flex-wrap: wrap; }
.focus-tags span { padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 11px; }

.sheet-dialog { width: 100%; max-width: 760px; height: 100%; max-height: none; margin: 0 auto; padding: 0; border: 0; background: transparent; }
.sheet-dialog::backdrop { background: rgba(14,16,14,.48); backdrop-filter: blur(4px); }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; padding: 12px 20px calc(26px + var(--safe-bottom)); display: grid; gap: 18px; border-radius: 24px 24px 0 0; background: var(--paper); box-shadow: 0 -10px 50px rgba(10,12,10,.18); animation: sheet-in 260ms ease-out; }
@keyframes sheet-in { from { transform: translateY(30%); opacity: 0; } }
.sheet-handle { width: 40px; height: 4px; margin: 0 auto 4px; border-radius: 3px; background: var(--line); }
.sheet-heading { display: flex; justify-content: space-between; align-items: start; gap: 20px; }
.sheet-heading h2 { margin: 5px 0 0; }
.icon-button { width: 36px; height: 36px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 50%; background: transparent; font-size: 22px; line-height: 1; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-note { margin: 0; color: var(--ink-soft); font-size: 11px; line-height: 1.45; }
.node-actions { display: grid; gap: 9px; }
.node-description { margin: 0; color: var(--ink-soft); line-height: 1.55; }

.toast { position: fixed; z-index: 30; left: 50%; bottom: calc(92px + var(--safe-bottom)); width: min(calc(100% - 36px), 480px); padding: 13px 16px; transform: translate(-50%, 20px); border: 1px solid var(--ink); background: var(--ink); color: white; font-size: 12px; line-height: 1.4; opacity: 0; pointer-events: none; transition: 180ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #8f2f20; }

@media (min-width: 720px) {
  .view { padding-left: 34px; padding-right: 34px; }
  .topbar { padding-left: 34px; padding-right: 34px; }
  .track-list { grid-template-columns: 1fr 1fr; }
  .lesson-intro { margin-left: -34px; margin-right: -34px; padding-left: 34px; padding-right: 34px; }
  .sheet { padding-left: 34px; padding-right: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
