/* Element defaults, app chrome and layout primitives. Components live in components.css. */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--text-md);
  font-weight: 400;
  font-stretch: 100%;
  line-height: 1.5;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.15;
  text-wrap: balance;
}

h1 {
  font-size: var(--text-2xl);
  font-stretch: var(--wide);
  font-weight: 760;
  letter-spacing: -0.015em;
}

h2 {
  font-size: var(--text-xl);
  font-stretch: 108%;
  font-weight: 700;
  letter-spacing: -0.01em;
}

h3 {
  font-size: var(--text-lg);
  font-weight: 650;
}

h4 {
  font-size: var(--text-md);
  font-weight: 650;
}

p {
  margin: 0;
  max-width: 68ch;
  text-wrap: pretty;
}

a {
  color: inherit;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.18em;
}

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

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

button {
  cursor: pointer;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

legend {
  padding: 0;
}

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

ul,
ol {
  margin: 0;
  padding: 0;
}

dl,
dd {
  margin: 0;
}

table {
  border-collapse: collapse;
  width: 100%;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

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

[hidden] {
  display: none !important;
}

.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;
}

.skip-link {
  position: absolute;
  left: var(--s3);
  top: -100px;
  z-index: 100;
  padding: var(--s2) var(--s4);
  background: var(--ink);
  color: var(--on-ink);
  border-radius: var(--r-control);
}

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

/* ---------- App chrome ---------- */

.app {
  min-height: 100dvh;
}

.screen {
  max-width: var(--content);
  margin: 0 auto;
  padding: var(--s4) var(--gutter) calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + var(--s10));
  outline: none;
}

.screen.no-tabs {
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--s10));
}

/* Bottom tab bar on phones; becomes the top bar from 900px. */
.tabbar {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding: 0 var(--s2) env(safe-area-inset-bottom, 0px);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.tabbar-brand {
  display: none;
}

.tab {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  color: var(--ink-muted);
  text-decoration: none;
  font-size: var(--text-xs);
  font-weight: 560;
  font-stretch: 90%;
}

.tab .icon {
  width: 24px;
  height: 24px;
}

.tab[aria-current="page"] {
  color: var(--ink);
  font-weight: 700;
}

.tab[aria-current="page"] .icon {
  stroke-width: 2.25;
}

.tab-add {
  flex: 0 0 auto;
  align-self: center;
  width: 52px;
  height: 52px;
  margin: 0 var(--s2);
  border-radius: 50%;
  background: var(--ink);
  color: var(--on-ink);
  box-shadow: var(--shadow-lift);
  transform: translateY(-10px);
}

.tab-add .icon {
  width: 26px;
  height: 26px;
  stroke-width: 2.25;
}

.tab-add .tab-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

body.hide-tabs .tabbar {
  display: none;
}

@media (min-width: 900px) {
  .screen {
    padding: calc(var(--topbar-h) + var(--s6)) var(--s8) var(--s14);
  }

  .screen.no-tabs {
    padding-top: var(--s6);
  }

  .tabbar {
    top: 0;
    bottom: auto;
    height: var(--topbar-h);
    padding: 0 max(var(--s8), calc((100vw - var(--content)) / 2 + var(--s8)));
    justify-content: flex-start;
    gap: var(--s2);
    border-top: 0;
    border-bottom: 1px solid var(--line);
  }

  .tabbar-brand {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-right: var(--s6);
    color: var(--ink);
    text-decoration: none;
    font-size: var(--text-lg);
    font-weight: 800;
    font-stretch: var(--extra-wide);
    letter-spacing: -0.02em;
  }

  .tab {
    flex: 0 0 auto;
    flex-direction: row;
    gap: var(--s2);
    padding: 0 var(--s3);
    font-size: var(--text-sm);
    font-stretch: 100%;
    border-bottom: 2px solid transparent;
  }

  .tab .icon {
    width: 18px;
    height: 18px;
  }

  .tab[aria-current="page"] {
    border-bottom-color: var(--ink);
  }

  .tab-add {
    order: 9;
    margin-left: auto;
    width: auto;
    height: 40px;
    padding: 0 var(--s4);
    border-radius: var(--r-control);
    border-bottom: 0;
    box-shadow: none;
    transform: none;
    color: var(--on-ink);
  }

  .tab-add .icon {
    width: 18px;
    height: 18px;
  }

  .tab-add .tab-text {
    position: static;
    width: auto;
    height: auto;
    clip: auto;
    font-weight: 650;
  }
}

.offline-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  gap: var(--s2);
  align-items: center;
  padding: var(--s2) var(--gutter);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--text-sm);
  font-weight: 560;
}

@media (min-width: 900px) {
  .offline-banner {
    top: var(--topbar-h);
  }
}

/* ---------- Layout primitives ---------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap, var(--s4));
}

.stack-xs { --gap: var(--s1); }
.stack-sm { --gap: var(--s2); }
.stack-md { --gap: var(--s3); }
.stack-lg { --gap: var(--s6); }
.stack-xl { --gap: var(--s10); }

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap, var(--s2));
}

.row {
  display: flex;
  align-items: center;
  gap: var(--gap, var(--s3));
  min-width: 0;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s3);
  min-width: 0;
}

.grow {
  flex: 1 1 auto;
  min-width: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s3);
}

.split {
  display: grid;
  gap: var(--s6);
}

@media (min-width: 900px) {
  .split {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: var(--s10);
    align-items: start;
  }

  .split-sticky > :first-child {
    position: sticky;
    top: calc(var(--topbar-h) + var(--s6));
  }
}

.section {
  padding-top: var(--s8);
}

.muted {
  color: var(--ink-muted);
}

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

.xsmall {
  font-size: var(--text-xs);
}

.code {
  font-stretch: var(--condensed);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.num {
  font-variant-numeric: tabular-nums;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Horizontal scrollers scroll inside themselves so the page never scrolls sideways. */
.scroller {
  display: flex;
  gap: var(--s2);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  margin: 0 calc(var(--gutter) * -1);
  padding: 2px var(--gutter);
}

.scroller::-webkit-scrollbar {
  display: none;
}

.scroller > * {
  flex: 0 0 auto;
  scroll-snap-align: start;
}

@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;
  }
}
