/* components.css — reusable UI pieces. Portrait-first: designed for a 6" phone
   screen; desktop derives from it (design/06, 08). Rows:
   meters / map (flex) / prompt / party / belt. */

#game {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}

/* grid tracks must never exceed the viewport — rows shrink, not overflow */
#game > * { min-width: 0; }

/* wider than a phone: give the column a soft card edge */
@media (min-width: 520px) {
  #game {
    border-left: var(--stroke-w) solid var(--wire);
    border-right: var(--stroke-w) solid var(--wire);
  }
}

/* ---------- meters header ---------- */

#meters {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--space) * 1.25) calc(var(--space) * 1.5);
}

.meter {
  display: flex;
  align-items: center;
  gap: 4px;
}

.meter svg { flex: none; }

.meter .pips {
  display: flex;
  gap: 2px;
}

.meter .pip {
  width: 7px;
  height: 15px;
  border-radius: 2.5px;
  background: var(--surface-2);
  border: 1px solid var(--wire);
}

.meter .pip.full { border-color: transparent; }
#meter-bandwidth .pip.full { background: var(--bw); }
#meter-deadline .pip.full { background: var(--deadline); }
.meter .pip.spent { background: var(--surface); }

.seed-chip {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.03em;
  white-space: nowrap;
}

/* ---------- map stage ---------- */

#stage {
  position: relative;
  min-height: 0;
}

#map-layer, #live-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#live-layer { pointer-events: none; } /* canvas juice sits over the SVG map */

.legend-chip {
  position: absolute;
  top: var(--space);
  right: var(--space);
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  border: var(--stroke-w) solid var(--wire-lit);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 20px;
  font-weight: 800;
}

/* ---------- prompt strip ---------- */

#prompt {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: var(--space);
  margin: 0 calc(var(--space) * 1.5);
  padding: var(--space) calc(var(--space) * 1.5);
  background: var(--surface);
  border: var(--stroke-w) solid var(--wire);
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.35;
  color: var(--ink);
}

#prompt .prompt-icon { flex: none; }

#prompt strong { color: var(--hazard); font-weight: 700; }

/* ---------- party row ---------- */

#party {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space);
  padding: calc(var(--space) * 1.25) calc(var(--space) * 1.5);
}

.pip-avatar {
  width: var(--touch-min);
  height: var(--touch-min);
  flex: none;
}

.fragment-chip {
  width: var(--touch-min);
  height: var(--touch-min);
  border-radius: var(--radius-sm);
  border: var(--stroke-w) solid var(--fragment);
  background: color-mix(in srgb, var(--fragment) 16%, var(--surface));
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.fragment-chip.lost {
  border-style: dashed;
  border-color: var(--fragment-lost);
  background: transparent;
  color: var(--fragment-lost);
}

.fragment-chip.threatened {
  border-color: var(--hazard);
  box-shadow: 0 0 10px var(--hazard-soft);
}

/* targetable uses an OUTLINE so a threatened chip keeps its amber border —
   the eye must still link "the storm names #2/#4" to "tap the right one" */
.fragment-chip.targetable {
  outline: var(--stroke-w) solid var(--road-pick);
  outline-offset: 2px;
  box-shadow: 0 0 12px rgba(123, 216, 143, 0.35);
  transform: translateY(-2px);
}

/* pushed through the flood: safe on the far side */
.fragment-chip.pushed {
  border-color: var(--safe);
  color: var(--safe);
  opacity: 0.8;
}

/* revealed corruption: the fragment visibly glitches (design/08) */
.fragment-chip.glitched {
  border-color: var(--fragment-corrupt);
  color: var(--fragment-corrupt);
  background: repeating-linear-gradient(
    -45deg,
    color-mix(in srgb, var(--fragment-corrupt) 22%, var(--surface)) 0 3px,
    var(--surface) 3px 6px
  );
  animation: glitch-jitter 0.5s steps(2) infinite;
}

@keyframes glitch-jitter {
  0% { transform: translate(0.5px, -0.5px); }
  50% { transform: translate(-0.5px, 0.5px); }
  100% { transform: translate(0.5px, 0); }
}

.fragment-chip .copy-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--copy);
  border: var(--stroke-w) solid var(--bg);
  color: var(--bg);
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- belt ---------- */

#belt {
  display: flex;
  gap: var(--space);
  padding: var(--space) calc(var(--space) * 1.5)
           max(var(--space), env(safe-area-inset-bottom));
  justify-content: center;
  align-items: stretch;
}

