@font-face {
  font-family: "Anton";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/anton-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Anton";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/anton-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/nunito-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Nunito";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("fonts/nunito-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --cream: #F6EFE1;
  --cream-2: #EDE4D2;
  --cream-3: #E3D8C2;
  --brown: #4C2A1B;
  --brown-soft: rgba(76, 42, 27, 0.72);
  --brown-faint: rgba(76, 42, 27, 0.12);
  --sage: #5F6E55;
  --sage-deep: #4A5642;
  --gold: #D4C247;
  --gold-deep: #B89E2C;
  --white: #FFFaf3;
  --danger: #8B3A2A;
  --top: calc(56px + env(safe-area-inset-top, 0px));
  --nav: calc(80px + env(safe-area-inset-bottom, 0px));
  --pad: 16px;
  --radius: 16px;
  --shadow: 0 1px 0 rgba(76, 42, 27, 0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--brown);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100%;
  height: 100%;
}
body {
  overscroll-behavior: none;
}
button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button {
  appearance: none;
  border: 0;
  background: none;
  cursor: pointer;
}
a { color: var(--sage); }
a.btn { text-decoration: none; color: inherit; }

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--cream);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(10px + env(safe-area-inset-top, 0px)) var(--pad) 10px;
  background: var(--cream);
  border-bottom: 1px solid var(--brown-faint);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  font-family: "Anton", sans-serif;
  font-size: 28px;
  letter-spacing: 0.02em;
  line-height: 1;
  color: var(--brown);
}
.top-meta {
  text-align: right;
  font-size: 12px;
  font-weight: 700;
  color: var(--brown-soft);
  line-height: 1.3;
}
.top-meta strong {
  display: block;
  color: var(--brown);
  font-size: 13px;
}

.screen {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px var(--pad) calc(var(--nav) + 24px);
  -webkit-overflow-scrolling: touch;
}

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  height: var(--nav);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  background: var(--white);
  border-top: 1px solid var(--brown-faint);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}
.nav button {
  min-height: 48px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brown-soft);
}
.nav button[aria-current="page"] {
  background: var(--cream-2);
  color: var(--brown);
}
.nav .ico {
  font-family: "Anton", sans-serif;
  font-size: 15px;
  line-height: 1;
  color: var(--sage);
}

.banner {
  background: var(--cream-2);
  border: 1px solid var(--cream-3);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 14px;
}
.banner button.linkish {
  display: inline;
  padding: 0;
  color: var(--sage);
  font-weight: 800;
  text-decoration: underline;
}

.grade-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.grade-card, .streak-card {
  flex: 1;
  background: var(--white);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  min-height: 70px;
}
.kicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--brown-soft);
  margin-bottom: 2px;
}
.grade-letter {
  font-family: "Anton", sans-serif;
  font-size: 36px;
  line-height: 1;
}
.grade-letter.green { color: var(--sage); }
.grade-letter.ok { color: var(--gold-deep); }
.grade-letter.low { color: var(--danger); }
.sub {
  font-size: 13px;
  color: var(--brown-soft);
  font-weight: 600;
}

.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.card h2, .section-title {
  font-family: "Anton", sans-serif;
  font-size: 22px;
  font-weight: 400;
  margin: 0 0 6px;
  letter-spacing: 0.01em;
}
.card h3 {
  font-family: "Anton", sans-serif;
  font-size: 18px;
  font-weight: 400;
  margin: 0 0 6px;
}
.muted, .intro {
  color: var(--brown-soft);
  font-size: 14px;
  margin: 0 0 10px;
}
.meta-line {
  font-size: 12px;
  font-weight: 700;
  color: var(--sage);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 15px;
  background: var(--cream-2);
  color: var(--brown);
}
.btn.primary {
  background: var(--brown);
  color: var(--cream);
}
.btn.sage {
  background: var(--sage);
  color: var(--cream);
}
.btn.gold {
  background: var(--gold);
  color: var(--brown);
}
.btn:disabled {
  opacity: 0.45;
}
.btn.wide { flex: 1 1 140px; min-width: 140px; }
.btn.full { flex: 1 1 100%; width: 100%; }

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 48px;
  padding: 8px 0;
  border-top: 1px solid var(--brown-faint);
}
.check-row:first-of-type { border-top: 0; }
.check {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  border: 2px solid var(--brown);
  border-radius: 8px;
  background: var(--white);
  display: grid;
  place-items: center;
}
.check[aria-pressed="true"] {
  background: var(--sage);
  border-color: var(--sage);
}
.check[aria-pressed="true"]::after {
  content: "";
  width: 7px;
  height: 12px;
  border: solid var(--cream);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg) translateY(-1px);
}
.check-row .label {
  flex: 1;
  font-weight: 700;
  padding-top: 4px;
}

