/* Components and tokens come from timeless (timeless.min.css). This file is
   the app's layout and the pieces timeless doesn't have: the course path,
   exercises and the character's speech bubble.

   Fredoka (fredoka.woff2) is by Milena Brandão, under the SIL Open Font
   License 1.1, from Google Fonts. */

@font-face {
  font-family: "Fredoka";
  src: url("/ui/fredoka.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
  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;
}

:root {
  /* Brand: open-color green */
  --color-brand-25: var(--color-green-25);
  --color-brand-50: var(--color-green-50);
  --color-brand-100: var(--color-green-100);
  --color-brand-200: var(--color-green-200);
  --color-brand-300: var(--color-green-300);
  --color-brand-400: var(--color-green-400);
  --color-brand-500: var(--color-green-500);
  --color-brand-600: var(--color-green-600);
  --color-brand-700: var(--color-green-700);
  --color-brand-800: var(--color-green-800);
  --color-brand-900: var(--color-green-900);
  --color-brand-950: var(--color-green-950);

  /* Tinted surfaces, softened in dark mode the way timeless's badges are */
  --tint-brand: var(--color-brand-50);
  --tint-success: var(--color-success-50);
  --tint-error: var(--color-error-50);
  --surface: var(--color-alpha-white);
  --gap: calc(var(--spacing) * 4);
  /* A rounded face for headings, the path and big numbers */
  --font-display: "Fredoka", var(--font-body);
}
.dark-mode {
  --tint-brand: color-mix(in srgb, var(--color-brand-500) 16%, transparent);
  --tint-success: color-mix(in srgb, var(--color-success-500) 14%, var(--color-gray-25));
  --tint-error: color-mix(in srgb, var(--color-error-500) 14%, var(--color-gray-25));
  --surface: var(--color-gray-50);
}

/* Element defaults sit in timeless's base layer so its components override
   them; everything unlayered below would win over any component */
@layer base {
  * { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body {
    margin: 0;
    background: var(--color-gray-25);
    color: var(--color-gray-900);
    font-size: var(--text-md);
    line-height: var(--text-md--line-height);
    -webkit-tap-highlight-color: transparent;
  }
  h1, h2 { font-family: var(--font-display); }
  h1 {
    margin: 0;
    font-size: var(--text-display-xs);
    line-height: var(--text-display-xs--line-height);
    font-weight: var(--font-weight-semibold);
  }
  h2 { margin: 0; font-size: var(--text-lg); line-height: var(--text-lg--line-height); font-weight: var(--font-weight-semibold); }
  h3 { margin: 28px 0 8px; font-size: var(--text-md); font-weight: var(--font-weight-semibold); }
  p { margin: 0; }
  a { color: var(--color-brand-700); }
  /* Links drawn as buttons */
  a[is~=Button] { text-decoration: none; }
  code { font-family: var(--font-mono); font-size: var(--text-sm); }
}

#app {
  max-width: 680px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left));
}
.muted { color: var(--color-gray-650); }
.small { font-size: var(--text-sm); line-height: var(--text-sm--line-height); }
.row { display: flex; gap: calc(var(--spacing) * 2); align-items: center; flex-wrap: wrap; }
.spread { display: flex; gap: calc(var(--spacing) * 2); align-items: center; justify-content: space-between; }
.topbar { margin: 0 -8px 12px; }
header.title { display: flex; flex-direction: column; align-items: flex-start; gap: calc(var(--spacing) * 2); margin-bottom: 12px; }
.card {
  background: var(--surface);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xs);
  padding: calc(var(--spacing) * 5);
}
/* An Empty state filling the screen: lesson complete, errors */
.empty { margin-top: 18vh; }
.empty code { display: block; margin-top: 8px; padding: 8px 12px; border-radius: var(--radius-md); background: var(--color-gray-100); color: var(--color-gray-900); }

.unlock { display: flex; gap: 8px; width: min(100%, 360px); }
.empty .problem { color: var(--color-error-600); }

/* Pressable: a 3D edge that drops when you press, for the actions that move
   you forward and the answers you pick */
.press[is~=Button] {
  --edge: var(--color-gray-300);
  font-family: var(--font-display);
  font-weight: 600;
  box-shadow: 0 4px 0 var(--edge);
  transition: transform .08s, box-shadow .08s, background-color .15s;
}
.press[is~=primary] { --edge: var(--color-brand-900); }
.press[is~=danger] { --edge: var(--color-error-900); }
.press[is~=Button]:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 var(--edge); }
.press[is~=Button]:disabled { box-shadow: 0 4px 0 var(--color-gray-200); }