.tool-btn {
  min-width: 56px;
  min-height: 56px;
  border: var(--stroke-w) solid var(--wire-lit);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tool-btn .cost {
  display: flex;
  gap: 5px;
  font-size: 10px;
  color: var(--ink-soft);
  font-weight: 600;
}

.tool-btn .cost span { display: flex; align-items: center; gap: 2px; }

.tool-btn:disabled { opacity: 0.35; }        /* unaffordable = greyed (build card #11) */
.tool-btn.armed {
  border-color: var(--road-pick);
  box-shadow: 0 0 12px rgba(123, 216, 143, 0.3);
}

.go-btn {
  min-width: 96px;
  min-height: 56px;
  border: none;
  border-radius: var(--radius);
  background: var(--road-pick);
  color: #0b2013;
  font-size: 16px;
  font-weight: 800;
}

.go-btn:disabled { opacity: 0.35; }

.wait-btn {
  min-width: 72px;
  background: transparent;
  border: var(--stroke-w) solid var(--fragment);
  color: var(--fragment);
}

/* a straggler: still yours, just behind — dashed cyan with a lag badge */
.fragment-chip.straggler {
  border-style: dashed;
  opacity: 0.75;
}

.fragment-chip .lag-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--deadline);
  border: var(--stroke-w) solid var(--bg);
  color: var(--bg);
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- the Static's arena (design/10 feel bar) ---------- */

body.dueling #stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(0deg, rgba(255, 93, 143, 0.05) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.02) 0 2px, transparent 2px 5px);
  animation: static-crawl 0.4s steps(3) infinite;
}

@keyframes static-crawl {
  0% { transform: translateY(0); opacity: 0.9; }
  50% { transform: translateY(1.5px); opacity: 0.6; }
  100% { transform: translateY(-1px); opacity: 0.9; }
}

body.dueling #prompt { border-color: var(--fragment-corrupt); }

#villain {
  display: none;
  position: absolute;
  top: 8px;
  left: 50%;
  width: 130px;
  margin-left: -65px;
  filter: drop-shadow(0 0 14px rgba(255, 93, 143, 0.35));
}

body.dueling #villain { display: block; }

.static-villain { animation: villain-jitter 0.55s steps(2) infinite; }

@keyframes villain-jitter {
  0% { transform-box: fill-box; }
  50% { translate: 1.2px -0.8px; }
  100% { translate: -0.8px 0.6px; }
}

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

@media (prefers-reduced-motion: reduce) {
  body.dueling #stage::after { animation: none; }
}

/* ---------- juice ---------- */

.road-signal.flowing { animation: dash-march 0.8s linear infinite; }
@keyframes dash-march { to { stroke-dashoffset: -12; } }

.hazard-cloud {
  transform-box: fill-box;
  transform-origin: center;
  animation: cloud-bob 3.2s ease-in-out infinite alternate;
}
@keyframes cloud-bob { from { transform: translateY(-2px); } to { transform: translateY(2.5px); } }

#stage.shake { animation: stage-shake 0.4s ease; }
@keyframes stage-shake {
  20% { transform: translate(-4px, 2px); }
  45% { transform: translate(4px, -2px); }
  70% { transform: translate(-3px, -1px); }
  100% { transform: none; }
}

.tool-btn:active:not(:disabled), .go-btn:active:not(:disabled),
.primary-btn:active, .ghost-btn:active { transform: scale(0.95); }

.meter .pip { transition: background 0.25s ease, border-color 0.25s ease; }

.float { animation: pip-float 2.6s ease-in-out infinite alternate; }
@keyframes pip-float { from { transform: translateY(-4px); } to { transform: translateY(5px); } }

.mute-btn {
  min-width: 34px;
  min-height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- prompt notices ---------- */

#prompt.flash { animation: prompt-flash 0.45s ease; }

@keyframes prompt-flash {
  0% { transform: scale(0.97); border-color: var(--road-pick); }
  100% { transform: scale(1); }
}

/* ---------- legend popover ---------- */

.legend-pop {
  position: absolute;
  top: calc(var(--space) + 52px);
  right: var(--space);
  width: 240px;
  padding: calc(var(--space) * 1.5);
  background: var(--surface);
  border: var(--stroke-w) solid var(--wire-lit);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
  line-height: 1.3;
  color: var(--ink);
  z-index: 5;
}

.legend-pop .row { display: flex; align-items: center; gap: 10px; }
.legend-pop .row svg { flex: none; }

/* ---------- overlay screens (start / win / loss) ---------- */

#overlay:empty { display: none; }

#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 13, 10, 0.82);
  z-index: 10;
  padding: calc(var(--space) * 2);
}

