/* BolehLah UI v2: "Apple style" (calm grey ground, white cards, one green tint).
   Mobile-first: these styles are for a phone. Sizes use rem, so the page grows
   when the text size changes (in the app's settings or the phone's).
   Every colour is a token (a named variable) here, so changing the look means
   changing it in one place. */

/* Figtree, saved in app/fonts, so it also works offline. One file holds every
   weight from 400 to 700 (a "variable" font). Only Latin letters are in it:
   Chinese falls through to the phone's own font. */
@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("../fonts/figtree-latin.woff2") format("woff2");
}

:root {
  /* the app's green (the same as the logo) is the one tint colour */
  --pandan: #1d6b3a;
  --pandan-dark: #14502b;
  --pandan-pale: #e8f3eb;

  /* iPhone-like greys: a soft ground, white cards, near-black ink */
  --ground: #f2f2f7;
  --card: #ffffff;
  --fill: #eeeef0; /* small grey surfaces: icon squares, a pressed row */
  --line: #e5e5ea; /* thin lines between rows (decoration only) */
  --line-strong: #d1d1d6;
  --ink: #1c1c1e;
  --ink-soft: #48484a;
  --muted: #636366; /* at least 5:1 on white and on the ground */
  --edge: #8e8e93; /* answer borders and small icons: at least 3:1 on white */

  /* the kuih lapis on the day card */
  --lapis-1: #f2a7bd;
  --lapis-2: #fdf0d5;
  --lapis-3: #7cc193;

  /* wrong answers: a warm amber, never an alarming red */
  --amber: #b45309;
  --amber-pale: #fdebd3;
  --amber-line: #e9b77a;
  --amber-ink: #7a3d00;

  /* a streak of 3, 5 or 10 */
  --gold: #f2c14e;

  --radius: 1rem; /* cards and answers */
  --radius-big: 1.25rem; /* topic tiles, the sheet */
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --font: "Figtree", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1.125rem;
  line-height: 1.45;
  color: var(--ink);
  background: var(--ground);
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

/* A clear ring around whatever has the keyboard or screen-reader focus.
   (:focus-visible: not shown after a finger tap, only when it helps.) */
:focus-visible {
  outline: 3px solid var(--pandan);
  outline-offset: 2px;
}

#action:focus-visible,
.primary-button:focus-visible {
  outline-color: var(--ink);
}

/* Text only for screen readers (a heading the eye does not need) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Line icons (home, look back, speaker...). They take the text colour around them. */
.icon {
  width: 1.375em;
  height: 1.375em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The page is one full-height column, like a phone app: top bar, the screen
   (which takes whatever height is left), and the big button. Nothing needs
   scrolling at the normal text size. `dvh` is the height of the visible window,
   so the browser's own address bar does not hide anything. */
body.app-body {
  display: flex;
  flex-direction: column;
  height: 100vh; /* for old browsers that do not know dvh */
  height: 100dvh;
}

#screen {
  flex: 1;
  min-height: 0; /* lets the screen shrink instead of pushing the button off the page */
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow-y: auto; /* only a safety net, for the bigger text sizes */
  outline: none;
}

.center {
  margin: auto 0; /* centred in the free height */
  text-align: center;
}

.lead {
  font-size: 1.25rem;
  margin: 0 0 1rem;
}

.screen-title {
  flex: none;
  margin: 0.5rem 0.25rem 1rem;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
}

.instruction {
  flex: none;
  margin: 1rem 0.25rem 1.25rem;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.35;
}

/* ===== Buttons used in many places ===== */

.primary-button,
#action {
  display: block;
  width: 100%;
  min-height: 4rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
  background: var(--pandan);
  border: 0;
  border-radius: var(--radius);
}

.primary-button:active,
#action:active {
  background: var(--pandan-dark);
}

#action:disabled {
  color: var(--muted);
  background: var(--line);
}

.quiet-button {
  display: block;
  width: 100%;
  min-height: 4rem;
  font-size: 1.125rem;
  font-weight: 600;
  background: var(--card);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
}

.quiet-button:active {
  background: var(--fill);
}

/* A row's chevron ›, drawn with two borders so it is crisp at any size */
.chevron {
  flex: none;
  width: 0.625rem;
  height: 0.625rem;
  margin: 0 0.375rem 0 0.25rem;
  border-top: 2.5px solid var(--edge);
  border-right: 2.5px solid var(--edge);
  transform: rotate(45deg);
}

/* ===== Home: the logo, the day card, the topic tiles ===== */

.home-head {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 3.5rem;
  margin-bottom: 0.75rem;
}

