/* ============================================================================
   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; }

/* ============================== 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); }

/* ============================== 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; }
}

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