/* Material 3 styling that matches the Android app. Sizes in px correspond to dp and sp there. */

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-display: block;
  font-weight: 100 900;
  src: url('fonts/roboto-latin-wght-normal.woff2') format('woff2-variations');
  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: 'Roboto';
  font-style: normal;
  font-display: block;
  font-weight: 100 900;
  src: url('fonts/roboto-latin-ext-wght-normal.woff2') format('woff2-variations');
  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-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-display: block;
  font-weight: 100 900;
  src: url('fonts/roboto-math-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+2190, U+2192, U+2194-21AE;
}

/* Noto Sans Thai Looped, with the traditional looped letterforms that learners see in textbooks. */
@font-face {
  font-family: 'Thai Looped';
  font-display: block;
  font-weight: 400;
  src: url('fonts/thai_looped_regular.ttf') format('truetype');
}

@font-face {
  font-family: 'Thai Looped';
  font-display: block;
  font-weight: 600;
  src: url('fonts/thai_looped_semibold.ttf') format('truetype');
}

:root {
  color-scheme: light;
  --primary: #34469d;
  --on-primary: #ffffff;
  --primary-container: #dde1ff;
  --on-primary-container: #001452;
  --secondary: #5a5d72;
  --on-secondary: #ffffff;
  --secondary-container: #dfe1f9;
  --on-secondary-container: #171b2c;
  --tertiary: #7a5900;
  --on-tertiary: #ffffff;
  --tertiary-container: #ffdea6;
  --on-tertiary-container: #261900;
  --error: #b3261e;
  --on-error: #ffffff;
  --error-container: #f9dedc;
  --on-error-container: #410e0b;
  --background: #fbf8ff;
  --on-background: #1b1b21;
  --surface: #fbf8ff;
  --on-surface: #1b1b21;
  --surface-variant: #e3e1ec;
  --on-surface-variant: #46464f;
  --surface-container-lowest: #ffffff;
  --surface-container-low: #f5f2fa;
  --surface-container: #efedf4;
  --surface-container-high: #eae7ef;
  --surface-container-highest: #e4e1e9;
  --outline: #767680;
  --outline-variant: #c7c5d0;

  /* Label colours for the consonant classes, which Thai learning material often colour-codes. */
  --class-low: #d3e4ff;
  --on-class-low: #001c38;
  --class-mid: #c4eFc6;
  --on-class-mid: #002108;
  --class-high: #ffd9e0;
  --on-class-high: #3f0018;
  --correct: #c4efc6;
  --on-correct: #002108;

  --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.15);
  --elevation-2: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.15);
  --scrim: rgba(0, 0, 0, 0.32);
  --dialog-scrim: rgba(0, 0, 0, 0.6);
  --emphasized: cubic-bezier(0.4, 0, 0.2, 1);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --primary: #b9c3ff;
    --on-primary: #0b2471;
    --primary-container: #263a91;
    --on-primary-container: #dde1ff;
    --secondary: #c3c5dd;
    --on-secondary: #2c2f42;
    --secondary-container: #434659;
    --on-secondary-container: #dfe1f9;
    --tertiary: #f6be48;
    --on-tertiary: #402d00;
    --tertiary-container: #5c4300;
    --on-tertiary-container: #ffdea6;
    --error: #f2b8b5;
    --on-error: #601410;
    --error-container: #8c1d18;
    --on-error-container: #f9dedc;
    --background: #121318;
    --on-background: #e4e1e9;
    --surface: #121318;
    --on-surface: #e4e1e9;
    --surface-variant: #46464f;
    --on-surface-variant: #c7c5d0;
    --surface-container-lowest: #0d0e13;
    --surface-container-low: #1b1b21;
    --surface-container: #1f1f25;
    --surface-container-high: #29292f;
    --surface-container-highest: #34343a;
    --outline: #90909a;
    --outline-variant: #46464f;

    --class-low: #00497d;
    --on-class-low: #d3e4ff;
    --class-mid: #1d5128;
    --on-class-mid: #c4efc6;
    --class-high: #6b1e36;
    --on-class-high: #ffd9e0;
    --correct: #1d5128;
    --on-correct: #c4efc6;
  }
}

