/* rpg.css — MathScape mobile gamified shell */

/* ── Shell layout ────────────────────────────────────────────── */
#rpg-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ── Stats bar ───────────────────────────────────────────────── */
.rpg-stats-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  /* Extra right padding reserves the top-right corner for the floating view-toggle button
     (app.js, position:fixed) so the level progress bar no longer runs under it. The top
     padding clears the status bar / Dynamic Island on a notched phone in standalone PWA mode,
     matching the bottom nav and lesson pages, which already honor the safe-area insets. */
  padding: calc(8px + env(safe-area-inset-top, 0px)) 50px 8px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
  overflow: hidden;
}

.rpg-stat-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.rpg-stat-val {
  font-variant-numeric: tabular-nums;
}

.rpg-streak {
  background: color-mix(in srgb, var(--gold) 15%, transparent);
  border: 1px solid var(--gold);
  color: var(--gold);
}

.rpg-streak-lapsed {
  background: var(--bg3);
  border-color: var(--border);
  color: var(--text-dim);
  opacity: 0.7;
}

.rpg-level {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 12px;
  padding: 3px 8px;
}

.rpg-daily {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 3px 8px;
  margin-left: auto;
}

.rpg-daily-done {
  background: color-mix(in srgb, var(--gold) 15%, transparent);
  border-color: var(--gold);
  color: var(--gold);
}

.rpg-lemmas {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: inherit;
  cursor: pointer;
}

.rpg-lv-wrap {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.rpg-xp-bar {
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}

.rpg-xp-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ── Scrollable content area ─────────────────────────────────── */
.rpg-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 16px calc(56px + env(safe-area-inset-bottom, 0px) + 16px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Onboarding ──────────────────────────────────────────────── */
.rpg-onboarding {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 24px;
  gap: 20px;
}

.rpg-welcome-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
}

.rpg-welcome-sub {
  font-size: 16px;
  color: var(--text-dim);
  text-align: center;
  max-width: 320px;
  line-height: 1.5;
}

.rpg-course-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  max-width: 400px;
}

.rpg-course-chip {
  padding: 14px 20px;
  border-radius: 12px;
  border: 2px solid var(--chip-color, var(--border));
  background: var(--bg2);
  color: var(--chip-color, var(--text));
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  min-width: 48px;
  min-height: 48px;
  transition: background 0.15s, transform 0.1s;
}

.rpg-course-chip:active {
  transform: scale(0.96);
}

.rpg-course-chip:hover {
  background: var(--bg3);
}

.rpg-chip-all {
  width: 100%;
  color: var(--text-dim);
}

/* ── Continue card ───────────────────────────────────────────── */
.rpg-continue-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  position: relative;
}

.rpg-course-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  background: var(--bg3);
  border: 1.5px solid var(--badge-color, var(--border));
  color: var(--badge-color, var(--text-dim));
  align-self: flex-start;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rpg-card-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.25;
}


.rpg-xp-hint {
  font-size: 13px;
  font-weight: 700;
  color: var(--gold);
}

.rpg-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.rpg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 13px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  text-decoration: none;
  min-height: 48px;
  transition: opacity 0.15s, transform 0.1s;
}

.rpg-btn:active {
  transform: scale(0.97);
}

.rpg-btn-primary {
  background: var(--accent);
  color: var(--bg);
  flex: 1;
}

.rpg-btn-primary:hover {
  opacity: 0.88;
}

/* "Mark learned" is the quiet secondary action: a ghost button that only takes the
   width it needs, so "Open lesson" (primary, filled, flex:1) clearly leads. */
.rpg-btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.rpg-btn-ghost:hover {
  color: var(--text);
  border-color: var(--accent);
}

.rpg-btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  background: var(--accent);
  color: var(--bg);
  border-radius: 8px;
  min-height: 44px;
}

.rpg-btn-sm:hover {
  opacity: 0.88;
}

/* Small ghost variant — beats .rpg-btn-sm's filled colours (higher specificity). */
.rpg-btn-sm.rpg-btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.rpg-btn-sm.rpg-btn-ghost:hover {
  color: var(--text);
  border-color: var(--accent);
  opacity: 1;
}

/* Disabled state: muted + blocked cursor; used when "Mark learned" converts
   to "Learned" so the Level Up Quiz button becomes the primary CTA. */
