/**
 * BG Shared UX — imported by all backgammon module HTML files
 * <link rel="stylesheet" href="/bg-core/bg-ux.css">
 *
 * Provides: design tokens, HUD layout, buttons, stats, dice, move options,
 * eval panel, feedback toast, XP toast, loading skeleton, animations,
 * focus-visible accessibility, prefers-reduced-motion, mobile breakpoints.
 */


/* ═══════════════════════════════════════════════════════════════
   DESIGN TOKENS
   ═══════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; }

:root {
  /* Surfaces */
  --bg: #080604;
  --panel: #0f0b08;
  --panel2: #150f0a;

  /* Borders */
  --border: #251c14;
  --border-light: #35291c;

  /* Text */
  --text: #ede6dc;
  --muted: #8d7e6e;
  --heading: #e8d5b7;

  /* Brand */
  --accent: #d4a574;
  --accent-dim: rgba(212,165,116,0.12);
  --accent-glow: rgba(212,165,116,0.06);

  /* Semantic */
  --good: #4ade80;
  --bad: #f87171;
  --warn: #fbbf24;
  --gold: #f5c842;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

html { scroll-behavior: smooth; }


/* ═══════════════════════════════════════════════════════════════
   HUD (Top Bar)
   ═══════════════════════════════════════════════════════════════ */

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
  gap: 8px;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}


/* ═══════════════════════════════════════════════════════════════
   BASE BUTTON
   ═══════════════════════════════════════════════════════════════ */

.btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: color 0.2s, border-color 0.2s;
}

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

.btn.primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.btn.primary:hover {
  filter: brightness(1.1);
}


/* ═══════════════════════════════════════════════════════════════
   STAT GROUP
   ═══════════════════════════════════════════════════════════════ */

.stat-group {
  display: flex;
  gap: 16px;
}

.stat {
  text-align: center;
}

.stat-label {
  font-size: 0.55rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-val {
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}


/* ═══════════════════════════════════════════════════════════════
   MAIN CONTENT AREA
   ═══════════════════════════════════════════════════════════════ */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 14px;
  overflow-y: auto;
}

.board-wrap {
  width: 100%;
  max-width: 600px;
}


/* ═══════════════════════════════════════════════════════════════
   DICE DISPLAY
   Use .die            (46 × 46) — default trainer size
   Use .die.lg         (52 × 52) — opening module emphasis
   Use .die.sm         (38 × 38) — mobile or compact
   Use .die.opp        — opponent dice (dark variant)
   ═══════════════════════════════════════════════════════════════ */