/* Base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--background);
  color: var(--on-surface);
  font-family: 'Roboto', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  /* Quick taps, such as on flashcards, shouldn't zoom in like on a web page. */
  touch-action: manipulation;
}

body {
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  margin: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

h1,
h2,
p {
  margin: 0;
  font-weight: inherit;
}

svg.icon {
  display: block;
  flex: none;
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.thai {
  font-family: 'Thai Looped', 'Roboto', sans-serif;
}

/* Typography, from the Material 3 type scale */

.display-small { font-size: 36px; line-height: 44px; font-weight: 400; letter-spacing: 0; }
.headline-medium { font-size: 28px; line-height: 36px; font-weight: 400; letter-spacing: 0; }
.headline-small { font-size: 24px; line-height: 32px; font-weight: 400; letter-spacing: 0; }
.title-large { font-size: 22px; line-height: 28px; font-weight: 400; letter-spacing: 0; }
.title-medium { font-size: 16px; line-height: 24px; font-weight: 500; letter-spacing: 0.15px; }
.title-small { font-size: 14px; line-height: 20px; font-weight: 500; letter-spacing: 0.1px; }
.body-large { font-size: 16px; line-height: 24px; font-weight: 400; letter-spacing: 0.5px; }
.body-medium { font-size: 14px; line-height: 20px; font-weight: 400; letter-spacing: 0.25px; }
.label-large { font-size: 14px; line-height: 20px; font-weight: 500; letter-spacing: 0.1px; }
.label-medium { font-size: 12px; line-height: 16px; font-weight: 500; letter-spacing: 0.5px; }
.semibold { font-weight: 600; }
.medium { font-weight: 500; }
.on-surface-variant { color: var(--on-surface-variant); }

/* Ripples, drawn in the content colour of the element that is pressed */

.ripple {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.ripple-wave {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.1;
  pointer-events: none;
  transform: scale(0.2);
  transition: transform 225ms var(--emphasized), opacity 150ms linear;
  z-index: -1;
}

.ripple-wave.expanded {
  transform: scale(1);
}

.ripple-wave.fading {
  opacity: 0;
}

/* Screens and navigation */

#app {
  position: fixed;
  inset: 0;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--background);
  transition: opacity 700ms var(--emphasized);
}

.screen.entering {
  opacity: 0;
}

.screen.leaving {
  opacity: 0;
  pointer-events: none;
}

.top-app-bar {
  flex: none;
  display: flex;
  align-items: center;
  height: calc(64px + var(--safe-top));
  padding: var(--safe-top) calc(4px + var(--safe-right)) 0 calc(4px + var(--safe-left));
  background: var(--surface);
  color: var(--on-surface);
}

.top-app-bar .title {
  flex: 1;
  min-width: 0;
  padding: 0 16px 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  color: var(--on-surface-variant);
}

.icon-button.nav {
  color: var(--on-surface);
}

.icon-button.checked {
  color: var(--primary);
}

.screen-content {
  flex: 1;
  min-height: 0;
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
}

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 58px;
  min-height: 40px;
  padding: 8px 24px;
  border-radius: 9999px;
  white-space: nowrap;
  transition: background-color 150ms linear, color 150ms linear;
}

.button.with-icon {
  padding: 8px 24px 8px 16px;
}

.button.with-trailing-icon {
  padding: 8px 16px 8px 24px;
}

.button.tall {
  min-height: 52px;
}

.button.taller {
  min-height: 56px;
}

.button.filled {
  background: var(--primary);
  color: var(--on-primary);
}

