/* frappe — shared primitives for the game layer (world, battles, dex, bosses, trainer, shop).
   Everything derives from the theme tokens in style.css: --bg --main --caret --sub --sub-alt --text --error.
   Module stylesheets (game-*.css) build on these classes instead of redefining them. */

:root {
  --g-radius: 0.75rem;
  --g-gap: 1rem;
  --g-hp: #5cc46b;
  --g-hp-mid: #e8b730;
  --g-hp-low: #e0525e;
  --g-coin: #f2c230;
  --g-xp: var(--main);
  --g-ok: #5cc46b;
  --g-a1: #7bc96f;
  --g-a2: #5aa9e6;
  --g-b1: #f4a259;
  --g-b2: #c77dff;
  /* word stages: seen → caught → trained → mastered */
  --g-st1: var(--sub);
  --g-st2: #5aa9e6;
  --g-st3: #7bc96f;
  --g-st4: #f2c230;
  --g-shadow: 0 0.4rem 1.4rem rgba(0, 0, 0, 0.25);
}

/* Text colours derived from the theme. Declared on every [data-theme] element as well as :root so they follow the
   theme wherever one is applied. Measured on all 16 themes (style.css + game-meta.css) against --bg and --sub-alt:
   --g-gloss  English glosses and secondary text that carries meaning (≥ 5:1). --sub is for decoration, disabled
              things and placeholders only: it is about 2:1 on most themes, unreadable as text.
   --g-edge   visible edge of inputs and outlined controls (≥ 3:1).
   --g-coin-ink / --g-ok-ink   coin gold and "correct" green as TEXT (≥ 4.7:1): the lightness moves towards
              --text (dark gold / green on light themes, bright on dark ones), hue and chroma stay. Keep --g-coin and
              --g-ok for fills, bars, borders and icons. Browsers without relative colours fall back to the
              inherited text colour. */
:root,
[data-theme] {
  --g-gloss: color-mix(in srgb, var(--text) 75%, var(--sub));
  --g-edge: color-mix(in srgb, var(--sub) 55%, var(--text));
  --g-coin-ink: oklch(from color-mix(in oklab, var(--g-coin) 25%, var(--text)) l 0.158 89);
  --g-ok-ink: oklch(from color-mix(in oklab, var(--g-ok) 25%, var(--text)) l 0.159 147);
}

.fr-view {
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  animation: fade 0.2s ease-out;
}
/* one typeface for every game screen and dialog (the dojo keeps the monospace of the typing test) */
.fr-view,
.g-modal {
  font-family: "Lexend Deca", sans-serif;
}
.fr-view kbd,
.g-modal kbd {
  font-family: "Roboto Mono", monospace;
}
.fr-error {
  color: var(--error);
  padding: 2rem;
  text-align: center;
}

/* page structure */
.g-page {
  display: flex;
  flex-direction: column;
  gap: var(--g-gap);
  padding-bottom: 2rem;
}
.g-top {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.g-top .g-spacer {
  flex: 1;
}
.g-h {
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 400;
  margin: 0;
}
/* The English gloss is what a beginner actually reads: readable colour, and never below 0.7rem (11.2 px) even
   inside small labels. */
.g-h small,
.g-en {
  color: var(--g-gloss);
  font-size: max(0.8em, 0.7rem);
  font-weight: 400;
}
.g-sub {
  color: var(--g-gloss);
  font-size: 0.85rem;
}
.g-label {
  color: var(--g-gloss);
  font-size: 0.75rem;
  text-transform: lowercase;
  letter-spacing: 0.03em;
}
.g-grid {
  display: grid;
  gap: var(--g-gap);
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
}
.g-grid.sm {
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
}
.g-row {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  flex-wrap: wrap;
}

/* surfaces */
.g-card {
  background: var(--sub-alt);
  border-radius: var(--g-radius);
  padding: 1rem 1.1rem;
  color: var(--text);
  position: relative;
}
.g-card.click {
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.g-card.click:hover {
  transform: translateY(-2px);
  box-shadow: var(--g-shadow);
}
.g-card.locked {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.7);
}
.g-card.hl {
  outline: 2px solid var(--main);
}

/* buttons */
/* --g-btn-bg / --g-field-bg: the fill of secondary buttons and inputs. On the page it is --sub-alt; a surface that
   is itself --sub-alt (.g-card, or a module's own card: set the two variables on it) switches them to --bg so the
   controls keep a visible shape. */
.g-card {
  --g-btn-bg: var(--bg);
  --g-field-bg: var(--bg);
}
.g-btn {
  appearance: none;
  border: 0;
  border-radius: 0.55rem;
  padding: 0.6rem 1.1rem;
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--g-btn-bg, var(--sub-alt));
  color: var(--text);
  transition: background 0.12s, color 0.12s, transform 0.08s;
  display: inline-flex;
  align-items: center;
  /* when label + gloss do not fit (360 px), the gloss drops to a line of its own, centred, instead of both
     shrinking side by side and breaking « ✍️ commencer » word by word */
  flex-wrap: wrap;
  justify-content: center;
  text-align: center;
  gap: 0.1rem 0.45rem;
}
.g-btn:hover {
  background: var(--text);
  color: var(--bg);
}
.g-btn:active {
  transform: scale(0.97);
}
.g-btn.primary {
  background: var(--main);
  color: var(--bg);
}
.g-btn.primary:hover {
  filter: brightness(1.1);
}
.g-btn.ghost {
  background: transparent;
  color: var(--g-gloss);
}
.g-btn.ghost:hover {
  color: var(--text);
  background: var(--g-btn-bg, var(--sub-alt));
}
/* glosses and key hints inside a button follow the button's own text colour (it changes on hover and on
   primary buttons, where the --g-gloss of the page would vanish) */
