* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* Many components below set their own `display` (flex/grid/block) so they
   render correctly when shown. Without this rule, a class like
   `.modal-backdrop { display: flex }` - an author-stylesheet rule - beats
   the browser's built-in `[hidden] { display: none }` at equal specificity,
   so toggling the `hidden` attribute/property stops working the moment an
   element also has a display rule. This makes `hidden` always win. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  max-width: 100%;
  overflow-x: clip;
}

/* scrollbar stability - the window scrollbar is always present
   (overflow-y: scroll) so it can never appear/disappear and shift the layout;
   the map page fills the viewport itself and is exempt. scrollbar-gutter keeps
   the track reserved where supported. overflow-x uses clip so it never turns
   the root into a scroll container that defeats all of the above. */
html {
  -webkit-text-size-adjust: 100%;
  color-scheme: dark;
  overflow-y: scroll;
  scrollbar-gutter: stable;
}
html:has(body[data-page="map"]) {
  overflow-y: auto;
  scrollbar-gutter: auto;
}

a {
  text-decoration: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* fixed grain overlay - breaks the flat-vector AI look.
   Both decorative layers sit at negative z-indexes and .app-shell no longer
   creates a stacking context: page-level overlays (dropdown menus z200,
   the map drawer z400, ...) must be able to outrank the fixed bottom tab bar
   (z100), which lives in the root context as a direct child of <body>. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background: radial-gradient(ellipse 900px 500px at 12% -10%, rgba(122, 99, 201, 0.1), transparent 60%), radial-gradient(ellipse 700px 500px at 100% 10%, rgba(122, 99, 201, 0.06), transparent 55%);
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}

p {
  margin: 0;
}

a {
  color: inherit;
}

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

button {
  cursor: pointer;
}

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

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

:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
  outline-offset: -2px;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
  background-clip: content-box;
}
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

/* Touch devices: drop the scrollbar chrome entirely. Horizontal strips (tab
   bars, filter rows, stat chips, ...) stay swipe-scrollable but no longer draw
   a bar that eats a slice of the strip and can swallow taps along its edge;
   vertical regions keep scrolling natively too. Desktop keeps the styled
   themed scrollbars above. */
@media (hover: none), (pointer: coarse) {
  * {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  *::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
  }
}

.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: fixed;
  top: -100px;
  left: var(--space-4);
  z-index: var(--z-modal);
  background: var(--accent);
  color: #0c0810;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus {
  top: var(--space-4);
}

.app-shell {
  position: relative;
  /* No z-index here on purpose: a stacking context on the shell would trap
     every page-level dropdown/drawer below the fixed bottom tab bar (which is
     a body child in the root context). Decorative body::before/::after layers
     moved to negative z-indexes instead. */
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.page-main {
  flex: 1;
  min-height: 0;
}

/* page container used by content (non-map) pages */
.page-container {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) calc(var(--space-8) + var(--bottom-nav-h) + var(--safe-b));
}

@media (min-width: 861px) {
  .page-container {
    padding: var(--space-8) var(--space-6) var(--space-8);
  }
}

.page-head {
  margin-bottom: var(--space-6);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.page-head h1 {
  font-size: var(--fs-2xl);
}

.page-head p {
  color: var(--text-muted);
  margin-top: var(--space-1);
  font-size: var(--fs-sm);
}

.tabular {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}

/* Cross-document page fade (native View Transitions, enabled per-page via
   <meta name="view-transition" content="same-origin">). No-op feature-wise
   on browsers without support; disabled for reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 220ms;
    animation-timing-function: ease-out;
  }
}
@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
  }
}

/* Touch ergonomics: on coarse pointers the small icon/inline controls get a
   comfortable thumb target. min-width/min-height always beat the component's
   own width/height, so sub-30px overrides elsewhere grow without !important. */
@media (hover: none), (pointer: coarse) {
  .icon-btn,
  .modal-close,
  .modal-tab,
  .btn-sm,
  .password-toggle,
  .log-entry-jump-btn,
  .log-entry-details-toggle,
  .log-detail-restore-btn,
  .leaderboard-card-head .icon-btn,
  .users-actions .icon-btn,
  .category-item-actions .icon-btn,
  .whitelist-row .icon-btn,
  .ac-code-cell .icon-btn,
  .ac-copy,
  .server-copy,
  .tps-range-btn,
  .waypoint-gallery-delete,
  .waypoint-gallery-star,
  .waypoint-gallery-caption-edit,
  .waypoint-collab-remove,
  .stat-picker-option,
  .category-filter-option,
  .category-picker-option {
    min-width: 40px;
    min-height: 40px;
  }
  .icon-btn--xs {
    min-width: 32px;
    min-height: 32px;
  }
  /* the toggle label *is* the control (the input inside is 0x0) */
  .switch {
    padding: 9px 0;
  }
  .tabs .tab {
    min-height: 44px;
  }
}

/* One global reduced-motion net: individual components already opt out in a
   few places, but transitions and looping decorations were missed. */
@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;
  }
}
