/* ============================================================================
   memory.css — "Memory training" feature (Brain -> Memory sub-tab).
   Scoped entirely under .mem- classes / #mem-* ids so nothing leaks into the
   rest of the app. Reuses the app's design tokens (--paper/--ink/--sage/…)
   and its existing global classes (.card, .chips/.chip, .btn-primary,
   .btn-ghost, .text-input, .bar/.track/.fill, .muted/.small) wherever they
   already match — only the Memory-specific bits get new rules here.
   Light theme only, mobile-first, 44px+ tap targets.
   ============================================================================ */

.mem-wrap { position: relative; }

/* Sub-tab chip row gets a faint underline "route" — a small signature touch
   that echoes the peg-route motif used throughout the tab. */
#mem-tabs { position: relative; padding-bottom: 0.6rem; margin-bottom: 0.5rem; }
#mem-tabs::after {
  content: "";
  position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--line) 15%, var(--line) 85%, transparent);
}

.mem-panel { animation: mem-fadein 0.15s ease; }
@keyframes mem-fadein { from { opacity: 0; } to { opacity: 1; } }

.mem-loading { text-align: center; padding: 2rem 1rem; }
.mem-error p { margin-bottom: 0.7rem; }

/* ---- Toast (scoped to this tab; do not reuse the app-wide #toast) ---- */
.mem-toast {
  position: fixed; left: 50%; bottom: 6.2rem; transform: translateX(-50%) translateY(60px);
  background: var(--ink); color: #fff; font-size: 0.85rem; font-weight: 500;
  padding: 0.7rem 1.1rem; border-radius: 999px; opacity: 0; transition: 0.3s;
  z-index: 30; pointer-events: none; white-space: nowrap; max-width: 90vw;
  text-overflow: ellipsis; overflow: hidden;
}
.mem-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ============================== HOME ============================== */

.mem-status-card { position: relative; }
.mem-streak-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.mem-streak { font-family: var(--display); font-weight: 600; font-size: 1.15rem; }
.mem-streak-n { font-family: var(--mono); }
.mem-lvl-badge {
  font-family: var(--mono); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em;
  color: var(--sage); background: #e7f1ec; padding: 0.2rem 0.6rem; border-radius: 999px;
}
.mem-xp-bar { margin: 0.3rem 0 0.2rem; }
.mem-xp-cap { margin-bottom: 0.6rem; }
.mem-timerline {
  font-family: var(--mono); font-size: 0.72rem; color: var(--muted);
  border-top: 1px solid var(--line-soft); padding-top: 0.55rem; margin-top: 0.1rem;
}

.mem-review-card, .mem-challenge-card { text-align: left; }
.mem-review-title, .mem-challenge-title { font-family: var(--display); font-weight: 600; font-size: 1.02rem; margin-bottom: 0.4rem; }
.mem-review-count { color: var(--red); font-family: var(--mono); font-size: 0.85rem; font-weight: 600; }
.mem-review-card .btn-primary, .mem-challenge-card .btn-ghost { margin-top: 0.3rem; }

