/* Base layout, reset and phone hardening. */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  background: var(--wall);
}

body {
  font-family: var(--font-body);
  font-size: var(--fs-m);
  line-height: var(--lh);
  color: var(--ink);
  background-color: var(--wall);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12'%3E%3Crect width='3' height='3' fill='%23E3E3F6'/%3E%3C/svg%3E");
  background-size: 12px 12px;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: none;
  text-rendering: optimizeSpeed;
}

input, textarea, [contenteditable="true"], .selectable {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { touch-action: manipulation; }
img, svg, canvas { display: block; }
p { margin: 0 0 0.6em; }
p:last-child { margin-bottom: 0; }
h1, h2, h3 { margin: 0; font-weight: 400; }

svg.sprite {
  shape-rendering: crispEdges;
  image-rendering: pixelated;
  flex: none;
}

canvas { image-rendering: pixelated; }

/* The OS frame fills the visible viewport (dvh tracks the iOS toolbars). */
.os {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.stage {
  position: relative;
  z-index: var(--z-stage);
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: manipulation; /* no double-tap zoom inside the scroll container (iOS) */
  outline: none;
}

.screen {
  min-height: 100%;
  padding: 16px var(--gutter) calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.os.has-nav .screen {
  padding-bottom: calc(var(--nav-h) + 32px + env(safe-area-inset-bottom));
}

.screen.is-in { animation: screen-in var(--t-med) steps(4) both; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

:focus-visible {
  outline: 3px dashed var(--ink);
  outline-offset: 3px;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

[hidden] { display: none !important; }

.muted { color: var(--ink-soft); }
.ui { font-family: var(--font-ui); text-transform: uppercase; letter-spacing: 0; }
.center { text-align: center; }

.noscript {
  position: fixed;
  inset: 20px;
  font-size: 20px;
}

/* Custom pixel cursors on devices with a real mouse (set from JS as --cursor-arrow / --cursor-hand). */
@media (hover: hover) and (pointer: fine) {
  html.has-cursors body { cursor: var(--cursor-arrow) 1 1, default; }
  html.has-cursors :is(button, a, [role="button"], label, select, .tap) { cursor: var(--cursor-hand) 11 1, pointer; }
  html.has-cursors :is(input[type="text"], textarea) { cursor: text; }
  html.has-cursors.is-busy body, html.has-cursors.is-busy * { cursor: var(--cursor-wait) 5 7, progress; }
}

/* Reduced motion: honour the OS setting (and ?reduced for tests).
   Transitions are switched off, not shortened: with a duration on every element, every inline size change
   (a canvas getting its size) becomes a transition, and a measurement right after it reads the old size. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
}
html.reduced-motion *, html.reduced-motion *::before, html.reduced-motion *::after {
  animation-duration: 1ms !important;
  animation-iteration-count: 1 !important;
  transition: none !important;
}

/* Scrollbars in the guide's style on desktops (phones use overlay scrollbars). */
.stage, .tos-scroll { scrollbar-width: thin; scrollbar-color: var(--lav) var(--shade); }
.stage::-webkit-scrollbar, .tos-scroll::-webkit-scrollbar { width: 12px; }
.stage::-webkit-scrollbar-track, .tos-scroll::-webkit-scrollbar-track { background: var(--shade); }
.stage::-webkit-scrollbar-thumb, .tos-scroll::-webkit-scrollbar-thumb { background: var(--lav); border: 3px solid var(--ink); }

/* Just after a screen change: no taps on the screen, the nav or Henk (see shieldInput in main.js). */
.os.is-arriving :is(.stage, .nav-layer, .henk-layer),
.os.is-arriving :is(.stage, .nav-layer, .henk-layer) * { pointer-events: none !important; }

/* ?dev: outline every tap area. */
html.dev-outline :is(button, a, [role="button"], input, label, .tap) {
  outline: 2px solid var(--red) !important;
  outline-offset: 0 !important;
}