.logo {
  display: block;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.7rem; /* rounded like an app icon */
}

.home-title-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.home-mode-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--pandan);
  letter-spacing: 0.03em;
}

.home-name {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.language-home {
  flex: none;
  min-width: 4.875rem;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  color: var(--pandan);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 700;
  text-align: center;
}

/* the settings button: a 4rem tap area around a smaller white circle */
.settings-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 4rem;
  height: 4rem;
  margin-right: -0.625rem;
  color: var(--ink-soft);
  background: none;
  border: 0;
}

.round-icon {
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  background: var(--card);
  border-radius: 50%;
  box-shadow: var(--shadow);
}

.settings-button:active .round-icon {
  background: var(--fill);
}

/* The green card with the day streak and a kuih lapis */
.day-card {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-height: 3.75rem;
  padding: 0.5rem 1rem;
  margin-bottom: 0.75rem;
  box-sizing: border-box;
  color: #fff;
  background: var(--pandan);
  border-radius: var(--radius-big);
}

.lapis {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: 2.375rem;
}

.lapis span {
  height: 0.375rem;
  border-radius: 0.2rem;
}

.lapis span:nth-child(1) { background: var(--lapis-1); }
.lapis span:nth-child(2) { background: var(--lapis-2); }
.lapis span:nth-child(3) { background: var(--lapis-3); }

.day-text {
  flex: 1;
  font-size: 1.125rem;
  font-weight: 700;
}

.day-cheer {
  flex: none;
  font-size: 1rem;
  font-weight: 600;
}

/* Two tiles in a row. Each topic gets the next colour, so neighbours never match. */
.topic-grid {
  flex: none;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.625rem;
}

.topic-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.125rem;
  min-height: 7.25rem;
  padding: 0.625rem 0.75rem 0.625rem 0.75rem;
  box-sizing: border-box;
  text-align: left;
  background: var(--card);
  border: 0;
  border-radius: var(--radius-big);
  box-shadow: var(--shadow);
}

.topic-tile:active {
  background: var(--fill);
}

.topic-tile:nth-child(6n + 1) { --tone: #e3f0e6; --tone-ink: #1d6b3a; }
.topic-tile:nth-child(6n + 2) { --tone: #f3e4d8; --tone-ink: #a35a2a; }
.topic-tile:nth-child(6n + 3) { --tone: #f8dde6; --tone-ink: #b03a64; }
.topic-tile:nth-child(6n + 4) { --tone: #dfe6f5; --tone-ink: #3a5fb0; }
.topic-tile:nth-child(6n + 5) { --tone: #fbefd0; --tone-ink: #8a6100; }
.topic-tile:nth-child(6n + 6) { --tone: #dcefee; --tone-ink: #1f6f6b; }

.tile-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  align-self: stretch;
  margin-bottom: 0.25rem;
}

/* The ring around the picture fills with her best score, like an Apple Watch ring.
   The circle's path length is set to 100, so app.js just sets --pct to the
   percentage and the stroke is drawn that far round. */
.ring-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  flex: none;
}

.ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg); /* start at the top, like a clock */
}

.ring circle {
  fill: none;
  stroke-width: 6;
}

.ring-track {
  stroke: var(--line);
}

.ring-fill {
  stroke: var(--tone-ink, var(--pandan));
  stroke-linecap: round;
  stroke-dasharray: var(--pct, 0) 100;
}

.topic-icon {
  display: grid;
  place-items: center;
  width: 2.125rem;
  height: 2.125rem;
  font-size: 1.25rem;
  line-height: 1;
  background: var(--tone, var(--pandan-pale));
  border-radius: 50%;
}

/* "✓ 8/10" in the tile's own colour: the number says it, not only the ring */
.topic-progress {
  font-size: 1rem;
  font-weight: 700;
  color: var(--tone-ink, var(--pandan));
}

.topic-mandarin {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.25;
}

.topic-malay {
  font-size: 1rem;
  line-height: 1.25;
  color: var(--muted);
}

/* Home holds the categories (7 and growing): a shorter tile, the picture beside the
   name instead of above it, so they fit one phone screen at her chosen text size. */
.topic-grid.compact .topic-tile {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "pic name" "pic malay";
  align-content: center;
  column-gap: 0.5rem;
  min-height: 5rem;
  padding: 0.5rem 0.625rem;
}

.topic-grid.compact .tile-top {
  grid-area: pic;
  flex-direction: column;
  justify-content: center;
  gap: 0.125rem;
  margin: 0;
}

.topic-grid.compact .topic-progress {
  font-size: 0.875rem;
}

.topic-grid.compact .topic-mandarin {
  grid-area: name;
  align-self: end;
}

.topic-grid.compact .topic-malay {
  grid-area: malay;
  align-self: start;
  font-size: 0.9375rem;
}

/* ===== Rows in a white card (the missed words, a topic's page) ===== */

.list-card,
.list-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 4.25rem;
  padding: 0.5rem 0.75rem 0.5rem 0.875rem;
  box-sizing: border-box;
  text-align: left;
  background: var(--card);
  border: 0;
}

.list-card {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.list-card:active,
.list-row:active {
  background: var(--fill);
}

.list-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.list-row + .list-row {
  border-top: 1px solid var(--line);
}

.row-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1.375rem;
  background: var(--fill);
  border-radius: 0.625rem;
}

.row-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.row-title {
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.3;
}

.row-sub {
  font-size: 1rem;
  line-height: 1.3;
  color: var(--muted);
}

.row-sub.topic-progress {
  font-weight: 600;
  color: var(--pandan);
}

/* "my missed words": an amber icon and count, so it stands out from the topics */
.missed-card {
  flex: none;
  margin-top: 0.75rem;
}

.missed-icon {
  color: var(--amber-ink);
  background: var(--amber-pale);
}

.missed-count {
  color: var(--amber-ink);
}

/* ===== A topic's page and the word list ===== */

.menu-head {
  flex: none;
  text-align: center;
  margin: 1rem 0 1.5rem;
}

.menu-icon {
  display: grid;
  place-items: center;
  width: 5rem;
  height: 5rem;
  margin: 0 auto 0.75rem;
  font-size: 2.75rem;
  background: var(--card);
  border-radius: 1.375rem;
  box-shadow: var(--shadow);
}

.menu-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
}

