/* Registered so rings and meters can animate their fill. */
@property --value {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

/* ---------- Reading progress ---------- */

.progress-bar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 45;
  height: 3px;
  pointer-events: none;
}

.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  transform: scaleX(0);
  transform-origin: left;
}

/* ---------- Lesson header ---------- */

.lesson-hero {
  padding-top: calc(var(--header-h) + clamp(2rem, 6vh, 4.5rem));
  padding-bottom: var(--space-6);
}

.lesson-hero__grid {
  display: grid;
  gap: var(--space-5);
  align-items: end;
}

@media (min-width: 64rem) {
  .lesson-hero__grid {
    grid-template-columns: minmax(0, 1fr) 22rem;
  }
}

.crumbs ol {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--on-wall-muted);
}

.crumbs li + li::before {
  content: "/";
  margin-right: 0.5rem;
  opacity: 0.6;
}

.crumbs a {
  text-decoration-color: var(--rule-wall);
}

.lesson-hero__eyebrow {
  margin-top: var(--space-4);
}

.lesson-hero__title {
  margin-top: 0.5rem;
  font-family: var(--font-display);
  font-size: clamp(3.25rem, 1.5rem + 7vw, 7rem);
  line-height: 1;
  text-shadow: 0 2px 24px rgb(40 10 6 / 0.35);
}

.lesson-hero__lead {
  max-width: 46ch;
  margin-top: var(--space-3);
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--on-wall-muted);
}

.lesson-hero__facts {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: var(--space-4);
}

.lesson-hero__facts li {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.95rem;
  border: 1px solid var(--rule-wall);
  border-radius: var(--r-pill);
  background: rgb(33 17 16 / 0.3);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
}

.lesson-hero__facts .icon {
  width: 1rem;
  height: 1rem;
  color: var(--gold);
}

.lesson-hero__actions {
  margin-top: var(--space-4);
}

.lesson-hero__actions .icon {
  width: 1.1rem;
  height: 1.1rem;
}

/* ---------- Progress card and ring ---------- */

.progress-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1.25rem;
  align-items: center;
  padding: 1.6rem;
}

.progress-card__ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 108px;
  height: 108px;
  transition: --value 1.1s var(--ease-out);
}

.progress-card__ring::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--gold) calc(var(--value) * 1turn), rgb(246 236 220 / 0.12) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 9px), #000 calc(100% - 8px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 9px), #000 calc(100% - 8px));
}

.progress-card__ring span {
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--on-night-muted);
  font-variant-numeric: lining-nums;
}

.progress-card__ring b {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  color: var(--plaster);
}

.progress-card__title {
  font-family: var(--font-display);
  font-size: 1.35rem;
}

.progress-card__label {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--gold);
}

.progress-card__parts {
  list-style: none;
  padding: 0;
  margin-top: 0.75rem;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
}

.progress-card__parts li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-block: 0.15rem;
  color: var(--on-night-muted);
}

.progress-card__parts .icon {
  width: 1rem;
  height: 1rem;
  color: rgb(246 236 220 / 0.25);
  transition: color 0.4s, scale 0.4s var(--ease-spring);
}

.progress-card__parts .is-done {
  color: var(--plaster);
}

.progress-card__parts .is-done .icon {
  color: var(--gold);
  scale: 1.1;
}

.progress-card__best {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule-night);
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--on-night-muted);
}

.progress-card__best b {
  display: block;
  font-weight: 600;
  color: var(--plaster);
}

/* ---------- Layout ---------- */

.lesson {
  display: grid;
  gap: var(--space-5);
  padding-bottom: var(--space-7);
}

.toc {
  display: none;
}

@media (min-width: 64rem) {
  .lesson {
    grid-template-columns: 14rem minmax(0, 1fr);
  }

  .toc {
    display: block;
  }
}

.toc__nav {
  position: sticky;
  top: calc(var(--header-h) + 1.5rem);
  padding: 1.1rem;
  border: 1px solid var(--rule-wall);
  border-radius: var(--r-lg);
  background: rgb(33 17 16 / 0.3);
}

