/* InsightRPG Base Styles
   ======================
   Reset, typography, and foundational element styles.
   Editorial-voice-dominant: Newsreader headings, Source Sans 3 body,
   monospace for structured data.
*/

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

/* --- Document --- */
html {
  font-size: 100%;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  hanging-punctuation: first last;
}

body {
  font-family: var(--font-clear);
  font-size: var(--text-base);
  font-weight: 400;
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--surface-0);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-variant-ligatures: common-ligatures;
}

::selection {
  background-color: var(--accent-lighter);
  color: var(--text-primary);
}

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

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  text-wrap: balance;
}

h1 {
  font-family: var(--font-editorial);
  font-size: clamp(var(--text-3xl), 5vw, var(--text-5xl));
  font-weight: 300;
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  margin-top: var(--rhythm-section);
  margin-bottom: var(--rhythm-subsection);
}

h2 {
  font-family: var(--font-editorial);
  font-size: var(--text-2xl);
  font-weight: 400;
  line-height: var(--leading-snug);
  margin-top: var(--rhythm-subsection);
  margin-bottom: var(--rhythm-paragraph);
  padding-left: var(--space-4);
  border-left: 2px solid var(--text-tertiary);
}

h3 {
  font-family: var(--font-editorial);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: var(--leading-snug);
  margin-top: var(--rhythm-block);
  margin-bottom: var(--rhythm-paragraph);
}

h4 {
  font-family: var(--font-editorial);
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: var(--leading-snug);
  margin-top: var(--rhythm-block);
  margin-bottom: var(--space-2);
}

h5, h6 {
  font-family: var(--font-clear);
  font-size: var(--text-base);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-top: var(--rhythm-block);
  margin-bottom: var(--space-2);
}

p {
  margin-bottom: var(--rhythm-paragraph);
  max-width: var(--content-width);
}

p:last-child {
  margin-bottom: 0;
}

strong, b {
  font-weight: 700;
}

em, i {
  font-style: italic;
}

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

abbr[title] {
  text-decoration: underline dotted;
  text-decoration-color: var(--text-tertiary);
  cursor: help;
}

/* Flavour text / in-character quotes */
blockquote {
  border-left: 3px solid var(--accent);
  padding-left: var(--space-6);
  margin: var(--rhythm-block) 0;
  font-family: var(--font-editorial);
  font-style: italic;
  font-weight: 400;
  color: var(--text-secondary);
  max-width: var(--content-width);
}

/* --- Links --- */
a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
  text-decoration-color: rgba(180, 83, 9, 0.35);
  transition: color var(--duration-fast) var(--ease-out),
              text-decoration-color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--color-primary-dark);
  text-decoration-color: var(--color-primary-dark);
}

a:active {
  color: var(--brand-teal);
}

[data-theme="dark"] a {
  text-decoration-color: rgba(212, 120, 10, 0.35);
}

/* --- Lists --- */
ul, ol {
  margin-bottom: var(--rhythm-paragraph);
  padding-left: var(--space-8);
  max-width: var(--content-width);
}

ul ul, ul ol, ol ul, ol ol {
  margin-top: var(--space-2);
  margin-bottom: var(--space-2);
}

li {
  margin-bottom: var(--space-2);
  padding-left: var(--space-1);
}

li::marker {
  color: var(--text-tertiary);
}

li:last-child {
  margin-bottom: 0;
}

dt {
  font-weight: 700;
  margin-top: var(--rhythm-paragraph);
}

dd {
  margin-left: 0;
  margin-bottom: var(--space-2);
  padding-left: var(--space-6);
}

/* --- Horizontal Rule --- */
hr {
  border: none;
  height: 2px;
  background: var(--surface-2);
  margin: var(--rhythm-subsection) 0;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--rhythm-block) 0;
  font-family: var(--font-clear);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

caption {
  font-family: var(--font-clear);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  text-align: left;
  padding-bottom: var(--space-3);
  font-style: italic;
}

thead {
  border-bottom: 2px solid var(--text-primary);
}

th {
  text-align: left;
  font-weight: 600;
  padding: var(--space-2) var(--space-3);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}

td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--surface-2);
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background-color: var(--surface-1);
}

tbody tr:hover {
  background-color: var(--surface-2);
}

td[rowspan] {
  vertical-align: top;
  font-weight: 600;
  border-right: 1px solid var(--surface-2);
}

/* --- Code (monospace for character sheets, stat blocks) --- */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--surface-1);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--surface-2);
}

pre {
  background: var(--surface-1);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--rhythm-block);
  border: 1px solid var(--surface-2);
}

pre code {
  background: none;
  padding: 0;
  border: none;
  font-size: var(--text-sm);
}

/* --- Media --- */
img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-md);
}

figure {
  margin: var(--rhythm-block) 0;
}

figcaption {
  font-family: var(--font-clear);
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-top: var(--space-2);
  font-style: italic;
}

/* --- Labels / Captions (Source Sans 3, 500, uppercase) --- */
.label {
  font-family: var(--font-clear);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wider);
  color: var(--text-tertiary);
}

/* --- Utility Classes --- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

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

.text-center {
  text-align: center;
}

.text-mono {
  font-family: var(--font-mono);
}

.no-print {
  /* Used in print.css */
}

/* --- Scroll-triggered entrance animations --- */
.fade-in-on-scroll {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.fade-in-on-scroll.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- 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;
  }
}