/* Meters and rings show progress */
.meter { height: 14px; border-radius: var(--radius-full); background: var(--color-gray-200); overflow: hidden; }
.meter > i {
  display: block;
  height: 100%;
  min-width: 14px;
  border-radius: inherit;
  background: var(--color-brand-600);
  /* a light stripe along the top, so it reads as filled */
  box-shadow: inset 0 4px 0 -1px color-mix(in srgb, var(--color-white) 30%, transparent);
  transition: width .4s cubic-bezier(.2, .8, .2, 1);
}
.ring {
  --size: 56px;
  flex: none;
  width: var(--size);
  height: var(--size);
  display: grid;
  place-items: center;
  border-radius: var(--radius-full);
  background:
    radial-gradient(closest-side, var(--surface) calc(100% - 7px), transparent calc(100% - 6px)),
    conic-gradient(var(--color-brand-600) calc(var(--value) * 1%), var(--color-gray-200) 0);
}
.ring strong { font: 600 var(--text-sm) / 1 var(--font-display); }
.ring.big { --size: 104px; }
.ring.big strong { font-size: var(--text-xl); }

/* Home */
h1 + .hero { margin-top: 16px; }
.hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "mascot pitch ring";
  align-items: center;
  gap: 16px 24px;
  padding: 20px 24px;
}
.hero .mascot { grid-area: mascot; }
.hero .ring { grid-area: ring; }
.hero .pitch { grid-area: pitch; min-width: 0; display: grid; gap: 4px; justify-items: start; }
.hero h2 { font-size: var(--text-xl); line-height: var(--text-xl--line-height); }
.hero .row { margin-top: 12px; }
.hero .mascot { width: 96px; flex: none; }
.courses-title { margin: 32px 0 12px; }
.courses { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.course { display: flex; align-items: center; gap: 14px; color: inherit; text-decoration: none; transition: border-color .15s, box-shadow .15s; }
.course:hover { border-color: var(--color-brand-300); box-shadow: var(--shadow-md); }
.course h3 { margin: 0; font: 600 var(--text-lg) / var(--text-lg--line-height) var(--font-display); }
@media (max-width: 560px) {
  .hero { grid-template-columns: 1fr auto; grid-template-areas: "mascot ring" "pitch pitch"; }
  .hero .mascot { width: 80px; }
}

/* The course path */
.meter.overall { margin: 4px 0 16px; }
.extras { margin-bottom: 8px; }
.part-title { display: flex; align-items: center; gap: 8px; margin: 36px 0 12px; font-size: var(--text-lg); }
.unit + .unit { margin-top: 28px; }
.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-radius: var(--radius-2xl);
  background: var(--unit);
  box-shadow: 0 4px 0 var(--unit-edge);
  color: var(--color-white);
}
.banner > div:first-child { flex: 1; min-width: 0; }
.banner span { font-size: var(--text-sm); opacity: .85; }
.banner h3 { margin: 0; font: 600 var(--text-xl) / var(--text-xl--line-height) var(--font-display); }
.banner [is~=Button] { --background: transparent; --border: color-mix(in srgb, var(--color-white) 45%, transparent); --color: var(--color-white); --svg-color: var(--color-white); --box-shadow: none; }
.banner [is~=Button]:hover { --background: color-mix(in srgb, var(--color-white) 15%, transparent); }

