/**
 * COEUS Design System V2 - Consolidated Typography
 *
 * PURPOSE:
 * 6 semantic typography classes replacing 12+ iOS classes
 * Based on analysis of 1,407 text elements
 *
 * COMPACT SIZE SCALE (consistent across all screens):
 * - Headlines (heading-1/2/3): 15px
 * - Main text (body-text, form-label): 13px
 * - Description (caption, helper-text): 12px
 *
 * FEATURES:
 * - Container-aware automatic scaling (depth-based)
 * - Noto JP/KR fonts for complete CJK support
 * - Theme-responsive colors (5 themes)
 * - Semantic naming for clarity
 *
 * CONSOLIDATION MAP:
 * ios-body + text-secondary → .body-text (197 uses)
 * font-figtree + ios-subheadline + text-primary → .form-label (115 uses)
 * ios-title2 + text-primary → .heading-2 (109 uses)
 * ios-caption1 + text-secondary → .caption (77 uses)
 * ios-title1 + text-primary → .heading-1 (57 uses)
 * ios-caption2 + text-tertiary → .helper-text (48 uses)
 */

/* ============================================ */
/*              FONT STACKS                     */
/* ============================================ */
:root {
  /* Primary fonts - Noto for complete language support */
  --font-sans: 'Noto Sans JP', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: 'Noto Serif JP', 'Noto Serif KR', Georgia, 'Times New Roman', serif;

  /* Font weights - limited to what we actually use */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Base size with user preference scaling */
  --base-font-size: calc(16px * var(--font-scale, 1));
}

