// ─────────────────────────────────────────────────────────────
// RopeCounter V2 — design tokens (Palette A2, locked 2026-05-08)
// Single source of truth mirrored from design-system/.../MASTER.md §1–§3
// ─────────────────────────────────────────────────────────────
const RC = {
  light: {
    primary:      '#0F172A',
    accent:       '#15803D', // emerald-700 (A2)
    accentSoft:   '#DCFCE7', // emerald-100 tint for fills
    onAccent:     '#FFFFFF',
    bg:           '#F8FAFC', // slate-50
    surface:      '#FFFFFF',
    surfaceMuted: '#F1F5F9', // slate-100
    border:       '#E2E8F0', // slate-200
    textPri:      '#0F172A',
    textSec:      '#64748B', // slate-500
    textTer:      '#94A3B8', // slate-400
    success:      '#059669',
    warning:      '#D97706',
    danger:       '#DC2626',
    examLow:      '#D97706', // amber-600
    examMid:      '#115E33', // accent decoupled −1
    examHigh:     '#16A34A', // emerald-600
    // ── warm "friendly gadget" framing (recording page) ──
    panel:        '#F0E7D8', // warm cream desk
    panelBorder:  '#E2D6C2',
    inset:        '#E7DCC8', // recessed tray
    insetBorder:  '#D7C9B1',
    cardWarm:     '#FFFDF8', // warm card surface
    cardBorder:   '#ECE2D2',
    matte:        '#FFFFFF', // camera white frame
    fun:          '#F59E0B', // sunny secondary, playful accents
    funSoft:      '#FEF1D8',
    bgWarm:       '#FAF4EA', // soft warm page bg for content screens
  },
  dark: {
    primary:      '#F8FAFC',
    accent:       '#34D399', // emerald-400
    accentSoft:   '#0F2E22',
    onAccent:     '#022C16', // chromatic-dark per §13
    bg:           '#0B1120',
    surface:      '#1E293B', // slate-800
    surfaceMuted: '#334155', // slate-700
    border:       '#334155',
    textPri:      '#F8FAFC',
    textSec:      '#94A3B8',
    textTer:      '#64748B',
    success:      '#34D399',
    warning:      '#FBBF24',
    danger:       '#F87171',
    examLow:      '#FBBF24', // amber-400
    examMid:      '#10B981', // emerald-500
    examHigh:     '#6EE7B7', // emerald-300
    // ── warm framing (dark) — warmer slate, not cool navy ──
    panel:        '#171b22', // warm charcoal desk
    panelBorder:  '#2a2f38',
    inset:        '#10131a', // recessed tray
    insetBorder:  '#272c35',
    cardWarm:     '#222730', // warm card surface
    cardBorder:   '#343a44',
    matte:        '#2c323c', // camera frame
    fun:          '#FBBF24',
    funSoft:      '#2e2716',
    bgWarm:       '#10141d', // content page bg (dark)
  },
};

// Platform-aware font stacks. iOS → SF; Android → Roboto.
const FONTS = {
  ios: {
    sans:    '-apple-system, "SF Pro Text", "PingFang SC", system-ui, sans-serif',
    rounded: '"SF Pro Rounded", -apple-system, "SF Pro Display", system-ui, sans-serif',
    mono:    '"SF Mono", ui-monospace, SFMono-Regular, Menlo, monospace',
  },
  android: {
    sans:    'Roboto, "Noto Sans SC", "Helvetica Neue", system-ui, sans-serif',
    rounded: '"Roboto Flex", Roboto, "Noto Sans SC", system-ui, sans-serif',
    mono:    '"Roboto Mono", ui-monospace, Menlo, monospace',
  },
};

// hex + alpha → rgba()
function rgba(hex, a) {
  const h = hex.replace('#', '');
  const r = parseInt(h.slice(0, 2), 16);
  const g = parseInt(h.slice(2, 4), 16);
  const b = parseInt(h.slice(4, 6), 16);
  return `rgba(${r},${g},${b},${a})`;
}

// Exam tier resolver — pct = score / maxScore. Boundaries: high ≥90%, mid 60–89%.
function examTier(score, maxScore) {
  const pct = score / maxScore;
  if (pct >= 0.9) return 'examHigh';
  if (pct >= 0.6) return 'examMid';
  return 'examLow';
}

// elevation shadows (light only; dark uses borders per §3)
const ELEV = {
  1: '0 1px 2px rgba(15,23,42,0.05)',
  2: '0 1px 2px rgba(15,23,42,0.04), 0 4px 12px rgba(15,23,42,0.08)',
  3: '0 8px 24px rgba(15,23,42,0.12)',
};

// 4 measurement modes (§5.10) — single source of truth, stable order
const MODES = [
  { key: 'free',      label: '自由模式', cap: true  },
  { key: 'goalCount', label: '目标次数', cap: false },
  { key: 'goalTime',  label: '目标时间', cap: false },
  { key: 'exam',      label: '体测评分', cap: false }, // grad-cap prefix
];

Object.assign(window, { RC, FONTS, rgba, examTier, ELEV, MODES });
