// ReturnScribe v3 — "The Ledger" design tokens
// Receipt paper + ink. Serif display, mono numerals, stamped statuses.
// Keys are kept compatible with all screens.

const RSTokens = {
  dark: {   // "Night ledger" — warm ink
    canvas:    '#161310',
    surface1:  '#1E1A15',
    surface2:  '#272219',
    surfaceGrad: '#1E1A15',
    hairline:  'rgba(239,233,222,0.18)',
    border:    'rgba(239,233,222,0.13)',
    borderStrong: 'rgba(239,233,222,0.26)',
    text1:     '#EFE8DB',
    text2:     '#A89F8E',
    text3:     '#6F6759',
    accent:    '#F0653A',
    accentDim: 'rgba(240,101,58,0.16)',
    success:   '#7DBE6E',
    warning:   '#D9A03F',
    danger:    '#E05C48',
    chip:      'rgba(239,233,222,0.08)',
    glassBg:   'rgba(30,26,21,0.82)',
    glassBorder: 'rgba(239,233,222,0.16)',
    tabBg:     'rgba(22,19,16,0.88)',
    scrim:     'rgba(10,8,6,0.55)',
  },
  light: {  // "Paper" — warm off-white
    canvas:    '#F4F0E6',
    surface1:  '#FBF8F1',
    surface2:  '#EDE8DC',
    surfaceGrad: '#FBF8F1',
    hairline:  'rgba(33,29,23,0.22)',
    border:    'rgba(33,29,23,0.14)',
    borderStrong: 'rgba(33,29,23,0.28)',
    text1:     '#211D16',
    text2:     '#6E6757',
    text3:     '#A59D8C',
    accent:    '#C2451E',
    accentDim: 'rgba(194,69,30,0.11)',
    success:   '#3A7D3E',
    warning:   '#96690F',
    danger:    '#B3402F',
    chip:      'rgba(33,29,23,0.06)',
    glassBg:   'rgba(251,248,241,0.86)',
    glassBorder: 'rgba(33,29,23,0.16)',
    tabBg:     'rgba(244,240,230,0.92)',
    scrim:     'rgba(33,29,23,0.35)',
  },
};

// Typography — three voices:
//   disp — Instrument Serif: titles, editorial moments
//   num  — IBM Plex Mono: every numeral, eyebrow, stamp (the register print)
//   sys  — Instrument Sans: body and controls
const RSFont = {
  sys:  '"Instrument Sans", -apple-system, system-ui, sans-serif',
  num:  '"IBM Plex Mono", "SF Mono", monospace',
  disp: '"Instrument Serif", Georgia, serif',
};

const RSType = {
  hero:       { size: 58, weight: 400, tracking: -1.6,  leading: 1.0 },
  large:      { size: 34, weight: 400, tracking: -0.4,  leading: 1.08 },
  title1:     { size: 28, weight: 400, tracking: -0.3,  leading: 1.14 },
  title2:     { size: 22, weight: 400, tracking: -0.2,  leading: 1.2 },
  headline:   { size: 16, weight: 600, tracking: -0.15, leading: 1.3 },
  body:       { size: 16, weight: 400, tracking: -0.12, leading: 1.4 },
  callout:    { size: 15, weight: 400, tracking: -0.1,  leading: 1.4 },
  subhead:    { size: 14, weight: 500, tracking: -0.05, leading: 1.35 },
  footnote:   { size: 13, weight: 400, tracking: 0,     leading: 1.35 },
  caption:    { size: 11.5, weight: 500, tracking: 0.2, leading: 1.25 },
  badge:      { size: 10,   weight: 600, tracking: 1.0, leading: 1.2 },
  eyebrow:    { size: 10.5, weight: 500, tracking: 1.8, leading: 1.2 },
};

const RSBrand = {
  blue:   '#3D6B9E',
  teal:   '#3E8F7C',
  mint:   '#85C5AD',
  purple: '#7A5CA8',
  orange: '#C2451E',
};

const RSSpace = [4, 8, 12, 16, 20, 24, 32, 40, 56, 80];

function applyType(t, extra = {}) {
  return {
    fontFamily: RSFont.sys,
    fontSize: t.size,
    fontWeight: t.weight,
    letterSpacing: t.tracking + 'px',
    lineHeight: t.leading,
    ...extra,
  };
}
// Serif display
function applyDisp(t, extra = {}) {
  return applyType(t, { fontFamily: RSFont.disp, fontWeight: 400, ...extra });
}
// Mono register print
function applyMono(t, extra = {}) {
  return applyType(t, { fontFamily: RSFont.num, ...extra });
}

const RSTabular = { fontVariantNumeric: 'tabular-nums', fontFeatureSettings: '"tnum"' };

Object.assign(window, { RSTokens, RSType, RSFont, RSBrand, RSSpace, applyType, applyDisp, applyMono, RSTabular });