.button.tonal {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

.button.outlined {
  border: 1px solid var(--outline-variant);
  color: var(--on-surface-variant);
}

.button.outlined.error {
  border-color: var(--error);
  color: var(--error);
}

.button.text {
  min-height: 40px;
  padding: 10px 12px;
  color: var(--primary);
}

.button.filled:disabled,
.button.tonal:disabled {
  background: color-mix(in srgb, var(--on-surface) 10%, transparent);
  color: color-mix(in srgb, var(--on-surface-variant) 38%, transparent);
}

.button.outlined:disabled {
  border-color: color-mix(in srgb, var(--outline-variant) 10%, transparent);
  color: color-mix(in srgb, var(--on-surface-variant) 38%, transparent);
}

.button .icon.small {
  width: 18px;
  height: 18px;
}

.button .label {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Cards and labels */

.elevated-card {
  border-radius: 28px;
  background: var(--surface-container-lowest);
  box-shadow: var(--elevation-1);
}

.labels {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-label {
  padding: 4px 12px;
  border-radius: 9999px;
  white-space: nowrap;
}

.chip-label.category { background: var(--secondary-container); color: var(--on-secondary-container); }
.chip-label.low { background: var(--class-low); color: var(--on-class-low); }
.chip-label.mid { background: var(--class-mid); color: var(--on-class-mid); }
.chip-label.high { background: var(--class-high); color: var(--on-class-high); }
.chip-label.badge { background: var(--tertiary-container); color: var(--on-tertiary-container); }

/* Progress */

.linear-progress {
  position: relative;
  height: 4px;
  --progress: 0;
}

.linear-progress .indicator,
.linear-progress .track,
.linear-progress .stop {
  position: absolute;
  top: 0;
  height: 4px;
  border-radius: 2px;
}

.linear-progress .indicator {
  left: 0;
  /* The rounded ends reach 2px past the progress, like the round caps on Android. */
  width: clamp(4px, calc(var(--progress) * 100% + 2px), 100%);
  background: var(--primary);
}

.linear-progress .track {
  /* The gap before the track shrinks along with the indicator when there's little progress. */
  left: calc(var(--progress) * 100% + min(var(--progress) * 100%, 8px) - 2px);
  right: 0;
  background: var(--secondary-container);
}

.linear-progress.empty .indicator {
  display: none;
}

.linear-progress.empty .track {
  left: 0;
}

.linear-progress .stop {
  right: 0;
  width: 4px;
  background: var(--primary);
}

.linear-progress.full .track,
.linear-progress.full .stop {
  display: none;
}

/* Letter cards */

.letter-card {
  position: relative;
  overflow: hidden;
}

.letter-card.clickable {
  cursor: pointer;
}

.letter-card-content {
  position: absolute;
  inset: 20px;
  display: flex;
  flex-direction: column;
  container: letter-card / size;
}

/* The space below the labels, whose shape decides whether the details go below or next to the letter. */
.letter-card-body {
  flex: 1;
  min-height: 0;
  margin-top: 16px;
  container-type: size;
}

/* On tall cards, the letter is followed by its details and the action, such as a button to listen. */
.letter-card-layout {
  display: grid;
  grid-template: 'symbol' minmax(0, 1fr) 'details' auto 'action' auto / 100%;
  justify-items: center;
  width: 100%;
  height: 100%;
  padding-bottom: 8px;
}

.letter-symbol {
  grid-area: symbol;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.letter-symbol span {
  font-family: 'Thai Looped', sans-serif;
  font-weight: 400;
  white-space: nowrap;
  font-size: calc(0.6 * min(100cqw, 60cqh));
  line-height: 1.5;
}

.letter-details {
  grid-area: details;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.letter-action {
  grid-area: action;
  margin-top: 16px;
}

/* On wide cards, the details and the action are centred next to the letter. */
@container (aspect-ratio > 1) {
  .letter-card-layout {
    grid-template:
      'symbol .' 1fr
      'symbol details' auto
      'symbol action' auto
      'symbol .' 1fr
      / minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    padding-bottom: 0;
  }

  .letter-symbol span {
    font-size: calc(0.6 * min(50cqw, 100cqh));
  }
}

/* Short cards, such as in landscape or split-screen, use smaller text and less spacing. */
@container letter-card (height < 300px) {
  .letter-card-body {
    margin-top: 8px;
  }

  .letter-details {
    gap: 8px;
  }

  .letter-action {
    margin-top: 8px;
  }

  .letter-answer .transliteration {
    font-size: 24px;
    line-height: 32px;
  }

  /* The details need the whole height of short, wide cards, so the action goes below the letter. */
  @container (aspect-ratio > 1) {
    .letter-card-layout {
      grid-template: 'symbol details' minmax(0, 1fr) 'action details' auto / minmax(0, 1fr) minmax(0, 1fr);
    }

    .letter-symbol span {
      font-size: calc(0.6 * min(50cqw, 100cqh - 56px));
    }
  }

  /* Very wide ones have room to put the action in a column of its own, next to the details. */
  @container (aspect-ratio >= 3) {
    .letter-card-layout {
      grid-template: 'symbol details action' minmax(0, 1fr) / minmax(0, 1fr) minmax(0, 1fr) auto;
      column-gap: 16px;
    }

    .letter-action {
      margin-top: 0;
    }

    .letter-symbol span {
      font-size: calc(0.6 * min(50cqw, 100cqh));
    }
  }
}

.letter-answer {
  display: grid;
  place-items: center;
  text-align: center;
}

.letter-answer > * {
  grid-area: 1 / 1;
}

.letter-answer .answer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: opacity 300ms var(--emphasized);
}

.letter-answer.hidden .answer {
  opacity: 0;
}

.name-and-meaning {
  line-height: 28px;
  color: var(--on-surface-variant);
  text-align: center;
}

.name-and-meaning .thai {
  font-weight: 500;
}

.pronounce-button {
  min-height: 48px;
}

.audio-spacer {
  height: 48px;
}

/* Home */

.home {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(32px + var(--safe-top)) calc(24px + var(--safe-right)) calc(32px + var(--safe-bottom))
    calc(24px + var(--safe-left));
}

.logo {
  width: 88px;
  height: 88px;
  border-radius: 24px;
  overflow: hidden;
  flex: none;
}

.logo svg {
  display: block;
  width: 100%;
  height: 100%;
}

.home-title {
  margin-top: 20px;
  text-align: center;
}

.filter-card {
  width: 100%;
  max-width: 960px;
  margin-top: 32px;
  overflow: hidden;
}

.filter-header {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 16px 24px;
  text-align: left;
}

.filter-header .filter-icon { color: var(--primary); }
.filter-header .filter-icon.error { color: var(--error); }
.filter-header .text { flex: 1; min-width: 0; }
.filter-header .summary { color: var(--on-surface-variant); }
.filter-header .summary.error { color: var(--error); }

.filter-header .chevron {
  transition: transform 300ms var(--emphasized);
}

.filter-card.expanded .filter-header .chevron {
  transform: rotate(180deg);
}

.filter-body {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows 300ms var(--emphasized), opacity 300ms var(--emphasized);
}

.filter-card.expanded .filter-body {
  grid-template-rows: 1fr;
  opacity: 1;
}

.filter-body > div {
  min-height: 0;
  overflow: hidden;
}

.filter-content {
  padding: 0 12px 16px;
}

.filter-content .segmented {
  margin: 0 0 16px;
}

.filter-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-options[hidden],
.letter-picker[hidden] {
  display: none;
}

.filter-option {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  min-height: 56px;
  padding: 0 12px;
  border-radius: 16px;
  background: var(--surface-container-high);
  color: var(--on-surface);
  text-align: left;
}

.filter-option.selected {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

.filter-option .name { flex: 1; }
.filter-option .count { opacity: 0.7; }

.rare-option {
  margin-top: 8px;
  padding: 8px 12px;
}

.rare-option .name {
  display: flex;
  flex-direction: column;
}

.rare-option .rare-letters {
  opacity: 0.7;
}

.rare-option .switch {
  margin-left: 0;
}

.checkbox {
  flex: none;
  width: 24px;
  display: flex;
  justify-content: center;
}

.checkbox span {
  display: flex;
  width: 20px;
  height: 20px;
  border: 2px solid var(--on-surface-variant);
  border-radius: 2px;
  transition: background-color 100ms linear, border-color 100ms linear;
}

.checkbox svg {
  width: 20px;
  height: 20px;
  margin: -2px;
  fill: none;
  stroke: var(--on-primary);
  stroke-width: 2px;
  stroke-dasharray: 20;
  stroke-dashoffset: 20;
  transition: stroke-dashoffset 150ms var(--emphasized);
}

.filter-option.selected .checkbox span {
  background: var(--primary);
  border-color: var(--primary);
}

.filter-option.selected .checkbox svg {
  stroke-dashoffset: 0;
}

.letter-picker {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 0 4px;
}

.picker-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.picker-group-header {
  display: flex;
  align-items: center;
}

.picker-group-header .text {
  flex: 1;
  min-width: 0;
}

.picker-group-header .picked-count {
  color: var(--on-surface-variant);
}

.class-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-chip {
  height: 32px;
  padding: 0 16px;
  border: 1px solid var(--outline-variant);
  border-radius: 8px;
  color: var(--on-surface-variant);
  transition: background-color 150ms linear, border-color 150ms linear;
}

.filter-chip.selected {
  border-color: var(--secondary-container);
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

/* As many columns as fit, with the tiles stretched to fill the width. */
.letter-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 8px;
}

/* A letter that can be picked, which is filled and outlined while it's picked. The outline is a
 * shadow, so its width can change without moving the symbol. */
.letter-tile {
  aspect-ratio: 1;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px var(--outline-variant);
  color: var(--on-surface-variant);
  overflow: hidden;
  transition: background-color 150ms linear, box-shadow 150ms linear;
}

.letter-tile.picked {
  background: var(--secondary-container);
  box-shadow: inset 0 0 0 2px var(--primary);
  color: var(--on-secondary-container);
}

.letter-tile svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.mode-cards {
  width: 100%;
  max-width: 960px;
  margin-top: 16px;
  display: grid;
  gap: 16px;
}

@media (min-width: 688px) {
  .mode-cards {
    grid-template-columns: 1fr 1fr;
  }
}

.mode-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px;
}

.mode-card-heading {
  display: flex;
  align-items: center;
  gap: 16px;
}

.mode-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary-container);
  color: var(--on-primary-container);
}

.mode-card-description {
  margin-top: 12px;
  color: var(--on-surface-variant);
}

.mode-buttons {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.mode-buttons > .grow {
  flex: 1 1 0;
  min-width: 0;
}

.switch-row {
  display: flex;
  align-items: center;
  width: 100%;
  margin-top: 12px;
  padding: 4px 0;
  text-align: left;
}

.switch-row .text {
  flex: 1;
}

.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  border-radius: 16px;
  border: 2px solid var(--outline);
  background: var(--surface-container-highest);
  transition: background-color 150ms linear, border-color 150ms linear;
}

.switch::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 14px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--outline);
  transform: translate(-50%, -50%);
  transition: left 150ms var(--emphasized), width 150ms var(--emphasized), height 150ms var(--emphasized),
    background-color 150ms linear;
}