.rpg-btn:disabled,
.rpg-btn[disabled] {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

/* Level Up Quiz button: gold tint so it reads as the next-action CTA
   once the student has marked a node learned. */
.rpg-quiz-btn {
  background: color-mix(in srgb, var(--gold) 18%, transparent);
  color: var(--gold);
  border: 1.5px solid var(--gold);
  /* Take a full row of its own (the row wraps): with "Open lesson" + "Learned" on the line
     above, three buttons no longer overflow a phone, and the gold CTA reads as the next step. */
  flex: 1 1 100%;
}

.rpg-quiz-btn:hover {
  background: color-mix(in srgb, var(--gold) 30%, transparent);
  border-color: var(--gold);
}

/* ── Up-next list ────────────────────────────────────────────── */
.rpg-upnext {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.rpg-upnext-hd {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 10px 16px 6px;
}

.rpg-upnext-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  min-height: 44px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

.rpg-upnext-item:hover {
  background: var(--bg3);
}

.rpg-mini-badge {
  flex-shrink: 0;
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1.5px solid var(--badge-color, var(--border));
  color: var(--badge-color, var(--text-dim));
  background: var(--bg3);
  white-space: nowrap;
}

.rpg-upnext-name {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rpg-upnext-xp {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--gold);
}

/* ── Map tab ─────────────────────────────────────────────────── */
.rpg-map-hd {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  padding-bottom: 4px;
}

.rpg-map-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.1s;
}

.rpg-map-item:hover {
  background: var(--bg3);
}

.rpg-map-left {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rpg-map-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rpg-map-concept {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rpg-map-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Profile tab ─────────────────────────────────────────────── */
.rpg-profile-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rpg-profile-lv {
  font-size: 16px;
  color: var(--text-dim);
}

.rpg-profile-lv-num {
  font-size: 36px;
  font-weight: 800;
  color: var(--accent);
}

.rpg-profile-xp {
  font-size: 14px;
  color: var(--text-dim);
}

.rpg-profile-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rpg-profile-bar {
  height: 8px;
  background: var(--bg3);
  border-radius: 4px;
  overflow: hidden;
}

.rpg-profile-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s;
}

.rpg-profile-bar-label {
  font-size: 11px;
  color: var(--text-dim);
}

.rpg-profile-streak {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 600;
  color: var(--gold);
}

.rpg-profile-mastered {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}

.rpg-profile-courses-hd {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-top: 4px;
}

.rpg-profile-course-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}

.rpg-profile-course-label {
  width: 120px;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rpg-profile-mini-bar {
  flex: 1;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}

.rpg-profile-mini-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s;
}

.rpg-profile-frac {
  width: 50px;
  text-align: right;
  font-size: 12px;
  color: var(--text-dim);
  flex-shrink: 0;
}

/* ── All-caught-up banner ────────────────────────────────────────── */
.rpg-caught-up {
  padding: 12px 16px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: 10px;
  font-size: 13px;
  color: var(--accent);
  text-align: center;
}

/* ── Profile goal picker ─────────────────────────────────────────── */
.rpg-profile-goal-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.rpg-profile-goal-btn {
  flex: 1;
  font-size: 12px;
  padding: 8px 10px;
  min-height: 44px;
}

.rpg-profile-goal-active {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* Keep text readable on the accent background when the active goal button
   is hovered. .rpg-btn-ghost:hover sets color:var(--text) (off-white on
   dark theme) which drops to ~1.8:1 contrast on the teal accent.
   This rule shares the same specificity (0-2-0) and appears later, so it wins. */
.rpg-profile-goal-active:hover {
  color: var(--bg);
  opacity: 0.88;
}

/* Modifier: gold-tinted text for review-needed headings and due counts */
.rpg-text-due { color: var(--gold); }

/* ── Due-review card ─────────────────────────────────────────────── */
.rpg-due-card {
  background: var(--bg2);
  border: 1px solid var(--gold);
  border-radius: 14px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rpg-due-hd {
  font-size: 15px;
  font-weight: 700;
  color: var(--gold);
  font-family: var(--font-display);
}

.rpg-due-sub {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
  margin-top: -4px;
}

.rpg-due-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
}

.rpg-due-row + .rpg-due-row {
  border-top: 1px solid var(--border);
}

.rpg-due-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.rpg-due-name {
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rpg-due-level {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.rpg-due-quiz-btn {
  flex-shrink: 0;
}

.rpg-due-more {
  font-size: 12px;
  color: var(--text-dim);
  text-align: right;
  font-family: var(--font-mono);
}

/* ── Profile export / import ─────────────────────────────────────── */
.rpg-profile-data-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  text-align: center;
  cursor: pointer;
}

.rpg-profile-export-ta {
  display: none;
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-mono);
  resize: vertical;
  box-sizing: border-box;
}

/* ── Bottom nav ──────────────────────────────────────────────── */
.rpg-bottom-nav {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.rpg-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  min-height: 56px;
  gap: 2px;
  transition: color 0.15s;
  text-decoration: none;
}

.rpg-nav-btn.active {
  color: var(--accent);
}

.rpg-nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  position: relative;
}

.rpg-nav-badge {
  position: absolute;
  top: -5px;
  right: -7px;
  min-width: 15px;
  height: 15px;
  background: var(--gold);
  color: #000;
  border-radius: 8px;
  font-size: 9px;
  font-weight: 800;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
  box-sizing: border-box;
}

.rpg-nav-badge[hidden] { display: none; }

/* ── Inline icons (Feather style, matched to the lesson pages) ──────────── */
.rpg-svg-icon {
  display: block;
  width: 100%;
  height: 100%;
}

.rpg-stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1em;
  height: 1em;
}