.toc__title {
  padding: 0 0.6rem 0.6rem;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--on-wall-muted);
}

.toc__list {
  list-style: none;
  padding: 0;
}

.toc__list a {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem;
  border-radius: var(--r-sm);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--on-wall-muted);
  text-decoration: none;
  transition:
    background-color 0.3s,
    color 0.3s;
}

.toc__list a:hover {
  background: rgb(255 255 255 / 0.06);
  color: var(--plaster);
}

.toc__list a.is-active {
  background: rgb(255 255 255 / 0.1);
  color: var(--plaster);
}

.toc__list .icon {
  width: 1.05rem;
  height: 1.05rem;
}

.toc__check {
  margin-left: auto;
  color: var(--gold);
  opacity: 0;
  scale: 0.4;
  transition:
    opacity 0.3s,
    scale 0.45s var(--ease-spring);
}

.toc__list .is-done .toc__check {
  opacity: 1;
  scale: 1;
}

.toc__meter {
  margin: 0.9rem 0.6rem 0.2rem;
}

/* ---------- Blocks ---------- */

.block + .block {
  margin-top: var(--space-7);
}

.block__head {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-3);
  align-items: start;
  margin-bottom: var(--space-4);
}

.block__badge {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: var(--night);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.4), var(--shadow-sm);
}

.block__badge .icon {
  width: 1.5rem;
  height: 1.5rem;
}

.block__kicker {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--on-wall-muted);
}

.block__title {
  margin-top: 0.3rem;
  font-family: var(--font-display);
  font-size: var(--text-xl);
}

.block__sub {
  max-width: 56ch;
  margin-top: 0.6rem;
  font-size: var(--text-md);
  line-height: 1.5;
  color: var(--on-wall-muted);
}

@media (max-width: 30rem) {
  .block__head {
    grid-template-columns: 1fr;
  }
}

/* ---------- Vocabulary flashcards ---------- */

.vocab {
  padding: clamp(1.25rem, 0.75rem + 2vw, 2rem);
}

.vocab__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.vocab__filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.vocab__flip-all .icon {
  width: 1rem;
  height: 1rem;
}

.flashcards {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 7rem), 1fr));
  gap: 0.65rem;
  margin-top: var(--space-3);
}

@media (min-width: 40rem) {
  .flashcards {
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
    gap: 0.9rem;
  }
}

@media (max-width: 30rem) {
  .flashcard__face {
    padding: 0.7rem 0.8rem;
  }

  .flashcard__word {
    font-size: 1.3rem;
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    scale: 0.94;
  }
}

.flashcards li {
  animation: card-in 0.45s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 25ms);
}

.flashcard {
  display: block;
  width: 100%;
  aspect-ratio: 5 / 4;
  padding: 0;
  border: 0;
  border-radius: var(--r-md);
  background: none;
  perspective: 900px;
}

.flashcard__inner {
  position: relative;
  display: block;
  height: 100%;
  transform-style: preserve-3d;
  transition:
    transform 0.7s var(--ease-out),
    translate 0.35s var(--ease-out);
}

.flashcard:hover .flashcard__inner {
  translate: 0 -3px;
}

.flashcard[aria-pressed="true"] .flashcard__inner {
  transform: rotateY(180deg);
}

.flashcard__face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 0.85rem 1rem;
  border-radius: var(--r-md);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  text-align: left;
}

.flashcard__front {
  justify-content: space-between;
  background-color: var(--parchment);
  background-image: var(--parchment-fibre);
  color: var(--ink);
  box-shadow: var(--shadow-sm), inset 0 0 0 1px rgb(35 21 15 / 0.08);
}

.flashcard__back {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--wall-glow), var(--wall-deep));
  color: var(--plaster);
  text-align: center;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgb(255 255 255 / 0.12);
  transform: rotateY(180deg);
}

.flashcard__type {
  font-family: var(--font-ui);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--wall);
}

.flashcard__word {
  font-size: clamp(1.45rem, 1.2rem + 0.8vw, 1.8rem);
  font-style: italic;
  line-height: 1.1;
}

.flashcard__hint {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ink-muted);
}