.path { display: grid; justify-items: center; gap: 18px; padding: 28px 0 8px; }
.level { position: relative; display: grid; justify-items: center; gap: 12px; transform: translateX(var(--x)); }
.node {
  position: relative;
  display: grid;
  place-items: center;
  width: 72px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background: var(--color-gray-200);
  box-shadow: 0 6px 0 var(--color-gray-300);
  color: var(--color-gray-500);
  font: 700 var(--text-xl) / 1 var(--font-display);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.node svg { width: 30px; height: 30px; stroke-width: 3; }
.node:active { transform: translateY(6px); box-shadow: 0 0 0 transparent; }
.done .node, .current .node { background: var(--unit-soft); box-shadow: 0 6px 0 var(--unit); color: var(--color-white); }
/* The lesson you're on stands out with a halo */
.current .node { outline: 6px solid color-mix(in srgb, var(--unit-soft) 30%, transparent); outline-offset: 4px; }
.current .node { animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { translate: 0 -4px; } }
.callout {
  position: relative;
  z-index: 1;
  display: none;
  width: 200px;
  padding: 14px;
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1px solid var(--color-gray-200);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.callout strong { display: block; margin-bottom: 10px; font-family: var(--font-display); }
.open .callout { display: block; }
/* Your character stands beside the lesson you're on, clear of its card */
.mascot.left, .mascot.right { position: absolute; top: -8px; width: 72px; }
.mascot.left { right: calc(50% + 108px); }
.mascot.right { left: calc(50% + 108px); }
.mascot .character { width: 100%; }

/* Lesson */
.lesson { display: flex; flex-direction: column; min-height: calc(100dvh - max(16px, env(safe-area-inset-top)) - 32px); }
.lesson > header { display: flex; gap: 12px; align-items: center; margin-left: -8px; }
.lesson > header .meter { flex: 1; }
.streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: var(--tint-brand);
  color: var(--color-brand-700);
  font: 600 var(--text-sm) / var(--text-sm--line-height) var(--font-display);
  white-space: nowrap;
}
.streak svg { width: 16px; height: 16px; }
.streak[hidden] { display: none; }
.dark-mode .streak { color: var(--color-brand-300); }
.challenge { flex: 1; padding: 24px 0; }
.challenge h2 { margin-bottom: 16px; }
.lesson footer {
  position: sticky;
  bottom: 0;
  margin: 0 -16px -32px;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  background: var(--color-gray-25);
  border-top: 1px solid var(--color-gray-200);
}
.lesson footer.ok { background: var(--tint-success); border-top-color: var(--color-success-300); }
.lesson footer.bad { background: var(--tint-error); border-top-color: var(--color-error-300); }
.feedback { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.feedback strong { display: block; font-size: var(--text-lg); line-height: var(--text-lg--line-height); }
.ok .feedback strong { color: var(--color-success-700); }
.bad .feedback strong { color: var(--color-error-700); }
.dark-mode .ok .feedback strong { color: var(--color-success-400); }
.dark-mode .bad .feedback strong { color: var(--color-error-400); }
.feedback p { margin-top: 4px; }
.feedback .solution { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.prompt { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 20px; }
.prompt .text { font-size: var(--text-xl); line-height: var(--text-xl--line-height); }
.romanized { color: var(--color-gray-650); font-size: var(--text-sm); }
.speaker.big { width: 80px; height: 80px; border-radius: var(--radius-2xl); }
/* Icon-only primary buttons: a white glyph reads better than the pale default */
.speaker.big, .mic > button { --svg-color: var(--color-white); }
.speaker.big svg { width: 36px; height: 36px; }
.listen { display: flex; gap: 12px; justify-content: center; align-items: flex-end; margin: 12px 0 24px; }
.tok[data-hint] { border-bottom: 2px dotted var(--color-gray-400); cursor: pointer; }
.tok.new { border-bottom-color: var(--color-brand-500); }
#hint {
  position: absolute;
  z-index: 10;
  max-width: 260px;
  padding: 8px 12px;
  border-radius: var(--radius-lg);
  background: var(--color-gray-900);
  color: var(--color-gray-25);
  font-size: var(--text-xs);
  line-height: var(--text-xs--line-height);
  font-weight: var(--font-weight-semibold);
  box-shadow: var(--shadow-lg);
}

/* A character says the prompt from a speech bubble */
.scene { display: flex; align-items: center; gap: 8px; margin-bottom: 24px; }
.character { flex: none; width: 112px; aspect-ratio: 118 / 175; display: grid; }
.character > * { grid-area: 1 / 1; width: 100%; height: 100%; }
.speech {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xs);
}
.speech::before {
  content: "";
  position: absolute;
  left: -8px;
  top: calc(50% - 7px);
  width: 14px;
  height: 14px;
  background: var(--surface);
  border-left: 1px solid var(--color-gray-200);
  border-bottom: 1px solid var(--color-gray-200);
  transform: rotate(45deg);
}
.speech .prompt, .speech h2 { margin: 0; }
.speech .listen { margin: 0; justify-content: flex-start; }
.speech .speaker.big { width: 64px; height: 64px; border-radius: var(--radius-xl); }
.speech .speaker.big svg { width: 28px; height: 28px; }
@media (max-width: 420px) { .character { width: 88px; } }

/* Answers */
.answer {
  min-height: 64px;
  padding: 8px 0;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--color-gray-200);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.bank { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip[is~=Button] { flex-direction: column; gap: 0; padding: 8px 14px; font-size: var(--text-md); line-height: var(--text-md--line-height); }
.chip small { color: var(--color-gray-650); font-size: var(--text-xs); font-weight: var(--font-weight-normal); }
.chip.used { visibility: hidden; }
.toggle { margin-top: 16px; }
[is~=Input] textarea { font-size: var(--text-md); }

.options { display: grid; gap: 10px; }
.option[is~=Button] { justify-content: flex-start; text-align: left; white-space: normal; font-size: var(--text-md); }
.option kbd {
  flex: none;
  min-width: 22px;
  padding: 0 6px;
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-md);
  color: var(--color-gray-500);
  font: var(--font-weight-medium) var(--text-xs) / var(--text-xs--line-height) var(--font-body);
  text-align: center;
}
/* Chosen, right and wrong answers */
:is(.option, .pairs button):is(.chosen, .right, .wrong) { --edge: var(--border); box-shadow: 0 0 0 1px var(--border), 0 4px 0 var(--edge); }
:is(.option, .pairs button).chosen { --border: var(--color-brand-500); --background: var(--tint-brand); }
:is(.option, .pairs button).right { --border: var(--color-success-500); --background: var(--tint-success); --color: var(--color-success-700); }
:is(.option, .pairs button).wrong { --border: var(--color-error-500); --background: var(--tint-error); --color: var(--color-error-700); }
.dark-mode :is(.option, .pairs button).right { --color: var(--color-success-300); }
.dark-mode :is(.option, .pairs button).wrong { --color: var(--color-error-300); }
.options.pictures { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.options.pictures .option { flex-direction: column; justify-content: center; text-align: center; position: relative; padding: 14px; }
.options.pictures .option kbd { position: absolute; top: 8px; left: 8px; }
.options.pictures img { width: 100%; max-width: 140px; aspect-ratio: 1; object-fit: contain; }
.pairs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pairs .col { display: grid; gap: 10px; align-content: start; }
.pairs button { flex-direction: column; gap: 0; white-space: normal; font-size: var(--text-md); }
.pairs button.right { opacity: .55; }

.sentence { font-size: var(--text-xl); line-height: 2.2; margin-bottom: 20px; }
.blank {
  display: inline-block;
  min-width: 4em;
  padding: 0 4px;
  border-bottom: 2px solid var(--color-gray-400);
  line-height: 1.4;
  text-align: center;
}
.blank.filled { border-bottom-color: var(--color-brand-500); cursor: pointer; }
input.blank { width: 7em; font: inherit; color: inherit; background: transparent; border: none; border-bottom: 2px solid var(--color-gray-400); border-radius: 0; outline: none; }
input.blank:focus { border-bottom-color: var(--color-brand-500); }
.passage { padding: 16px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--color-gray-200); border-radius: var(--radius-xl); }

.chat { display: grid; gap: 10px; margin-bottom: 20px; }
.bubble { max-width: 85%; display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: var(--surface); border: 1px solid var(--color-gray-200); border-radius: var(--radius-xl); }
.bubble.B { justify-self: end; }

.mic { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 28px; text-align: center; }
.mic > button { width: 88px; height: 88px; border-radius: var(--radius-full); }
.mic > button svg { width: 36px; height: 36px; }
.mic > button.on { --background: var(--color-error-600); --border: var(--color-error-600); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px color-mix(in srgb, var(--color-error-500) 25%, transparent); } }