.screen {
  width: min(400px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--bg);
  border: var(--stroke-w) solid var(--wire-lit);
  border-radius: calc(var(--radius) * 1.5);
  padding: calc(var(--space) * 3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--space) * 2);
  text-align: center;
}

.screen h1 { margin: 0; font-size: 26px; letter-spacing: 0.01em; }
.screen h2 { margin: 0; font-size: 21px; }
.screen p { margin: 0; font-size: 15px; line-height: 1.45; color: var(--ink-soft); }
.screen p strong { color: var(--ink); }

.screen .btn-row { display: flex; gap: var(--space); flex-wrap: wrap; justify-content: center; }

.primary-btn, .ghost-btn {
  min-height: var(--touch-min);
  padding: 10px 22px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 800;
}

.primary-btn {
  border: none;
  background: var(--road-pick);
  color: #0b2013;
}

.ghost-btn {
  border: var(--stroke-w) solid var(--wire-lit);
  background: transparent;
  color: var(--ink);
}

.seed-note { font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); }

.start-extras {
  display: flex;
  align-items: center;
  gap: calc(var(--space) * 2);
}

.gentle-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  min-height: var(--touch-min);
}

.gentle-toggle input { width: 18px; height: 18px; accent-color: var(--safe); }

.daily-btn { font-size: 13px; min-height: var(--touch-min); padding: 6px 14px; }

/* win: the message unfurls line by line as the payoff */
.message-card {
  width: 100%;
  background: #fdf7ea;
  color: #3c3427;
  border-radius: var(--radius);
  padding: calc(var(--space) * 2);
  text-align: left;
  font-size: 15px;
  line-height: 1.5;
}

.message-card .win-line {
  opacity: 0;
  transform: translateY(6px);
  animation: unfurl 0.5s ease forwards;
}

@keyframes unfurl { to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .message-card .win-line { opacity: 1; transform: none; }
}

.grownups-link { color: var(--ink-faint); }

.share-card {
  margin: 8px auto 0;
  padding: 10px 14px;
  border: var(--stroke-w) solid var(--wire-lit);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
  max-width: 340px;
}

.reveal-card {
  margin: 8px 0;
  padding: 12px 16px;
  border: var(--stroke-w) solid var(--star);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--star) 8%, var(--surface));
  font-size: 14px;
  text-align: left;
  max-width: 340px;
}

.reveal-card p { margin: 6px 0 0; color: var(--ink-soft); }

.act-up {
  color: var(--star);
  font-size: 15px;
  margin: 4px 0;
}

.win-stars { display: flex; gap: 6px; }

.stat-line { font-size: 13px; color: var(--ink-soft); }

.loss-line { font-size: 16px; line-height: 1.45; color: var(--ink); }
.concept-line { font-style: italic; }

/* reward pick-1-of-3 */
.reward-cards {
  display: flex;
  gap: var(--space);
  width: 100%;
}

.reward-card {
  flex: 1;
  min-height: 110px;
  padding: 12px 8px;
  border: var(--stroke-w) solid var(--wire-lit);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.reward-card strong { font-size: 13px; }
.reward-card span { color: var(--ink-soft); line-height: 1.25; }
.reward-card:active { transform: scale(0.96); }

.tool-btn.passive { opacity: 0.8; border-style: dashed; }

/* the live-call render: played frames vs glitch gaps */
.call-frames {
  display: flex;
  gap: 6px;
  width: 100%;
  justify-content: center;
}

.call-frame {
  width: 52px;
  height: 64px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--stroke-w) solid var(--fragment);
  background: color-mix(in srgb, var(--fragment) 10%, var(--surface));
}

.call-frame.gap {
  border-color: var(--wire-lit);
  background: repeating-linear-gradient(
    0deg,
    var(--surface) 0 3px,
    var(--surface-2) 3px 6px
  );
}

/* fragment states unique to live calls */
.fragment-chip.expired {
  border-style: dotted;
  border-color: var(--ink-faint);
  color: var(--ink-faint);
  background: transparent;
}

.fragment-chip.skipped {
  border-style: dashed;
  border-color: var(--wire);
  color: var(--ink-faint);
  background: transparent;
  opacity: 0.55;
}

#belt { flex-wrap: wrap; }
.go-btn { flex: 1; max-width: 180px; }
.wait-btn { flex: 0.7; }

.grandma-react { animation: react-pop 0.6s ease; }
@keyframes react-pop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}
