:root {
  color: #18212b;
  background: #f6f3ed;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 100%;
  line-height: 1.55;
  --ink: #18212b;
  --muted: #59636d;
  --paper: #fffdf9;
  --wash: #f6f3ed;
  --brand: #c94f16;
  --brand-dark: #8e310d;
  --navy: #16324a;
  --border: #d8d2c8;
  --error: #a32121;
  --success: #17643a;
  --focus: #075fa8;
  --shadow: 0 1rem 3rem rgb(37 30 22 / 10%);
  --tile-size: 0.75rem;
}

/* Practice level hues (in-1971). The level tab and the segments of the words
   bar name each level by its belt (White, Yellow, Green, Blue, Black,
   Themes), so the hues are those belts as birds, the same in every course:
   snow owl, canary, parakeet, mountain bluebird, blackbird and peacock for
   the themes. They stay light enough to read on the dark status band (the
   blackbird is a slate, not pure black) and, tinted, behind the question. */
:root {
  --level-0: #d4dce3;
  --level-1: #f2c40c;
  --level-2: #5fb233;
  --level-3: #5b9fe0;
  --level-4: #656b72;
  --level-5: #1a8fa0;
}

/* Course palettes (in-1961). The selected course's target language sets
   data-course on the root element. Each palette has a dark band colour for the
   practice status bar and the colours of the tile border under the band: its
   ground, the two alternating tiles and their centre dot. Without a course
   the Spanish palette applies: the terracotta brand with a deep azulejo
   blue. */
:root,
:root[data-course="es"] {
  --course-band: #1c3058;
  --tile-ground: #ecb22e;
  --tile-a: #c9562c;
  --tile-b: #2b5fb4;
  --tile-dot: #fffdf9;
}

/* English: pillar-box red, daffodil, racing green and royal blue. */
:root[data-course="en"] {
  --course-band: #7d1a2a;
  --tile-ground: #fffdf9;
  --tile-a: #1f3a7a;
  --tile-b: #c8102e;
  --tile-dot: #fffdf9;
}

/* Dutch: orange with Delft blue tiles, Gouda yellow and tulip colours. */
:root[data-course="nl"] {
  --course-band: #853507;
  --tile-ground: #fffdf9;
  --tile-a: #2a4fa3;
  --tile-b: #6f8fd0;
  --tile-dot: #fffdf9;
}

/* German: anthracite with red and gold, fir green and cornflower blue. */
:root[data-course="de"] {
  --course-band: #25272c;
  --tile-ground: #e8b620;
  --tile-a: #1d1d20;
  --tile-b: #c9382c;
  --tile-dot: #e8b620;
}

/* French: Provence lavender with poppy, mimosa, lime tree and bleu de France. */
:root[data-course="fr"] {
  --course-band: #37296a;
  --tile-ground: #f3ead7;
  --tile-a: #8f74c9;
  --tile-b: #6f8f45;
  --tile-dot: #f0c13b;
}

/* Italian: cypress green with tomato, lemon, basil, azure and burnt sienna. */
:root[data-course="it"] {
  --course-band: #23472f;
  --tile-ground: #f6f1e4;
  --tile-a: #2f7d46;
  --tile-b: #cf3b2c;
  --tile-dot: #f6f1e4;
}

/* Portuguese: Atlantic teal with roof-tile red, azulejo blue and jacaranda. */
:root[data-course="pt"] {
  --course-band: #0c4a55;
  --tile-ground: #fffdf9;
  --tile-a: #2d5fb3;
  --tile-b: #e0a81c;
  --tile-dot: #fffdf9;
}

/* Swedish: flag blue and yellow with Falu red, forest, blueberry and lingon. */
:root[data-course="sv"] {
  --course-band: #084f84;
  --tile-ground: #f4c430;
  --tile-a: #084f84;
  --tile-b: #c9483a;
  --tile-dot: #f4c430;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 20rem;
}

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
}

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

button,
select {
  cursor: pointer;
}

a {
  color: var(--brand-dark);
}

:focus-visible {
  outline: 0.2rem solid var(--focus);
  outline-offset: 0.2rem;
}

.skip-link {
  position: fixed;
  z-index: 20;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.65rem 1rem;
  color: white;
  background: var(--navy);
  border-radius: 0.35rem;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.site-header,
#primary-navigation {
  /* Header-only aubergine palette (in-1521); the global tokens are re-themed separately.
     The navigation carries it too, because Practice moves it out of the header (in-1972). */
  --header-top: #40152f;
  --header-bottom: #15040c;
  --header-ink: #fbf6ef;
  --header-accent: #40152f;
  --header-focus: #ffc2e2;
}

.site-header {
  position: relative;
  min-height: 4.75rem;
  padding: 0.75rem clamp(1rem, 4vw, 4rem);
  display: flex;
  align-items: center;
  gap: clamp(1rem, 1.25vw, 2.5rem);
  color: white;
  background: linear-gradient(to bottom, var(--header-top), var(--header-bottom));
}

/* Practice has no site header (in-1972). */
.site-header[hidden] {
  display: none;
}

/* --focus is too dark on aubergine, so header controls get a light ring (in-1521). */
.site-header :focus-visible,
#primary-navigation :focus-visible {
  outline-color: var(--header-focus);
}

.brand {
  display: inline-flex;
  align-items: center;
  color: white;
  text-decoration: none;
}

.brand-logo {
  width: 15rem;
  height: auto;
  /* The supplied image has black letterboxing outside the artwork. Leave a two-pixel inset to avoid edge sampling.
     Crop it from the displayed box while retaining the high-DPI source (in-1811). */
  aspect-ratio: 2172 / 346;
  display: block;
  object-fit: cover;
  object-position: center;
}

/* The primary navigation is a menu button with a dropdown list (in-1968). */
#primary-navigation {
  position: relative;
  flex: none;
}

.menu-button {
  min-height: 2.65rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid rgb(255 255 255 / 45%);
  border-radius: 0.35rem;
  color: var(--header-ink);
  background: transparent;
  font: inherit;
  font-size: 0.925rem;
  font-weight: 650;
  cursor: pointer;
}

.menu-button:hover,
.menu-button[aria-expanded="true"] {
  color: white;
  background: rgb(255 255 255 / 13%);
}

/* Three bars: the middle one is the span, the outer two its pseudo-elements. */
.menu-icon {
  position: relative;
  width: 1.15rem;
  height: 0.85rem;
}

.menu-icon span,
.menu-icon::before,
.menu-icon::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 0.125rem;
  border-radius: 1px;
  background: currentcolor;
}

.menu-icon::before { top: 0; }
.menu-icon span { top: calc(50% - 0.0625rem); }
.menu-icon::after { bottom: 0; }

.primary-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 13rem;
  max-width: calc(100vw - 2rem);
  padding: 0.4rem;
  border: 1px solid rgb(255 255 255 / 25%);
  border-radius: 0.5rem;
  background: var(--header-bottom);
  box-shadow: 0 0.75rem 2rem rgb(21 4 12 / 35%);
}

.primary-menu[hidden] {
  display: none;
}

.nav-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.15rem;
  list-style: none;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 0.35rem;
  color: var(--header-ink);
  font-size: 0.95rem;
  text-decoration: none;
  text-underline-offset: 0.16em;
  white-space: nowrap;
}

