/* SPINE — Spatial Position Intuitive Native Elements
   App/game layout. Body is always viewport-centered; H/T are equal mirrors. */

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

:root {
  --spine-vw: 100vw;
  --spine-vh: 100vh;
  --spine-side: min(var(--spine-vw), var(--spine-vh));
  --spine-edge: 0px;
  --spine-ink: #d7dde8;
  --spine-muted: #8b95a8;
  --spine-line: #888;
  --spine-head: #141820;
  --spine-body: #1a1f2a;
  --spine-tail: #141820;
  --spine-stage: #12151c;
  --spine-label: #f0d27a;
  --spine-ghost: #3a4254;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background: var(--spine-stage);
  color: var(--spine-ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  position: relative;
  min-height: 100%;
}

/* ---- Regions: body is always the viewport center (C) ---- */

ux-head,
ux-body,
ux-tail {
  position: fixed;
  display: grid;
  margin: 0;
  padding: 0;
  min-width: min-content;
  min-height: min-content;
  overflow: visible;
  background: var(--spine-head);
}

/* Same centering in both orientations so wide↔tall does not jump. */
ux-body {
  background: var(--spine-body);
  left: 50%;
  top: 50%;
  width: var(--spine-side);
  height: var(--spine-side);
  transform: translate(-50%, -50%);
}

ux-tail {
  background: var(--spine-tail);
}

/* Wide: equal left/right mirrors. Span never 0. */
html[data-spine-orient="wide"] ux-head {
  top: 0;
  left: 0;
  width: var(--spine-edge);
  height: 100vh;
}

html[data-spine-orient="wide"] ux-tail {
  top: 0;
  right: 0;
  width: var(--spine-edge);
  height: 100vh;
}

/* Tall: equal top/bottom mirrors. Span never 0. */
html[data-spine-orient="tall"] ux-head {
  top: 0;
  left: 0;
  width: 100vw;
  height: var(--spine-edge);
}

html[data-spine-orient="tall"] ux-tail {
  bottom: 0;
  left: 0;
  width: 100vw;
  height: var(--spine-edge);
}

ux-head[data-pack="list"],
ux-body[data-pack="list"],
ux-tail[data-pack="list"] {
  display: block;
}

/* ---- Cells: intrinsic min size, never clip ---- */

ux {
  display: block;
  position: relative;
  min-width: min-content;
  min-height: min-content;
  overflow: visible;
  padding: 0.4em 0.55em;
  border: 1px solid #888;
}

ux:not([data-box]) {
  display: grid;
  place-items: center;
}

ux[data-box] {
  display: grid;
  overflow: visible;
}

ux[data-spine-ghost] {
  pointer-events: none;
  background: transparent;
  color: transparent;
  padding: 0;
  min-width: 0;
  min-height: 0;
}

/* ---- ux-list: tight pack (column when wide, row when tall) ---- */

ux-list {
  display: flex;
  width: 100%;
  height: 100%;
  min-width: min-content;
  min-height: min-content;
  margin: 0;
  padding: 0;
  gap: 0;
  overflow: visible;
}

html[data-spine-orient="wide"] ux-list {
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
}

html[data-spine-orient="tall"] ux-list {
  flex-direction: row;
  justify-content: flex-start;
  align-items: stretch;
}

html[data-spine-orient="wide"] ux-list > ux {
  flex: 0 0 auto;
  width: 100%;
  height: auto;
  min-width: min-content;
  min-height: min-content;
}

html[data-spine-orient="tall"] ux-list > ux {
  flex: 0 0 auto;
  height: 100%;
  width: auto;
  min-width: min-content;
  min-height: min-content;
}

ux[square],
ux[tall],
ux[wide] {
  place-self: center;
}

html[data-spine-debug] ux[data-path]::after {
  content: attr(data-path);
  position: absolute;
  top: 3px;
  left: 4px;
  z-index: 4;
  padding: 1px 4px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--spine-stage) 72%, transparent);
  color: var(--spine-label);
  font: 600 10px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  pointer-events: none;
  user-select: none;
}

html[data-spine-debug] ux[data-spine-ghost]::after {
  color: var(--spine-ghost);
}
