/* Low-Poly Horse — layout and UI chrome. The 3D scene fills the viewport; the
   panels float over it as warm, nearly opaque cards: secondary text keeps a
   contrast of at least 7:1 even over the brightest parts of the scene. */

:root {
  --panel-bg: rgba(26, 20, 15, 0.9);
  --panel-border: rgba(255, 236, 214, 0.16);
  --panel-shadow: 0 12px 32px rgba(48, 28, 10, 0.28);
  --text: #fbf4ec;
  --muted: #d9d0c5;
  --accent: #ffb25b;
  --accent-ink: #2b1a0b;
  --radius: 14px;
  --gutter: 16px;
  --safe-top: max(var(--gutter), env(safe-area-inset-top));
  --safe-right: max(var(--gutter), env(safe-area-inset-right));
  --safe-bottom: max(var(--gutter), env(safe-area-inset-bottom));
  --safe-left: max(var(--gutter), env(safe-area-inset-left));
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #f2d9b6; /* matches the horizon while the scene loads */
  color: var(--text);
}

#stage {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
  cursor: grab;
}

#stage:active {
  cursor: grabbing;
}

/* ------------------------------------------------------------------ panels */

.panel {
  position: fixed;
  z-index: 2;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  -webkit-backdrop-filter: blur(14px) saturate(1.25);
  backdrop-filter: blur(14px) saturate(1.25);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.ui-hidden .panel {
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
}

.title-card {
  top: var(--safe-top);
  left: var(--safe-left);
  padding: 12px 16px 11px;
}

.title-card h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.title-card p {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

.hint {
  top: var(--safe-top);
  right: var(--safe-right);
  margin: 0;
  padding: 9px 12px;
  max-width: min(460px, 50vw);
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

.controls {
  left: var(--safe-left);
  bottom: var(--safe-bottom);
  width: 300px;
  padding: 14px;
  display: grid;
  gap: 14px;
}

.gait-card {
  right: var(--safe-right);
  bottom: var(--safe-bottom);
  width: 330px;
  padding: 12px 14px 10px;
}

/* ------------------------------------------------------------------ fields */

.field {
  display: grid;
  gap: 7px;
}

.field-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-label output {
  font-family: var(--mono);
  letter-spacing: 0;
  color: var(--text);
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  margin-left: 2px;
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.13);
  font: 600 10px/1.5 var(--mono);
  text-align: center;
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
}

.segmented button {
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.segmented button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.segmented button[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.segmented button[aria-checked="true"] kbd {
  background: rgba(43, 26, 11, 0.16);
}

input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  padding: 8px 6px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.button:hover {
  background: rgba(255, 255, 255, 0.13);
}

.button[data-action="orbit"][aria-pressed="true"] {
  border-color: var(--accent);
  background: rgba(255, 178, 91, 0.2);
}

/* --------------------------------------------------------------- gait card */

.gait-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.gait-heading strong {
  font-size: 15px;
}

.gait-heading span {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.footfall {
  display: block;
  width: 100%;
  height: 92px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 10px;
  margin: 8px 0 0;
}

.stats div {
  min-width: 0;
}

.stats dt {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--muted);
}

.stats dd {
  margin: 2px 0 0;
  font: 600 12px/1.3 var(--mono);
  white-space: nowrap;
}

/* --------------------------------------------------------- loader & errors */

.loader {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: linear-gradient(#5d8fd0, #f2d9b6 72%);
  color: #2a1d12;
  font-weight: 600;
  transition: opacity 0.45s ease, visibility 0s linear 0.45s;
}

.loader p {
  margin: 0;
}

.loader-shoe {
  width: 46px;
  height: 52px;
  border: 9px solid #2a1d12;
  border-bottom-color: transparent;
  border-radius: 50% 50% 46% 46%;
  animation: shoe 1.1s ease-in-out infinite;
}

@keyframes shoe {
  50% {
    transform: translateY(-8px) rotate(-8deg);
  }
}

.is-ready .loader,
.has-fatal .loader {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.fatal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: rgba(36, 26, 18, 0.55);
}

.fatal[hidden] {
  display: none;
}

.fatal-box {
  max-width: 460px;
  padding: 22px 24px;
  border-radius: var(--radius);
  background: #2d2219;
  box-shadow: var(--panel-shadow);
  line-height: 1.55;
}

.fatal-box h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.fatal-box p {
  margin: 8px 0;
  color: var(--muted);
}

.fatal-box pre {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  overflow-x: auto;
}

.fatal-box code {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
}

.fatal-box a {
  color: var(--accent);
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 860px) {
  .hint {
    display: none;
  }
}

@media (max-width: 720px) {
  :root {
    --gutter: 10px;
  }

  .title-card {
    padding: 8px 12px;
  }

  .title-card h1 {
    font-size: 15px;
  }

  .title-card p {
    display: none;
  }

  .gait-card {
    top: var(--safe-top);
    bottom: auto;
    left: auto;
    width: min(330px, calc(100vw - 2 * var(--gutter) - 150px));
    min-width: 200px;
    padding: 8px 10px;
  }

  .gait-card .stats,
  .gait-heading span {
    display: none;
  }

  .footfall {
    height: 76px;
  }

  .controls {
    right: var(--safe-right);
    width: auto;
    padding: 10px;
    gap: 10px;
  }

  .buttons {
    grid-template-columns: repeat(3, 1fr);
  }

  kbd {
    display: none;
  }
}

@media (hover: none) {
  kbd {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loader-shoe {
    animation: none;
  }

  .panel,
  .loader {
    transition: none;
  }
}
