/* ==========================================================================
   Base: reset, document defaults, typography, forms, accessibility, motion.
   ========================================================================== */

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + var(--space-6));
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  letter-spacing: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body.is-locked {
  overflow: hidden;
}

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

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

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

svg {
  flex-shrink: 0;
}

/* Icon defaults. Symbols carry no presentation attributes; the inheritable
   paint and geometry properties come from here, so sizing is all components
   need to override. */
.icon {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------- typography */
/* Two weights only (400 and 500), tight tracking on headings. */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text);
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.25rem, 5vw, 4rem);
}

h2 {
  font-size: clamp(1.5rem, 3vw, 2.25rem);
}

h3 {
  font-size: 1.125rem;
  line-height: var(--leading-snug);
  letter-spacing: -0.02em;
}

h4 {
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
  letter-spacing: -0.015em;
}

p {
  text-wrap: pretty;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

strong,
b {
  font-weight: var(--weight-medium);
  color: var(--text);
}

/* Components that are anchors keep their own affordance: an underline on a
   button, card or chip reads as a link, not a control. */
.btn:hover,
.btn:focus,
.chip:hover,
.chip:focus,
.site-nav__link:hover,
.brand:hover,
.mobile-menu__link:hover,
.tool-card__link:hover,
.category-card__link:hover,
.pagination__link:hover,
.search-result:hover,
.quick-match:hover,
.section__link:hover,
.tool-card__open:hover {
  text-decoration: none;
}

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

code,
kbd,
samp,
pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

code {
  padding: 0.15em 0.35em;
  background: var(--surface);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}

hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-8) 0;
}

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

/* ------------------------------------------------------------------ focus */
/* One ring, used everywhere. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: none;
  border-radius: var(--radius-sm);
  box-shadow: var(--focus-ring);
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: var(--z-toast);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-weight: var(--weight-medium);
  transition: top var(--duration-base) var(--ease-out);
}

.skip-link:focus {
  top: var(--space-4);
}

/* ------------------------------------------------------- accessibility aid */
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------- controls */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field__label {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  color: var(--text-muted);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.field__error {
  font-size: var(--text-sm);
  color: var(--danger-text);
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--text-muted);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.field--error .input,
.field--error .textarea,
.field--error .select {
  border-color: var(--danger);
}

.textarea {
  resize: vertical;
  min-height: 140px;
  line-height: var(--leading-relaxed);
}

.select {
  appearance: none;
  padding-right: 2.25rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235F6B63' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 16px;
  cursor: pointer;
}

/* Checkbox and radio keep a native feel but inherit the accent colour. */
input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
}

/* ------------------------------------------------------------------ prose */
.prose {
  max-width: var(--container-prose);
  color: var(--text-2);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
}

.prose > * + * {
  margin-top: var(--space-5);
}

.prose h2 {
  font-size: var(--text-2xl);
  color: var(--text);
  margin-top: var(--space-12);
  scroll-margin-top: calc(var(--header-height) + var(--space-6));
}

.prose h3 {
  font-size: var(--text-xl);
  color: var(--text);
  margin-top: var(--space-10);
  scroll-margin-top: calc(var(--header-height) + var(--space-6));
}

.prose h2 + *,
.prose h3 + * {
  margin-top: var(--space-3);
}

.prose strong {
  color: var(--text);
}

.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 3px;
}

.prose a:hover {
  text-decoration-color: var(--accent);
}

.prose ul,
.prose ol {
  padding-left: 1.4rem;
  display: grid;
  gap: var(--space-2);
}

.prose li::marker {
  color: var(--text-4);
}

.prose blockquote {
  padding: var(--space-4) var(--space-5);
  border-left: 1px solid var(--accent);
  background: var(--surface);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--text);
  font-size: var(--text-lg);
}

.prose img {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

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

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse-soft {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.animate-rise {
  animation: rise-in var(--duration-slow) var(--ease-out) both;
}

.animate-fade {
  animation: fade-in var(--duration-base) var(--ease-out) both;
}
