/* Design rules for this app, all of them serving one small person:
     - every control is at least 64px tall, thumb-sized, and separated
     - one idea per row; the label under each icon never changes meaning
     - the selected state is shown by shape AND colour AND text, never colour alone
     - nothing animates unless it has to, and nothing is allowed to flash
     - type is large, heavy, and set in the system font so it is always crisp   */

:root {
  --ink: #17252c;
  --ink-soft: #46586a;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-sunk: #eef1f2;
  --line: rgba(23, 37, 44, 0.12);
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --focus: #0a66c2;
  --radius: 22px;
  --dock-gap: 10px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;                 /* kills iPad pull-to-refresh */
  background: #dfe9ee;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
  /* A small child explores by pressing and holding. Without this, iPad Safari
     answers that with a Save Image / Copy popup over the scene, and there is no
     obvious way back for someone who did not mean to do it. */
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;                        /* OrbitControls owns the gestures */
}

/* ---- start-up states ---------------------------------------------------- */

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: #dfe9ee;
  transition: opacity 0.4s ease;
}
.loading[hidden] { display: none; }
.loading.gone { opacity: 0; pointer-events: none; }
.loading-mark { font-size: 68px; line-height: 1; }
.loading-text { font-size: 20px; font-weight: 600; color: var(--ink-soft); margin: 0; }

.boot-error {
  position: fixed;
  inset: auto 16px calc(24px + var(--safe-b)) 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  font-size: 17px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
}
.boot-error-detail { color: var(--ink-soft); font-size: 15px; overflow-wrap: anywhere; }

/* ---- the dock ----------------------------------------------------------- */

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 12px calc(12px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: var(--dock-gap);
  pointer-events: none;
}

.dock-row {
  display: flex;
  gap: var(--dock-gap);
  justify-content: center;
  pointer-events: auto;
  flex-wrap: nowrap;
}

/* touch-action does not inherit: every interactive element has to opt in or it
   silently keeps the browser's double-tap-zoom behaviour. */
button, input, select, textarea, label {
  touch-action: manipulation;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  min-height: 74px;
  min-width: 74px;
  padding: 9px 14px;
  flex: 1 1 0;
  max-width: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  box-shadow: 0 6px 18px rgba(12, 30, 40, 0.12);
  cursor: pointer;
  /* touch-action does NOT inherit, so the body-level rule below never reached
     the buttons. Left at `auto`, iPad Safari waits out its double-tap-zoom
     delay on every press and a happy double-tap zooms the whole page. */
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

.btn-icon {
  font-size: 30px;
  line-height: 1;
  filter: saturate(0.85);
}
.btn-label { white-space: nowrap; }

.btn[aria-pressed='true'] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: 0 8px 22px rgba(31, 111, 92, 0.32);
}
.btn[aria-pressed='true'] .btn-icon { filter: none; }

/* Selected gait also gets a marker, so the state survives a colour-blind check. */
.btn[aria-pressed='true'] .btn-label::after {
  content: '';
  display: block;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.85;
  margin-top: 3px;
}

.btn--wide { max-width: 168px; }

/* ---- settings sheet ----------------------------------------------------- */

.sheet {
  position: fixed;
  inset: 0;
  background: #f4f6f7;
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.sheet[hidden] { display: none; }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 18px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.sheet-head h1 { font-size: 26px; margin: 0; font-weight: 800; }
.sheet-body { overflow-y: auto; padding: 18px 18px calc(28px + var(--safe-b)); -webkit-overflow-scrolling: touch; }

.row {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px 18px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 74px;
}
.row-text { flex: 1; min-width: 0; }
.row-title { font-size: 19px; font-weight: 700; }
.row-sub { font-size: 14px; color: var(--ink-soft); margin-top: 3px; }

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 42%;
  min-width: 130px;
  height: 40px;
  background: transparent;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 12px;
  border-radius: 6px;
  background: var(--surface-sunk);
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  margin-top: -11px;
}
input[type='range']::-moz-range-thumb {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); border: 3px solid #fff;
}
input[type='range']:focus-visible { outline: 4px solid var(--focus); outline-offset: 2px; border-radius: 12px; }

.toggle {
  appearance: none;
  border: none;
  width: 82px;
  height: 46px;
  border-radius: 23px;
  background: #c9d1d4;
  position: relative;
  cursor: pointer;
  flex: none;
  transition: background 0.18s ease;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 4px; left: 4px;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.28);
  transition: transform 0.18s ease;
}
.toggle[aria-checked='true'] { background: var(--accent); }
.toggle[aria-checked='true']::after { transform: translateX(36px); }
.toggle:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }
.toggle-label { font-size: 17px; font-weight: 700; width: 34px; text-align: center; }

.btn-reset {
  width: 100%;
  min-height: 76px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: #fff;
  font: inherit;
  font-size: 19px;
  font-weight: 800;
  color: var(--ink);
  margin-top: 10px;
  cursor: pointer;
}
.btn-reset:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

/* ---- install hint ------------------------------------------------------- */

.install-hint {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.14);
  z-index: 15;
}
.install-hint p { margin: 0; font-size: 15px; flex: 1; }
.share-glyph { font-size: 18px; }
#install-dismiss {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  border-radius: 14px;
  min-width: 72px;
  min-height: 48px;
  cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .btn:active { transform: none; }
}

@media (max-width: 560px) {
  .btn { min-width: 62px; padding: 8px 6px; font-size: 13px; }
  .btn-icon { font-size: 26px; }
}
