:root {
  --ink: #0a1b33;
  --navy: #13447c;
  --muted: #5c6b82;
  --rule: #d3dae6;
  --stock: #eef1f6;
  --paper: #ffffff;
  --signal: #ffc629;
  --orb: #1a7a4c;
  --display: "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --body: "Segoe UI", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #fff7d6 0%, transparent 55%),
    linear-gradient(180deg, #f7f9fc 0%, #e8edf5 100%);
  line-height: 1.5;
}

.view[hidden] { display: none !important; }
.view--landing {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.landing {
  width: min(34rem, 100%);
  padding: 1.5rem 1.6rem 1.75rem;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 12px 40px rgba(10, 27, 51, .08);
}
.intro__eyebrow {
  font-family: var(--mono); font-size: .72rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 .6rem;
}
.intro__eyebrow a { color: var(--navy); text-decoration: none; }
.intro__eyebrow a:hover { text-decoration: underline; }
.landing h1 {
  font-family: var(--display); font-weight: 750;
  font-size: clamp(1.55rem, 3.4vw, 2.2rem);
  line-height: 1.15; margin: 0 0 .75rem; letter-spacing: -.02em;
}
.intro__lead { margin: 0 0 1rem; color: var(--muted); font-size: 1rem; }
.legend {
  list-style: none; margin: 0 0 1.15rem; padding: 0;
  display: grid; gap: .45rem; font-size: .9rem; color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: .55rem; }
.legend i {
  width: 1rem; height: 1rem; border-radius: 50%; flex-shrink: 0;
  display: inline-block;
}
.legend .dot { background: var(--signal); width: .55rem; height: .55rem; margin: 0 .225rem; }
.legend .orb { background: var(--orb); box-shadow: 0 0 0 2px rgba(26, 122, 76, .25); }
.legend .g--rand { background: #7c3aed; }
.legend .g--chase { background: #dc2626; }
.legend .g--sight { background: #0891b2; }

.btn {
  appearance: none; border: 0; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: .95rem;
  padding: .7rem 1.15rem; border-radius: 6px;
  background: var(--stock); color: var(--ink);
  width: 100%;
}
.btn--signal { background: var(--signal); }
.btn--signal:hover { filter: brightness(.97); }

.view--game {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(1rem, 3vh, 2rem) 0;
}
.page--game {
  width: min(720px, calc(100% - 1.5rem));
  margin: 0 auto;
}
.board {
  position: relative;
  display: grid;
  justify-items: center;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--stock);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(10, 27, 51, .06);
}
.board canvas {
  display: block;
  max-width: 100%;
  height: auto;
}
.game__top {
  position: static;
  z-index: 3;
  width: 100%;
  margin: 0 0 .4rem;
  pointer-events: none;
}
.hud__card {
  pointer-events: auto;
  margin: 0;
  padding: .22rem .45rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 4px 14px rgba(10, 27, 51, .06);
  display: flex;
  align-items: center;
  gap: .55rem;
  flex-wrap: nowrap;
}
.hud__lab {
  margin: 0;
  font-family: var(--mono); font-size: .62rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--muted);
}
.hud__meters { display: flex; gap: .7rem; flex: 1; }
.hud__meters b {
  display: block; font-family: var(--display); font-weight: 750;
  font-size: 1rem; line-height: 1; font-variant-numeric: tabular-nums;
}
.hud__meters span {
  display: block; margin-top: .12rem; font-family: var(--mono);
  font-size: .52rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.hud__bar {
  height: 4px; width: 3.4rem; background: var(--rule); border-radius: 3px;
  overflow: hidden; flex-shrink: 0;
}
.hud__bar i { display: block; height: 100%; width: 0; background: var(--orb); }
.hud__power {
  margin: 0;
  font-family: var(--mono); font-size: .58rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--orb); font-weight: 700;
}
.hud__power[hidden] { display: none !important; }

.sfx-toggle {
  appearance: none; border: 1px solid var(--rule); background: var(--stock);
  border-radius: 6px; cursor: pointer; font-size: .9rem; line-height: 1;
  padding: .28rem .4rem; color: var(--ink);
}
.sfx-toggle[aria-pressed="true"] { opacity: .55; }

.board__over {
  grid-area: 1 / 1;
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  background: rgba(10, 27, 51, .94);
  padding: 1.5rem 1rem;
  text-align: center;
}
.board__over[hidden] { display: none !important; }
.board__box { max-width: 22rem; width: 100%; }
.board__box h3 {
  font-family: var(--display); font-weight: 750;
  font-size: clamp(1.25rem, 3vw, 1.75rem); color: #fff; margin: 0 0 .75rem;
}
.board__box p { color: #c7d6ea; margin: 0 0 1rem; font-size: .95rem; }
.board__box .btn { width: auto; min-width: 8rem; }

.pad {
  display: none;
  position: absolute;
  left: .5rem;
  bottom: .5rem;
  z-index: 2;
  grid-template-columns: repeat(3, 3rem);
  grid-template-rows: repeat(2, 3rem);
  gap: .3rem;
  opacity: .55;
  touch-action: manipulation;
}
body.ctrl-touch .pad,
.pad:not([hidden]) { display: grid; }
.pad[hidden] { display: none !important; }
.pad button {
  border: 1px solid var(--rule); background: var(--paper);
  border-radius: 8px; font-size: 1.1rem; color: var(--navy); cursor: pointer;
}
.pad .up { grid-column: 2; grid-row: 1; }
.pad .left { grid-column: 1; grid-row: 2; }
.pad .down { grid-column: 2; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; }

.game__hint { margin: .85rem 0 0; font-size: .86rem; color: var(--muted); }
.game__hint kbd {
  font-family: var(--mono); font-size: .76rem; background: var(--paper);
  border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 3px;
  padding: .08rem .32rem;
}

.app-switch {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top, 0px));
  right: calc(8px + env(safe-area-inset-right, 0px));
  z-index: 9999;
  display: flex;
  flex-direction: row;
  gap: 4px;
  padding: 0;
  background: transparent;
  border-radius: 0;
  opacity: 0.55;
}
.app-switch a {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border: 1px solid #FED7AA;
  border-radius: 6px;
  color: #78716C;
  text-decoration: none;
  font-weight: 700; font-size: 0.7rem;
  font-family: inherit;
  background: #FFFFFF;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.app-switch a.is-current {
  background: #FF6531;
  border-color: #FF6531;
  color: #FFFFFF;
  opacity: 1;
  transform: none;
}
.app-switch a:hover { background: #FFEDD5; color: #EA580C; border-color: #FF6531; }
.app-switch a.is-current:hover { background: #EA580C; color: #FFFFFF; }