.flashcard__hint::before {
  content: "↻";
  font-size: 1rem;
  line-height: 1;
}

/* A gold dot marks cards already seen. */
.flashcard__front::after {
  content: "";
  position: absolute;
  top: 0.85rem;
  right: 0.9rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold-ink);
  scale: 0;
  transition: scale 0.4s var(--ease-spring);
}

.flashcard.is-seen .flashcard__front::after {
  scale: 1;
}

.flashcard__meaning {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 1.15rem + 0.8vw, 1.75rem);
  line-height: 1.1;
}

.flashcard__note {
  margin-top: 0.4rem;
  font-size: var(--text-sm);
  font-style: italic;
  line-height: 1.3;
  color: rgb(246 236 220 / 0.88);
}

.vocab__foot {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: var(--space-3);
}

.vocab__meter {
  flex: 1;
}

.vocab__meter > span {
  width: calc(var(--seen, 0) * 100%);
}

.vocab__count {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  color: var(--on-night-muted);
  font-variant-numeric: lining-nums tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .flashcard[aria-pressed="true"] .flashcard__inner {
    transform: none;
  }

  .flashcard__back {
    transform: none;
    opacity: 0;
  }

  .flashcard[aria-pressed="true"] .flashcard__back {
    opacity: 1;
  }

  .flashcard[aria-pressed="true"] .flashcard__front {
    opacity: 0;
  }
}

/* ---------- Case explorer ---------- */

.cases {
  display: grid;
  overflow: hidden;
}

.cases__list {
  display: flex;
  gap: 0.25rem;
  padding: 0.75rem;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--rule-night);
  background: rgb(0 0 0 / 0.14);
}

.cases__tab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 44px;
  padding: 0.55rem 0.9rem;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--on-night-muted);
  text-align: left;
  white-space: nowrap;
  transition:
    background-color 0.25s,
    color 0.25s;
}

.cases__tab:hover {
  background: rgb(255 255 255 / 0.05);
  color: var(--plaster);
}

.cases__tab[aria-selected="true"] {
  background: rgb(227 176 75 / 0.14);
  color: var(--plaster);
}

.cases__ending {
  font-family: var(--font-text);
  font-size: var(--text-base);
  font-style: italic;
  color: var(--gold);
}

.cases__panel {
  padding: clamp(1.5rem, 1rem + 2.5vw, 3rem);
  animation: rise 0.5s var(--ease-out) both;
}

.cases__name {
  font-family: var(--font-display);
  font-size: var(--text-xl);
}

.cases__use {
  max-width: 42ch;
  margin-top: 0.5rem;
  font-size: var(--text-md);
  color: var(--on-night-muted);
}

.cases__example {
  margin-top: var(--space-4);
  font-size: clamp(2rem, 1.4rem + 2.4vw, 3.25rem);
  font-style: italic;
  line-height: 1.15;
}

.cases__example .end {
  position: relative;
  color: var(--gold);
}

@keyframes end-line {
  to {
    scale: 1 1;
  }
}

.cases__example .end::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.02em;
  height: 2px;
  border-radius: 2px;
  background: var(--gold);
  scale: 0 1;
  transform-origin: left;
  animation: end-line 0.6s var(--ease-out) 0.3s forwards;
}

.cases__tr {
  margin-top: 0.5rem;
  font-size: var(--text-md);
  color: var(--on-night-muted);
}

.cases__forms {
  padding: 1.25rem clamp(1.5rem, 1rem + 2.5vw, 3rem) 1.6rem;
  border-top: 1px solid var(--rule-night);
}

.cases__forms-title {
  font-family: var(--font-ui);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.cases__forms-title i {
  font-family: var(--font-text);
  font-size: 1.15em;
  letter-spacing: 0;
  text-transform: none;
}

.cases__strip {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr));
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.cases__strip li {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--rule-night);
  border-radius: var(--r-sm);
  transition:
    background-color 0.3s,
    border-color 0.3s;
}

.cases__strip span {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--on-night-muted);
}

.cases__strip b {
  font-size: var(--text-md);
  font-style: italic;
  font-weight: 400;
}