.counter {
  background: var(--white);
  border-radius: 20px;
  padding: 16px 14px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  text-align: center;
}
.counter.hero .value {
  font-size: 72px;
}
.counter .value {
  font-family: "Anton", sans-serif;
  font-size: 48px;
  line-height: 0.95;
  color: var(--brown);
}
.counter.done .value { color: var(--sage); }
.counter .denom {
  font-family: "Nunito", sans-serif;
  font-size: 18px;
  font-weight: 800;
  color: var(--brown-soft);
}
.stepper {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.stepper button {
  min-width: 56px;
  min-height: 56px;
  border-radius: 16px;
  background: var(--cream-2);
  font-family: "Anton", sans-serif;
  font-size: 22px;
  color: var(--brown);
}
.stepper button.plus {
  background: var(--sage);
  color: var(--cream);
}
.stepper button.minus {
  background: var(--cream-3);
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 0;
}
.seg button {
  flex: 1 1 auto;
  min-height: 44px;
  min-width: 90px;
  padding: 0 10px;
  border-radius: 12px;
  background: var(--cream-2);
  font-weight: 800;
  font-size: 13px;
}
.seg button[aria-pressed="true"] {
  background: var(--brown);
  color: var(--cream);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  background: var(--white);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.toggle-row .txt { font-weight: 800; }
.switch {
  flex: 0 0 56px;
  width: 56px;
  height: 34px;
  border-radius: 999px;
  background: var(--cream-3);
  position: relative;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--white);
  transition: transform 0.15s ease;
}
.switch[aria-pressed="true"] { background: var(--sage); }
.switch[aria-pressed="true"]::after { transform: translateX(22px); }

.bar {
  height: 8px;
  background: var(--cream-3);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 0;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--sage);
  border-radius: 999px;
  min-width: 0;
}
.bar.gold > span { background: var(--gold); }

.history {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.chip {
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  background: var(--cream-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  font-weight: 800;
  font-size: 11px;
  color: var(--brown-soft);
}
.chip .ltr {
  font-family: "Anton", sans-serif;
  font-size: 16px;
  color: var(--brown);
  line-height: 1;
}
.chip.green { background: #dce5d4; }
.chip.green .ltr { color: var(--sage-deep); }
.chip.today { outline: 2px solid var(--brown); }

.module {
  background: var(--white);
  border-radius: var(--radius);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.module > button.head {
  width: 100%;
  text-align: left;
  min-height: 56px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.module > button.head .name {
  font-family: "Anton", sans-serif;
  font-size: 18px;
}
.module > button.head .count {
  font-size: 12px;
  font-weight: 800;
  color: var(--brown-soft);
  white-space: nowrap;
}
.module .body { padding: 0 14px 12px; }
.lesson {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid var(--brown-faint);
  min-height: 52px;
}
.lesson .title { font-weight: 700; font-size: 15px; padding-top: 3px; }
.lesson a.ext, a.ext {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
  color: var(--sage);
  text-decoration: none;
  white-space: nowrap;
}
.locked {
  background: var(--cream-2);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.locked h3 { margin: 0 0 6px; font-family: "Anton", sans-serif; font-size: 18px; }

.step-block { margin: 12px 0; }
.step-block .st {
  font-weight: 800;
  margin-bottom: 4px;
}
.prompt {
  background: var(--cream);
  border: 1px solid var(--cream-3);
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 8px 0;
  max-height: 240px;
  overflow: auto;
}
.lesson-full + .lesson-full {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 2px solid var(--cream-3);
}

.field {
  margin: 10px 0;
}
.field label {
  display: block;
  font-weight: 800;
  font-size: 13px;
  margin-bottom: 6px;
}
.field input, .field select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--cream-3);
  border-radius: 12px;
  background: var(--white);
  padding: 0 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav) + 12px);
  transform: translateX(-50%);
  z-index: 50;
  background: var(--brown);
  color: var(--cream);
  font-weight: 800;
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 14px;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast[hidden] { display: none; }

.note {
  font-size: 13px;
  color: var(--brown-soft);
  margin: 8px 0 0;
}
.list {
  margin: 0;
  padding-left: 18px;
}
.list li { margin: 0 0 6px; }

.progress-line {
  font-size: 13px;
  font-weight: 800;
  color: var(--brown-soft);
  margin: 0 0 8px;
}

@media (min-width: 540px) {
  #app { max-width: 430px; margin: 0 auto; box-shadow: 0 0 0 1px var(--brown-faint); }
  .nav { max-width: 430px; left: 50%; transform: translateX(-50%); }
}