/* The ring is drawn inside the link: light against the dark menu, with a dark
   inner ring against the current page's wash (in-1521). */
.nav-link:focus-visible {
  outline-offset: -0.2rem;
}

.nav-link[aria-current="page"]:focus-visible {
  box-shadow: inset 0 0 0 0.35rem var(--header-accent);
}

.nav-link:hover {
  color: white;
  background: rgb(255 255 255 / 13%);
}

.nav-link[aria-current="page"] {
  color: var(--header-accent);
  background: var(--wash);
  font-weight: 750;
  text-decoration: none;
}

/* Forced colours flatten the wash, so the current page is underlined instead. */
@media (forced-colors: active) {
  .nav-link[aria-current="page"] .nav-label {
    text-decoration: underline;
    text-decoration-thickness: 0.15em;
  }
}

/* Pending friend requests and challenge invitations (in-1260). */
.nav-badge {
  display: inline-block;
  min-width: 1.35em;
  padding: 0 0.35em;
  /* The transparent border keeps the badge outlined in forced colors. */
  border: 1px solid transparent;
  border-radius: 999px;
  color: white;
  background: var(--brand-dark);
  font-size: 0.75rem;
  font-weight: 750;
  line-height: 1.35em;
  text-align: center;
  vertical-align: 0.1em;
}

.header-actions,
.button-row,
.profile-row,
.dialog-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Signed out, the Language select and Sign in sit before the menu button. The
   label sits above the select and the select fits its current option rather
   than its longest one ("Portuguese (Portugal)") (in-1782). Below 52rem the
   label returns beside the select. */
.site-header .header-actions {
  margin-left: auto;
  gap: 0.5rem;
}

.site-header .header-actions .button {
  padding-inline: 0.65rem;
}

.locale-control {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  font-size: 0.75rem;
}

.locale-control select {
  field-sizing: content;
  min-height: 2.65rem;
  font-size: 0.875rem;
  padding: 0.35rem 1.6rem 0.35rem 0.5rem;
  border: 1px solid #d8bccb;
  border-radius: 0.35rem;
  color: var(--ink);
  background: white;
}

.primary-menu .header-actions {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.4rem;
  padding: 0.5rem 0.35rem 0.35rem;
  border-top: 1px solid rgb(255 255 255 / 25%);
  color: var(--header-ink);
}

.primary-menu .locale-control {
  display: grid;
  gap: 0.25rem;
  font-size: 0.875rem;
}

.primary-menu .locale-control select {
  field-sizing: fixed;
  width: 100%;
}

.global-status {
  min-height: 0;
  padding: 0 clamp(1rem, 4vw, 4rem);
  color: white;
  background: var(--success);
  text-align: center;
}

.global-status:not(:empty) {
  padding-block: 0.5rem;
}

.global-status[data-kind="error"] {
  background: var(--error);
}

main {
  width: min(76rem, 100%);
  margin: 0 auto;
  padding: clamp(2rem, 6vw, 5.5rem) clamp(1rem, 4vw, 4rem);
  flex: 1;
}

/* Route and skip-link focus targets the content, not an interactive control (in-1555). */
#main-content:focus {
  outline: none;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(18rem, 0.85fr);
  align-items: center;
  gap: clamp(2rem, 7vw, 6rem);
}

.eyebrow {
  margin: 0 0 0.8rem;
  color: var(--brand-dark);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  color: var(--navy);
  line-height: 1.15;
}

h1 {
  max-width: 18ch;
  margin: 0 0 1.25rem;
  font-size: clamp(2.15rem, 6vw, 4.7rem);
  letter-spacing: -0.045em;
}

h2 {
  font-size: clamp(1.45rem, 3vw, 2rem);
}

/* Keep the translated heading balanced without forcing English-only breaks. */
.hero h1 {
  max-width: none;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.hero > div > p:not(.eyebrow) {
  max-width: 39rem;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.2rem);
}

.panel {
  padding: clamp(1.2rem, 4vw, 2rem);
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.panel > :first-child,
.page-heading > :first-child {
  margin-top: 0;
}

.panel > :last-child,
.page-heading > :last-child {
  margin-bottom: 0;
}

.language-form,
.stack,
dialog form {
  display: grid;
  gap: 0.75rem;
  align-content: start;
}

.language-form {
  gap: 1.25rem;
}

.language-form h2 {
  margin: 0;
}

.language-field {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.language-form select,
.language-form .button {
  min-height: 3.1rem;
}

.language-form select {
  border-color: var(--muted);
  border-radius: 0.4rem;
  background-color: var(--wash);
}

label {
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 2.9rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid #777f86;
  border-radius: 0.35rem;
  background: white;
}

input[aria-invalid="true"],
select[aria-invalid="true"] {
  border: 0.15rem solid var(--error);
}

.hint,
.muted {
  color: var(--muted);
  font-size: 0.92rem;
}

.button {
  min-height: 2.75rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.4rem;
  font-weight: 750;
}

.button-primary {
  color: white;
  background: var(--brand);
  border-color: var(--brand-dark);
}

.button-primary:hover {
  background: var(--brand-dark);
}

.button-secondary {
  color: var(--navy);
  background: white;
  border-color: #9aa6af;
}

.button-quiet {
  color: var(--brand-dark);
  background: transparent;
  text-decoration: underline;
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.form-error {
  padding: 0.75rem;
  border-left: 0.3rem solid var(--error);
  color: var(--error);
  background: #fff1f0;
  font-weight: 650;
}

.check-control {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-weight: 500;
}

.check-control input {
  width: 1.25rem;
  min-height: 1.25rem;
  margin-top: 0.15rem;
}

.page-heading {
  max-width: 46rem;
  margin-bottom: 2rem;
}

.page-heading h1 {
  font-size: clamp(2rem, 5vw, 3.5rem);
}

/* Practice fills the window width so the status band can run edge to edge;
   the page content keeps main's usual column and gutters. A faint lattice in
   the course colour gives the cream some texture behind the cards (in-1961). */
main.study-main {
  --study-top: clamp(1rem, 2.5vw, 2rem);
  --texture: color-mix(in srgb, var(--course-band) 5%, transparent);
  --texture-line: transparent calc(50% - 0.5px), var(--texture) calc(50% - 0.5px) calc(50% + 0.5px), transparent calc(50% + 0.5px);
  width: 100%;
  padding: 0 0 var(--study-top);
  /* The band is as wide as the viewport, scrollbar included. */
  overflow-x: clip;
  background:
    radial-gradient(circle, var(--texture) 0 0.16rem, transparent 0.19rem) 0 0 / 3rem 3rem,
    linear-gradient(45deg, var(--texture-line)) 0 0 / 3rem 3rem,
    linear-gradient(-45deg, var(--texture-line)) 0 0 / 3rem 3rem;
}

/* Without the site header, the menu sits at the top right of the course band
   (in-1972). The band starts at main's top edge (see .study-status). */
main.study-main {
  position: relative;
}

.study-main > #primary-navigation {
  position: absolute;
  z-index: 30;
  top: 0.9rem;
  right: clamp(1rem, 4vw, 4rem);
}

/* Below 66rem the button would reach the 48rem status strip, so it becomes
   icon only and the strip leaves room for it, pending badge included. */
@media (max-width: 66rem) {
  .study-main > #primary-navigation .menu-button-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .study-main .study-status {
    padding-right: 5.5rem;
  }
}

.study-main > .learn-page {
  width: min(76rem, 100%);
  margin-inline: auto;
  padding: var(--study-top) clamp(1rem, 4vw, 4rem) 0;
}

.learn-page > .page-heading {
  max-width: 76rem;
  margin: 0 auto 0.65rem;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.75rem;
}

.learn-page > .page-heading h1,
.learn-page > .page-heading p {
  margin: 0;
}

.learn-page > .page-heading h1 {
  max-width: none;
  flex: none;
  font-size: clamp(1.4rem, 2.5vw, 1.8rem);
  letter-spacing: -0.025em;
}

.learn-page > .page-heading p {
  color: var(--muted);
  font-size: 0.92rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
  gap: 1rem;
  align-items: start;
  align-content: start;
}

.account-layout {
  display: grid;
  gap: 1rem;
  width: min(48rem, 100%);
  align-content: start;
  align-items: start;
}

.account-layout .panel {
  min-width: 0;
  width: 100%;
}

.account-layout .panel > .button,
.account-layout form > .button {
  justify-self: start;
}

.account-layout .button-row {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.account-layout .account-signed-out {
  width: min(32rem, 100%);
}

.placeholder-panel {
  width: min(42rem, 100%);
}

.progress-dashboard {
  min-width: 0;
  width: min(64rem, 100%);
  margin-inline: auto;
}

.progress-totals {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.progress-totals h2 {
  grid-column: 1 / -1;
  margin-block: 0;
}

.progress-stat {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  background: var(--paper);
}

.progress-stat span,
.progress-stat strong {
  display: block;
}

.progress-stat span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.progress-stat strong {
  margin-top: 0.2rem;
  color: var(--navy);
  font-size: 1.4rem;
}

.progress-dashboard .stack,
.progress-dashboard .panel {
  min-width: 0;
}

.progress-stat {
  overflow-wrap: anywhere;
}

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
}

/* Keep a collapsed table from being a user-scrollable 1px box: Chromium makes
   such scrollers keyboard focusable even without tabindex (in-1801). */
.table-scroll.visually-hidden {
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 0.65rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  color: var(--muted);
  font-size: 0.82rem;
}

.current-ranking {
  background: #e6f4eb;
  font-weight: 800;
}

.ranking-gap th {
  padding-top: 1rem;
  text-align: left;
}

.ranking-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  /* Long metric labels must not widen the panel on narrow screens. */
  min-width: 0;
}

.milestone-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
  list-style: none;
}

