/**
 * NusaIQ Malaysia — shared game shell
 * ====================================
 * Hierarchy, responsive composition, disclosure, and accessibility utilities
 * for migrated games only. Everything is namespaced under `.ep-game-shell`
 * or an `ep-game-` class, so a game that has not opted in cannot be restyled
 * by this file.
 *
 * Consumers: ALL 41 games. Every game page calls NusaIQGameShell.init, so any
 * change here must be verified against the whole catalogue, not a pilot subset.
 *
 * This comment said "6 of 41 games ... the rest of the catalogue does not load
 * this file" until 2026-08-20. That was true on 2026-08-15 and was overtaken by
 * the 2026-08-17 reconciliation, which completed the rollout. The stale figure
 * outlived the fact by three days and propagated into docs/handoff.md and two
 * session logs, where it was read as authorising no further migration.
 *
 * The count is asserted, not remembered: tests/game_a11y_static.js checks every
 * game page adopts the shell, and docs/stage0/current-game-migration-map.json
 * records per-game adoption, regenerated by npm test.
 *
 * This layer owns NO curriculum content, question logic, scoring, persistence,
 * licence checks, or gamification awards. It composes with nusaiq-shell.css,
 * nusaiq-module-layer.css, nusaiq-gamify.css, and nusaiq-fx.css.
 */

.ep-game-shell {
  /* Documented theme slots. A game may override these semantic properties,
     but may not redefine global components or use color as the only signal. */
  --ep-game-ink: var(--ep-ink, #17233c);
  --ep-game-ink-soft: var(--ep-muted, #5a6578);
  --ep-game-surface: var(--ep-white, #ffffff);
  --ep-game-line: var(--ep-line-strong, #7b879a);
  --ep-game-accent: var(--ep-coral, #b63a35);
  --ep-game-accent-dark: #8f2c28;
  --ep-game-success: var(--ep-forest, #0b6b5f);
  --ep-game-focus: var(--ep-focus, #6d28d9);

  --ep-game-gap: 12px;
  --ep-game-radius: var(--ep-radius-3, 20px);
  --ep-game-target: var(--ep-target-min, 44px);
  --ep-game-text: 1rem;      /* 16px supporting text floor */
  --ep-game-text-action: 1.125rem; /* 18px primary interaction text */
}

/* `hidden` must win over the layout display values declared below. */
.ep-game-shell [hidden] {
  display: none !important;
}

/* ── Page and layout ─────────────────────────────────────────────────────── */

.ep-game-page {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
}

.ep-game-header {
  text-align: center;
  margin-bottom: var(--ep-game-gap);
}

.ep-game-title {
  font-size: 1.75rem;
  line-height: 1.2;
  color: var(--ep-game-accent);
}

.ep-game-subtitle {
  font-size: var(--ep-game-text);
  line-height: 1.5;
  color: var(--ep-game-ink-soft);
}

/* Learning objective sits above the primary stage on every viewport. */
.ep-game-intro {
  background: var(--ep-game-surface);
  border: 2px dashed var(--ep-game-line);
  border-radius: var(--ep-game-radius);
  padding: 16px;
  margin-bottom: var(--ep-game-gap);
  text-align: left;
}

.ep-game-objective-title {
  font-size: 1.125rem;
  line-height: 1.3;
  color: var(--ep-game-ink);
  margin-bottom: 6px;
}

.ep-game-objective {
  font-size: var(--ep-game-text);
  line-height: 1.55;
  color: var(--ep-game-ink);
}

.ep-game-objective-list {
  margin: 8px 0 0;
  padding-left: 1.2em;
  font-size: var(--ep-game-text);
  line-height: 1.55;
  color: var(--ep-game-ink);
}

.ep-game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px; /* 8px minimum separation between touch targets */
  margin-top: 12px;
}

.ep-game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--ep-game-gap);
  align-items: start;
}

.ep-game-stage,
.ep-game-panel {
  min-width: 0;
}

/* Desktop gets a real supporting column instead of a stretched phone column. */
@media (min-width: 1024px) {
  .ep-game-page--wide {
    max-width: 1040px;
  }

  .ep-game-layout--split {
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
    gap: 20px;
  }
}

/* ── Interactive surfaces ────────────────────────────────────────────────── */

.ep-game-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--ep-target-child, 48px);
  min-width: var(--ep-game-target);
  padding: 12px 22px;
  border: none;
  border-radius: 14px;
  background: var(--ep-game-accent);
  color: #ffffff;
  font-family: inherit;
  font-size: var(--ep-game-text-action);
  font-weight: 800;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
}

.ep-game-btn:hover {
  background: var(--ep-game-accent-dark);
}

.ep-game-btn--ghost {
  background: var(--ep-game-surface);
  color: var(--ep-game-ink);
  border: 2px solid var(--ep-game-ink-soft);
}

.ep-game-btn--ghost:hover {
  background: #f1f3f5;
}

.ep-game-btn[disabled] {
  background: #d2d5d8;
  color: #3c4043;
  cursor: not-allowed;
}

.ep-game-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--ep-game-target);
  padding: 10px 16px;
  border: 2px solid var(--ep-game-line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ep-game-ink);
  font-family: inherit;
  font-size: var(--ep-game-text);
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

/* Any control the shell owns keeps a comfortable target on touch screens. */
.ep-game-target {
  min-height: var(--ep-game-target);
  min-width: var(--ep-game-target);
}

/*
 * The shared gamify layer drops a transient reward toast onto the page when a
 * round is recorded, and its one control renders at 74x31 — under the target
 * floor this shell guarantees for every control on a migrated page. The shell
 * cannot edit that layer's source, but it does own target size inside pages
 * that opted in, so it raises the control here. Scoped to `.ep-game-shell`, so
 * no un-migrated page is affected. This only ever grows the control.
 */
.ep-game-shell .eg-score-toast button,
.ep-game-shell .eg-toast-ach button {
  min-height: var(--ep-game-target);
  min-width: var(--ep-game-target);
  font-size: var(--ep-game-text);
}

/*
 * Keep the global rewards entry point in normal document flow. A fixed FAB
 * covered answer buttons and game controls on narrow screens, especially in
 * older single-card games. The drawer itself remains fixed when opened.
 */
.ep-game-shell #eg-global-shell {
  display: flex;
  flex: 0 0 auto;
  width: auto;
  max-width: 100%;
  align-self: stretch;
  justify-content: flex-end;
  padding: 8px 14px max(8px, env(safe-area-inset-bottom));
  pointer-events: none;
  box-sizing: border-box;
}

