/* base — reset, typography, layout, buttons, forms */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
:root { color-scheme: light dark; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--ink);
  background: var(--background);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink); line-height: var(--leading-tight); letter-spacing: -0.02em; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
  background: var(--background);
}
.app.no-tabbar { padding-bottom: 0; }

.screen {
  animation: screen-in var(--duration-normal) var(--ease);
  padding: 0 var(--space-5);
}
@keyframes screen-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .screen { animation: none; }
  * { transition-duration: 0.01ms !important; }
}

/* Typography utilities */
.display { font-size: var(--text-4xl); font-weight: 800; line-height: var(--leading-tight); letter-spacing: -0.03em; }
.h1 { font-size: var(--text-2xl); font-weight: 800; margin-top: var(--space-3); letter-spacing: -0.02em; }
.h2 { font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.015em; }
.h3 { font-size: var(--text-lg); font-weight: 700; }
.body { font-size: var(--text-base); line-height: var(--leading-relaxed); }
.caption { font-size: var(--text-sm); color: var(--muted); line-height: var(--leading-normal); }
.overline { font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.muted { color: var(--muted); }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.stack > * + * { margin-top: var(--space-3); }
.stack-lg > * + * { margin-top: var(--space-5); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }
.mt-6 { margin-top: var(--space-6); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 52px;
  padding: 12px 24px;
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: var(--text-base);
  transition: transform var(--duration-fast) var(--ease), background-color var(--duration-fast) var(--ease), opacity var(--duration-fast), box-shadow var(--duration-fast) var(--ease);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .toggle:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(14, 107, 90, 0.2);
}
.btn-primary:hover {
  background: var(--primary-deep);
}
.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), inset 0 0 0 1px var(--line);
}
.btn-secondary:hover {
  background: var(--sand);
}
.btn-tint {
  background: var(--accent);
  color: var(--primary);
}
.btn-tint:hover {
  background: color-mix(in srgb, var(--accent) 80%, var(--primary) 20%);
}
.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: inset 0 0 0 1px var(--tint-red);
}
.btn-danger:hover {
  background: #fecaca;
}
.btn-ghost {
  background: transparent;
  color: var(--ink);
}
.btn-ghost:hover {
  background: var(--sand);
}
.btn-sm {
  min-height: 38px;
  padding: 8px 16px;
  font-size: var(--text-sm);
  border-radius: var(--radius-pill);
}
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.5; pointer-events: none; transform: none; }
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  padding: var(--space-2);
  font-size: var(--text-sm);
}
.link-btn:hover { text-decoration: underline; }

/* Forms */
.field { display: block; margin-top: var(--space-4); }
.field > span { display: block; font-size: var(--text-sm); font-weight: 600; color: var(--muted); margin-bottom: var(--space-2); }
.input, textarea.input, select.input {
  width: 100%;
  min-height: 50px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: var(--text-base);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast), background-color var(--duration-fast);
}
.input:focus, textarea.input:focus, select.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--tint-mint);
  outline: none;
}
.input::placeholder { color: var(--faint); }
textarea.input { resize: vertical; min-height: 100px; }
.field-error { color: var(--danger); font-size: var(--text-sm); margin-top: var(--space-2); font-weight: 500; }
.field-hint { color: var(--faint); font-size: var(--text-xs); margin-top: var(--space-1); }

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

/* Skip navigation — visually hidden until focused (WCAG 2.1 AA) */
.skip-nav {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: calc(var(--z-tooltip) + 1);
  padding: 12px 20px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 700;
  font-size: var(--text-base);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none;
  transition: top var(--duration-fast);
}
.skip-nav:focus {
  top: 0;
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}