.switch.checked {
  background: var(--primary);
  border-color: var(--primary);
}

.switch.checked::after {
  left: 34px;
  width: 24px;
  height: 24px;
  background: var(--on-primary);
}

.segmented {
  display: flex;
  width: 100%;
  /* The segments are 40px high within a 48px touch target, like on Android. */
  margin: 20px 0 4px;
}

.segment {
  flex: 1 1 0;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--outline);
  color: var(--on-surface);
  white-space: nowrap;
}

.segment:first-child {
  border-radius: 20px 0 0 20px;
}

.segment:last-child {
  border-radius: 0 20px 20px 0;
  margin-left: -1px;
}

.segment.selected {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
}

/* Menus and dialogs */

.menu-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
}

.menu {
  position: fixed;
  min-width: 112px;
  max-width: 280px;
  padding: 8px 0;
  border-radius: 4px;
  background: var(--surface-container);
  box-shadow: var(--elevation-2);
  transform-origin: top left;
  animation: menu-enter 120ms var(--emphasized);
}

.menu.above {
  transform-origin: bottom left;
}

.menu.leaving {
  opacity: 0;
  transition: opacity 75ms linear;
}

@keyframes menu-enter {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 48px;
  padding: 0 12px;
  color: var(--on-surface);
  text-align: left;
  white-space: nowrap;
}

