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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--text-body) / 1.5 var(--font-body);
  overflow-x: hidden;
}

h1, h2, h3, p { margin: 0; }

h1 { font-size: var(--text-title); font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-size: var(--text-heading); font-weight: 700; line-height: 1.3; }

a { color: var(--action); }

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

button { cursor: pointer; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-control); }

img, svg { max-width: 100%; }

#outlet {
  min-height: 100dvh;
  padding: calc(var(--safe-top) + var(--space-5)) var(--gutter) calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-5));
}

body[data-bar="off"] #outlet { padding-bottom: calc(var(--safe-bottom) + var(--space-5)); }

#outlet:focus, #outlet:focus-visible { outline: none; box-shadow: none; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding: 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-control);
  background: var(--action);
  color: var(--on-action);
  font-weight: 600;
  text-decoration: none;
}

.button:active { background: var(--action-pressed); }

.button--quiet { background: var(--wash); color: var(--ink); }

.button--danger { background: var(--danger); }

.button[disabled] { opacity: 0.5; cursor: default; pointer-events: none; }

.back-link { display: inline-flex; align-items: center; gap: var(--space-1); min-height: var(--tap-target); margin-left: -6px; color: var(--ink-2); font-size: var(--text-small); font-weight: 600; text-decoration: none; }

.field { display: grid; gap: var(--space-1); }

.field__label { font-size: var(--text-small); font-weight: 600; color: var(--ink-2); }

.field__input {
  width: 100%;
  min-height: var(--tap-target);
  padding: 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--paper);
}

textarea.field__input { padding: var(--space-3); min-height: 96px; }

.field__input[aria-invalid="true"] { border-color: var(--danger); }

.field__hint { font-size: var(--text-small); color: var(--ink-3); }

.field__error { font-size: var(--text-small); color: var(--danger); }

.failure { display: grid; gap: var(--space-2); padding-top: var(--space-6); }

.failure p { color: var(--ink-3); }

.status-page { display: grid; gap: var(--space-2); padding: var(--space-6) var(--gutter); }

.status-page p { color: var(--ink-3); }

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  height: calc(var(--tabbar-height) + var(--safe-bottom));
  padding: 0 var(--space-2) var(--safe-bottom);
  border-top: 1px solid var(--line);
  background: var(--paper);
}

body[data-bar="off"] .tabbar { display: none; }

.tabbar__item {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: var(--space-2) 0;
  color: var(--ink-3);
  font-size: var(--text-micro);
  font-weight: 600;
  text-decoration: none;
}

.tabbar__item[aria-current="page"] { color: var(--action); }

.tabbar__item svg { width: 24px; height: 24px; }

.tabbar__new {
  display: grid;
  place-items: center;
  justify-self: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--action);
  color: var(--on-action);
}

.tabbar__new svg { width: 26px; height: 26px; }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0 var(--gutter) calc(var(--space-5) + var(--safe-bottom));
  border: 0;
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--lift-sheet);
  overflow-y: auto;
}

.sheet::backdrop { background: rgba(10, 27, 51, 0.45); }

.sheet__grab { display: flex; justify-content: center; padding: var(--space-3) 0; touch-action: none; }

.sheet__grab::before { content: ""; width: 40px; height: 4px; border-radius: 2px; background: var(--line); }

.sheet__close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
}

.toast {
  position: fixed;
  inset: auto var(--gutter) calc(var(--tabbar-height) + var(--safe-bottom) + var(--space-3));
  width: auto;
  height: auto;
  border: 0;
  overflow: visible;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-control);
  background: var(--ink);
  color: var(--paper);
  font-size: var(--text-small);
  box-shadow: var(--lift);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast:not(:popover-open) { display: none; }

.toast.is-visible { opacity: 1; transform: none; pointer-events: auto; }

.toast--error { background: var(--danger); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

@media (min-width: 760px) {
  #outlet { max-width: 720px; margin: 0 auto; }
}
