/* ==========================================================================
   CODEFORGE — CSS RESET
   --------------------------------------------------------------------------
   Modern normalization layer. Removes browser defaults so component styles
   behave predictably. No visual opinions — just consistency.
   Depends on: css/tokens.css (loaded before this file in index.html)
   ========================================================================== */

/* ======================================================================
   1. BOX MODEL
   ====================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ======================================================================
   2. DOCUMENT
   ====================================================================== */

html {
  /* Prevent font-size inflation on mobile */
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;

  /* Smooth scrolling — only when user hasn't opted out */
  scroll-behavior: smooth;

  /* Default tab size for code blocks */
  tab-size: 2;

  /* Prevent iOS tap highlight */
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport height for mobile browsers */

  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  font-weight: var(--fw-regular);
  color: var(--text-primary);
  background-color: var(--bg-app);

  /* Improve font rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;

  /* Prevent horizontal overflow */
  overflow-x: hidden;
  overflow-y: auto;
}

/* ======================================================================
   3. SECTIONS & GROUPING
   ====================================================================== */

main {
  display: block; /* IE11 fallback — harmless in modern browsers */
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
}

p {
  margin: 0;
}

ol, ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

dl {
  margin: 0;
}

dd {
  margin: 0;
}

blockquote, figure {
  margin: 0;
}

hr {
  margin: 0;
  border: none;
  border-top: var(--border-width) solid var(--border-subtle);
  color: inherit;
}

pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: inherit;
}

/* ======================================================================
   4. TEXT-LEVEL SEMANTICS
   ====================================================================== */

a {
  color: var(--text-link);
  text-decoration: none;
  text-underline-offset: 2px;
}

a:hover {
  text-decoration: underline;
}

b, strong {
  font-weight: var(--fw-semibold);
}

small {
  font-size: var(--fs-xs);
}

sub, sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

sub { bottom: -0.25em; }
sup { top: -0.5em; }

abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

mark {
  background-color: var(--bg-selection);
  color: var(--text-primary);
  padding: 0.1em 0.2em;
  border-radius: var(--radius-xs);
}

/* ======================================================================
   5. EMBEDDED CONTENT
   ====================================================================== */

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

img, video {
  height: auto;
}

iframe {
  border: 0;
}

/* ======================================================================
   6. FORMS
   ====================================================================== */

/*
 * Remove default styling from form controls.
 * We re-style everything in components.css.
 */

button,
input,
optgroup,
select,
textarea {
  font: inherit;               /* Inherit font from body */
  color: inherit;              /* Inherit text color */
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  outline: none;
}

button,
[type="button"],
[type="reset"],
[type="submit"] {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

button:disabled,
[type="button"]:disabled,
[type="reset"]:disabled,
[type="submit"]:disabled {
  cursor: not-allowed;
  opacity: var(--opacity-disabled);
}

input {
  -webkit-appearance: none;
  appearance: none;
}

/* Fix iOS date input styling */
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"] {
  -webkit-appearance: none;
}

/* Remove spin buttons from number inputs */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

/* Search input normalization */
input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
}

input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
}

textarea {
  resize: vertical;
  overflow: auto;
}

/* Placeholder styling */
::placeholder {
  color: var(--text-tertiary);
  opacity: 1; /* Firefox */
}

/* Fieldset */
fieldset {
  margin: 0;
  padding: 0;
  border: none;
  min-width: 0;
}

legend {
  padding: 0;
  display: table;
  max-width: 100%;
  white-space: normal;
}

/* ======================================================================
   7. INTERACTIVE
   ====================================================================== */

summary {
  display: list-item;
  cursor: pointer;
}

details > summary::-webkit-details-marker {
  display: none;
}

dialog {
  padding: 0;
  border: none;
  background: none;
  color: inherit;
}

dialog::backdrop {
  background: var(--bg-overlay);
}

/* ======================================================================
   8. TABLES
   ====================================================================== */

table {
  border-collapse: collapse;
  border-spacing: 0;
  text-indent: 0;
}

th {
  font-weight: var(--fw-semibold);
  text-align: left;
}

/* ======================================================================
   9. ACCESSIBILITY
   ====================================================================== */

/*
 * Remove default focus outline.
 * Components MUST provide their own focus styles using --focus-ring.
 * We use :focus-visible to only show focus for keyboard navigation.
 */
:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/*
 * Visually hidden but accessible to screen readers.
 * Use class="sr-only" on elements.
 */
.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;
}

/* Allow sr-only elements to become visible when focused (skip links) */
.sr-only--focusable:focus,
.sr-only--focusable:focus-visible {
  position: static;
  width: auto;
  height: auto;
  padding: var(--space-2) var(--space-4);
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Reduced motion: disable all animations and transitions */
@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;
  }
}

/* ======================================================================
   10. SELECTION
   ====================================================================== */

::selection {
  background-color: var(--bg-selection);
  color: var(--text-primary);
}

/* ======================================================================
   11. SCROLLBARS
   ====================================================================== */

/* WebKit (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: var(--scrollbar-size);
  height: var(--scrollbar-size);
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
  background-clip: padding-box;
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* ======================================================================
   12. MISC
   ====================================================================== */

/* Prevent images from being draggable (optional, but cleaner for UI apps) */
img {
  -webkit-user-drag: none;
  user-select: none;
}

/* Prevent text selection on UI chrome (buttons, labels, icons) */
.no-select {
  -webkit-user-select: none;
  user-select: none;
}

/* Ensure hidden attribute works even with display overrides */
[hidden] {
  display: none !important;
}