.menu-malay {
  margin: 0;
  font-size: 1.125rem;
  color: var(--muted);
}

/* A group page holds up to 6 topic tiles, so its heading is a smaller row */
.category-head {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.75rem;
  align-items: center;
  text-align: start;
  margin: 0.5rem 0 1rem;
}

.category-head .menu-icon {
  grid-row: span 2;
  width: 3.5rem;
  height: 3.5rem;
  margin: 0;
  font-size: 2rem;
  border-radius: 1rem;
}

.category-head .menu-title {
  font-size: 1.5rem;
}

.menu-best {
  display: inline-block;
  margin: 0.75rem 0 0;
  padding: 0.25rem 0.875rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--pandan);
  background: var(--pandan-pale);
  border-radius: 999px;
}

.vocab-help {
  flex: none;
  margin: -0.5rem 0.25rem 1rem;
  color: var(--muted);
}

.vocab-stage {
  flex: 1 0 auto; /* never squeezed below the card: if it does not fit, the page shrinks the text (fit.js) */
  display: flex;
  flex-direction: column;
  justify-content: center; /* the card sits in the middle of the free height */
  touch-action: pan-y; /* up and down still scroll (only if it must); sideways is ours, for the swipe */
}

/* the card slides in from the side it came from */
.vocab-card[data-slide] {
  animation: vocab-slide 0.22s ease-out;
}

.vocab-card[data-slide="from-left"] {
  --from: -1.5rem;
}

.vocab-card[data-slide="from-right"] {
  --from: 1.5rem;
}

@keyframes vocab-slide {
  from { opacity: 0; transform: translateX(var(--from)); }
}

/* the two buttons and the count under the card */
.vocab-nav {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.vocab-nav button {
  flex: 1;
  min-height: 4rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--pandan);
  background: var(--card);
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.vocab-nav button:active {
  background: var(--fill);
}

.vocab-nav button:disabled {
  color: var(--edge);
  background: transparent;
  box-shadow: none;
}

.vocab-count {
  flex: none;
  min-width: 4.5rem;
  text-align: center;
  font-weight: 600;
  color: var(--muted);
}

/* One word: a white card. Every line inside it is a button that reads that line aloud. */
.vocab-card {
  flex: none;
  overflow: hidden;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.vocab-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  width: 100%;
  min-height: 4.5rem;
  padding: 0.5rem 1rem;
  text-align: left;
  background: none;
  border: 0;
}

.vocab-line:active {
  background: var(--fill);
}

.vocab-line + .vocab-line {
  border-top: 1px solid var(--line);
}

.vocab-malay {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--pandan);
}

.vocab-mandarin {
  font-size: 1.5rem;
  font-weight: 500;
}

/* the example, in its own quiet block: the Malay sentence, then the Chinese */
.vocab-example {
  margin: 0.25rem 0.5rem 0.5rem;
  background: var(--ground);
  border-radius: 0.75rem;
  overflow: hidden;
}