.milestone-list li {
  padding: 0.75rem;
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(0, 2fr) auto;
  gap: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.milestone-list time,
.empty-state {
  color: var(--muted);
}

.friends-layout {
  display: grid;
  gap: 1rem;
  width: min(48rem, 100%);
  align-content: start;
}

.friends-layout .button-row {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.friend-code code {
  font-size: 1.6rem;
  font-weight: 750;
  letter-spacing: 0.12em;
  overflow-wrap: anywhere;
}

.friends-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
  list-style: none;
}

.friends-list li {
  padding: 0.75rem 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.friends-list li > div:first-child {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.friends-list .challenge-form {
  grid-column: 1 / -1;
}

.account-identity,
.challenge-scores {
  margin: 0.35rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}

.account-identity div,
.challenge-scores div {
  display: grid;
}

.account-identity dt,
.challenge-scores dt {
  color: var(--muted);
  font-size: 0.92rem;
}

.challenge-scores dd {
  margin: 0;
  font-weight: 750;
}

.account-identity dd {
  margin: 0;
  overflow-wrap: anywhere;
}

@media (max-width: 35rem) {
  .friends-list li {
    grid-template-columns: minmax(0, 1fr);
  }
}

.course-summary,
.study-panel,
.study-status {
  width: min(48rem, 100%);
  margin-inline: auto;
}

.study-session,
.study-workspace {
  width: min(76rem, 100%);
  margin-inline: auto;
}

.study-session {
  gap: 0.75rem;
}

/* The exercise fills the first column. Feedback, its details and the
   registration invitation stack in the second; the last, flexible row absorbs
   the exercise height so the feedback rows stay joined. */
.study-workspace {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: auto auto auto 1fr;
  align-items: start;
  gap: 0 1rem;
}

/* Keep an unanswered exercise aligned with the status strip. */
.study-workspace:not(:has(.study-feedback, .study-feedback-details, .study-registration)) {
  grid-template-columns: minmax(0, 1fr);
  width: min(48rem, 100%);
}

@media (width > 52rem) and (prefers-reduced-motion: no-preference) {
  .study-workspace-expanding {
    animation: study-workspace-expand 240ms ease-out;
  }

  @keyframes study-workspace-expand {
    from {
      width: min(48rem, 100%);
      grid-template-columns: minmax(0, 1fr) minmax(0, 0fr);
      column-gap: 0;
    }
    to {
      width: min(76rem, 100%);
      grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
      column-gap: 1rem;
    }
  }

  .study-workspace-expanding > :is(.study-feedback, .study-feedback-details, .study-registration) {
    animation: study-feedback-appear 240ms ease-out;
  }

  @keyframes study-feedback-appear {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}

.study-workspace > .study-panel {
  width: 100%;
  margin: 0;
  padding: 1rem clamp(1rem, 2vw, 1.5rem);
}

.study-workspace > .study-exercise {
  grid-column: 1;
  grid-row: 1 / -1;
}

.study-workspace > .study-feedback,
.study-workspace > .study-feedback-details,
.study-workspace > .study-registration {
  grid-column: 2;
}

.study-workspace > .study-feedback { grid-row: 1; }
.study-workspace > .study-feedback-details { grid-row: 2; }

.study-workspace > .study-registration {
  grid-row: 3;
  margin-top: 1rem;
}

/* Side by side, the result and its details read as one panel. */
.study-workspace > .study-feedback:has(~ .study-feedback-details) {
  padding-bottom: 0.75rem;
  border-bottom-width: 0;
  border-end-start-radius: 0;
  border-end-end-radius: 0;
}

.study-feedback-details {
  display: grid;
  gap: 0.75rem;
  box-shadow: none;
}

.study-workspace > .study-feedback-details {
  padding-top: 0;
  border-top-width: 0;
  border-start-start-radius: 0;
  border-start-end-radius: 0;
}

.feedback-diagnosis {
  margin: 0;
  line-height: 1.5;
}

/* A rival's name is user text; long names wrap instead of widening the panel. */
.rivalry-message {
  margin: 0;
  line-height: 1.5;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* The status facts are cards on a band in the course colour that runs the
   full window width and ends in a tile border (in-1961). The strip itself
   keeps the 48rem study column. */
.study-status {
  --status-card: color-mix(in srgb, white 10%, var(--course-band));
  --status-line: color-mix(in srgb, white 22%, var(--course-band));
  --status-track: color-mix(in srgb, black 40%, var(--course-band));
  --status-label: color-mix(in srgb, white 88%, var(--course-band));
  --status-accent: color-mix(in srgb, var(--level-1) 60%, white);
  position: relative;
  /* Keeps the band behind the cards and above the page texture. */
  isolation: isolate;
  margin-top: calc(-1 * var(--study-top, 0rem));
  padding: 0.9rem 0 calc(0.9rem + var(--tile-size));
  color: white;
}

.study-status::before,
.study-status::after {
  position: absolute;
  z-index: -1;
  left: 50%;
  width: 100vw;
  content: "";
  transform: translateX(-50%);
}

.study-status::before {
  inset-block: 0;
  background: var(--course-band);
}

/* A row of diamonds: stripes of the two tile colours, their corners cut away
   in the ground colour, with a dot in the middle of each tile. */
.study-status::after {
  --tile-corner: var(--tile-ground) 25%, transparent calc(25% + 0.5px);
  bottom: 0;
  height: var(--tile-size);
  background:
    radial-gradient(circle, var(--tile-dot) 0 calc(var(--tile-size) * 0.12), transparent calc(var(--tile-size) * 0.12 + 0.5px)),
    linear-gradient(45deg, var(--tile-corner)),
    linear-gradient(135deg, var(--tile-corner)),
    linear-gradient(225deg, var(--tile-corner)),
    linear-gradient(315deg, var(--tile-corner)),
    repeating-linear-gradient(90deg, var(--tile-a) 0 var(--tile-size), var(--tile-b) var(--tile-size) calc(2 * var(--tile-size)));
  background-size: var(--tile-size) var(--tile-size), var(--tile-size) var(--tile-size), var(--tile-size) var(--tile-size), var(--tile-size) var(--tile-size), var(--tile-size) var(--tile-size), auto;
}

.study-status-facts {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Cards take the width of their text, so a fact wraps to the next row
   before its label or value breaks. */
.study-status-facts > div {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  align-content: center;
  column-gap: 0.65rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--status-line);
  border-radius: 0.65rem;
  background: var(--status-card);
}

.study-status-facts > .status-words {
  flex: 4 1 13rem;
}

/* A round chip in one of the level hues holds each fact's icon. */
.status-icon {
  grid-row: 1 / span 2;
  width: 2.1rem;
  height: 2.1rem;
  padding: 0.45rem;
  border-radius: 50%;
  color: var(--course-band);
  background: var(--status-chip);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-icon-time { --status-chip: color-mix(in srgb, var(--level-1) 72%, white); }
.status-icon-words { --status-chip: color-mix(in srgb, var(--level-2) 72%, white); }
.status-icon-points { --status-chip: color-mix(in srgb, var(--level-0) 72%, white); }
.status-icon-goal { --status-chip: color-mix(in srgb, var(--level-3) 72%, white); }
.status-icon-streak { --status-chip: color-mix(in srgb, var(--level-4) 72%, white); }

.status-icon-points path {
  fill: currentColor;
}

/* The flame of the daily streak burns in the brand terracotta on a white chip;
   the level hues are the belt birds and have no warm one (in-1971). */
.status-icon-days {
  --status-chip: white;
  color: var(--brand);
}

.study-status-facts dt {
  grid-column: 2;
  color: var(--status-label);
  font-size: 0.76rem;
  font-weight: 750;
}

/* The one-time placement results screen (in-1935). */
.placement-result-facts {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.5rem;
}

.placement-result-facts div {
  flex: 1 1 9rem;
  min-width: 0;
}

.placement-result-facts dt {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
}

.placement-result-facts dd {
  margin: 0.15rem 0 0;
  font-size: 1.35rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

/* Generation diagnostics for the debug account (in-1389). */
.study-debug {
  width: min(76rem, 100%);
  margin-inline: auto;
  padding: 0.6rem 1rem;
  border: 1px dashed var(--border);
  border-radius: 0.65rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.study-debug summary {
  font-weight: 750;
  cursor: pointer;
}

.study-debug dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.2rem 0.75rem;
  margin: 0.5rem 0 0;
}

.study-debug dt {
  font-weight: 750;
}

.study-debug dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.study-status-facts .streak-fact {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.streak-meter {
  grid-column: 3;
  grid-row: 1 / span 2;
  width: 3.75rem;
  height: auto;
}

.rainbow-band {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
}

/* Light enough to read on every course band. */
.rainbow-band-track { stroke: var(--status-track); }
.rainbow-band-violet { stroke: #b78cff; }
.rainbow-band-indigo { stroke: #7f8cff; }
.rainbow-band-blue { stroke: #4fa8ff; }
.rainbow-band-green { stroke: #5fd068; }
.rainbow-band-yellow { stroke: #ffd84a; }
.rainbow-band-orange { stroke: #ff9d42; }
.rainbow-band-red { stroke: #ff6b5e; }

.study-status-facts dd {
  grid-column: 2;
  margin: 0;
  color: white;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

/* Mastered out of all words, with a thin bar for the share (in-1522). */
.status-words-bar,
.status-level-bar {
  display: block;
  width: 100%;
  height: 0.45rem;
  margin-top: 0.25rem;
  border-radius: 999px;
  overflow: hidden;
}

.status-words-bar {
  border: 0;
  appearance: none;
  background: var(--status-track);
  color: var(--level-2);
}

.status-words-bar::-webkit-progress-bar {
  background: var(--status-track);
}

.status-words-bar::-webkit-progress-value {
  background: var(--level-2);
}

.status-words-bar::-moz-progress-bar {
  background: var(--level-2);
}

/* With the per-level counts the bar has one segment per level, filled in the
   level's hue up to its mastered share (in-1961). */
.status-level-track { fill: var(--status-track); }
.status-level[data-level="0"] .status-level-fill { fill: var(--level-0); }
.status-level[data-level="1"] .status-level-fill { fill: var(--level-1); }
.status-level[data-level="2"] .status-level-fill { fill: var(--level-2); }
.status-level[data-level="3"] .status-level-fill { fill: var(--level-3); }
.status-level[data-level="4"] .status-level-fill { fill: var(--level-4); }
.status-level[data-level="5"] .status-level-fill { fill: var(--level-5); }

/* Points are a score, not learning progress: the accent sets them apart. */
.study-status-facts .status-points dd {
  color: var(--status-accent);
}

/* Forced colours drop the band, so the cards rely on their borders and the
   icons and bars on system colours. */
@media (forced-colors: active) {
  .status-level-track { fill: Canvas; stroke: CanvasText; stroke-width: 1; vector-effect: non-scaling-stroke; }
  .status-level .status-level-fill { fill: Highlight; }
}

.course-summary {
  width: min(76rem, 100%);
  margin-top: 0;
  margin-bottom: 0.65rem;
  color: var(--muted);
  text-align: center;
}

.answer-form {
  display: grid;
  gap: 0.9rem;
}

.study-workspace .answer-form {
  gap: 0.65rem;
}

.study-instruction {
  margin: 0;
  color: var(--brand-dark);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.study-question {
  --question-border: #b9d6d2;
  --question-background: #edf6f5;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin: 0.4rem 0 1rem;
}

.study-prompt {
  align-self: stretch;
  margin: 0;
  color: var(--navy);
  font-size: clamp(1.65rem, 5vw, 2.8rem);
  font-weight: 720;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.study-workspace .study-question {
  margin-block: 0.15rem 0.35rem;
}

.study-prompt.has-replay {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.study-prompt-phrase {
  flex: 1;
  min-width: 0;
}

.study-prompt ruby {
  ruby-position: under;
}

.study-prompt-annotation {
  font-size: 0.75rem;
  font-weight: 500;
}

.study-prompt .replay-button {
  font-size: 1rem;
}

/* The exercise level picks the hue of the question and its tab, so they
   change colour as the learner advances (in-1961). */
.study-question[data-level="0"] { --level-color: var(--level-0); }
.study-question[data-level="1"] { --level-color: var(--level-1); }
.study-question[data-level="2"] { --level-color: var(--level-2); }
.study-question[data-level="3"] { --level-color: var(--level-3); }
.study-question[data-level="4"] { --level-color: var(--level-4); }
.study-question[data-level="5"] { --level-color: var(--level-5); }

.study-question[data-level] {
  --question-border: color-mix(in srgb, var(--level-color) 55%, white);
  --question-background: color-mix(in srgb, var(--level-color) 15%, white);
}

/* The question and its level tab share the direction colours (in-1541):
   reverse turns stay grey whatever the level. */
.study-question.study-question-reverse {
  --question-border: #b8a3af;
  --question-background: #ede6ea;
}

/* The solid level hue marks both directions: a bar along the question's
   leading edge and a dot in the tab. */
.study-question[data-level] > .study-prompt {
  border-inline-start: 0.4rem solid var(--level-color);
}

.study-question[data-level] > .study-level::before {
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  margin-inline-end: 0.4em;
  border-radius: 50%;
  background: var(--level-color);
  content: "";
}

.study-prompt-forward,
.study-prompt-reverse {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--question-border);
  border-radius: 0.5rem;
  background: var(--question-background);
}

.study-question:has(> .study-level) > .study-prompt {
  border-top-right-radius: 0;
}

/* The tab joins the question's top border, flush with its right edge. */
.study-level {
  position: relative;
  margin: 0 0 -1px;
  padding: 0.18rem 0.65rem 0.12rem;
  border: 1px solid var(--question-border);
  border-bottom: 0;
  border-radius: 0.5rem 0.5rem 0 0;
  color: var(--navy);
  background: var(--question-background);
  font-size: 0.8rem;
  font-weight: 800;
}

.study-guidance {
  margin: 0;
  padding: 0.75rem 0.9rem 0.75rem 2rem;
  border-left: 0.25rem solid #b27a00;
  border-radius: 0.35rem;
  background: #fff8dd;
}

.study-guidance li {
  list-style: none;
}

.study-examples {
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--wash);
}

.study-examples > h2 {
  margin: 0 0 0.6rem;
  font-size: 1.05rem;
}

.study-examples section + section {
  margin-top: 0.65rem;
}

.study-examples h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.study-examples p {
  margin: 0.15rem 0 0;
  overflow-wrap: anywhere;
}

.study-examples strong {
  text-decoration: underline;
  text-decoration-thickness: 0.12em;
  text-underline-offset: 0.12em;
}

.answer-form input {
  min-height: 3.4rem;
  font-size: 1.12rem;
}

/* A small aside under the answer field, not body text (in-1532). It stays
   light and muted so the colour goes to the question and the answer (in-1961). */
.study-abbreviations {
  min-width: 0;
  display: grid;
  gap: 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.study-abbreviations > p {
  margin: 0;
  overflow-wrap: anywhere;
}

.study-abbreviations > p:first-child {
  font-weight: 600;
}

.study-abbreviations > ul {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.study-abbreviations li {
  /* Keep each group whole; oversized chips can scroll with touch or keyboard
     without widening the exercise or the page. */
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  white-space: nowrap;
}

.study-abbreviations kbd {
  font-family: monospace;
  font-size: 1em;
  font-weight: 700;
}

.study-actions {
  margin-top: 0.35rem;
}

/* Skipping is the lesser action: lighter and smaller than Check answer (in-1961). */
.study-actions .study-skip {
  min-height: 2.25rem;
  padding: 0.3rem 0.8rem;
  border-color: var(--border);
  color: var(--muted);
  background: transparent;
  font-size: 0.875rem;
  font-weight: 600;
}

.study-actions .study-skip:hover {
  color: var(--navy);
  background: var(--wash);
}

.pending-answer input[readonly],
.study-failure input[readonly] {
  color: var(--navy);
  background: var(--wash);
}

.study-answer-pending {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.study-answer-pending::before {
  width: 0.8rem;
  height: 0.8rem;
  border: 0.14rem solid color-mix(in srgb, var(--brand) 28%, transparent);
  border-top-color: var(--brand);
  border-radius: 50%;
  content: "";
  animation: pending-answer-spin 0.8s linear infinite;
}

@keyframes pending-answer-spin {
  to { transform: rotate(360deg); }
}

.study-feedback {
  border-width: 1px;
  box-shadow: none;
  padding: 1rem 1.5rem;
  gap: 0.75rem;
}

.study-feedback > p {
  margin: 0;
  line-height: 1.5;
}

.feedback-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.3;
}

.feedback-heading::before {
  display: inline-grid;
  flex: 0 0 1.75rem;
  width: 1.75rem;
  height: 1.75rem;
  box-sizing: border-box;
  place-items: center;
  /* Matches the 900-weight glyph and bold heading at both ring sizes (in-1523). */
  border: 2px solid currentColor;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: 900;
  line-height: 1;
}

.feedback-correct {
  border-color: var(--success);
  background: #f2faf5;
}

.feedback-correct h2 {
  color: var(--success);
}

.feedback-correct h2::before,
.feedback-correct .feedback-heading::before {
  content: "✓";
}

.feedback-incorrect {
  border-color: var(--error);
  background: #fff7f5;
}

.feedback-incorrect h2 {
  color: var(--error);
}

/* A bare ✗ rather than a ringed ×, which read as a close button (in-1531). */
.feedback-incorrect h2::before,
.feedback-incorrect .feedback-heading::before {
  content: "✗";
  border: 0;
}

/* Without the ring the glyph carries the mark alone, so it scales with the heading. */
.study-feedback.feedback-incorrect .feedback-heading::before {
  font-size: 1.3em;
}

.feedback-warning {
  margin-block: 0;
  border: 0.12rem solid #8a6500;
  border-left-width: 0.45rem;
  border-radius: 0.45rem;
  background: #fff9df;
}

.feedback-warning h2 {
  margin-block: 0 0.4rem;
  color: #684b00;
  font-size: 1.25rem;
}

.feedback-warning p {
  margin-block: 0;
}

.correction {
  margin: 0;
  display: grid;
  gap: 0;
}

.correction > div {
  display: grid;
  grid-template-columns: minmax(0, 10rem) minmax(0, 1fr);
  align-items: baseline;
  gap: 0.35rem 1rem;
  padding-block: 0.65rem;
}

.correction > div + div {
  border-block-start: 1px solid var(--border);
}

.correction dt {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.correction dd {
  min-width: 0;
  margin: 0;
  font-size: 1.08rem;
  overflow-wrap: anywhere;
}

.correction dd.has-replay {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

@media (max-width: 480px) {
  .correction > div {
    grid-template-columns: minmax(0, 1fr);
  }
}

.correction-phrase {
  flex: 0 1 auto;
  min-width: 0;
  overflow-wrap: break-word;
}

.replay-button {
  position: relative;
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 1.4em;
  height: 1.2em;
  padding: 0;
  border: 0;
  border-radius: 0.3rem;
  color: var(--muted);
  background: none;
  line-height: 1;
  cursor: pointer;
}

/* The icon stays text-sized while the touch target extends past it without affecting layout. */
.replay-button::after {
  content: "";
  position: absolute;
  inset: -0.8rem;
}

.replay-button:hover {
  color: var(--ink);
}

.replay-icon {
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.replay-icon path:first-child {
  fill: currentColor;
}

.correction mark {
  padding-inline: 0.08em;
  border-block-end: 0.16em double currentColor;
  color: inherit;
  background: #fff0a8;
  font-weight: 800;
}

.correction-help {
  padding-block-start: 0.35rem;
  border-block-start: 1px solid var(--border);
}

.correction-help summary {
  min-height: 2.75rem;
  padding-block: 0.7rem;
  color: var(--brand-dark);
  font-weight: 800;
  cursor: pointer;
}

.word-help {
  display: grid;
  gap: 0.5rem;
}

.word-help div {
  display: grid;
  grid-template-columns: minmax(7rem, 0.3fr) minmax(0, 1fr);
  gap: 0.75rem;
}

.word-help dt {
  color: var(--muted);
  font-weight: 750;
}

.word-help dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.correction-help h3 {
  margin-block-end: 0.45rem;
  font-size: 1rem;
}

.conjugation-help {
  display: grid;
  gap: 0.35rem;
  margin-block: 0;
  padding-inline-start: 1.4rem;
  overflow-wrap: anywhere;
}

.registration-prompt {
  margin-top: 0.5rem;
  padding: 1rem;
  border: 1px dashed #9aa6af;
  border-radius: 0.45rem;
  background: var(--paper);
}

.registration-prompt h3,
.registration-prompt p {
  margin-top: 0;
}

.registration-prompt h3 {
  font-size: 1.1rem;
}

.error-code {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 0.85rem;
}

.profile-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
  list-style: none;
}

.courses-panel {
  border-top: 0.25rem solid var(--brand);
  background: linear-gradient(135deg, #fff4e8, var(--paper) 45%);
}

.courses-panel > h2 {
  margin-bottom: 0.5rem;
}

.profile-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--paper);
}

.course-monogram {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.8rem;
  color: var(--navy);
  background: #e9edf3;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.profile-details {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.profile-row .button {
  text-align: center;
  text-decoration: none;
}

.profile-row[data-selected="true"] {
  border-color: var(--success);
  background: #f0f8f2;
  box-shadow: inset 0.25rem 0 var(--success);
}

.profile-row[data-selected="true"] .course-monogram {
  color: var(--success);
  background: #dceee1;
}

.course-add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 1rem;
  margin-top: 0.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

.course-add-form .form-error {
  grid-column: 1 / -1;
}

.course-add-form select {
  min-width: 0;
}

.tag {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  color: var(--success);
  background: #e6f4eb;
  font-size: 0.82rem;
  font-weight: 750;
}

.loading-panel {
  min-height: 15rem;
  display: grid;
  place-items: center;
}

.loading-panel p::before {
  content: "";
  width: 1rem;
  height: 1rem;
  margin-right: 0.65rem;
  display: inline-block;
  border: 0.2rem solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  vertical-align: -0.15rem;
  animation: spin 0.8s linear infinite;
}

dialog {
  width: min(32rem, calc(100% - 2rem));
  max-height: calc(100% - 2rem);
  padding: 0;
  border: 0;
  border-radius: 0.75rem;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 1.25rem 5rem rgb(0 0 0 / 35%);
}

dialog::backdrop {
  background: rgb(9 24 36 / 72%);
}

.dialog-frame {
  padding: clamp(1.2rem, 5vw, 2rem);
}

.dialog-heading {
  justify-content: space-between;
  margin-bottom: 1rem;
}

.dialog-heading h2 {
  margin: 0;
}

.icon-button {
  width: 2.75rem;
  height: 2.75rem;
  border: 0;
  border-radius: 50%;
  color: var(--navy);
  background: transparent;
  font-size: 1.7rem;
}

.icon-button:hover {
  background: var(--wash);
}

.site-footer {
  padding: 1.25rem clamp(1rem, 4vw, 4rem);
  color: #dbe5eb;
  background: var(--navy);
  text-align: center;
}

.site-footer p {
  margin: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 52rem) {
  .locale-control {
    flex-direction: row;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.875rem;
  }

  .locale-control select {
    field-sizing: fixed;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .learn-page > .page-heading {
    display: block;
    text-align: center;
  }

  .learn-page > .page-heading p {
    margin-top: 0.25rem;
  }

  .study-workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    gap: 0.5rem;
  }

  .study-workspace > .study-exercise,
  .study-workspace > .study-feedback,
  .study-workspace > .study-feedback-details,
  .study-workspace > .study-registration {
    grid-column: 1;
    grid-row: auto;
    margin-top: 0;
  }

  /* With the on-screen keyboard open a phone shows only a few hundred pixels:
     the previous correction and the new question, its input and its actions
     come first; diagnosis, guidance, examples and abbreviations follow them. */
  .study-workspace {
    scroll-margin-top: 0.25rem;
  }

  .study-workspace > .study-feedback {
    gap: 0.25rem;
    padding: 0.45rem 0.85rem;
  }

  /* Stacked, the details become a separate panel after the exercise. */
  .study-workspace > .study-feedback:has(~ .study-feedback-details) {
    padding-bottom: 0.45rem;
    border-bottom-width: 1px;
    border-radius: 0.8rem;
  }

  .study-workspace > .study-feedback-details {
    padding: 0.75rem 0.85rem;
    border-top-width: 1px;
    border-radius: 0.8rem;
  }

  /* A correct answer's heading says enough; its details would only push the
     next question down (in-1472). */
  .study-workspace > .study-feedback-details.feedback-correct {
    display: none;
  }

  /* The debug account's diagnostics are for desktop review; on a phone they
     would only crowd the exercise (in-1477). */
  .study-debug {
    display: none;
  }

  .study-workspace > .feedback-warning:is(.study-feedback, .study-feedback-details) {
    border-block-width: 0.12rem;
    border-radius: 0.45rem;
  }

  .study-feedback .feedback-heading {
    gap: 0.5rem;
    font-size: 1.05rem;
  }

  .study-feedback .feedback-heading::before {
    flex-basis: 1.4rem;
    width: 1.4rem;
    height: 1.4rem;
    font-size: 0.95rem;
  }

  .study-feedback .correction > div {
    gap: 0.1rem 1rem;
    padding-block: 0.25rem;
  }

  .study-feedback .correction dt {
    font-size: 0.75rem;
    line-height: 1.2;
  }

  .study-feedback .correction dd {
    font-size: 1rem;
    line-height: 1.35;
  }

  .study-workspace > .study-exercise {
    gap: 0.45rem;
    padding: 0.5rem 0.85rem 0.65rem;
  }

  .study-exercise > .study-guidance,
  .study-exercise > .study-examples,
  .study-exercise > .study-abbreviations {
    order: 1;
  }

  .study-exercise .study-instruction {
    font-size: 0.75rem;
    line-height: 1.2;
  }

  .study-exercise .study-question {
    margin-block: 0;
  }

  /* A compact level tab keeps the answer actions above the keyboard. */
  .study-exercise .study-level {
    padding: 0 0.5rem 0.05rem;
    font-size: 0.7rem;
    line-height: 1.3;
  }

  .study-exercise .study-prompt {
    padding-block: 0.3rem;
    font-size: 1.2rem;
  }

  /* The instruction above the question already says what to type. */
  .study-exercise > label[for="study-answer"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  /* Checkboxes (the theme intermission) keep their compact size. */
  .study-exercise input:not([type="checkbox"]) {
    min-height: 2.75rem;
  }

  .study-exercise .study-actions {
    flex-flow: row wrap;
    gap: 0.5rem;
    margin-top: 0;
  }

  /* Labels never wrap (in-1967): both buttons start from the width of their
     label and share the rest of the row, Check answer never shrinks, and Skip
     moves to its own full-width row when the two do not fit side by side. */
  .study-exercise .study-actions .button {
    flex: 1 1 auto;
    width: auto;
    white-space: nowrap;
  }

  .study-exercise .study-actions .button-primary {
    flex-shrink: 0;
    max-width: 100%;
  }

  /* Side by side on a phone, both actions keep the full touch height. */
  .study-exercise .study-actions .study-skip {
    min-height: 2.75rem;
  }

  .progress-totals {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 35rem) {
  .header-actions,
  .button-row,
  .profile-row {
    align-items: stretch;
  }

  .site-header {
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
  }

  .brand-logo {
    width: 12rem;
  }

  /* The logo and menu button share the first row; Language and Sign in get
     their own row below them (in-1968). */
  #primary-navigation {
    margin-left: auto;
  }

  /* Icon only, so the button fits beside the logo at 320px; the label still
     names it. */
  .menu-button-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .site-header .header-actions {
    order: 3;
    width: 100%;
    margin-left: 0;
  }

  .site-header .header-actions:not(:has(> :not([hidden]))) {
    display: none;
  }

  .locale-control {
    flex: 1;
  }

  .locale-control select {
    min-width: 0;
  }

  .button-row,
  .profile-row {
    flex-direction: column;
  }

  .button-row .button,
  .profile-row .button {
    width: 100%;
  }

  /* On a phone the facts are bare text on the band, each label led by a
     small icon in its chip colour. */
  .study-status {
    padding: 0.55rem 0 calc(0.55rem + var(--tile-size));
  }

  /* Practice time and points share the first row; the words and their bar,
     the daily streak, the goal and the answer streak each take a full row. */
  .study-status-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-flow: dense;
    gap: 0.4rem 0.65rem;
  }

  .study-status-facts > div {
    column-gap: 0.3rem;
    align-content: space-between;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
  }

  .status-icon {
    grid-row: 1;
    width: 0.9rem;
    height: 0.9rem;
    padding: 0;
    border-radius: 0;
    color: var(--status-chip);
    background: none;
  }

  .status-icon-days {
    color: var(--status-accent);
  }

  .study-status-facts dt {
    font-size: 0.7rem;
  }

  .study-status-facts dd {
    grid-column: 1 / -1;
  }

  /* Goal values include a unit that needs more room than the compact facts. */
  .study-status-facts .status-words,
  .study-status-facts .status-days,
  .study-status-facts .status-goal {
    grid-column: 1 / -1;
  }

  .study-status-facts .streak-fact {
    grid-column: 1 / -1;
    justify-self: start;
    align-content: center;
  }

  .study-status-facts .streak-fact dd {
    grid-column: 1 / span 2;
  }

  /* The menu button only reaches the first row, so an empty third column
     under it replaces the strip's right padding; the full-row facts span it.
     Practice time keeps its natural width so its label stays on one line, and
     points take what is left (in-1972). */
  .study-main > #primary-navigation {
    top: 0.55rem;
  }

  .study-main > #primary-navigation .menu-button {
    padding-inline: 0.5rem;
  }

  .study-main .study-status {
    padding-right: 0;
  }

  .study-main .study-status-facts {
    grid-template-columns: max-content minmax(0, 1fr) 4.25rem;
  }

  .progress-totals,
  .ranking-filters,
  .milestone-list li {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

.chart-panel-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.chart-panel-heading h2 { margin: 0; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 0.15rem; background: var(--wash); }
.segmented .button { min-height: 2.2rem; padding: 0.3rem 0.9rem; border: 0; border-radius: 999px; background: transparent; box-shadow: none; font-size: 0.9rem; }
.segmented .button[aria-pressed="true"] { background: var(--navy); color: white; }

.practice-plot:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
.chart-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem 1.25rem; margin: 0; padding: 0; list-style: none; font-size: 0.9rem; }
.chart-legend li { display: inline-flex; align-items: center; gap: 0.35rem; }
.chart-legend strong { font-variant-numeric: tabular-nums; }
.chart-swatch { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 0.2rem; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 12%); }
.chart-readout { min-height: 1.6em; margin: 0; text-align: center; font-weight: 600; overflow-wrap: anywhere; }


.practice-controls { display: flex; flex-wrap: wrap; gap: .5rem; }
.practice-controls [aria-pressed="true"] { text-decoration: underline; font-weight: bold; }
.practice-figure { position: relative; height: 400px; margin: 0 auto; padding: 32px 20px 0 44px; width: min(100%, 366px); box-sizing: border-box; font-size: 0.7rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.practice-plot { position: relative; width: 100%; height: 180px; }
.practice-plot canvas { display: block; width: 100%; height: 180px; }
.practice-legend { position: absolute; top: 6px; left: 44px; font-size: 0.8rem; color: var(--ink); }
.practice-legend::before { content: ""; display: inline-block; width: 20px; border-top: 3px solid #294FC9; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.practice-axis { position: absolute; left: 2px; right: calc(100% - 40px); top: 40px; height: 164px; display: flex; flex-direction: column; justify-content: space-between; text-align: right; overflow-wrap: anywhere; }
.practice-dates { position: relative; height: 60px; }
.practice-dates span { position: absolute; top: 8px; transform: translateX(-100%) rotate(-45deg); transform-origin: right top; white-space: nowrap; }

.retention-figure { width: min(100%, 666px); height: 500px; padding-left: 46px; }
.retention-plot, .retention-plot canvas { height: 360px; }
.retention-axis { top: 48px; height: 328px; }
.retention-horizons span:first-child { transform: rotate(-45deg); transform-origin: left top; }
.chart-marker { position: absolute; z-index: 1; width: 0.75rem; height: 0.75rem; border: 2px solid white; border-radius: 50%; background: #294FC9; box-shadow: 0 0 0 1px #294FC9; transform: translate(-50%, -50%); pointer-events: none; }
.chart-unavailable { border-bottom: 1px solid var(--border); }

.progress-dashboard select, .ranking-filters select { width: auto; max-width: 100%; min-width: 0; }

@media (max-width: 35rem) {
  .profile-row {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }

  .profile-row .button {
    grid-column: 1 / -1;
  }

  .course-add-form {
    grid-template-columns: minmax(0, 1fr);
  }

  .account-layout .course-add-form > .button {
    width: 100%;
  }
}

.progress-bars { display: grid; grid-template-columns: max-content minmax(0, 1fr) max-content; gap: 0.8rem; width: 100%; margin-top: 0.5rem; }
.progress-bars:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
.progress-bar-row { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; align-items: center; gap: 0.8rem; }
.progress-bar-label { display: flex; align-items: center; gap: 0.4rem; font-weight: 600; }
/* Inline level contents keep WebKit's subgrid sizing wide enough for the swatch and full label. */
.progress-bars:not(.theme-bars) .progress-bar-label { display: block; white-space: nowrap; }
.progress-level-swatch { display: inline-block; width: 0.8rem; height: 0.8rem; margin-inline-end: 0.4rem; vertical-align: middle; border: 1px solid var(--muted); border-radius: 2px; }
.progress-level-swatch[data-level="0"] { background: #fff; }
.progress-level-swatch[data-level="1"] { background: #ffd500; }
.progress-level-swatch[data-level="2"] { background: #228b22; }
.progress-level-swatch[data-level="3"] { background: #2463eb; }
.progress-level-swatch[data-level="4"] { background: #000; }
/* Themes have no belt color of their own. */
.progress-level-swatch[data-level="5"] { background: linear-gradient(135deg, #fff 20%, #ffd500 20% 40%, #228b22 40% 60%, #2463eb 60% 80%, #000 80%); }
.progress-bar-track { display: block; width: 100%; height: 1.5rem; overflow: visible; }
.progress-bar-empty { fill: var(--paper); stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.progress-bar-figure { display: flex; justify-content: space-between; gap: 1rem; font-variant-numeric: tabular-nums; }
.progress-bar-figure span:first-child { min-width: 3ch; text-align: right; }
.progress-bar-figure span:last-child { min-width: 9ch; text-align: right; }
@media (max-width: 36rem) {
  .progress-bars { grid-template-columns: max-content minmax(0, 1fr); }
  .progress-bar-row { gap: 0.25rem 0.5rem; }
  .progress-bar-figure { grid-column: 2; flex-wrap: wrap; gap: 0.25rem 0.5rem; font-size: 0.85rem; }
  .progress-bar-figure span:last-child { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
}
.chart-panel { grid-template-columns: minmax(0, 1fr); }

.theme-bars { grid-template-columns: fit-content(35%) minmax(0, 1fr) max-content; }
.theme-bars .progress-bar-label { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 36rem) {
  .theme-bars { grid-template-columns: fit-content(45%) minmax(0, 1fr); }
}

/* Recent activity (in-1797): one column per calendar day with practice minutes.
   Bars are blue for minutes; the best day uses --brand-dark (not the points
   accent) plus a ring, a legend entry and text in the readout and table. */
.daily-panel { --daily-bar: #2f6db0; --daily-empty: #8c8379; }
.daily-heading { align-items: baseline; }
.daily-range { margin: 0; }
.daily-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; }
.daily-stat { padding: 0.75rem 1rem; background: var(--wash); hyphens: auto; }
.daily-stat strong { line-height: 1.25; font-variant-numeric: tabular-nums; }
.daily-stat-detail { display: inline-block; color: var(--muted); font-size: 0.85rem; font-weight: 400; line-height: 1.3; }
.daily-chart {
  container-type: inline-size;
  display: grid;
  grid-template-columns: repeat(var(--daily-columns, 14), minmax(0, 1fr));
  gap: 0 0.25rem;
  margin-top: 0.5rem;
  overflow-x: clip;
  border-radius: 0.35rem;
}
.daily-chart:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
.daily-column { display: grid; grid-template-rows: auto auto; min-width: 0; border-radius: 0.35rem; }
.daily-chart:is(:focus-visible, :hover) .daily-column[data-selected] { background: var(--wash); }
.daily-plot {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 10rem;
  padding-top: 1.4rem;
  box-sizing: border-box;
  border-bottom: 1px solid var(--border);
}
.daily-value { padding-bottom: 0.15rem; color: var(--navy); font-size: 0.8rem; font-weight: 700; line-height: 1.1; white-space: nowrap; font-variant-numeric: tabular-nums; }
.daily-bar { flex: none; width: min(70%, 2.6rem); min-height: 3px; border-radius: 0.25rem 0.25rem 0 0; background: var(--daily-bar); }
.daily-dot { flex: none; width: 0.5rem; height: 0.5rem; margin-bottom: 0.3rem; border-radius: 50%; background: var(--daily-empty); }
.daily-column[data-best] .daily-bar { background: var(--brand-dark); box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--brand-dark); }
.daily-column[data-best] .daily-value { color: var(--brand-dark); }
.daily-label { display: grid; padding: 0.3rem 0 0.2rem; text-align: center; font-size: 0.75rem; line-height: 1.25; white-space: nowrap; }
.daily-weekday { color: var(--ink); font-weight: 700; }
.daily-date { color: var(--muted); }
.daily-column[data-today] .daily-label > * { color: var(--brand-dark); font-weight: 750; text-decoration: underline; text-underline-offset: 0.15em; }
.daily-narrow { display: none; }
@container (max-width: 40rem) {
  .daily-column { border-radius: 0.2rem; }
  .daily-wide { display: none; }
  .daily-narrow { display: block; }
  .daily-value { font-size: 0.65rem; }
  .daily-bar { width: 75%; }
}
.daily-chart:has(.daily-column:nth-child(15)) { gap: 0 1px; }
.daily-legend { justify-content: flex-start; }
.daily-swatch-bar { background: var(--daily-bar); }
.daily-swatch-best { background: var(--brand-dark); }
.daily-swatch-empty { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--daily-empty); box-shadow: none; }
.daily-table-toggle {
  justify-self: start;
  padding: 0.2rem 0;
  border: 0;
  background: none;
  color: var(--focus);
  font-weight: 750;
  text-align: start;
}
.daily-table-toggle::before { content: "▸" / ""; display: inline-block; margin-inline-end: 0.4rem; }
.daily-table-toggle[aria-expanded="true"]::before { content: "▾" / ""; }
.daily-table-toggle:hover { text-decoration: underline; }
@media (max-width: 52rem) {
  .daily-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
  .daily-stat { padding: 0.6rem 0.75rem; }
  .daily-stat strong { font-size: 1.2rem; }
  .daily-chart { gap: 0 2px; }
}
/* Forced colours drop backgrounds and shadows: bars and dots keep system fills, the best day an outline. */
@media (forced-colors: active) {
  .daily-bar, .daily-dot, .daily-swatch-bar, .daily-swatch-empty { forced-color-adjust: none; background: CanvasText; }
  .daily-column[data-best] .daily-bar, .daily-swatch-best { forced-color-adjust: none; background: Highlight; outline: 2px solid CanvasText; outline-offset: 2px; }
  .daily-chart:is(:focus-visible, :hover) .daily-column[data-selected] { outline: 2px solid Highlight; outline-offset: -2px; }
}