.mem-modlist { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.2rem; }
.mem-modrow {
  display: flex; align-items: center; justify-content: space-between; gap: 0.7rem;
  width: 100%; min-height: 56px; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.75rem 0.9rem; font: inherit; color: var(--ink);
}
.mem-modrow:active { transform: translateY(1px); }
.mem-modrow-locked { opacity: 0.55; cursor: default; }
.mem-modrow-locked:active { transform: none; }
.mem-mod-main { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.mem-mod-title { font-weight: 600; font-size: 0.96rem; }
.mem-mod-tech { }
.mem-pill {
  font-family: var(--mono); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap; flex-shrink: 0;
}
.mem-pill-available { background: var(--line-soft); color: var(--muted); }
.mem-pill-learning { background: #f3eee3; color: var(--amber); }
.mem-pill-mastered { background: #e7f1ec; color: var(--good); }

/* ============================== LEARN ============================== */

.mem-lesson-card, .mem-pegs-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.2rem 1.1rem; min-height: 8rem; margin-bottom: 0.9rem;
}
.mem-lesson-title { font-family: var(--display); font-weight: 600; font-size: 1.15rem; margin-bottom: 0.6rem; }
.mem-lesson-body { line-height: 1.6; font-size: 0.98rem; }
.mem-pegs-note { margin-bottom: 0.8rem; }

/* Peg list: a vertical "route" line connects the pegs, feet (1) at the
   bottom to ceiling (10) at the top — the tab's signature motif. */
.mem-peg-list { position: relative; display: flex; flex-direction: column; gap: 0.4rem; padding-left: 0.2rem; }
.mem-peg-list::before {
  content: "";
  position: absolute; left: 1.15rem; top: 1.4rem; bottom: 1.4rem; width: 2px;
  background: repeating-linear-gradient(to bottom, var(--line) 0 4px, transparent 4px 9px);
}
.mem-peg-row { position: relative; display: flex; align-items: center; gap: 0.7rem; padding: 0.4rem 0; }
.mem-peg-num {
  position: relative; z-index: 1; flex-shrink: 0;
  width: 2.3rem; height: 2.3rem; border-radius: 50%;
  background: var(--paper); border: 1px solid var(--line);
  font-family: var(--mono); font-weight: 600; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
}
.mem-peg-label { flex: 1; min-width: 0; font-size: 0.95rem; overflow-wrap: break-word; }
.mem-peg-edit {
  flex-shrink: 0; border: 0; background: transparent; font-size: 1rem; line-height: 1;
  cursor: pointer; padding: 0.5rem; min-width: 44px; min-height: 44px; color: var(--muted);
}
.mem-peg-edit:active { opacity: 0.6; }
.mem-peg-row-editing { align-items: center; flex-wrap: wrap; }
.mem-peg-input {
  flex: 1; min-width: 6rem; font: inherit; font-size: 0.92rem; padding: 0.5rem 0.6rem;
  border: 1px solid var(--line); border-radius: 9px; background: var(--paper); min-height: 42px;
}
.mem-peg-input:focus { outline: none; border-color: var(--ink); background: #fff; }
.mem-peg-savebtn {
  font: inherit; font-size: 0.8rem; font-weight: 600; color: var(--sage);
  background: #e7f1ec; border: 1px solid #bfe3d2; border-radius: 8px;
  padding: 0.45rem 0.7rem; min-height: 40px; cursor: pointer;
}
.mem-peg-cancelbtn {
  border: 0; background: transparent; color: var(--muted); font-size: 1rem; cursor: pointer;
  padding: 0.4rem; min-width: 40px; min-height: 40px;
}

.mem-learn-nav { display: flex; gap: 0.6rem; margin-top: 0.2rem; }
.mem-learn-nav .btn-ghost { flex: 0 0 33%; }
.mem-learn-nav .btn-primary { flex: 1; margin-top: 0; }
.mem-step-dots { display: flex; gap: 0.35rem; justify-content: center; margin-top: 0.8rem; }
.mem-step-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.mem-step-dot.on { background: var(--ink); }

/* ============================== GAMES ============================== */

.mem-game-card { }
.mem-game-title { font-family: var(--display); font-weight: 600; font-size: 1.1rem; margin-bottom: 0.35rem; }
.mem-game-card .btn-primary { margin-top: 0.5rem; }

/* -- Peg Flash -- */
.mem-pf-wrap { }
.mem-pf-progress { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
.mem-combo { color: var(--red); font-weight: 700; text-transform: none; letter-spacing: 0; animation: mem-combobump 0.3s ease; }
@keyframes mem-combobump { from { transform: scale(1.35); } to { transform: scale(1); } }
.mem-pf-timerbar { margin-bottom: 0.9rem; height: 6px; }
.mem-pf-timerbar .fill.mem-pf-fill { background: var(--amber); }
.mem-pf-prompt { font-family: var(--display); font-size: 1.15rem; font-weight: 600; text-align: center; margin: 0.6rem 0 1.1rem; line-height: 1.4; }
.mem-pf-num { color: var(--sage); }
.mem-pf-label { color: var(--sage); }
.mem-pf-choices { display: flex; flex-direction: column; gap: 0.55rem; }
.mem-pf-choice {
  font: inherit; font-size: 0.98rem; font-weight: 500; text-align: center;
  min-height: 48px; padding: 0.7rem; border: 1px solid var(--line); border-radius: 12px;
  background: var(--paper); color: var(--ink); cursor: pointer;
}
.mem-pf-choice:active { background: var(--ink); color: #fff; border-color: var(--ink); }
.mem-pf-numpad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.5rem; }
.mem-pf-num-btn {
  font: inherit; font-family: var(--mono); font-weight: 600; font-size: 1.05rem;
  min-height: 48px; border: 1px solid var(--line); border-radius: 11px;
  background: var(--paper); color: var(--ink); cursor: pointer;
}
.mem-pf-num-btn:active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* -- List Attack: encode -- */
.mem-la-encode { text-align: center; padding: 1.6rem 1.1rem; }
.mem-la-progress { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.8rem; }
.mem-la-word { font-family: var(--display); font-weight: 700; font-size: 2rem; line-height: 1.1; margin-bottom: 0.6rem; }
.mem-la-peg { font-size: 0.95rem; color: var(--ink-soft); margin-bottom: 0.9rem; }
.mem-la-see { font-style: italic; font-size: 0.9rem; margin-bottom: 1.2rem; line-height: 1.4; }
.mem-la-encode .btn-primary { width: 100%; }

/* -- List Attack: recall -- */
.mem-la-recall { padding: 1.3rem 1.1rem; }
.mem-la-recall-prompt { font-family: var(--display); font-weight: 600; font-size: 1.1rem; line-height: 1.4; margin: 0.3rem 0 1rem; }
.mem-la-input { font-size: 1.05rem; text-align: center; }

/* ============================== RESULTS ============================== */

.mem-results { text-align: center; padding: 1.6rem 1.1rem; }
.mem-results-score { font-family: var(--mono); font-weight: 700; font-size: 2.4rem; letter-spacing: -0.02em; }
.mem-results-max { font-size: 1.3rem; color: var(--muted); font-weight: 500; }
.mem-results-xp { color: var(--sage); font-weight: 700; font-size: 1.05rem; margin: 0.2rem 0 0.8rem; }
.mem-badges { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin-bottom: 0.8rem; }
.mem-badge-chip {
  font-size: 0.85rem; font-weight: 600; background: #f3eee3; color: var(--amber);
  border-radius: 999px; padding: 0.3rem 0.7rem;
}
.mem-tip {
  text-align: left; background: var(--paper); border-radius: 12px; padding: 0.75rem 0.9rem;
  font-size: 0.9rem; line-height: 1.5; color: var(--ink-soft); margin-bottom: 1rem;
}
.mem-results-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.mem-results-actions .btn-primary { margin-top: 0; }

/* ============================== quit / misses (audit fixes) ============================== */

/* gameQuitHtml() renders the button as a SIBLING of the game card (both are
   direct children of the sub-tab panel), so the panel itself is the
   positioning context — not the card. */
.mem-panel { position: relative; }
.mem-quit-btn {
  position: absolute; top: 0; right: 0; z-index: 5;
  width: 40px; height: 40px; min-width: 40px; min-height: 40px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  color: var(--muted); font-size: 1rem; line-height: 1; cursor: pointer;
  box-shadow: 0 2px 6px rgba(20, 23, 28, 0.12);
}
.mem-quit-btn:active { background: var(--line-soft); }

.mem-misses { text-align: left; background: var(--paper); border-radius: 12px; padding: 0.7rem 0.9rem; margin-bottom: 0.9rem; }
.mem-misses-title { font-weight: 600; margin-bottom: 0.35rem; }
.mem-miss-row { font-size: 0.86rem; padding: 0.2rem 0; color: var(--ink-soft); }
.mem-miss-arrow { color: var(--muted); }

/* ============================== home hero / streak chips / mastery bar ============================== */

.mem-hero-cta { margin: 0.2rem 0 0.8rem; }
.mem-streak-chip {
  font-family: var(--mono); font-size: 0.72rem; font-weight: 700;
  background: var(--line-soft); color: var(--ink-soft); border: 0;
  border-radius: 999px; padding: 0.25rem 0.55rem; cursor: default; white-space: nowrap;
}
.mem-freeze-chip { cursor: pointer; }
.mem-freeze-chip:active { background: var(--line); }

.mem-modmastery { margin: 0.2rem 0 0.7rem; }
.mem-modmastery-bar { margin-bottom: 0.25rem; }
.mem-modmastery-bar .fill { background: var(--sage); }

.mem-badge-tile { border: 0; font: inherit; cursor: pointer; }
.mem-badge-tile:active { transform: translateY(1px); }

.mem-tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px; margin-left: 0.3rem;
  border-radius: 999px; background: var(--red); color: #fff;
  font-family: var(--mono); font-size: 0.62rem; font-weight: 700; vertical-align: middle;
}

/* ============================== word-bank chips (Younger mode) ============================== */

.mem-wordbank { }
.mem-wordbank .chip { min-height: 44px; }

/* ============================== GLUE LAB ============================== */

.mem-glue-intro { text-align: center; padding: 1.6rem 1.1rem; }
.mem-glue-intro-line { font-size: 0.92rem; font-weight: 600; margin: 0.9rem 0 1rem; }

.mem-glue-chiprow, .mem-glue-chiprow-static {
  display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; margin: 0.8rem 0;
}
.mem-glue-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-family: var(--mono); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em;
  padding: 0.35rem 0.65rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--line-soft); color: var(--muted); opacity: 0.6; transition: opacity 0.15s ease;
}
.mem-glue-chip.lit { opacity: 1; color: #fff; border-color: transparent; }
.mem-glue-chip-motion.lit { background: var(--blue); }
.mem-glue-chip-collision.lit { background: var(--red); }
.mem-glue-chip-senses.lit { background: var(--amber); }
.mem-glue-chip-feeling.lit { background: var(--sage); }
.mem-glue-chip-wow.lit { background: var(--good); }

.mem-glue-encode { text-align: center; padding: 1.4rem 1.1rem; }
.mem-glue-weld { font-family: var(--display); font-weight: 700; font-size: 1.35rem; line-height: 1.3; margin-bottom: 0.9rem; }
.mem-glue-a, .mem-glue-b { color: var(--sage); }
.mem-glue-link { color: var(--muted); font-weight: 400; }
.mem-glue-textarea { text-align: left; font-size: 1rem; }
.mem-glue-meter { margin: 0.4rem 0 0.6rem; }
.mem-glue-count { font-family: var(--mono); }

.mem-glue-coach-bubble {
  display: flex; align-items: flex-start; gap: 0.6rem; text-align: left;
  background: var(--paper); border: 1px solid var(--line-soft); border-radius: 12px;
  padding: 0.7rem 0.85rem; margin-top: 0.6rem;
}
.mem-glue-coach-icon { width: 34px; height: 34px; flex-shrink: 0; }
.mem-glue-coach-text { font-size: 0.9rem; line-height: 1.45; }

.mem-glue-proof { text-align: left; background: var(--paper); border-radius: 12px; padding: 0.85rem 0.95rem; margin-bottom: 1rem; }
.mem-glue-proof-title { font-family: var(--display); font-weight: 600; margin-bottom: 0.5rem; }
.mem-glue-proof-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0; font-size: 0.88rem; }
.mem-glue-proof-label { flex: 1; min-width: 0; overflow-wrap: break-word; }
.mem-glue-proof-dots { display: flex; gap: 3px; flex-shrink: 0; }
.mem-glue-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex-shrink: 0; }
.mem-glue-dot.lit { background: var(--sage); }
.mem-glue-proof-mark { flex-shrink: 0; }
.mem-glue-takeaway { font-size: 0.9rem; line-height: 1.5; margin-top: 0.5rem; }

