/* ============================================================
   Pathway Puzzle — game-specific styles
   Layers on ../../css/theme.css (tokens, buttons) and
   ../../css/game-shell.css (topbar, HUD, overlays, choices).

   Local token: --hue is set on #app per pathway and tints the
   track, the locked steps and the insight panel.
   ============================================================ */

:root { --hue: 205; }

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

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
  padding: clamp(10px, 1.6vw, 20px);
  gap: clamp(10px, 1.4vw, 18px);
}

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 28vw, 390px);
  gap: clamp(10px, 1.4vw, 18px);
  align-items: start;
}

.choices--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ------------------------------------------------------------ track */

.trackwrap {
  padding: clamp(16px, 2vw, 26px) clamp(14px, 2.2vw, 30px) clamp(20px, 2.4vw, 32px);
  background: linear-gradient(180deg, rgb(255 255 255 / 0.045), rgb(255 255 255 / 0.012));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  min-width: 0;
}

.trackhead { margin-bottom: 18px; }
.trackhead__kicker {
  margin: 0 0 4px;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: hsl(var(--hue) 70% 70%);
}
.trackhead__title {
  margin: 0;
  font-size: clamp(1.25rem, 2.4vw, 1.7rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}
.trackhead__mode { margin: 4px 0 0; font-size: 0.8rem; color: var(--ink-3); }

.track {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 620px;
  display: grid;
}

/* A metabolite: rounded box on the line. */
.node {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 10px 16px;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  border: 1px solid hsl(var(--hue) 45% 42% / 0.6);
  background: linear-gradient(160deg, hsl(var(--hue) 50% 21%), hsl(var(--hue) 40% 13%));
  box-shadow: inset 0 1px 0 hsl(var(--hue) 60% 60% / 0.2);
}
.node--start { border-color: hsl(var(--hue) 60% 55% / 0.8); }
.node__dot {
  flex: none;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: hsl(var(--hue) 75% 60%);
  box-shadow: 0 0 12px hsl(var(--hue) 85% 55% / 0.8);
}
.node__label { min-width: 0; overflow-wrap: anywhere; }
.node__tag {
  margin-left: auto;
  flex: none;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: hsl(var(--hue) 60% 72%);
}

/* The reaction arrow between two metabolites, with the enzyme beside it. */
.arrow {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  min-height: 64px;
  padding: 6px 0;
}
.arrow__line {
  justify-self: center;
  position: relative;
  width: 2px;
  height: 100%;
  min-height: 48px;
  background: linear-gradient(hsl(var(--hue) 60% 55% / 0.65), hsl(var(--hue) 60% 55% / 0.35));
}
.arrow__line::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -2px;
  width: 9px; height: 9px;
  border-right: 2px solid hsl(var(--hue) 60% 55% / 0.65);
  border-bottom: 2px solid hsl(var(--hue) 60% 55% / 0.65);
  transform: translateX(-50%) rotate(45deg);
}
.arrow__body { display: grid; gap: 4px; justify-items: start; min-width: 0; }

/* A fixed enzyme label on the arrow. */
.enzyme {
  display: inline-grid;
  gap: 1px;
  padding: 7px 12px;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  background: rgb(0 0 0 / 0.28);
  border: 1px solid var(--line-soft);
}
.enzyme small { font-size: 0.68rem; font-weight: 500; color: var(--ink-3); }

.cofactor {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: hsl(var(--hue) 55% 72%);
  opacity: 0.85;
}

/* Step mode: one slot spans the arrow and the node. */
.stepslot { display: grid; grid-template-columns: 34px minmax(0, 1fr); align-items: stretch; padding: 6px 0 0; }
.stepslot .arrow__line { min-height: 0; height: auto; }
.stepslot .slot { margin: 4px 0 10px; }

/* ------------------------------------------------------------ slots */