.vocab-example-malay {
  font-size: 1.125rem;
  font-weight: 500;
  color: var(--ink);
}

.vocab-example-mandarin {
  font-size: 1.125rem;
  color: var(--muted);
}

.vocab-weak {
  margin: 0;
  padding: 0 1rem 0.625rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--amber-ink);
}

/* ===== Settings ===== */

.settings-card {
  flex: none;
  margin-bottom: 0.875rem;
  background: var(--card);
  border-radius: var(--radius-big);
  box-shadow: var(--shadow);
}

.settings-card:not(.switch-card) {
  padding: 0.875rem;
}

.settings-label {
  margin: 0 0 0.625rem 0.25rem;
  font-size: 1.125rem;
  font-weight: 600;
}

/* Three big choices, each showing how big the text will be */
.lang-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.lang-options .size-option {
  font-size: 0.875rem;
  padding: 0.25rem;
}

.size-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.size-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 4.75rem;
  font-size: 1rem;
  color: var(--muted);
  background: var(--card);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
}

.size-sample {
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink);
}

.size-option[data-size="normal"] .size-sample { font-size: 1.25rem; }
.size-option[data-size="large"] .size-sample { font-size: 1.5625rem; }
.size-option[data-size="huge"] .size-sample { font-size: 1.875rem; }

.size-option[aria-checked="true"] {
  font-weight: 700;
  color: var(--pandan);
  background: var(--pandan-pale);
  border: 3px solid var(--pandan);
}

.size-option[aria-checked="true"] .size-sample {
  color: var(--pandan);
}

/* A row that is one big switch: the words on the left, an iPhone-style switch on the right */
.switch-card {
  overflow: hidden;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  min-height: 4.5rem;
  padding: 0.5rem 1rem;
  text-align: left;
  background: var(--card);
  border: 0;
}

.switch-row + .switch-row {
  border-top: 1px solid var(--line);
}

.switch-row:active {
  background: var(--fill);
}

.switch {
  flex: none;
  display: flex;
  width: 3.25rem;
  height: 2rem;
  padding: 0.1875rem;
  box-sizing: border-box;
  background: var(--line-strong);
  border-radius: 1rem;
  transition: background 0.2s;
}

.switch-knob {
  width: 1.625rem;
  height: 1.625rem;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}

.switch-row[aria-checked="true"] .switch {
  background: var(--pandan);
}

.switch-row[aria-checked="true"] .switch-knob {
  transform: translateX(1.25rem);
}

.reset-button {
  flex: none;
  color: var(--amber-ink);
}


/* ===== Top bar: home, progress, look back ===== */

.top-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.25rem 0.75rem 0;
  box-sizing: border-box;
}

/* The home and look-back buttons: a white rounded button with an icon and a word.
   The button itself stays 4rem tall (an easy tap); only the drawn pill is smaller. */
.bar-button {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 4rem;
  min-height: 4rem;
  padding: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--pandan);
  background: none;
  border: 0;
}

.bar-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 2.25rem;
  padding: 0 0.75rem 0 0.5rem;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 999px;
}

.bar-pill .icon {
  width: 1.125rem;
  height: 1.125rem;
}

.language-button {
  min-width: 4.875rem;
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.875rem;
}

.language-setting {
  min-height: 4rem;
  margin: 0 0 0.75rem;
}

.bar-button:active .bar-pill {
  background: var(--pandan-pale);
  border-color: var(--pandan);
}

/* nothing to look back at yet: still readable, just quiet (and not tappable) */
#review-button:disabled {
  color: var(--muted);
}

#review-button:disabled .bar-pill {
  background: var(--fill);
  border-color: transparent;
}

/* The first time: one soft glow around 回顾, twice, so she notices it (no bouncing) */
#review-button.nudge .bar-pill {
  animation: glow 1.6s ease-in-out 2;
}

@keyframes glow {
  0%, 100% { background: var(--card); box-shadow: 0 0 0 0 transparent; }
  50% { background: var(--amber-pale); box-shadow: 0 0 0 0.25rem var(--amber-pale); }
}

.progress {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
}

.progress-bar {
  display: block;
  height: 0.5rem;
  overflow: hidden;
  background: var(--line);
  border-radius: 999px;
}

.progress-fill {
  display: block;
  width: var(--done, 0%);
  height: 100%;
  background: var(--pandan);
  border-radius: 999px;
  transition: width 0.4s ease-out;
}

.progress-line {
  margin: 0;
  text-align: center;
  font-size: 1rem;
  color: var(--muted);
}