/* ============================== LEARN pacing ============================== */

.mem-lesson-para { opacity: 0; animation: mem-para-fadein 0.45s ease forwards; }
@keyframes mem-para-fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ============================== IDEAS ============================== */

.mem-ideas-card h3 { margin-bottom: 0.6rem; }
.mem-feedback-textarea {
  width: 100%; font: inherit; font-size: 0.95rem; line-height: 1.5; padding: 0.75rem 0.85rem;
  border: 1px solid var(--line); border-radius: 12px; background: var(--paper);
  resize: vertical; min-height: 6rem; margin-bottom: 0.6rem;
}
.mem-feedback-textarea:focus { outline: none; border-color: var(--ink); background: #fff; }
.mem-feedback-status { margin-top: 0.6rem; }
.mem-feedback-status.mem-feedback-err { color: var(--red); }

/* ============================== picture letters ============================== */
/* Owner's hand-made A-Z glyphs (/spell-letters/*.png) — same source art as the
   family's spelling app, used for encode-card words and the live typing
   preview so the letters stay visually identical everywhere the kid sees
   them. --sl is set inline per usage (spellWordHtml's sizePx). */

.mem-spellword {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center;
  gap: 2px; line-height: 1;
}
.mem-sl-wrap { display: inline-flex; align-items: flex-end; }
.mem-spellletter { width: var(--sl); height: var(--sl); object-fit: contain; object-position: bottom; }
.mem-spellletter-tall { height: calc(var(--sl) * 1.2); }
.mem-spellletter-txt { font-weight: 700; font-size: calc(var(--sl) * 0.8); line-height: 1; }

/* Live typing preview strip — sits above a recall <input id="mem-la-input">,
   hidden while the input is empty. */
.mem-spell-preview {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center;
  gap: 2px; min-height: 2.2rem; margin-bottom: 0.5rem;
}
.mem-spell-preview[hidden] { display: none; }

/* Encode-card word rendered as picture letters keeps the card's usual
   spacing — only the content changes from a text glyph to an image row. */
.mem-la-word .mem-spellword,
.mem-glue-a .mem-spellword,
.mem-glue-b .mem-spellword { justify-content: center; }

/* ============================== a11y / motion ============================== */

@media (prefers-reduced-motion: reduce) {
  .mem-panel { animation: none !important; }
  .mem-toast { transition: none !important; }
  .mem-pf-timerbar .fill { transition: none !important; }
  .mem-combo { animation: none !important; }
  .mem-lesson-para { animation: none !important; opacity: 1 !important; transform: none !important; }
  .mem-glue-chip { transition: none !important; }
}

@media (max-width: 380px) {
  .mem-pf-numpad { grid-template-columns: repeat(5, 1fr); gap: 0.4rem; }
  .mem-la-word { font-size: 1.6rem; }
}