.cases__strip em {
  font-style: inherit;
  color: var(--gold);
}

.cases__strip .is-current {
  border-color: rgb(227 176 75 / 0.7);
  background: rgb(227 176 75 / 0.12);
}

@media (min-width: 52rem) {
  .cases {
    grid-template-columns: 15rem minmax(0, 1fr);
  }

  .cases__list {
    flex-direction: column;
    overflow: visible;
    border-bottom: 0;
    border-right: 1px solid var(--rule-night);
  }

  .cases__tab[aria-selected="true"]::before {
    content: "";
    position: absolute;
    left: -0.75rem;
    top: 0.5rem;
    bottom: 0.5rem;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--gold);
  }

  .cases__forms {
    grid-column: 1 / -1;
  }
}

/* ---------- Etymology ---------- */

.segmented {
  position: relative;
  display: inline-flex;
  max-width: 100%;
  padding: 4px;
  border: 1px solid var(--rule-wall);
  border-radius: var(--r-pill);
  background: rgb(33 17 16 / 0.5);
  box-shadow: inset 0 1px 3px rgb(0 0 0 / 0.3);
}

.segmented__thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  width: var(--w, 0);
  border-radius: var(--r-pill);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.4), var(--shadow-sm);
  translate: var(--x, 0) 0;
  transition:
    translate 0.45s var(--ease-out),
    width 0.45s var(--ease-out);
}

.segmented__tab {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.5rem 1.15rem;
  border: 0;
  border-radius: var(--r-pill);
  background: none;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--on-wall-muted);
  white-space: nowrap;
  transition: color 0.3s;
}

.segmented__tab:hover {
  color: var(--plaster);
}

.segmented__tab[aria-selected="true"] {
  color: var(--night);
}

.segmented__tab .icon {
  width: 1.1rem;
  height: 1.1rem;
}

@media (max-width: 30rem) {
  .segmented {
    display: flex;
    width: 100%;
  }

  .segmented__tab {
    flex: 1 1 auto;
    padding-inline: 0.5rem;
    font-size: var(--text-xs);
  }

  .segmented__tab .icon {
    display: none;
  }
}

.etym__panel {
  margin-top: var(--space-4);
}

.etym__panel:focus-visible {
  outline-offset: 6px;
  border-radius: var(--r-sm);
}

.etym__intro {
  max-width: 60ch;
  color: var(--on-wall-muted);
}

.roots {
  list-style: none;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  gap: 0.9rem;
  margin-top: var(--space-3);
}

.root {
  padding: 1.2rem 1.35rem 1.3rem;
  border: 1px solid rgb(246 236 220 / 0.08);
  border-radius: var(--r-md);
  background: linear-gradient(180deg, var(--night-2), var(--night));
  box-shadow: var(--highlight), var(--shadow-sm);
  transition:
    transform 0.35s var(--ease-out),
    box-shadow 0.35s,
    border-color 0.35s;
}

.root:hover {
  transform: translateY(-3px);
  border-color: rgb(227 176 75 / 0.35);
  box-shadow: var(--highlight), var(--shadow-md);
}

.root__term {
  font-size: var(--text-lg);
  font-style: italic;
  line-height: 1.2;
}

.root__meaning {
  margin-top: 0.3rem;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--gold);
}

.root__meaning i {
  font-family: var(--font-text);
  font-size: 1.1em;
}

.root__use {
  margin-top: 0.5rem;
  color: var(--on-night-muted);
}

.root__use b {
  font-weight: inherit;
  color: var(--gold);
}

.etym__panel.is-entering .root {
  animation: rise 0.55s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 40ms);
}

/* ---------- Next chapter ---------- */

.lesson-next {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: var(--space-6);
  padding-top: var(--space-3);
  border-top: 1px solid var(--rule-wall);
}

.lesson-next__soon {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  color: var(--on-wall-muted);
}

.lesson-next__soon .icon {
  width: 1rem;
  height: 1rem;
}

.lesson-next__soon span {
  font-family: var(--font-text);
  font-size: var(--text-base);
  font-style: italic;
}