.dice-area,
.dice-display {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.die {
  width: 46px;
  height: 46px;
  background: #f5f0e8;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  color: #1a1a1a;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  transition: transform 0.15s ease;
  user-select: none;
}

.die.lg  { width: 52px; height: 52px; font-size: 1.6rem; }
.die.sm  { width: 38px; height: 38px; font-size: 1.1rem; }
.die.opp { background: #2a2420; color: #e8d5c0; }


/* ═══════════════════════════════════════════════════════════════
   MOVE OPTIONS
   ═══════════════════════════════════════════════════════════════ */

.move-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 560px;
  width: 100%;
}

.move-opt {
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.move-opt:hover            { border-color: var(--accent); background: var(--accent-glow); }
.move-opt.correct          { border-color: var(--good); background: rgba(74,222,128,0.08); }
.move-opt.wrong            { border-color: var(--bad);  background: rgba(248,113,113,0.08); }
.move-opt.selected         { border-color: var(--accent); background: var(--accent-dim); }
.move-opt:disabled         { cursor: default; opacity: 0.5; }

.move-opt .badge {
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.move-opt.correct .badge { background: rgba(74,222,128,0.15); color: var(--good); }
.move-opt.wrong .badge   { background: rgba(248,113,113,0.15); color: var(--bad); }


/* ═══════════════════════════════════════════════════════════════
   EVAL PANEL
   ═══════════════════════════════════════════════════════════════ */

.eval-panel {
  max-width: 560px;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  animation: bg-fadeUp 0.35s ease;
}

.eval-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.eval-verdict {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 700;
}

.eval-verdict.good { color: var(--good); }
.eval-verdict.bad  { color: var(--bad); }

.eval-insights {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.insight-tag {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.insight-tag.pos     { background: rgba(74,222,128,0.1);  color: var(--good); border: 1px solid rgba(74,222,128,0.15); }
.insight-tag.neg     { background: rgba(248,113,113,0.08); color: var(--bad);  border: 1px solid rgba(248,113,113,0.12); }
.insight-tag.neutral { background: var(--panel2); color: var(--muted); border: 1px solid var(--border); }

.eval-principle {
  font-size: 0.82rem;
  color: var(--accent);
  line-height: 1.5;
  padding: 10px 14px;
  background: rgba(212,165,116,0.05);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
}

.eval-stats {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.eval-stat       { text-align: center; flex: 1; }
.eval-stat-val   { font-size: 0.85rem; font-weight: 700; color: var(--text); }
.eval-stat-label { font-size: 0.5rem; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }


/* ═══════════════════════════════════════════════════════════════
   ACTION / NEXT BUTTONS
   ═══════════════════════════════════════════════════════════════ */

.action-btn,
.next-btn {
  padding: 10px 28px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #000;
  font-family: inherit;
  transition: filter 0.2s;
}

.action-btn:hover,
.next-btn:hover { filter: brightness(1.1); }

.action-btn:disabled,
.next-btn:disabled { opacity: 0.4; cursor: default; filter: none; }

.action-btn.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}

.action-btn.secondary:hover { border-color: var(--accent); }


/* ═══════════════════════════════════════════════════════════════
   DIFFICULTY SELECTOR
   ═══════════════════════════════════════════════════════════════ */

.diff-select,
.diff-bar,
.diff-row {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.diff-opt,
.diff-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.diff-opt:hover,
.diff-btn:hover { color: var(--text); border-color: var(--accent); }

.diff-opt.active,
.diff-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }


/* ═══════════════════════════════════════════════════════════════
   FEEDBACK TOAST (top-center)
   ═══════════════════════════════════════════════════════════════ */

.feedback {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-60px);
  padding: 8px 24px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 999;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}

.feedback.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.feedback.good { background: var(--good); color: #000; }
.feedback.bad  { background: var(--bad);  color: #000; }


/* ═══════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS (bottom-center)
   ═══════════════════════════════════════════════════════════════ */

.bg-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: min(90vw, 400px);
  text-align: center;
  backdrop-filter: blur(8px);
}

.bg-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.bg-toast.error   { background: rgba(248,113,113,0.92); color: #000; box-shadow: 0 4px 20px rgba(248,113,113,0.4); }
.bg-toast.success { background: rgba(74,222,128,0.92);  color: #000; box-shadow: 0 4px 20px rgba(74,222,128,0.4); }
.bg-toast.info    { background: rgba(212,165,116,0.92); color: #000; box-shadow: 0 4px 20px rgba(212,165,116,0.4); }


/* ═══════════════════════════════════════════════════════════════
   XP TOAST
   ═══════════════════════════════════════════════════════════════ */

@keyframes bg-xpPop {
  0%   { opacity: 0; transform: translateY(12px) scale(0.9); }
  20%  { opacity: 1; transform: translateY(-4px) scale(1.05); }
  40%  { opacity: 1; transform: translateY(0) scale(1); }
  85%  { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-14px) scale(0.95); }
}

.bg-xp-toast {
  position: fixed;
  bottom: 28px;
  right: 20px;
  background: var(--accent);
  color: #000;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 10px 20px;
  border-radius: 10px;
  pointer-events: none;
  opacity: 0;
  z-index: 9998;
  box-shadow: 0 4px 18px rgba(212,165,116,0.35);
}

.bg-xp-toast.show {
  animation: bg-xpPop 1.4s ease forwards;
}


/* ═══════════════════════════════════════════════════════════════
   LOADING SKELETON
   ═══════════════════════════════════════════════════════════════ */

@keyframes bg-shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}

.bg-skeleton {
  background: linear-gradient(90deg,
    rgba(255,255,255,0.04) 25%,
    rgba(255,255,255,0.08) 50%,
    rgba(255,255,255,0.04) 75%
  );
  background-size: 800px 100%;
  animation: bg-shimmer 1.5s ease infinite;
  border-radius: 8px;
}

body.bg-loaded .bg-skeleton { display: none; }


/* ═══════════════════════════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════════════════════════ */

@keyframes bg-fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes bg-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

@keyframes bg-correctFlash {
  0%   { box-shadow: 0 0 0 0 rgba(74,222,128,0.5); }
  100% { box-shadow: 0 0 0 12px rgba(74,222,128,0); }
}

@keyframes bg-wrongFlash {
  0%   { box-shadow: 0 0 0 0 rgba(248,113,113,0.5); }
  100% { box-shadow: 0 0 0 12px rgba(248,113,113,0); }
}

/* Smooth entrance for any panel/section */
.bg-enter {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.bg-enter.visible {
  opacity: 1;
  transform: translateY(0);
}

.ai-thinking {
  font-size: 0.7rem;
  color: var(--accent);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 700;
  animation: bg-pulse 1s ease infinite;
}


/* ═══════════════════════════════════════════════════════════════
   ACCESSIBILITY — FOCUS-VISIBLE
   ═══════════════════════════════════════════════════════════════ */

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #ffd54f;
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}


/* ═══════════════════════════════════════════════════════════════
   REDUCED MOTION
   ═══════════════════════════════════════════════════════════════ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}


/* ═══════════════════════════════════════════════════════════════
   MOBILE BREAKPOINTS
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 560px) {
  .die       { width: 40px; height: 40px; font-size: 1.2rem; }
  .die.lg    { width: 44px; height: 44px; font-size: 1.3rem; }
  .stat-group { gap: 10px; }
  .eval-insights { gap: 4px; }
}

@media (max-width: 420px) {
  .die       { width: 36px; height: 36px; font-size: 1rem; }
  .die.lg    { width: 40px; height: 40px; font-size: 1.1rem; }
  .stat-group { gap: 8px; }
  .stat-label { font-size: 0.5rem; }
}


/* ═══════════════════════════════════════════════════════════════
   UTILITIES
   ═══════════════════════════════════════════════════════════════ */

.bg-hidden { display: none !important; }

.bg-hint {
  color: rgba(255,255,255,0.4);
  font-size: 0.78rem;
  text-align: center;
  padding: 16px;
}