.menu-item .icon {
  color: var(--on-surface-variant);
}

.dialog-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--dialog-scrim);
  animation: fade-in 150ms linear;
}

.dialog-layer.leaving {
  opacity: 0;
  transition: opacity 75ms linear;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.dialog {
  width: min(560px, calc(100vw - 68px));
  min-width: 280px;
  padding: 24px;
  border-radius: 28px;
  background: var(--surface-container-high);
  color: var(--on-surface);
  animation: dialog-enter 150ms var(--emphasized);
}

@keyframes dialog-enter {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
}

.dialog .dialog-icon {
  display: flex;
  justify-content: center;
  padding-bottom: 16px;
  color: var(--secondary);
}

.dialog .dialog-title {
  padding-bottom: 16px;
  text-align: center;
}

.dialog .dialog-text {
  padding-bottom: 24px;
  color: var(--on-surface-variant);
}

.dialog .dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Flashcards */

.deck {
  height: 100%;
  container-type: size;
}

.deck-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.deck-progress {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 560px;
  padding: 0 24px;
}

.deck-progress .linear-progress {
  flex: 1;
}

.deck-progress .position {
  color: var(--on-surface-variant);
  font-variant-numeric: tabular-nums;
}

.pager {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  gap: 16px;
  padding: 16px 32px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 32px;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.pager::-webkit-scrollbar {
  display: none;
}

.pager::after {
  /* Scroll containers leave out the end padding, so a spacer keeps it in place. */
  content: '';
  flex: 0 0 16px;
}

.page {
  flex: 0 0 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}

.page .letter-card {
  width: 100%;
  height: 100%;
  max-width: 560px;
  max-height: 720px;
}

.deck-navigation {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  padding: 0 24px 16px;
}

.deck-navigation .button {
  flex: 1 1 0;
}

/*
 * On short, wide screens, such as phones in landscape, the buttons are round icons on either side
 * of the card instead of below it, which leaves the card more height.
 */
@container (aspect-ratio >= 1.5) {
  .deck-layout {
    display: grid;
    grid-template: '. progress .' auto 'previous pager next' minmax(0, 1fr) / auto minmax(0, 1fr) auto;
    justify-items: center;
    align-items: center;
    padding: 0 24px;
  }

  .deck-progress {
    grid-area: progress;
  }

  .pager {
    grid-area: pager;
    height: 100%;
  }

  .deck-navigation {
    display: contents;
  }

  .deck-navigation .button {
    flex: none;
    width: 56px;
    min-width: 0;
    height: 56px;
    min-height: 0;
    padding: 0;
  }

  .deck-navigation .button:first-child {
    grid-area: previous;
  }

  .deck-navigation .button:last-child {
    grid-area: next;
  }

  /* Only the icon shows, while the text still names the button for screen readers. */
  .deck-navigation .button .label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Quiz */

.quiz-layout {
  height: 100%;
  container: quiz / size;
}

.quiz-column {
  display: grid;
  grid-template-rows: auto minmax(0, 720px) auto;
  align-content: start;
  width: 100%;
  max-width: 560px;
  height: 100%;
  margin: 0 auto;
  padding: 12px 24px 16px;
}

.quiz-card-area {
  min-height: 0;
  padding: 16px 0;
}

/* Only when there's room for both, so not in split-screen. */
@container (aspect-ratio >= 1.5) and (max-height: 559.98px) and (min-width: 600px) {
  .quiz-column {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: 1fr auto auto 1fr;
    align-content: stretch;
    column-gap: 24px;
    max-width: none;
    padding: 12px 24px;
  }

  .quiz-card-area {
    grid-column: 1;
    grid-row: 1 / -1;
    padding: 0;
  }

  .quiz-progress {
    grid-column: 2;
    grid-row: 2;
  }

  .quiz-controls {
    grid-column: 2;
    grid-row: 3;
    margin-top: 24px;
  }
}

.quiz-progress-text {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.quiz-progress-text .learned {
  flex: 1;
  color: var(--on-surface-variant);
}

.quiz-progress-text .repeats {
  color: var(--tertiary);
}

.question-slot {
  position: relative;
  height: 100%;
}

.question {
  position: absolute;
  inset: 0;
  transition: transform 400ms var(--emphasized), opacity 250ms linear;
}

.question.static {
  position: relative;
  inset: auto;
}

.question.entering {
  transform: translateX(33%);
  opacity: 0;
}

.question.leaving {
  transform: translateX(-33%);
  opacity: 0;
  pointer-events: none;
}

.question .letter-card,
.question .prompt-card {
  width: 100%;
  height: 100%;
}

.quiz-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.quiz-actions .question-text {
  padding-bottom: 12px;
  transition: opacity 150ms linear;
}

.quiz-actions .question-text.hidden {
  opacity: 0;
}

.quiz-actions .row {
  display: flex;
  gap: 12px;
  width: 100%;
}

.quiz-actions .row .button,
.quiz-actions > .button {
  flex: 1 1 0;
  width: 100%;
}

.prompt-card {
  position: relative;
}

.prompt-card-content {
  position: absolute;
  inset: 20px;
}

.prompt-card-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  padding-top: 32px;
  text-align: center;
}

.prompt-card .details {
  transition: opacity 300ms var(--emphasized);
}

.prompt-card .details.hidden {
  opacity: 0;
}

.prompt-card .labels {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

.find-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.choice-slot {
  position: relative;
  height: calc(72px * 2 + 8px);
}

.choice {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 72px;
  border-radius: 16px;
  border: 1px solid var(--outline-variant);
  background: var(--surface-container-lowest);
  color: var(--on-surface);
}

.choice .thai {
  font-size: 32px;
  line-height: 48px;
}

.choice.other .thai {
  opacity: 0.38;
}

.choice.correct {
  border-color: transparent;
  background: var(--correct);
  color: var(--on-correct);
}

.choice.wrong {
  border-color: transparent;
  background: var(--error-container);
  color: var(--on-error-container);
}

.choice .result-icon {
  position: absolute;
  right: 12px;
  width: 20px;
  height: 20px;
}

.feedback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

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

.feedback .text.hint {
  color: var(--on-surface-variant);
}

.feedback .button {
  width: 100%;
}

/*
 * Questions with their controls below the card and little height, such as in split-screen, show
 * the choices in one row and the hint next to the button, while the card leaves out its prompt and
 * shows the button to listen as an icon next to the transliteration.
 */
@container quiz (max-height: 479.98px) and ((aspect-ratio < 1.5) or (max-width: 599.98px)) {
  .quiz-card-area {
    padding: 8px 0;
  }

  .prompt-card-content {
    inset: 12px;
  }

  .prompt-card-body {
    display: grid;
    grid-template: 'name listen' auto 'details details' auto / auto auto;
    justify-content: center;
    align-content: center;
    row-gap: 4px;
  }

  .prompt-card-body .prompt {
    display: none;
  }

  .prompt-card-body .transliteration {
    grid-area: name;
    align-self: center;
    font-size: 28px;
    line-height: 36px;
  }

  .prompt-card-body .details {
    grid-area: details;
  }

  .prompt-card-body .pronounce-button {
    grid-area: listen;
    width: 48px;
    min-width: 0;
    height: 48px;
    margin-left: 8px;
    padding: 0;
  }

  /* Only the icon shows, while the text still names the button for screen readers. */
  .prompt-card-body .pronounce-button .label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .choice-slot {
    height: 56px;
  }

  .choice-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
  }

  .choice {
    height: 56px;
  }

  /* The narrow buttons keep the icon in the corner, clear of the letter. */
  .choice .result-icon {
    top: 6px;
    right: 6px;
    width: 16px;
    height: 16px;
  }

  .feedback {
    flex-direction: row;
    gap: 16px;
    text-align: start;
  }

  .feedback .text {
    flex: 1;
  }

  .feedback .button {
    width: auto;
    min-height: 48px;
  }
}

/* Quiz results */

.results {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.results-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  text-align: center;
}

.trophy {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--tertiary-container);
  color: var(--on-tertiary-container);
}

.trophy .icon {
  width: 48px;
  height: 48px;
}

.missed-letters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 720px;
}

.missed-letter {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 104px;
  padding: 12px 8px;
  border-radius: 16px;
  background: var(--surface-container-high);
}

.missed-letter .thai {
  font-size: 36px;
  line-height: 54px;
}

.missed-letter .count {
  color: var(--error);
}

.results-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 560px;
  margin-top: 32px;
}
