// Shared tokens + StatusBar for RopeCounter App Store screenshots.
// All values are in CANVAS pixels (1290 × 2796 device).

const RC = {
  // Backgrounds
  bgLight: '#F8FAFC',
  bgDark: '#0B1120',
  // Surfaces
  surfaceLight: '#FFFFFF',
  surfaceDark: '#1E293B',
  surfaceMutedLight: '#F1F5F9',
  surfaceMutedDark: '#334155',
  // Text
  textPrimaryLight: '#0F172A',
  textPrimaryDark: '#F8FAFC',
  textSecondaryLight: '#64748B',
  textSecondaryDark: '#94A3B8',
  textTertiaryLight: '#94A3B8',
  textTertiaryDark: '#64748B',
  // Accent (Emerald-700 / 400)
  accentLight: '#15803D',
  accentDark: '#34D399',
  onAccentLight: '#FFFFFF',
  onAccentDark: '#022C16',
  // Exam tiers
  examLowLight: '#D97706', examLowDark: '#FBBF24',
  examMidLight: '#115E33', examMidDark: '#10B981',
  examHighLight: '#16A34A', examHighDark: '#6EE7B7',
  // Semantic
  successLight: '#059669', successDark: '#34D399',
  borderLight: '#E2E8F0', borderDark: '#334155',
  // Fonts
  fontSans: '"SF Pro Display","SF Pro Text",-apple-system,BlinkMacSystemFont,"Helvetica Neue",system-ui,sans-serif',
  fontRounded: '"SF Pro Rounded",ui-rounded,"SF Pro Display",-apple-system,system-ui,sans-serif',
  fontMono: '"SF Mono",ui-monospace,"Menlo","Roboto Mono",monospace',
};

// Canvas dimensions (App Store 6.7")
const CANVAS_W = 1290;
const CANVAS_H = 2796;
const ZONE_A_H = Math.round(CANVAS_H * 0.22);   // 615
const ZONE_B_H = Math.round(CANVAS_H * 0.62);   // 1734
const ZONE_C_H = CANVAS_H - ZONE_A_H - ZONE_B_H; // 447

// iOS 17 Status Bar (1290 wide canvas, ~132px tall incl Dynamic Island)
function StatusBar({ dark = false }) {
  const fg = dark ? '#FFFFFF' : '#0F172A';
  return (
    <div style={{
      position: 'absolute', top: 0, left: 0, right: 0, height: 132,
      zIndex: 50, pointerEvents: 'none',
      fontFamily: RC.fontSans, color: fg,
      display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      padding: '0 70px',
    }}>
      <div style={{ fontWeight: 600, fontSize: 51, letterSpacing: -0.5, fontVariantNumeric: 'tabular-nums' }}>
        9:41
      </div>
      {/* Dynamic Island */}
      <div style={{
        position: 'absolute', top: 30, left: '50%', transform: 'translateX(-50%)',
        width: 360, height: 110, borderRadius: 999,
        background: '#000',
      }} />
      <div style={{ display: 'flex', alignItems: 'center', gap: 18 }}>
        {/* Signal bars */}
        <svg width="60" height="36" viewBox="0 0 60 36" fill="none">
          <rect x="2" y="22" width="8" height="12" rx="2" fill={fg}/>
          <rect x="16" y="16" width="8" height="18" rx="2" fill={fg}/>
          <rect x="30" y="9" width="8" height="25" rx="2" fill={fg}/>
          <rect x="44" y="2" width="8" height="32" rx="2" fill={fg}/>
        </svg>
        {/* Wifi */}
        <svg width="50" height="36" viewBox="0 0 50 36" fill="none">
          <path d="M25 30a3 3 0 100-6 3 3 0 000 6z" fill={fg}/>
          <path d="M11 18c4-4 9-6 14-6s10 2 14 6" stroke={fg} strokeWidth="3.5" strokeLinecap="round" fill="none"/>
          <path d="M4 11c6-6 13-9 21-9s15 3 21 9" stroke={fg} strokeWidth="3.5" strokeLinecap="round" fill="none"/>
        </svg>
        {/* Battery */}
        <svg width="84" height="36" viewBox="0 0 84 36" fill="none">
          <rect x="2" y="6" width="68" height="24" rx="6" stroke={fg} strokeOpacity="0.45" strokeWidth="2.5" fill="none"/>
          <rect x="72" y="13" width="5" height="10" rx="2" fill={fg} fillOpacity="0.45"/>
          <rect x="6" y="10" width="56" height="16" rx="3" fill={fg}/>
        </svg>
      </div>
    </div>
  );
}

// Zone A — marketing text at top
function ZoneA({ dark = false, headline, subline }) {
  return (
    <div style={{
      height: ZONE_A_H,
      background: dark ? RC.bgDark : RC.bgLight,
      display: 'flex', flexDirection: 'column',
      alignItems: 'center', justifyContent: 'center',
      padding: '0 96px',
      textAlign: 'center',
      fontFamily: RC.fontSans,
    }}>
      <h1 style={{
        margin: 0,
        fontSize: 100, lineHeight: 1.08, fontWeight: 700,
        color: dark ? RC.textPrimaryDark : RC.textPrimaryLight,
        letterSpacing: -1.5,
      }}>{headline}</h1>
      <p style={{
        margin: '24px 0 0',
        fontSize: 48, lineHeight: 1.3, fontWeight: 400,
        color: dark ? RC.textSecondaryDark : RC.textSecondaryLight,
        letterSpacing: -0.2,
      }}>{subline}</p>
    </div>
  );
}

// Zone C — bottom caption stripe
function ZoneC({ dark = false, caption }) {
  return (
    <div style={{
      height: ZONE_C_H,
      background: dark ? RC.bgDark : RC.bgLight,
      display: 'flex', alignItems: 'flex-start', justifyContent: 'center',
      paddingTop: 70,
      fontFamily: RC.fontSans,
    }}>
      <p style={{
        margin: 0,
        fontSize: 42, lineHeight: 1.3, fontWeight: 400,
        color: dark ? RC.textTertiaryDark : RC.textTertiaryLight,
        letterSpacing: 0,
        textAlign: 'center',
      }}>{caption}</p>
    </div>
  );
}

// Wrapper that lays out A / B / C with absolute Zone B child positioning
function ScreenshotShell({ dark, headline, subline, caption, children }) {
  return (
    <div style={{
      width: CANVAS_W, height: CANVAS_H, position: 'relative',
      background: dark ? RC.bgDark : RC.bgLight,
      overflow: 'hidden',
      fontFamily: RC.fontSans,
      WebkitFontSmoothing: 'antialiased',
      MozOsxFontSmoothing: 'grayscale',
    }}>
      <ZoneA dark={dark} headline={headline} subline={subline} />
      <div style={{
        position: 'absolute', top: ZONE_A_H, left: 0, right: 0,
        height: ZONE_B_H, overflow: 'hidden',
        background: dark ? RC.bgDark : RC.bgLight,
      }}>
        {children}
      </div>
      <div style={{ position: 'absolute', top: ZONE_A_H + ZONE_B_H, left: 0, right: 0 }}>
        <ZoneC dark={dark} caption={caption} />
      </div>
    </div>
  );
}

Object.assign(window, {
  RC, CANVAS_W, CANVAS_H, ZONE_A_H, ZONE_B_H, ZONE_C_H,
  StatusBar, ZoneA, ZoneC, ScreenshotShell,
});