/* Lesson complete */
.finish { display: grid; justify-items: center; gap: 20px; padding: 6vh 0 24px; text-align: center; }
.finish > .character { width: 140px; }
.finish h1 { font-size: var(--text-display-sm); line-height: var(--text-display-sm--line-height); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: min(100%, 420px); }
.stats .ring { --size: 72px; }
.stats .ring strong { font-size: var(--text-lg); }
.stats > div {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 6px;
  padding: 16px 12px;
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-xl);
  background: var(--surface);
}
.stats > div > strong { font: 600 var(--text-display-xs) / 1 var(--font-display); font-variant-numeric: tabular-nums; }
.stats span { color: var(--color-gray-650); font-size: var(--text-sm); }
.finish .actions { display: grid; gap: 10px; width: min(100%, 360px); margin-top: 8px; }
.quiet { color: var(--color-gray-650); font-size: var(--text-sm); }

/* Guidebook */
.guide .phrase { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; }
.guide .phrase .muted { margin-top: 2px; }
.guide .dialogue { padding: 4px 16px; margin: 8px 0; background: var(--surface); border: 1px solid var(--color-gray-200); border-radius: var(--radius-xl); }
.guide [is~=Table] { margin: 8px 0; overflow-x: auto; }
.guide .actions { margin-top: 28px; }

/* Settings */
.toggles { display: grid; gap: 16px; }

@media (min-width: 720px) {
  .challenge { padding-top: 40px; }
  .lesson footer { margin: 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0; border: 1px solid var(--color-gray-200); border-bottom: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* Answers can't change once checked; speakers still play */
.locked :is(.option, .chip, .blank, textarea, input) { pointer-events: none; }
@media (hover: none) { .option kbd { display: none; } }