.rpg-profile-streak-dim {
  color: var(--text-dim);
  opacity: 0.7;
}

.rpg-profile-streak .rpg-stat-icon {
  width: 1.1em;
  height: 1.1em;
}

.rpg-nav-label {
  font-size: 11px;
  font-weight: 600;
}

/* ── Empty state ─────────────────────────────────────────────── */
.rpg-empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Desktop: hide RPG shell by default (app.js controls it) ─── */
@media (min-width: 900px) {
  #rpg-shell:not([style]) {
    display: none;
  }
}

/* ── Notyf z-index fix ───────────────────────────────────────────
   notyf.min.css ships with z-index:9999, which puts toasts behind
   the quiz overlay and settings overlay (both at z-index:10000).
   XP and level-up toasts fired during or after a quiz pass would be
   invisible. Raise the Notyf container above all app overlays. */
.notyf {
  z-index: 10002 !important;
}

/* ── Focus styles (keyboard navigation) ─────────────────────────
   Use :focus-visible so mouse clicks don't show the ring, only keyboard Tab.
   High-contrast ring so keyboard users never lose their position. */
.rpg-btn:focus-visible,
.rpg-nav-btn:focus-visible,
.rpg-course-chip:focus-visible,
.rpg-upnext-item:focus-visible,
.rpg-map-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Reduced motion ──────────────────────────────────────────────
   Suppress all CSS transitions and animations for users who have
   opted into prefers-reduced-motion at the OS level.
   JS confetti/sound are gated separately in gamification.js and quiz.js. */
@media (prefers-reduced-motion: reduce) {
  .rpg-xp-fill,
  .rpg-profile-bar-fill,
  .rpg-profile-mini-fill,
  .rpg-btn,
  .rpg-course-chip,
  .rpg-upnext-item,
  .rpg-map-item,
  .rpg-nav-btn {
    transition: none !important;
    animation:  none !important;
  }
}

/* ── Typography cohesion with the lesson pages ───────────────────
   The lessons set titles in a display face and labels/numbers in a mono face.
   We mirror that here so the gamified shell and the lessons read as one product.
   Grouped at the end so the intent is obvious and easy to audit. */
.rpg-welcome-title,
.rpg-card-title,
.rpg-due-hd,
.rpg-map-hd,
.rpg-profile-lv-num {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}
.rpg-stat-chip,
.rpg-xp-hint,
.rpg-upnext-xp,
.rpg-upnext-hd,
.rpg-mini-badge,
.rpg-course-badge,
.rpg-nav-label,
.rpg-profile-courses-hd,
.rpg-profile-frac,
.rpg-profile-bar-label {
  font-family: var(--font-mono);
}

/* ── Detail panel on phones ──────────────────────────────────────
   The desktop detail drawer (#panel) is reused in the mobile shell. On a phone it must span
   the full width, clear the status bar, stop above the bottom nav, and carry a finger-sized,
   clearly visible close button (the desktop float:right glyph sits flush to the notch). The
   panel stays below the nav's z-index so the tabs remain tappable while it is open. */
@media (max-width: 899px) {
  #panel {
    width: 100%;
    max-width: 100%;
    border-left: none;
    top: 0 !important;
    bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
    z-index: 90;
  }
  #panel-close {
    float: none;
    position: absolute;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: 14px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: var(--text);
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 50%;
  }
  #panel-title { padding-right: 52px; }
}