/* 🔥 and the number: it never relies on colour, the number says it all */
.streak {
  display: inline-block;
  margin-left: 0.375rem;
  font-weight: 700;
  color: var(--amber-ink);
}

.streak.pop {
  animation: pop 0.4s ease-out;
}

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

/* ===== The one big button, always in the same place ===== */

.action-bar {
  flex: none;
  padding: 0.75rem 1rem 1rem;
  background: var(--ground);
}

#action {
  max-width: 40rem;
  margin: 0 auto;
}

/* ===== Questions ===== */

/* the big round play button of a listen question */
.play {
  display: grid;
  place-items: center;
  border: 0;
}

.play-big {
  flex: none;
  width: 4.5rem; /* big enough to find, no bigger: the answers matter more */
  height: 4.5rem;
  margin: 0 auto 1.25rem;
  color: #fff;
  background: var(--pandan);
  border-radius: 50%;
  box-shadow: 0 0 0 0.375rem var(--pandan-pale);
}

.play-big:active {
  background: var(--pandan-dark);
}

.icon-big {
  width: 50%;
  height: 50%;
}

/* the speaker buttons in the popup: a 4rem pale green circle */
/* Answers */
.choices {
  flex: 1; /* the answers share the height that is left */
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.choice-row {
  display: flex;
  flex: 1 1 4rem;
  min-height: 4rem; /* never smaller than a comfortable tap target */
  max-height: 4.75rem; /* and not huge on a tall phone */
}

.choice {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.5rem 1rem;
  font-size: 1.375rem;
  font-weight: 500;
  text-align: left;
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* The circle on the left, like a radio button: empty, a dot when selected, then
   ✓ (right) or ✗ (wrong) after 确认. The shape always says it, not only the colour. */
.marker {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  box-sizing: border-box;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  border: 2px solid var(--edge);
  border-radius: 50%;
}

.choice[data-state="selected"],
.choice[data-state="right"] {
  font-weight: 600;
  background: var(--pandan-pale);
  border: 2.5px solid var(--pandan);
  padding: calc(0.5rem - 1px) calc(1rem - 1px);
}

.choice[data-state="selected"] .marker {
  border-color: var(--pandan);
  background: radial-gradient(circle, var(--pandan) 0 0.3rem, transparent 0.32rem);
}

.choice[data-state="right"] .marker {
  border-color: var(--pandan);
  background: var(--pandan);
}

.choice[data-state="right"] .marker::before {
  content: "✓";
}

.choice[data-state="wrong"] {
  background: var(--amber-pale);
  border: 2.5px solid var(--amber);
  padding: calc(0.5rem - 1px) calc(1rem - 1px);
}

.choice[data-state="wrong"] .marker {
  border-color: var(--amber);
  background: var(--amber);
}

.choice[data-state="wrong"] .marker::before {
  content: "✗";
}

/* The speaker inside a Malay answer: it tells her "tap me to hear it".
   It stays still, and moves gently only while its own word plays. */
.speaker {
  display: flex;
  margin-left: auto;
  flex: none;
  color: var(--edge);
}

.choice[data-state="selected"] .speaker,
.choice[data-state="right"] .speaker,
.choice[data-speaking="true"] .speaker,
.vocab-line .speaker {
  color: var(--pandan);
}

.choice[data-speaking="true"] .speaker,
.vocab-line[data-speaking="true"] .speaker {
  animation: talk 0.7s ease-in-out infinite;
}

@keyframes talk {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.12); opacity: 0.7; }
}

/* Sentence questions: tap the words into order. Placed words leave the pool, so
   the screen stays the same height while she builds the sentence. */
.instruction-small {
  margin-bottom: 0.25rem;
  font-size: 1.0625rem;
  font-weight: 500;
  color: var(--muted);
}

.order-prompt {
  flex: none;
  margin: 0;
  font-size: 1.625rem;
  font-weight: 600;
}

.built,
.tile-pool {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.5rem;
}

.built {
  min-height: 5.25rem;
  padding: 0.5rem;
  margin-bottom: 1.25rem;
  box-sizing: border-box;
  background: var(--card);
  border: 2px dashed var(--edge);
  border-radius: var(--radius-big);
}

.built:empty::before {
  content: "点下面的词，排成句子";
  align-self: center;
  padding-left: 0.5rem;
  font-size: 1rem;
  color: var(--muted);
}

.tile {
  min-height: 4rem;
  min-width: 4rem;
  padding: 0.25rem 1.125rem;
  font-size: 1.375rem;
  font-weight: 500;
  background: var(--card);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 2px 0 var(--line-strong);
}

.built .tile {
  color: #fff;
  background: var(--pandan);
  border-color: var(--pandan);
  box-shadow: none;
}

