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

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

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

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

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

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

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

ul,
ol {
  list-style: none;
}

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

blockquote,
q {
  quotes: none;
}

blockquote::before,
blockquote::after,
q::before,
q::after {
  content: "";
}

/* ===== DESIGN TOKENS ===== */
:root {
  /* Colors */
  --color-paper: #FDFCF7;
  --color-note: #FFF3CD;
  --color-ink: #3D3A3A;
  --color-sketch: #4EA8DE;
  --color-ink-soft: #5A5757;
  --color-paper-dark: #F2EFE6;

  /* Typography */
  --font-heading: 'Caveat', cursive;
  --font-body: 'Karla', sans-serif;

  --text-display: clamp(2rem, 5vw, 3rem);
  --text-h1: clamp(1.75rem, 4vw, 2.25rem);
  --text-h2: clamp(1.5rem, 3vw, 1.75rem);
  --text-h3: clamp(1.125rem, 2.5vw, 1.25rem);
  --text-body: 1rem;
  --text-small: 0.875rem;

  --leading-display: 1.2;
  --leading-h1: 1.3;
  --leading-h2: 1.3;
  --leading-h3: 1.4;
  --leading-body: 1.6;
  --leading-small: 1.5;

  --weight-heading: 700;
  --weight-body: 400;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 2rem;
  --space-xl: 3rem;
  --space-xxl: 4rem;

  /* Containers */
  --container-max: 1200px;
  --gutter-mobile: var(--space-md);
  --gutter-desktop: var(--space-lg);

  /* Surfaces */
  --surface-paper: var(--color-paper);
  --surface-note: var(--color-note);
  --surface-dark: var(--color-paper-dark);

  /* Borders */
  --border-thin: 1px solid rgba(61, 58, 58, 0.2);

  /* Shadows */
  --shadow-soft: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-lifted: 0 4px 8px rgba(0, 0, 0, 0.12);

  /* Corner scale */
  --radius-small: 4px;
  --radius-medium: 8px;
  --radius-large: 16px;

  /* Interaction */
  --transition-fast: 0.2s ease-in-out;
  --focus-ring: 2px solid var(--color-sketch);
  --focus-offset: 2px;

  /* Touch target */
  --touch-target-min: 44px;
}

/* ===== DOCUMENT TYPOGRAPHY ===== */
body {
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: var(--weight-body);
  line-height: var(--leading-body);
  color: var(--color-ink);
  background-color: var(--color-paper);
  overflow-wrap: break-word;
  word-wrap: break-word;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--font-heading);
  font-weight: var(--weight-heading);
  color: var(--color-ink);
  line-height: var(--leading-h1);
}

h1 {
  font-size: var(--text-h1);
  line-height: var(--leading-h1);
  margin-block-end: var(--space-md);
}

h2 {
  font-size: var(--text-h2);
  line-height: var(--leading-h2);
  margin-block-end: var(--space-md);
}

h3 {
  font-size: var(--text-h3);
  line-height: var(--leading-h3);
  margin-block-end: var(--space-sm);
}

h4,
h5,
h6 {
  font-size: var(--text-body);
  line-height: var(--leading-body);
  margin-block-end: var(--space-sm);
}

p {
  font-size: var(--text-body);
  line-height: var(--leading-body);
  margin-block-end: var(--space-md);
}

small,
.text-small {
  font-size: var(--text-small);
  line-height: var(--leading-small);
}

strong,
b {
  font-weight: 700;
}

em,
i {
  font-style: italic;
}

a {
  color: var(--color-sketch);
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color var(--transition-fast);
}

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

a:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: var(--radius-small);
}

blockquote {
  margin-block-end: var(--space-md);
  padding-inline-start: var(--space-md);
  border-inline-start: 3px solid var(--color-sketch);
  font-style: italic;
  color: var(--color-ink-soft);
}

ul,
ol {
  margin-block-end: var(--space-md);
  padding-inline-start: var(--space-lg);
}

ul {
  list-style: disc;
}

ol {
  list-style: decimal;
}

li {
  line-height: var(--leading-body);
}

/* Scoped list spacing for ordinary content lists */
.content-list li + li,
article li + li,
main /* Last-child safe handling */
h1:last-child,
h2:last-child,
h3:last-child,
h4:last-child,
h5:last-child,
h6:last-child,
p:last-child,
blockquote:last-child,
ul:last-child,
ol:last-child {
  margin-block-end: 0;
}

/* ===== MEDIA DEFAULTS ===== */
img,
video {
  max-width: 100%;
  height: auto;
  object-fit: cover;
}

figure {
  margin-block-end: var(--space-md);
}

figcaption {
  font-size: var(--text-small);
  line-height: var(--leading-small);
  color: var(--color-ink-soft);
  margin-block-start: var(--space-xs);
}

