/* ==========================================================================
   Global reset, iPad touch hardening, the app shell, and the shared
   primitives (button, icon button, panel, field, empty state, icon).
   Screen-specific styles live in their own files.
   ========================================================================== */

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

html, body {
  margin: 0;
  height: 100%;
  /* The game is a fixed stage, not a scrolling page: no rubber-banding,
     no pull-to-refresh. js/ui/touchGuards.js backs this up for older iOS. */
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-sky-top);
  /* Touch hardening for small hands:
     - manipulation: kills double-tap-to-zoom (and its 300ms tap delay)
     - user-select / touch-callout: a long press on a button shouldn't
       select text or pop up the iOS "Copy / Look up" menu
     - tap-highlight: we draw our own pressed state */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

input, select, textarea { -webkit-user-select: auto; user-select: auto; }
img { display: block; max-width: 100%; }
button, select { font: inherit; color: inherit; }
h1, h2, h3, p, figure, ol, ul, dl, dd { margin: 0; }
ol, ul { padding: 0; list-style: none; }

/* `hidden` must win over any display rule a component sets. */
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}

/* ---------- App shell ---------------------------------------------------- */

.app {
  position: fixed;
  top: var(--app-top, 0px);
  left: var(--app-left, 0px);
  /* The measured window size, refreshed after every rotation by
     js/ui/viewportFit.js (iOS can leave a stale size behind). */
  width: var(--app-width, 100%);
  height: var(--app-height, 100%);
  /* Sky fading to two rolling hills along the bottom. Pure CSS so there is
     no background image to swap or load. */
  background:
    radial-gradient(120% 60% at 15% 115%, var(--color-grass) 49.5%, transparent 50%),
    radial-gradient(120% 55% at 90% 120%, var(--color-grass-dark) 49.5%, transparent 50%),
    linear-gradient(var(--color-sky-top), var(--color-sky-bottom) 70%);
}

/* Every screen fills the shell; safe-area insets keep content clear of the
   status bar and home indicator in full-screen home-screen mode. */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding:
    max(var(--space-3), env(safe-area-inset-top))
    max(var(--space-4), env(safe-area-inset-right))
    max(var(--space-3), env(safe-area-inset-bottom))
    max(var(--space-4), env(safe-area-inset-left));
}

.top-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--tap-min);
  flex-shrink: 0;
}

/* Each scroll surface owns its gestures; the page itself stays fixed. */
[data-scrollable] {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scroll-padding: var(--space-3);
}

.top-bar__spacer { flex: 1; }

/* Middle slot (the team meter on the gate screen). */
.top-bar__center {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.boot-message {
  position: fixed;
  inset: auto var(--space-4) var(--space-4);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-warning-soft);
  color: var(--color-warning);
  font-weight: 700;
  z-index: 300;
}

.boot-message__detail {
  display: block;
  margin-block: var(--space-2) var(--space-3);
  font-weight: 400;
  font-size: 0.9em;
  overflow-wrap: anywhere;
}

/* ---------- Icon ---------------------------------------------------------- */
/* Inline SVG from js/ui/icons.js: 24×24, stroke-only, currentColor. */

.icon {
  width: 1.2em;
  height: 1.2em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Button --------------------------------------------------------- */
/* Chunky, with a solid "ledge" shadow that collapses when pressed so a tap
   feels physical. Hover is deliberately not used for anything: on an iPad it
   sticks after a tap. */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-small);
  padding: var(--space-3) var(--space-5);
  border: 0;
  border-radius: var(--radius-pill);
  font-weight: 800;
  font-size: var(--font-size-base);
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.btn:active:not(:disabled) { transform: translateY(4px); }

.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn--primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: 0 6px 0 var(--color-primary-dark);
}
.btn--primary:active:not(:disabled) { box-shadow: 0 2px 0 var(--color-primary-dark); }

.btn--secondary {
  background: var(--color-primary-soft);
  color: var(--color-primary-text);
  box-shadow: 0 4px 0 var(--color-dot-soft);
}
.btn--secondary:active:not(:disabled) { box-shadow: 0 1px 0 var(--color-dot-soft); }

.btn--ghost {
  background: var(--color-surface);
  color: var(--color-text);
  border: 2px solid var(--color-border-strong);
  box-shadow: 0 4px 0 var(--color-border);
}
.btn--ghost:active:not(:disabled) { box-shadow: 0 1px 0 var(--color-border); }

.btn--danger {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  box-shadow: 0 4px 0 var(--color-border);
}

.btn--large {
  min-height: var(--tap-min);
  padding-inline: var(--space-6);
  font-size: var(--font-size-md);
}

.btn--huge {
  min-height: 96px;
  padding-inline: var(--space-7);
  font-size: var(--font-size-lg);
}

/* ---------- Icon button ------------------------------------------------- */

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap-min);
  height: var(--tap-min);
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--color-surface);
  color: var(--color-primary-text);
  box-shadow: 0 5px 0 var(--color-border-strong);
  font-size: 1.6rem;
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.icon-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--color-border-strong); }

.icon-btn--small {
  width: var(--tap-small);
  height: var(--tap-small);
  font-size: 1.3rem;
}

/* Pressed = sound off. Shown with a different icon *and* a muted look,
   not by colour alone. */
.icon-btn[aria-pressed="false"] {
  background: var(--color-surface-tint);
  color: var(--color-text-muted);
}

@media (max-width: 600px), (max-height: 500px) {
  .btn--huge { min-height: 64px; }
  .icon-btn { font-size: 1.3rem; box-shadow: 0 4px 0 var(--color-border-strong); }
  .icon-btn--small { font-size: 1.15rem; }
  .screen {
    padding:
      max(var(--space-2), env(safe-area-inset-top))
      max(var(--space-3), env(safe-area-inset-right))
      max(var(--space-2), env(safe-area-inset-bottom))
      max(var(--space-3), env(safe-area-inset-left));
  }
}

/* ---------- Panel ---------------------------------------------------------- */

/* Shared by the login, title and map screens, including the public gate. */
.rainbow-stripe {
  flex: none;
  align-self: stretch;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--rainbow);
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
}

.panel__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.panel__title { font-size: var(--font-size-md); font-weight: 800; }

.panel__desc {
  max-width: 60ch;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

/* ---------- Empty state / note ------------------------------------------ */

.empty-state {
  padding: var(--space-4);
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  text-align: center;
}
.empty-state--note { text-align: left; font-size: var(--font-size-sm); }

/* ---------- Field ---------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field__caption {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-weight: 700;
}

.field__control {
  min-width: 0;
  max-width: 100%;
  min-height: var(--tap-small);
  padding: 0 var(--space-3);
  border: 2px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  /* Keep Safari from zooming the whole app when a phone field is focused. */
  font-size: max(16px, var(--font-size-sm));
}