.tile:disabled {
  cursor: default;
}

/* Finish the sentence: the first words are already in place. They look like placed words
   but paler and flat, so she sees they are part of the sentence and cannot be moved. */
.built .tile-given {
  display: inline-flex;
  align-items: center;
  color: var(--pandan-dark);
  background: var(--pandan-pale);
  border: 1.5px solid var(--pandan-pale);
}

.built[data-state="wrong"] .tile-given {
  color: var(--ink);
  background: transparent;
  border-color: transparent;
}

/* Fill the gap: the Malay sentence with a dashed slot. The word she picks drops into it. */
.gap-sentence {
  flex: none;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 2.2;
  text-align: center;
  background: var(--card);
  border-radius: var(--radius-big);
  box-shadow: var(--shadow);
}

.gap {
  display: inline-block;
  min-width: 5.5rem;
  margin: 0 0.25rem;
  padding: 0 0.5rem;
  line-height: 1.5;
  vertical-align: middle;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
}

/* an empty gap shows a soft "?" so it reads as "something goes here" */
.gap:not([data-filled]) .gap-word::before {
  content: "？";
  color: var(--muted);
}

.gap[data-filled] {
  font-weight: 700;
  color: var(--pandan-dark);
  background: var(--pandan-pale);
  border: 2px solid var(--pandan);
}

.gap.drop {
  animation: pop 0.3s ease-out;
}

/* After 确认: ✓ or ✗ beside the word, so colour is not the only sign */
.gap[data-state="right"]::after {
  content: " ✓";
  color: var(--pandan);
}

.gap[data-state="wrong"] {
  color: var(--amber-ink);
  background: var(--amber-pale);
  border-color: var(--amber);
  text-decoration: underline wavy var(--amber);
  text-underline-offset: 0.3em;
}

.gap[data-state="wrong"]::after {
  content: " ✗";
}

/* After 确认: the whole line is marked, with a ✓ or ✗ so colour is not the only sign */
.built[data-state="right"] {
  border: 3px solid var(--pandan);
  background: var(--pandan-pale);
}

.built[data-state="wrong"] {
  border: 3px solid var(--amber);
  background: var(--amber-pale);
}

.built[data-state="wrong"] .tile {
  color: var(--ink);
  background: var(--card);
  border-color: var(--line-strong);
}

/* a word that is not in its right place: an amber border and a wavy underline (a shape, not only a colour) */
.built[data-state="wrong"] .tile[data-place="wrong"] {
  border: 2px solid var(--amber);
  background: var(--amber-pale);
  text-decoration: underline wavy var(--amber);
  text-underline-offset: 0.3em;
}

.built[data-state="right"]::before,
.built[data-state="wrong"]::before {
  align-self: center;
  padding: 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.built[data-state="right"]::before {
  content: "✓";
  color: var(--pandan);
}

.built[data-state="wrong"]::before {
  content: "✗";
  color: var(--amber-ink);
}

/* ===== Score screen ===== */

/* The score inside a ring that fills up to the share of right answers */
.score-ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 10rem;
  height: 10rem;
  margin: 0 auto 1rem;
}

.score-ring .ring circle {
  stroke-width: 10;
}

.score-ring .ring-fill {
  stroke: var(--pandan);
  animation: ring-in 0.9s ease-out;
}

@keyframes ring-in {
  from { stroke-dasharray: 0 100; }
}

.score {
  margin: 0;
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--pandan);
}

.done-title {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 700;
}

.best-streak {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--amber-ink);
}

.new-best {
  display: inline-block;
  margin: 0 0 0.75rem;
  padding: 0.25rem 1rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--pandan);
  background: var(--pandan-pale);
  border-radius: 999px;
}

.done-cheer {
  margin: 0 0 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.done-reviewed {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--pandan);
}

.secondary-button {
  margin-top: 1.5rem;
  color: var(--pandan);
}

/* Shown only in review mode (?review=1) */
.review-banner {
  margin: 0;
  padding: 0.5rem 1rem;
  text-align: center;
  background: #ffe28a;
  border-bottom: 3px solid #b8860b;
}

/* ===== Small "are you sure?" popups (home, reset) ===== */

.ask-dialog {
  width: min(24rem, calc(100vw - 2rem));
  padding: 1.5rem 1.25rem 1.25rem;
  box-sizing: border-box;
  color: var(--ink);
  background: var(--card);
  border: 0;
  border-radius: 1.5rem;
}

.ask-dialog::backdrop,
#lesson-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.ask-question {
  margin: 0 0 1.25rem;
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
}