.g-btn .g-en {
  color: inherit;
  opacity: 0.8;
}
.g-btn.primary .g-en,
.g-btn.ghost .g-en {
  opacity: 1;
}
.g-btn:focus-visible,
.g-tab:focus-visible {
  outline: 2px solid var(--main);
  outline-offset: 2px;
}
.g-btn.small {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}
.g-btn.big {
  padding: 0.9rem 1.6rem;
  font-size: 1.1rem;
}
.g-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
.g-btn kbd {
  font-size: 0.7em;
  background: transparent;
  color: inherit;
  box-shadow: inset 0 0 0 1px currentColor;
}

/* pills, badges, level tags */
.g-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.6rem;
  border-radius: 2rem;
  background: var(--sub-alt);
  color: var(--text);
  font-size: 0.8rem;
  white-space: nowrap;
}
.g-pill.coin {
  color: var(--g-coin-ink);
}
.g-lv {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  border-radius: 0.35rem;
  font-size: 0.72rem;
  font-weight: 500;
  color: #111;
  background: var(--sub);
}
.g-lv[data-lv="A1"] {
  background: var(--g-a1);
}
.g-lv[data-lv="A2"] {
  background: var(--g-a2);
}
.g-lv[data-lv="B1"] {
  background: var(--g-b1);
}
.g-lv[data-lv="B2"] {
  background: var(--g-b2);
}

/* progress bars: <div class="g-bar"><i style="width:40%"></i></div> */
.g-bar {
  height: 0.5rem;
  border-radius: 1rem;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}
.g-card .g-bar {
  background: var(--bg);
}
.g-bar > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--main);
  transition: width 0.4s ease;
}
.g-bar.hp > i {
  background: var(--g-hp);
}
.g-bar.hp.mid > i {
  background: var(--g-hp-mid);
}
.g-bar.hp.low > i {
  background: var(--g-hp-low);
}
.g-bar.xp > i {
  background: var(--g-xp);
}

/* tabs */
.g-tabs {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.g-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--g-gloss);
  font: inherit;
  padding: 0.4rem 0.8rem;
  border-radius: 0.5rem;
  cursor: pointer;
}
.g-tab:hover {
  color: var(--text);
}
.g-tab.active {
  background: var(--g-btn-bg, var(--sub-alt));
  color: var(--main);
}

/* modal overlay: <div class="g-modal"><div class="g-dialog">…</div></div> */
.g-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
  animation: fade 0.15s ease-out;
}
.g-dialog {
  background: var(--bg);
  color: var(--text);
  border-radius: 1rem;
  padding: 1.5rem;
  max-width: 34rem;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--g-shadow);
}

/* text inputs for typed answers */
.g-input {
  width: 100%;
  box-sizing: border-box;
  background: var(--g-field-bg, var(--sub-alt));
  color: var(--text);
  border: 2px solid var(--g-edge);
  border-radius: 0.6rem;
  padding: 0.7rem 0.9rem;
  font-family: "Lexend Deca", sans-serif;
  font-size: 1.1rem;
  outline: none;
}
.g-input:focus {
  border-color: var(--main);
}
.g-input.ok {
  border-color: var(--g-ok);
}
.g-input.ko {
  border-color: var(--error);
}

/* French text in reading passages and prompts */
.g-fr {
  font-family: "Lexend Deca", sans-serif;
  line-height: 1.6;
}
.g-empty {
  color: var(--g-gloss);
  text-align: center;
  padding: 2rem 1rem;
}

@media (max-width: 640px) {
  .g-grid {
    grid-template-columns: 1fr 1fr;
  }
  .g-dialog {
    padding: 1rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  .g-card.click,
  .g-bar > i,
  .fr-view {
    transition: none;
    animation: none;
  }
}