.ep-game-shell #eg-global-shell > * {
  pointer-events: auto;
}

.ep-game-shell #eg-fab {
  position: static;
  flex: 0 0 auto;
}

body.ep-game-shell {
  flex-direction: column;
  flex-wrap: nowrap;
}

.ep-game-field {
  min-height: var(--ep-game-target);
  font-family: inherit;
  font-size: var(--ep-game-text);
}

.ep-game-label {
  display: block;
  font-size: var(--ep-game-text);
  font-weight: 800;
  color: var(--ep-game-ink);
  margin-bottom: 4px;
}

/* Tab strips must expose every destination without clipping the final tab. */
@media (max-width: 420px) {
  .ep-game-shell .tabs {
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .ep-game-shell .tabs .tab-btn {
    flex: 1 1 calc(50% - 8px);
    min-width: min(132px, 100%);
    justify-content: center;
    text-align: center;
  }
}

/* ── Focus ──────────────────────────────────────────────────────────────── */

.ep-game-shell :focus,
.ep-game-shell :focus-visible {
  outline: 3px solid var(--ep-game-focus);
  outline-offset: 2px;
  box-shadow:
    0 0 0 2px var(--ep-game-surface),
    0 0 0 5px var(--ep-game-focus);
}

/* ── Feedback that never depends on colour alone ─────────────────────────── */

.ep-game-feedback {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 1.6em;
  font-size: var(--ep-game-text);
  font-weight: 700;
  line-height: 1.5;
  color: var(--ep-game-ink);
}

.ep-game-feedback::before {
  content: "•";
  flex-shrink: 0;
}

/* Do not paint a placeholder marker before any feedback exists. */
.ep-game-feedback:empty::before {
  content: none;
}

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

.ep-game-feedback--correct::before {
  content: "\2714"; /* check mark */
}

.ep-game-feedback--wrong {
  color: var(--ep-game-accent);
}

.ep-game-feedback--wrong::before {
  content: "\2716"; /* cross mark */
}

/*
 * Some games write rich feedback (a composed fact card, a bolded answer) into
 * the same region. Flex would turn every inline child into its own flex item
 * and space the words apart, so those games opt into normal flow instead. The
 * empty-marker contract above is unaffected: `::before` still renders, and
 * still disappears when the region holds no message.
 */
.ep-game-feedback--rich {
  display: block;
}

/* ── Progressive disclosure for secondary panels ─────────────────────────── */

.ep-game-disclosure {
  border: 2px solid var(--ep-game-line);
  border-radius: var(--ep-game-radius);
  background: var(--ep-game-surface);
}

.ep-game-disclosure > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--ep-game-target);
  padding: 10px 14px;
  font-size: var(--ep-game-text);
  font-weight: 800;
  color: var(--ep-game-ink);
  cursor: pointer;
  list-style: none;
}