.ask-dialog .primary-button {
  margin-bottom: 0.625rem;
}

/* ===== The answer popup: a sheet on the bottom edge ===== */

#lesson-dialog {
  width: 100%;
  max-width: 32rem;
  max-height: calc(100% - 1.5rem); /* never taller than the window; scrolls inside only if it must */
  margin: auto auto 0; /* sits on the bottom edge */
  overflow-y: auto;
  padding: 0.75rem 1rem 1rem;
  box-sizing: border-box;
  color: var(--ink);
  background: var(--ground);
  border: 0;
  border-radius: 1.375rem 1.375rem 0 0;
}

#lesson-dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lesson-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center; /* 答对了！ sits in the middle, like the amber band */
  gap: 0.375rem 0.75rem;
}

/* The result line. Right: green with a ✓ in a circle. Wrong: a warm amber band,
   never an alarming red, because a wrong answer is encouragement. The words say it too. */
.lesson-result {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--pandan);
}

.lesson-result::before {
  content: "✓";
  flex: none;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  font-size: 1.125rem;
  color: #fff;
  background: var(--pandan);
  border-radius: 50%;
}

#lesson-dialog[data-result="wrong"] .lesson-result {
  justify-content: center;
  padding: 0.5rem 1rem;
  color: var(--amber-ink);
  background: var(--amber-pale);
  border-radius: var(--radius);
}

#lesson-dialog[data-result="wrong"] .lesson-result::before {
  content: none;
}

.lesson-streak {
  flex: none;
  margin: 0;
  padding: 0.25rem 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--amber-ink);
  background: var(--amber-pale);
  border-radius: 999px;
}

/* a streak of 3, 5 or 10: a warm gold chip that fades in, with a fanfare to match */
.lesson-streak[data-milestone="true"] {
  color: var(--ink);
  background: var(--gold);
  animation: fade-in 0.5s ease-out;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(0.25rem); }
}

/* the dictionary card: the word, its speaker, and the usage note */
.entry-card {
  padding: 0.125rem 0.75rem 0.5rem 1rem;
  background: var(--card);
  border-radius: var(--radius);
}

.entry-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.entry-words {
  flex: 1;
  min-width: 0;
}

.entry-malay {
  margin: 0;
  font-size: 1.875rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--pandan);
}

.entry-mandarin {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.entry-note {
  margin: 0.125rem 0 0;
  font-size: 1.0625rem;
  color: var(--ink-soft);
}

.entry-note:empty {
  display: none;
}

.entry-example {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.375rem 0.5rem 0.125rem 1rem;
  background: var(--card);
  border-radius: var(--radius);
}

.example-text {
  flex: 1;
  min-width: 0;
}

/* A sentence question: the right sentence (in the example card) comes first,
   straight after the result and the order she made; the word card follows. */
#lesson-dialog[data-kind="sentence"] > * {
  order: 2;
}

#lesson-dialog[data-kind="sentence"] > .lesson-top,
#lesson-dialog[data-kind="sentence"] > .picked-line {
  order: 0;
}

#lesson-dialog[data-kind="sentence"] > .entry-example {
  order: 1;
}

#lesson-dialog[data-kind="sentence"] .entry-example-label {
  font-weight: 600;
  color: var(--pandan);
}

.entry-example p {
  margin: 0;
}

.entry-example-label {
  font-size: 1rem;
  color: var(--muted);
}

.entry-example-malay {
  font-size: 1.125rem;
  font-weight: 600;
}

.entry-example-mandarin {
  font-size: 1.0625rem;
  color: var(--ink-soft);
}

/* "你选的是": the word she picked, first, so it is noticed; its speaker stays a big tap target */
.picked-line {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  padding: 0.25rem 0.25rem 0.25rem 0.875rem;
  color: var(--amber-ink);
  background: var(--card);
  border: 2px solid var(--amber-line);
  border-radius: var(--radius);
}

.picked-text {
  margin: 0;
  padding: 0.25rem 0;
  font-size: 1.1875rem;
  word-break: keep-all; /* a Chinese phrase stays on one line instead of splitting in the middle */
}

.picked-label {
  display: block;
  font-size: 1rem;
  font-weight: 600;
}

.picked-malay {
  font-weight: 700;
}

.correct-label {
  margin: 0 0 0.125rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--amber-ink);
}

/* after a wrong sentence: the right sentence, big enough to read */

.entry-unchecked {
  margin: 0;
  padding: 0.5rem;
  background: #ffe28a;
  border: 3px solid #b8860b;
  border-radius: 0.5rem;
}

/* the one-time tip in the first popup */
.lesson-hint {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  background: var(--amber-pale);
  border-radius: var(--radius);
}