.slot {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 50px;
  padding: 9px 14px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  background: rgb(255 255 255 / 0.02);
  text-align: left;
  cursor: pointer;
  transition: border-color 160ms, background 160ms, box-shadow 160ms, transform 160ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.slot:hover { border-color: hsl(var(--hue) 60% 55% / 0.7); background: rgb(255 255 255 / 0.05); }
.slot:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.slot--enzyme { width: auto; min-width: min(260px, 100%); min-height: 44px; border-radius: 10px; }

.slot__num {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px; height: 24px;
  border-radius: 7px;
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  background: rgb(255 255 255 / 0.05);
  border: 1px solid var(--line-soft);
}
.slot__empty { font-size: 0.82rem; color: var(--ink-3); font-style: italic; }
.slot__fill { display: grid; gap: 2px; min-width: 0; }
.slot__fill b { font-size: 0.92rem; font-weight: 600; overflow-wrap: anywhere; }
.slot__fill small { font-size: 0.7rem; color: var(--ink-3); }
.slot__fill .slot__product { font-size: 0.92rem; font-weight: 600; }
.slot__fill .slot__product::before { content: "→ "; color: hsl(var(--hue) 60% 65%); }

/* Armed: the next tap on a piece lands here. */
.slot.is-armed {
  border-style: solid;
  border-color: var(--gold);
  background: hsl(43 90% 55% / 0.08);
  box-shadow: 0 0 0 3px hsl(43 90% 55% / 0.16);
}
.slot.is-armed .slot__num { color: #241a00; background: var(--gold); border-color: var(--gold); }

.slot.is-dragover {
  border-style: solid;
  border-color: var(--accent);
  background: hsl(210 80% 50% / 0.12);
  transform: scale(1.01);
}

.slot.is-filled {
  border-style: solid;
  border-color: hsl(210 50% 50% / 0.55);
  background: linear-gradient(160deg, #15264a, #0e1a33);
}
.slot.is-filled .slot__num { color: var(--ink-2); }

.slot.is-locked {
  cursor: default;
  border-style: solid;
  border-color: hsl(var(--hue) 70% 58% / 0.9);
  background: linear-gradient(160deg, hsl(var(--hue) 50% 22%), hsl(var(--hue) 40% 13%));
  box-shadow: 0 0 22px -6px hsl(var(--hue) 80% 55% / 0.55);
}
.slot.is-locked:hover { transform: none; }
.slot.is-locked .slot__num {
  color: #04140c;
  background: hsl(var(--hue) 75% 62%);
  border-color: transparent;
}
.slot.is-hinted .slot__num { background: var(--ink-3); }
.slot.is-locking { animation: lockin 620ms var(--ease); }
@keyframes lockin {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.035); }
}

.slot.is-wrong {
  border-color: hsl(350 80% 60% / 0.9);
  background: hsl(350 70% 40% / 0.16);
  animation: wrong 460ms var(--ease);
}
@keyframes wrong {
  0%, 100% { transform: translateX(0); }
  18% { transform: translateX(-7px); }
  42% { transform: translateX(6px); }
  68% { transform: translateX(-3px); }
}

/* Locked enzyme pills shouldn't stretch to full width. */
.slot--enzyme.is-locked, .slot--enzyme.is-filled { min-width: 0; }

/* ------------------------------------------------------------ side column */

.side {
  position: sticky;
  top: clamp(10px, 1.6vw, 20px);
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.4vw, 18px);
  max-height: calc(100dvh - 2 * clamp(10px, 1.6vw, 20px));
  min-width: 0;
}

.tray,
.insight {
  padding: clamp(14px, 1.5vw, 20px);
  background: linear-gradient(180deg, rgb(255 255 255 / 0.05), rgb(255 255 255 / 0.015));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  min-width: 0;
}

/* Both panels share the sticky column; the tray's tile list scrolls when it runs out of room. */
.tray { display: flex; flex-direction: column; gap: 12px; flex: 0 1 auto; min-height: 180px; }
.insight { flex: 0 1 auto; min-height: 0; max-height: 50%; }
.tray.is-dragover { border-color: var(--accent); }

.tray__head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.tray__title {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--ink-3);
}
.tray__count { font-size: 0.74rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.tray__tiles {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 7px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px;
}

.tray__done { margin: 0; font-size: 0.82rem; color: var(--gold); text-align: center; padding: 10px 0; }

.tray__actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }

/* A movable piece. */
.tile {
  display: grid;
  gap: 1px;
  max-width: 100%;
  padding: 8px 12px;
  text-align: left;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, #15264a, #0e1a33);
  box-shadow: 0 6px 16px -10px rgb(0 0 0 / 0.8);
  cursor: grab;
  transition: transform 140ms var(--ease), border-color 140ms, box-shadow 140ms;
  animation: deal 380ms var(--ease) backwards;
  animation-delay: var(--deal-delay, 0ms);
  -webkit-tap-highlight-color: transparent;
}
.tile:hover { transform: translateY(-2px); border-color: hsl(210 70% 55% / 0.7); }
.tile:active { cursor: grabbing; }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile b { font-size: 0.85rem; font-weight: 600; overflow-wrap: anywhere; }
.tile small { font-size: 0.68rem; color: var(--ink-3); }
.tile .tile__product { font-size: 0.85rem; font-weight: 600; }
.tile .tile__product::before { content: "→ "; color: var(--accent); }
.tile.is-dragging { opacity: 0.35; }

@keyframes deal {
  from { opacity: 0; transform: translateY(10px) scale(0.95); }
  to { opacity: 1; transform: none; }
}

/* ------------------------------------------------------------ insight */

.insight { overflow-y: auto; overscroll-behavior: contain; }

.insight__empty { display: grid; gap: 8px; font-size: 0.83rem; line-height: 1.55; color: var(--ink-3); }
.insight__empty p { margin: 0; }
.insight__empty strong, .insight__empty b { color: var(--ink-2); }

.insight__card { animation: rise 380ms var(--ease); }

.insight__tag {
  display: inline-block;
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
  color: hsl(var(--hue) 80% 78%);
  background: hsl(var(--hue) 70% 50% / 0.16);
  border: 1px solid hsl(var(--hue) 70% 60% / 0.3);
}
.insight__enzyme { margin: 0; font-size: 1.08rem; font-weight: 650; letter-spacing: -0.02em; line-height: 1.25; }
.insight__arrow { color: hsl(var(--hue) 70% 60%); margin: 7px 0 5px; }
.insight__arrow svg { width: 30px; height: 12px; }
.insight__product { margin: 0; font-size: 0.98rem; font-weight: 600; color: hsl(var(--hue) 65% 82%); }
.insight__cofactor {
  margin: 8px 0 0;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--ink-3);
}
.insight__cofactor:empty { display: none; }
.insight__note {
  margin: 12px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  font-size: 0.83rem;
  line-height: 1.6;
  color: var(--ink-2);
}

/* ------------------------------------------------------------ win + codex extras */

.recap__summary { margin: 4px 0 10px; font-size: 0.8rem; line-height: 1.55; color: var(--ink-2); }

.codex__group .codex__lede { margin: -2px 0 10px; font-size: 0.78rem; line-height: 1.5; color: var(--ink-3); }
.codex__start { margin: 0 0 6px; font-size: 0.8rem; color: var(--ink-2); }
.codex__start b { color: hsl(var(--hue) 65% 78%); }
.codex__row .codex__num { color: var(--ink-3); font-variant-numeric: tabular-nums; margin-right: 6px; }

/* Pathway choice: title + meta line, tinted by pathway hue. */
#choicePathway .choice b { color: hsl(var(--hue) 70% 76%); }
#choicePathway .choice.is-selected b { color: hsl(var(--hue) 80% 72%); }

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

@media (max-width: 900px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .side { display: contents; }
  .insight { order: -1; padding: 12px 14px; max-height: none; }
  .insight__empty p:not(:first-child) { display: none; }

  /* The tray rides along at the bottom so pieces are always one tap away. */
  .tray {
    position: sticky;
    bottom: 8px;
    z-index: 5;
    max-height: 42dvh;
    background: rgb(9 17 36 / 0.94);
    box-shadow: 0 -18px 40px -20px rgb(0 0 0 / 0.9);
  }
  .tray__tiles {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 6px;
  }
  .tile { flex: none; max-width: 78vw; }
}

@media (max-width: 720px) {
  .choices--three { grid-template-columns: minmax(0, 1fr); }
  .arrow, .stepslot { grid-template-columns: 26px minmax(0, 1fr); }
  .node { padding: 9px 12px; font-size: 0.9rem; }
  .node__tag { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
