/*
 * HUD layout, theming, focus states and reduced motion (SPEC §3, §15, §16).
 *
 * The playfield is a canvas in a virtual 1000 x 1600 space. Everything in this
 * file is the fixed frame around it, positioned in percentages of that same
 * box so the two stay lined up at any size.
 */

:root {
  --bg: #0b0d12;
  --field: #12151c;
  --panel: rgba(23, 27, 36, 0.86);
  --edge: rgba(255, 255, 255, 0.09);
  --ink: #e9ecf4;
  --muted: #8d95ab;
  --accent: #5eead4;
  --warn: #f5b451;

  /* CPK, mirrored from config.js. Atoms only — never UI decoration (§16.2). */
  --el-h: #f2f2f2;
  --el-c: #303035;
  --el-n: #3358d4;
  --el-o: #d93a2b;

  --radius: 10px;
  --tap: 44px;
  --switch-ms: 250ms;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 500 16px/1.3 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  display: grid;
  place-items: center;
  overflow: hidden;
  /* Suppress scrolling, pull-to-refresh and double-tap zoom (§15). */
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/*
 * The stage keeps the 1000 x 1600 portrait shape and is letterboxed and
 * centred on anything wider (§3).
 */
#stage {
  position: relative;
  container-type: inline-size;
  aspect-ratio: 1000 / 1600;
  height: min(100dvh, 100vh);
  max-width: 100vw;
  background: var(--field);
  overflow: hidden;
}

#playfield {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon-defs {
  position: absolute;
  width: 0;
  height: 0;
}

:where(button):focus-visible,
:where(.dot):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* --- HUD (§3) ------------------------------------------------------------ */

#hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 2%;
  padding: 3.2% 3.6%;
  background: linear-gradient(to bottom, var(--panel), rgba(23, 27, 36, 0));
  pointer-events: none;
}

#hud button {
  pointer-events: auto;
}

#plate-name {
  margin: 0 0 0.5em;
  font-size: clamp(11px, 2.4cqw, 15px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.dots {
  display: flex;
  gap: 4px;
}

/* The dot itself is small; the button around it meets the 44px rule (§15). */
.dot {
  width: var(--tap);
  height: var(--tap);
  margin: calc(var(--tap) / -2 + 7px) calc(var(--tap) / -2 + 7px);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.dot::after {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.4;
  transition: opacity 160ms ease, background-color 160ms ease;
}

.dot.is-active::after {
  background: var(--accent);
  opacity: 1;
}

.dot.is-dead::after {
  background: var(--muted);
  opacity: 0.18;
}

.score {
  text-align: center;
  line-height: 1;
}

#score {
  display: block;
  font-size: clamp(20px, 5cqw, 30px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.caption {
  font-size: clamp(9px, 1.9cqw, 11px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.targets {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 2px;
  justify-items: end;
  font-size: clamp(11px, 2.5cqw, 15px);
}

.targets li {
  display: flex;
  gap: 0.7em;
  align-items: baseline;
  transition: opacity 200ms ease;
}

.targets .formula {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.targets .points {
  min-width: 3ch;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* §10.4: out of reach dims, right atoms in the wrong arrangement pulses. */
.targets li.is-overshot {
  opacity: 0.34;
}

.targets li.is-shape {
  color: var(--warn);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

/* --- Atom queue (§3, §12) ------------------------------------------------ */

.queue {
  position: absolute;
  right: 2.6%;
  top: 30%;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  justify-items: center;
}

/*
 * The bottom entry is the next atom into the gun, so it reads slightly larger.
 * New arrivals enter at the top and the column shifts down.
 */
.queue li {
  width: clamp(26px, 6.4cqw, 40px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.45);
  font-weight: 700;
  font-size: clamp(12px, 3cqw, 18px);
  color: #10131a;
  opacity: 0.62;
}

.queue li:last-child {
  opacity: 1;
  transform: scale(1.16);
}

.queue li[data-element='H'] { background: var(--el-h); }
.queue li[data-element='C'] { background: var(--el-c); color: #eef1f8; }
.queue li[data-element='N'] { background: var(--el-n); color: #eef1f8; }
.queue li[data-element='O'] { background: var(--el-o); color: #fff4f2; }

/* --- Scissors tray (§11) ------------------------------------------------- */

.tray {
  position: absolute;
  left: 3%;
  bottom: 3%;
  display: flex;
  gap: 2px;
}

.scissors {
  width: var(--tap);
  height: var(--tap);
  padding: 8px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  color: var(--ink);
  cursor: pointer;
  transition: transform 140ms ease, color 140ms ease;
}

.scissors svg {
  width: 100%;
  height: 100%;
  display: block;
}

.scissors.is-loaded {
  color: var(--accent);
  transform: translateY(-6px) scale(1.1);
}

.scissors:disabled {
  color: var(--muted);
  opacity: 0.22;
  cursor: default;
}

/* --- Game over (§14) ----------------------------------------------------- */

.gameover {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1.4rem;
  padding: 8%;
  text-align: center;
  background: rgba(11, 13, 18, 0.93);
  backdrop-filter: blur(6px);
}

.gameover[hidden] {
  display: none;
}

.gameover h2 {
  margin: 0;
  font-size: clamp(20px, 5.4cqw, 30px);
  letter-spacing: 0.02em;
}

.final {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.2em 1.4em;
  margin: 0;
  align-items: baseline;
}

.final dt {
  color: var(--muted);
  font-size: 0.8em;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.final dd {
  margin: 0;
  font-size: 1.5em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.thumbnails {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.thumbnails svg {
  width: clamp(48px, 13cqw, 78px);
  aspect-ratio: 1;
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
}

.restart {
  min-height: var(--tap);
  padding: 0 1.6em;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #06231e;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* --- Reduced motion (§15) ------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }

  .targets li.is-shape {
    animation: none;
    opacity: 1;
  }
}
