/* ============================================================
   TALKBACK — CSS RESET
   ============================================================
   File: css/reset.css
   Purpose: Normalize browser defaults. Establish consistent
            baseline for all elements. Improve accessibility
            defaults. Optimize for mobile-first.
   
   Load order: This file must load BEFORE all other CSS files
   except variables.css.
   
   Load sequence:
   1. variables.css
   2. reset.css      ← THIS FILE
   3. components.css
   4. layout.css
   5. app.css
   ============================================================ */


/* ============================================================
   1. BOX MODEL
   ============================================================ */

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}


/* ============================================================
   2. ROOT & HTML
   ============================================================ */

html {
  /* Prevent font size inflation on mobile */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  /* Smooth scrolling for anchor links */
  scroll-behavior: smooth;

  /* Prevent horizontal overflow */
  overflow-x: hidden;

  /* Better tab size */
  tab-size: 4;
  -moz-tab-size: 4;

  /* Consistent line height */
  line-height: 1.5;

  /* Prevent iOS tap highlight */
  -webkit-tap-highlight-color: transparent;
}


/* ============================================================
   3. BODY
   ============================================================ */

body {
  font-family: var(--font-primary);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;

  /* Transition for theme switching */
  transition: background-color var(--duration-normal) var(--ease-default),
              color var(--duration-normal) var(--ease-default);
}


/* ============================================================
   4. TYPOGRAPHY
   ============================================================ */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
  overflow-wrap: break-word;
  word-break: break-word;
}

h1 {
  font-size: var(--text-4xl);
  letter-spacing: var(--tracking-tight);
}

h2 {
  font-size: var(--text-3xl);
  letter-spacing: var(--tracking-snug);
}

h3 {
  font-size: var(--text-2xl);
}

h4 {
  font-size: var(--text-xl);
}

h5 {
  font-size: var(--text-lg);
}

h6 {
  font-size: var(--text-md);
}

p {
  overflow-wrap: break-word;
  word-break: break-word;
}

strong, b {
  font-weight: var(--weight-semibold);
}

em, i {
  font-style: italic;
}

small {
  font-size: var(--text-sm);
}

/* Prevent sub and sup from affecting line height */
sub, sup {
  font-size: 75%;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

sub {
  bottom: -0.25em;
}

sup {
  top: -0.5em;
}


/* ============================================================
   5. LINKS
   ============================================================ */

a {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-default),
              opacity var(--duration-fast) var(--ease-default);
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}


/* ============================================================
   6. LISTS
   ============================================================ */

ul, ol {
  list-style: none;
}

/* Restore list style when role is not explicitly set */
ul[role="list"],
ol[role="list"] {
  list-style: none;
}


/* ============================================================
   7. IMAGES & MEDIA
   ============================================================ */

img, svg, video, canvas, audio, iframe, embed, object {
  display: block;
}

img, video {
  max-width: 100%;
  height: auto;
}

img {
  /* Remove border in older browsers */
  border-style: none;

  /* Prevent image dragging */
  -webkit-user-drag: none;
  user-select: none;
}

svg {
  /* SVGs should not overflow their container */
  overflow: hidden;
}


/* ============================================================
   8. FORMS — BUTTONS
   ============================================================ */

button {
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  line-height: inherit;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Prevent button text selection on rapid clicks */
button {
  user-select: none;
  -webkit-user-select: none;
}

/* Remove default button styles in iOS */
button,
[type="button"],
[type="reset"],
[type="submit"] {
  -webkit-appearance: none;
  appearance: none;
}

/* Clickable labels */
label {
  cursor: pointer;
}


/* ============================================================
   9. FORMS — INPUTS
   ============================================================ */

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  line-height: inherit;
  border: none;
  background: none;
  appearance: none;
  -webkit-appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-radius: var(--radius-md);
}

/* Remove inner spin button 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;
}

/* Remove clear button from search inputs */
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

/* Consistent textarea behavior */
textarea {
  resize: vertical;
  overflow: auto;
}

/* Placeholder styling */
::placeholder {
  color: var(--input-placeholder);
  opacity: 1;
}

::-webkit-input-placeholder {
  color: var(--input-placeholder);
}

::-moz-placeholder {
  color: var(--input-placeholder);
  opacity: 1;
}

/* Autofill styling — prevent browser yellow/white background */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-primary);
  -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset;
  box-shadow: 0 0 0 1000px var(--input-bg) inset;
  transition: background-color 5000s ease-in-out 0s;
}

/* Disabled state */
input:disabled,
textarea:disabled,
select:disabled,
button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}


/* ============================================================
   10. TABLES
   ============================================================ */

table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  text-indent: 0;
}

th {
  text-align: left;
  font-weight: var(--weight-semibold);
}


/* ============================================================
   11. HORIZONTAL RULE
   ============================================================ */

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-6) 0;
  height: 0;
  color: inherit;
}


/* ============================================================
   12. CODE & PREFORMATTED
   ============================================================ */

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

pre {
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

code {
  padding: 2px 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-xs);
}

pre code {
  padding: 0;
  background: none;
  border-radius: 0;
}


/* ============================================================
   13. SELECTION
   ============================================================ */

::selection {
  background: var(--accent-soft);
  color: var(--text-primary);
}

::-moz-selection {
  background: var(--accent-soft);
  color: var(--text-primary);
}


/* ============================================================
   14. SCROLLBAR STYLING
   ============================================================ */

/* Webkit scrollbars (Chrome, Safari, Edge, Samsung Internet) */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* Firefox scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}


/* ============================================================
   15. FOCUS MANAGEMENT
   ============================================================ */

/* Remove default focus outlines — we use :focus-visible instead */
:focus {
  outline: none;
}

/* Visible focus only for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  padding: var(--space-3) var(--space-6);
  background: var(--accent);
  color: var(--text-on-accent);
  border-radius: var(--radius-md);
  font-weight: var(--weight-semibold);
  z-index: var(--z-max);
  transition: top var(--duration-fast) var(--ease-default);
}

.skip-link:focus {
  top: var(--space-4);
}


/* ============================================================
   16. ACCESSIBILITY UTILITIES
   ============================================================ */

/* Visually hidden but accessible to screen readers */
.sr-only,
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Make sure visually hidden elements that are focusable
   become visible when focused */
.sr-only:focus,
.visually-hidden:focus {
  position: static;
  width: auto;
  height: auto;
  padding: var(--space-2) var(--space-4);
  margin: 0;
  overflow: visible;
  clip: auto;
  clip-path: none;
  white-space: normal;
}


/* ============================================================
   17. DIALOG / DETAILS
   ============================================================ */

dialog {
  padding: 0;
  border: none;
  background: transparent;
}

details summary {
  cursor: pointer;
  list-style: none;
}

details summary::-webkit-details-marker {
  display: none;
}

summary::marker {
  display: none;
  content: '';
}


/* ============================================================
   18. TOUCH BEHAVIOR
   ============================================================ */

/* Improve touch scrolling performance */
.scroll-container {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Prevent pull-to-refresh on app screens */
.app-container {
  overscroll-behavior-y: contain;
}

/* Prevent text selection on interactive elements */
.no-select {
  user-select: none;
  -webkit-user-select: none;
}

/* Prevent callout on long press (iOS) */
.no-callout {
  -webkit-touch-callout: none;
}


/* ============================================================
   19. PRINT RESET
   ============================================================ */

@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  img {
    page-break-inside: avoid;
  }

  p, h2, h3 {
    orphans: 3;
    widows: 3;
  }

  h2, h3 {
    page-break-after: avoid;
  }
}


/* ============================================================
   20. REDUCED MOTION
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}