.ep-game-disclosure > summary::-webkit-details-marker {
  display: none;
}

/* A summary may hold a single heading, which keeps the outline unbroken when a
   composed panel renders its own lower-level headings. */
.ep-game-disclosure__title {
  margin: 0;
  font-size: var(--ep-game-text);
  font-weight: 800;
  line-height: 1.4;
  color: inherit;
}

.ep-game-disclosure > summary::after {
  content: "\25BE"; /* down caret */
  margin-left: auto;
}

.ep-game-disclosure[open] > summary::after {
  content: "\25B4"; /* up caret */
}

.ep-game-disclosure__body {
  padding: 0 14px 14px;
  font-size: var(--ep-game-text);
  line-height: 1.55;
  color: var(--ep-game-ink);
}

/*
 * Secondary panels often host content rendered by another shared system
 * (module layer, gamify). The shell owns readability inside its own regions,
 * so it raises supporting text to the 16px floor. Scoped to the disclosure
 * body, so a game that has not opted in keeps its own type scale.
 */
.ep-game-shell .ep-game-disclosure__body h4,
.ep-game-shell .ep-game-disclosure__body h5,
.ep-game-shell .ep-game-disclosure__body p,
.ep-game-shell .ep-game-disclosure__body li,
.ep-game-shell .ep-game-disclosure__body span,
.ep-game-shell .ep-game-disclosure__body small,
.ep-game-shell .ep-game-disclosure__body button {
  font-size: var(--ep-game-text);
  line-height: 1.4;
}

/*
 * A module-layer panel composed inside a disclosure is already framed by the
 * disclosure: its own card surface, border, shadow and outer margin would draw
 * a second box inside the first. Flattening it here keeps every migrated
 * consumer from repeating the same local override, and it makes the panel's
 * text contrast deterministic against the disclosure's opaque surface.
 *
 * Darab Dash carries an id-scoped copy of exactly these declarations from the
 * 2026-08-13 pilot, which is more specific and still wins, so this rule cannot
 * change what that pilot renders.
 */
.ep-game-shell .ep-game-disclosure__body > .eml-panel {
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

/* ── Screen-reader utility ──────────────────────────────────────────────── */

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

/* ── Legacy game contrast floor ────────────────────────────────────────── */

/* Older games used pastel text colours that disappear against white cards. */
.ep-game-shell :is(
  .subtitle,
  .sub,
  .card > p,
  .cat-label,
  .picture-attribution,
  #diffDesc
) {
  color: #455a64 !important;
}

.ep-game-shell :is(.score, #totalQ, #t, #qLabel, #hsDisplay, #picCap) {
  color: #1b5e20 !important;
}

.ep-game-shell :is(.tab-btn.active, .diff-btn.active) {
  background: #2d6a4f !important;
  color: #fff !important;
}

.ep-game-shell :is(#startBtn, #btnStart, #start-btn) {
  background: #a93636 !important;
  color: #fff !important;
}

.ep-game-shell #hintBtn {
  background: #8a5200 !important;
  color: #fff !important;
}

.ep-game-shell button[onclick="skipWord()"] {
  background: #2d6a4f !important;
  color: #fff !important;
}

.ep-game-shell :is(
  .badge-year,
  .cat-tag,
  .cat-pill,
  .pill,
  .tatabahasa,
  .karangan,
  .sastera,
  .kefahaman,
  .cat-tumbuhan,
  .cat-ekosistem,
  .cat-klasifikasi
) {
  color: #102a22 !important;
  text-shadow: none !important;
}

.ep-game-shell :is(.start-card h2, .start-card h3, h1.title) {
  color: #7d2530 !important;
}

.ep-game-shell .sf-learn-card__t > span {
  color: #37474f !important;
  opacity: 1 !important;
}

.ep-game-shell .subj-tag {
  color: #01579b !important;
}

.ep-game-shell .ba-pill.active,
.ep-game-shell .pills .pill {
  background: #2d6a4f !important;
  color: #fff !important;
  text-shadow: none !important;
}

.ep-game-shell .cat-klasifikasi {
  color: #061a15 !important;
}

.ep-game-shell footer {
  color: #616161 !important;
}

/* ── Reduced motion ─────────────────────────────────────────────────────── */

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

/* Focus mode removes ambient treatment while preserving mechanics and state. */
[data-ep-mode="focus"] .ep-game-shell [data-ep-decoration] {
  display: none !important;
}
