/* ========================================================================
   TrinetraWatch — Base Stylesheet
   Reset · Design Tokens · Typography · Dark Mode · Print
   ======================================================================== */

/* ========================================================================
   1. Modern CSS Reset
   ======================================================================== */

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

html {
  font-size: 100%;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  tab-size: 4;
}

body {
  min-height: 100vh;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

a {
  text-decoration: none;
  color: inherit;
}

ul,
ol {
  list-style: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
  text-wrap: balance;
}

p {
  overflow-wrap: break-word;
  text-wrap: pretty;
}

/* ========================================================================
   2. Design Tokens — Custom Properties
   ======================================================================== */

:root {
  /* ── Brand ─────────────────────────────────────────────────────────── */
  --color-primary:       #0B1F3A;
  --color-accent:        #C1272D;
  --color-accent-hover:  #9E1F24;

  /* ── Backgrounds ──────────────────────────────────────────────────── */
  --color-bg:            #FFFFFF;
  --color-surface:       #F6F6F7;
  --color-surface-alt:   #EDEEF0;

  /* ── Text ─────────────────────────────────────────────────────────── */
  --color-text-primary:   #191A1C;
  --color-text-secondary: #3A3B3E; /* Darkened for better contrast */
  --color-text-muted:     #5A5B60; /* Darkened for better contrast */

  /* ── UI ───────────────────────────────────────────────────────────── */
  --color-border:       #DCDDE0;
  --color-link:         #0B1F3A;
  --color-link-hover:   #C1272D;
  --color-tag-bg:       #EEF1F6;

  /* ── Dark-mode palette (referenced in dark mode swap) ─────────── */
  --color-bg-dark:       #0E0F10;
  --color-surface-dark:  #1A1B1E;
  --color-text-dark:     #E4E5E9;
  --color-border-dark:   #2C2D31;

  /* ── Font Families ────────────────────────────────────────────────── */
  --font-display: 'Playfair Display', serif;
  --font-heading: 'Playfair Display', serif;
  --font-body:    'Inter', sans-serif;
  --font-ui:      'Inter', sans-serif;

  /* ── Type Scale ───────────────────────────────────────────────────── */
  --text-xs:   0.75rem;    /* 12px */
  --text-sm:   0.875rem;   /* 14px */
  --text-base: 1rem;       /* 16px */
  --text-md:   1.125rem;   /* 18px */
  --text-lg:   1.25rem;    /* 20px */
  --text-xl:   1.5rem;     /* 24px */
  --text-2xl:  1.875rem;   /* 30px */
  --text-3xl:  2.25rem;    /* 36px */
  --text-4xl:  3rem;       /* 48px */
  --text-5xl:  4rem;       /* 64px */

  /* ── Spacing (8 px base) ──────────────────────────────────────────── */
  --space-1:   4px;
  --space-2:   8px;
  --space-3:   12px;
  --space-4:   16px;
  --space-6:   24px;
  --space-8:   32px;
  --space-12:  48px;
  --space-16:  64px;
  --space-24:  96px;
  --space-32:  128px;

  /* ── Border Radius ────────────────────────────────────────────────── */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 9999px;

  /* ── Shadows ──────────────────────────────────────────────────────── */
  --shadow-sm:  0 1px  2px  rgba(0, 0, 0, 0.05);
  --shadow-md:  0 4px  6px  rgba(0, 0, 0, 0.07),
                0 2px  4px  rgba(0, 0, 0, 0.05);
  --shadow-lg:  0 10px 24px rgba(0, 0, 0, 0.10),
                0  4px  8px rgba(0, 0, 0, 0.06);
  --shadow-xl:  0 20px 48px rgba(0, 0, 0, 0.14),
                0  8px 16px rgba(0, 0, 0, 0.08);

  /* ── Transitions ──────────────────────────────────────────────────── */
  --transition-fast: 150ms ease;
  --transition-base: 300ms ease;
  --transition-slow: 500ms ease;

  /* ── Z-Index Scale ────────────────────────────────────────────────── */
  --z-header:  100;
  --z-overlay: 200;
  --z-modal:   300;
  --z-tooltip: 400;
}

/* ========================================================================
   3. Dark Mode
   ======================================================================== */

/* Manual toggle via data attribute */
[data-theme='dark'] {
  --color-bg:             #0E0F10;
  --color-surface:        #1A1B1E;
  --color-surface-alt:    #222326;
  --color-text-primary:   #E4E5E9;
  --color-text-secondary: #D0D1D5; /* Lightened for better contrast */
  --color-text-muted:     #A0A1A5; /* Lightened for better contrast */
  --color-border:         #2C2D31;
  --color-link:           #8AB4F8;
  --color-link-hover:     #C1272D;
  --color-tag-bg:         #2A2B2F;
}

/* System preference auto-detect (only if user hasn't explicitly set theme) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --color-bg:             #0E0F10;
    --color-surface:        #1A1B1E;
    --color-surface-alt:    #222326;
    --color-text-primary:   #E4E5E9;
    --color-text-secondary: #D0D1D5;
    --color-text-muted:     #A0A1A5;
    --color-border:         #2C2D31;
    --color-link:           #8AB4F8;
    --color-link-hover:     #C1272D;
    --color-tag-bg:         #2A2B2F;
  }
}

/* ========================================================================
   4. Base Typography
   ======================================================================== */

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.6;
  font-weight: 500;
  color: var(--color-text-primary);
  background-color: var(--color-bg);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.2;
  color: var(--color-text-primary);
  margin-bottom: var(--space-4);
}

h1 { font-size: var(--text-5xl); }
h2 { font-size: var(--text-4xl); }
h3 { font-size: var(--text-3xl); }
h4 { font-size: var(--text-2xl); }
h5 { font-size: var(--text-xl);  }
h6 { font-size: var(--text-lg);  }

p {
  margin-bottom: var(--space-4);
  max-width: 72ch;
}

a {
  color: var(--color-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-link-hover);
}

.post-meta a, .post-category-links a {
  color: inherit;
}

strong,
b {
  font-weight: 700;
}

small {
  font-size: var(--text-sm);
}

blockquote {
  border-left: 4px solid var(--color-accent);
  padding-left: var(--space-6);
  margin: var(--space-6) 0;
  font-style: italic;
  color: var(--color-text-secondary);
}

hr {
  border: none;
  height: 1px;
  background: var(--color-border);
  margin: var(--space-8) 0;
}

/* ========================================================================
   5. Focus & Selection
   ======================================================================== */

*:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

::selection {
  background: var(--color-accent);
  color: #fff;
}

/* ========================================================================
   6. Reduced Motion
   ======================================================================== */

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

/* ========================================================================
   7. Print Styles
   ======================================================================== */

@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  body {
    font-size: 12pt;
    line-height: 1.5;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]::after {
    content: ' (' attr(href) ')';
    font-size: 0.8em;
    font-weight: normal;
  }

  a[href^='#']::after,
  a[href^='javascript']::after {
    content: '';
  }

  .site-header,
  .site-footer,
  .ticker,
  .mobile-nav,
  .search-overlay,
  .ad-zone,
  nav {
    display: none !important;
  }

  img {
    max-width: 100% !important;
    page-break-inside: avoid;
  }

  h2, h3 {
    page-break-after: avoid;
  }

  p {
    orphans: 3;
    widows: 3;
  }
}