/* ===== FORM DEFAULTS ===== */
label {
  display: block;
  font-size: var(--text-small);
  line-height: var(--leading-small);
  color: var(--color-ink);
  margin-block-end: var(--space-xs);
}

input,
textarea,
select {
  width: 100%;
  min-height: var(--touch-target-min);
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-body);
  font-size: var(--text-body);
  line-height: var(--leading-body);
  color: var(--color-ink);
  background-color: var(--color-paper);
  border: var(--border-thin);
  border-radius: var(--radius-small);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-sketch);
  box-shadow: 0 0 0 2px rgba(78, 168, 222, 0.25);
}

input::placeholder,
textarea::placeholder {
  color: var(--color-ink-soft);
  opacity: 0.7;
}

textarea {
  resize: vertical;
  min-height: 100px;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%233D3A3A' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-md) center;
  padding-inline-end: var(--space-xl);
}

fieldset {
  border: var(--border-thin);
  border-radius: var(--radius-medium);
  padding: var(--space-md);
  margin-block-end: var(--space-md);
}

legend {
  font-family: var(--font-heading);
  font-size: var(--text-h3);
  line-height: var(--leading-h3);
  padding-inline: var(--space-sm);
}

/* ===== BUTTONS ===== */
button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target-min);
  padding: var(--space-sm) var(--space-lg);
  font-family: var(--font-body);
  font-size: var(--text-body);
  font-weight: 700;
  line-height: var(--leading-body);
  color: var(--color-paper);
  background-color: var(--color-sketch);
  border-radius: var(--radius-small);
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
  text-decoration: none;
}

button:hover,
.button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lifted);
  background-color: #3d8ec4;
}

button:active,
.button:active {
  transform: translateY(1px);
  box-shadow: var(--shadow-soft);
}

button:focus-visible,
.button:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

button:disabled,
.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ===== CONTAINERS ===== */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding-inline: var(--gutter-mobile);
}

@media (min-width: 768px) {
  .container {
    padding-inline: var(--gutter-desktop);
  }
}

.container-fluid {
  width: 100%;
  padding-inline: var(--gutter-mobile);
}

@media (min-width: 768px) {
  .container-fluid {
    padding-inline: var(--gutter-desktop);
  }
}

/* ===== SURFACES ===== */
.surface-paper {
  background-color: var(--surface-paper);
}

.surface-note {
  background-color: var(--surface-note);
  border: 1px solid rgba(61, 58, 58, 0.15);
}

.surface-dark {
  background-color: var(--surface-dark);
}

.card {
  background-color: var(--surface-paper);
  border: var(--border-thin);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-soft);
  padding: var(--space-md);
}

.card-note {
  background-color: var(--surface-note);
  border: 1px solid rgba(61, 58, 58, 0.15);
  border-radius: var(--radius-medium);
  box-shadow: var(--shadow-soft);
  padding: var(--space-md);
}

/* ===== FLEX UTILITIES ===== */
.flex {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
}

.flex > * {
  min-width: 0;
  flex-shrink: 1;
}

.flex-nowrap {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-md);
}

.flex-nowrap > * {
  min-width: 0;
  flex-shrink: 1;
}

.flex-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.flex-column > * {
  min-width: 0;
  flex-shrink: 1;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
}

.flex-center > * {
  min-width: 0;
  flex-shrink: 1;
}

.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.flex-between > * {
  min-width: 0;
  flex-shrink: 1;
}

/* ===== SELF-CONTAINED GRID ===== */
.grid-auto {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.grid-auto > * {
  min-width: 0;
}

.grid-2 {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: 1fr;
}

.grid-2 > * {
  min-width: 0;
}

@media (min-width: 768px) {
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

.grid-3 {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: 1fr;
}

.grid-3 > * {
  min-width: 0;
}

@media (min-width: 768px) {
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.grid-4 {
  display: grid;
  gap: var(--space-md);
  grid-template-columns: 1fr;
}

.grid-4 > * {
  min-width: 0;
}

@media (min-width: 768px) {
  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ===== IMAGE TREATMENT ===== */
.img-polaroid {
  border: 4px solid var(--color-paper);
  box-shadow: var(--shadow-lifted);
  border-radius: var(--radius-small);
  object-fit: cover;
}

.img-ratio-4-3 {
  aspect-ratio: 4 / 3;
  object-fit: cover;
  width: 100%;
}

.img-ratio-16-9 {
  aspect-ratio: 16 / 9;
  object-fit: cover;
  width: 100%;
}

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

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  z-index: 10000;
  background-color: var(--color-sketch);
  color: var(--color-paper);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-small);
  transition: top var(--transition-fast);
}

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

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