/* Root font size for rem calculations */
html {
  font-size: var(--base-font-size);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ============================================ */
/*         CONSOLIDATED TYPOGRAPHY CLASSES      */
/* ============================================ */

/**
 * 1. BODY TEXT (Default)
 * Replaces: ios-body + text-secondary
 * Usage: 197 instances (most common)
 * Purpose: Standard body text, paragraphs, descriptions
 * SIZE: 13px at medium scale (main text)
 */
.body-text,
body {
  font-family: var(--font-sans);
  font-size: calc(0.8125rem * var(--depth-scale, 1)); /* 13px at 16px base */
  font-weight: var(--font-normal);
  line-height: 1.6;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

/* Allow color override while keeping typography */
.body-text.text-primary {
  color: var(--text-primary);
}

.body-text.text-tertiary {
  color: var(--text-tertiary);
}

/**
 * 2. FORM LABEL
 * Replaces: font-figtree + ios-subheadline + text-primary
 * Usage: 115 instances
 * Purpose: Form labels, input labels, field names
 * SIZE: 13px at medium scale (main text)
 */
.form-label {
  font-family: var(--font-sans);
  font-size: calc(0.8125rem * var(--depth-scale, 1)); /* 13px at 16px base */
  font-weight: var(--font-medium);
  line-height: 1.4;
  color: var(--text-primary);
  letter-spacing: 0.02em;
  display: block;
  margin-bottom: 0.25rem;
}

/**
 * 3. HEADING 1
 * Replaces: ios-title1 + text-primary
 * Usage: 57 instances
 * Purpose: Main page titles, hero headings
 * SIZE: 15px at medium scale (headline)
 */
.heading-1 {
  font-family: var(--font-serif);
  font-size: calc(0.9375rem * var(--depth-scale, 1)); /* 15px at 16px base */
  font-weight: var(--font-bold);
  line-height: 1.3;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  margin-top: 0;
  margin-bottom: 0.75rem;
}

/**
 * 4. HEADING 2
 * Replaces: ios-title2 + text-primary
 * Usage: 109 instances
 * Purpose: Section headings, card titles
 * SIZE: 15px at medium scale (headline)
 */
.heading-2 {
  font-family: var(--font-serif);
  font-size: calc(0.9375rem * var(--depth-scale, 1)); /* 15px at 16px base */
  font-weight: var(--font-semibold);
  line-height: 1.4;
  color: var(--text-primary);
  letter-spacing: -0.005em;
  margin-top: 0;
  margin-bottom: 0.5rem;
}

/**
 * 5. HEADING 3
 * Replaces: ios-title3 + text-primary
 * Usage: 37 instances
 * Purpose: Subsection headings, list titles
 * SIZE: 15px at medium scale (headline)
 */
.heading-3 {
  font-family: var(--font-serif);
  font-size: calc(0.9375rem * var(--depth-scale, 1)); /* 15px at 16px base */
  font-weight: var(--font-semibold);
  line-height: 1.4;
  color: var(--text-primary);
  letter-spacing: 0;
  margin-top: 0;
  margin-bottom: 0.5rem;
}

/**
 * 6. CAPTION
 * Replaces: ios-caption1 + text-secondary
 * Usage: 77 instances
 * Purpose: Small labels, button text, metadata
 * SIZE: 12px at medium scale (description)
 */
.caption {
  font-family: var(--font-sans);
  font-size: calc(0.75rem * var(--depth-scale, 1)); /* 12px at 16px base */
  font-weight: var(--font-normal);
  line-height: 1.5;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

/**
 * 7. HELPER TEXT
 * Replaces: ios-caption2 + text-tertiary
 * Usage: 48 instances
 * Purpose: Form hints, error messages, footnotes
 * SIZE: 12px at medium scale (description)
 */
.helper-text {
  font-family: var(--font-sans);
  font-size: calc(0.75rem * var(--depth-scale, 1)); /* 12px at 16px base */
  font-weight: var(--font-normal);
  line-height: 1.5;
  color: var(--text-tertiary);
  letter-spacing: 0.03em;
}

/* ============================================ */
/*              UTILITY MODIFIERS               */
/* ============================================ */

/* Font weight modifiers (simplified from 8 to 4) */
.font-400 { font-weight: 400; }
.font-500 { font-weight: 500; }
.font-600 { font-weight: 600; }
.font-700 { font-weight: 700; }

/* Text color overrides (only what's actually used) */
.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-tertiary { color: var(--text-tertiary) !important; }

/* Text alignment (keep minimal) */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Text transformation */
.uppercase { text-transform: uppercase; }
.lowercase { text-transform: lowercase; }
.capitalize { text-transform: capitalize; }

/* ============================================ */
/*         BACKWARDS COMPATIBILITY              */
/* ============================================ */
/* Map old classes to new ones for gradual migration */

.ios-body { @extend .body-text; }
.ios-title1 { @extend .heading-1; }
.ios-title2 { @extend .heading-2; }
.ios-title3 { @extend .heading-3; }
.ios-caption1 { @extend .caption; }
.ios-caption2 { @extend .helper-text; }
.ios-subheadline { @extend .form-label; }

/* Remove unused iOS classes */
.ios-large-title,
.ios-headline,
.ios-callout,
.ios-footnote {
  /* Deprecated - use semantic classes instead */
  display: none !important;
}

/* ============================================ */
/*              SPECIAL ELEMENTS                */
/* ============================================ */

/* Placeholders */
::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}

/* Selection */
::selection {
  background-color: var(--accent-color, #007AFF);
  color: white;
}

/* Links */
a {
  color: var(--link-color, var(--text-primary));
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--link-hover-color, var(--accent-color));
  text-decoration: underline;
}

/* Code blocks */
code, pre {
  font-family: var(--font-sans); /* Use Noto for consistency */
  font-size: 0.875em;
  background: var(--glass-primary);
  padding: 0.125em 0.25em;
  border-radius: 0.25em;
}

/* ============================================ */
/*         RESPONSIVE TYPOGRAPHY                */
/* ============================================ */

/* Mobile adjustments - maintain compact scale */
@media (max-width: 48em) { /* 768px */
  :root {
    --base-font-size: calc(16px * var(--font-scale, 1));
  }
  /* Compact scale maintained: no heading overrides needed */
}

/* Large screens - maintain compact scale */
@media (min-width: 75em) { /* 1200px */
  :root {
    --base-font-size: calc(16px * var(--font-scale, 1));
  }
  /* Compact scale maintained: 15px/13px/12px across all screens */
}

/* ============================================ */
/*              PRINT STYLES                    */
/* ============================================ */

@media print {
  body {
    font-size: 13pt;
    line-height: 1.5;
    color: black;
  }

  /* Compact scale for print: 15pt/13pt/12pt */
  .heading-1 { font-size: 15pt; }
  .heading-2 { font-size: 15pt; }
  .heading-3 { font-size: 15pt; }
  .body-text { font-size: 13pt; }
  .caption { font-size: 12pt; }
  .helper-text { font-size: 12pt; }
}

/**
 * USAGE EXAMPLES:
 *
 * <h1 class="heading-1">Main Page Title</h1>
 * <h2 class="heading-2">Section Title</h2>
 * <p class="body-text">Standard paragraph text...</p>
 * <label class="form-label">Email Address</label>
 * <span class="caption">Last updated: 2025</span>
 * <small class="helper-text">Enter valid email</small>
 *
 * COLOR OVERRIDES:
 * <p class="body-text text-primary">Primary colored body text</p>
 * <span class="caption text-tertiary">Tertiary caption</span>
 */