/* ← 前一题 / 后一题 → when looking back */
.review-nav {
  display: flex;
  gap: 0.625rem;
}

.review-nav button {
  flex: 1;
  min-height: 4rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--pandan);
  background: var(--card);
  border: 0;
  border-radius: var(--radius);
}

.review-nav button:disabled {
  color: var(--edge);
}

/* ===== Short phones: tighten a little so everything still fits without scrolling ===== */

/* the question keeps its size (it must stay bigger than the answers); only the space around it shrinks */
@media (max-height: 40rem) {
  .instruction {
    margin: 0.5rem 0.25rem 0.75rem;
  }

  .play-big {
    margin-bottom: 1rem;
  }
}

@media (max-height: 42rem) {
  #lesson-dialog[open] {
    gap: 0.5rem;
  }

  .lesson-result {
    font-size: 1.25rem;
  }

  .entry-malay {
    font-size: 1.625rem;
  }

  .entry-mandarin {
    font-size: 1.125rem;
  }

  .entry-note {
    font-size: 1rem;
  }

  .entry-example {
    padding: 0.5rem 0.875rem;
  }

  .entry-example-malay,
  .entry-example-mandarin {
    font-size: 1rem;
  }

  .picked-text {
    font-size: 1.0625rem;
  }
}

/* No moving parts when she switches animations off in the settings (app.js sets
   data-motion="off"), or when the phone itself asks for less motion. */
:root[data-motion="off"] *,
:root[data-motion="off"] *::before,
:root[data-motion="off"] *::after {
  animation: none !important;
  transition: none !important;
}

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

/* ===== Pinyin above the Chinese characters (the 拼音 setting; see js/pinyin.js) ===== */

ruby {
  ruby-position: over;
}

/* never smaller than 0.6875rem (11px), so it can still be read; it takes the colour of the
   text around it, so it also works on the green buttons */
rt {
  font-size: max(0.6em, 0.6875rem);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.1;
  opacity: 0.85;
}

/* ===== The Chinese word (or sentence) to read in a question, with its speaker ===== */

.prompt-card {
  flex: none;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 5.5rem;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  box-sizing: border-box;
  text-align: center;
  background: var(--card);
  border: 0;
  border-radius: var(--radius-big);
  box-shadow: var(--shadow);
}

.prompt-card:active {
  background: var(--fill);
}

.prompt-text {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.3;
}

/* a whole sentence is longer than a word: a little smaller */
.prompt-text.order-prompt {
  font-size: 1.5rem;
  font-weight: 600;
}

/* The speakers in the popup: a small round icon right beside the word or sentence it reads.
   The button is still 4rem wide and tall (an easy tap), only the drawn circle is small. */
/* A line of the popup: the word or sentence with a small speaker icon right after it.
   The whole line is the button, so the target is big even though the icon is small. */
.speak-line {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.625rem;
  width: calc(100% + 1rem);
  min-height: 3.5rem; /* the whole line is the button: wide, so this height is still an easy tap */
  margin: 0 -0.5rem;
  padding: 0.25rem 0.5rem;
  box-sizing: border-box;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 0.75rem;
}

.speak-line:active:not(:disabled) {
  background: var(--fill);
}

/* a thin line between two lines of the same card, so the space between them looks planned */
.speak-line + .speak-line {
  border-top: 1px solid var(--line);
  border-radius: 0;
}

.speak-line:disabled {
  color: inherit; /* a line with no audio file is plain text, not a greyed-out button */
  cursor: default;
}

.speak-line > span:first-child {
  min-width: 0;
}

.speak-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  color: var(--pandan);
  background: var(--pandan-pale);
  border-radius: 50%;
}

.speak-line:active:not(:disabled) .speak-icon {
  background: #cfe3d6;
}

.speak-icon .icon {
  width: 1.375rem;
  height: 1.375rem;
}

.speak-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 4rem;
  height: 4rem;
  margin-block: -0.5rem; /* the touch area is a little taller than the row, so the rows stay close together */
  padding: 0;
  color: var(--pandan);
  background: radial-gradient(circle, var(--pandan-pale) 0 1.125rem, transparent 1.2rem);
  border: 0;
}

.speak-btn:active {
  background: radial-gradient(circle, #cfe3d6 0 1.125rem, transparent 1.2rem);
}

.speak-btn .icon {
  width: 1.375rem;
  height: 1.375rem;
}

.picked-line .speak-btn {
  color: var(--amber-ink);
  background: radial-gradient(circle, var(--amber-pale) 0 1.125rem, transparent 1.2rem);
}
