/* AEGIS · the look
   A printed tactical scope. Three inks, each with one job:
   bone = what we hold · vermilion = what falls · ice = what you send up. */

:root {
  --ground: #05070a;
  --bone: #e8e4da;
  --bone-2: rgba(232, 228, 218, 0.62);
  --bone-3: rgba(232, 228, 218, 0.34);
  --bone-4: rgba(232, 228, 218, 0.14);
  --threat: #ff4c2e;
  --you: #78e8ff;
  --font: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --pad-l: max(18px, env(safe-area-inset-left));
  --pad-r: max(18px, env(safe-area-inset-right));
  --pad-t: max(16px, env(safe-area-inset-top));
  --ground-h: 90px;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--ground);
  color: var(--bone);
  font-family: var(--font);
  font-weight: 400;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }

/* ── the sky, layer by layer ── */

/* without a camera: a dark screen with a faint warmth at the horizon */
#horizon {
  position: fixed; inset: 0;
  background: radial-gradient(130% 70% at 50% 100%, #10161a 0%, #070a0d 55%, var(--ground) 100%);
}

/* the camera, printed in one warm grey */
#camera {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0;
  filter: grayscale(1) sepia(0.16) contrast(1.3) brightness(0.62);
  transition: opacity 1.4s var(--ease);
}
body.has-camera #camera { opacity: 0.92; }
body.mirror #camera { transform: scaleX(-1); }

/* a halftone screen over the camera, darker toward the top where threats fall */
#tone {
  position: fixed; inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(5, 7, 10, 0.74) 0%, rgba(5, 7, 10, 0.34) 62%, rgba(5, 7, 10, 0.5) 100%),
    radial-gradient(circle, rgba(5, 7, 10, 0.62) 0.85px, transparent 1.45px) 0 0 / 4px 4px;
}

#sky {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
}
body[data-screen="play"] #sky { cursor: none; }

/* damage and the pulse are light over the whole screen: the compositor draws them, not the canvas */
#hurt, #flash {
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0;
  will-change: opacity;
}
#hurt { background: radial-gradient(ellipse at center, transparent 42%, rgba(255, 76, 46, 0.36) 100%); }
#flash { background: rgba(120, 232, 255, 0.16); }

#grain {
  position: fixed; inset: -40px;
  pointer-events: none;
  opacity: 0.08;
  background-size: 160px 160px;
  animation: grain 0.6s steps(3) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); }
  33% { transform: translate(-23px, 17px); }
  66% { transform: translate(19px, -29px); }
  100% { transform: translate(-7px, 11px); }
}

/* the scope refreshing: one faint band rolls down the screen */
#scan {
  position: fixed;
  left: 0; right: 0; top: 0;
  height: 22vh;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent, rgba(232, 228, 218, 0.035) 70%, rgba(232, 228, 218, 0.07) 96%, transparent);
  animation: scan 7s linear infinite;
}
@keyframes scan {
  from { transform: translateY(-25vh); }
  to { transform: translateY(105vh); }
}

/* ── type ── */

.label {
  font-size: 10px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--bone-3);
}

.num { font-variant-numeric: tabular-nums; }

/* ── HUD ── */

#hud {
  position: fixed; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.8s var(--ease);
}
body[data-screen="play"] #hud { opacity: 1; }

.hud-top {
  position: absolute;
  top: var(--pad-t); left: var(--pad-l); right: var(--pad-r);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.hud-big {
  font-size: clamp(30px, 6.4vw, 46px);
  font-weight: 300;
  line-height: 1;
  margin-top: 4px;
  letter-spacing: 0.02em;
}

.hud-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-top: 10px;
  font-size: 12px;
  color: var(--bone-2);
}
.hud-right { text-align: right; }
.hud-right .hud-row { justify-content: flex-end; }

.sites {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 9px;
  height: 22px;
  align-items: flex-end;
}
.sites i {
  display: block;
  width: 7px;
  height: 100%;
  background: var(--bone);
  transition: height 0.5s var(--ease), background 0.3s;
}
.sites i.lost { height: 3px; background: var(--threat); }

/* the message line: wave numbers, losses, holds */
#hud-msg {
  position: absolute;
  top: 27%;
  left: 0; right: 0;
  text-align: center;
  opacity: 0;
}
#hud-msg.show { animation: msg 2.6s var(--ease) both; }
#hud-msg .m-title {
  display: block;
  font-size: clamp(30px, 8vw, 66px);
  font-weight: 300;
  letter-spacing: 0.34em;
  margin-right: -0.34em;
}
#hud-msg .m-sub {
  display: block;
  margin-top: 14px;
  font-size: 11px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--bone-2);
}
#hud-msg.threat .m-title { color: var(--threat); font-size: clamp(18px, 4.4vw, 30px); letter-spacing: 0.3em; }
#hud-msg.you .m-title { color: var(--you); }
@keyframes msg {
  0% { opacity: 0; letter-spacing: 0.7em; filter: blur(6px); }
  14% { opacity: 1; filter: blur(0); }
  78% { opacity: 1; }
  100% { opacity: 0; }
}

.hud-foot {
  position: absolute;
  left: var(--pad-l); right: var(--pad-r);
  bottom: calc(var(--ground-h) + 14px);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

#hud-input { display: flex; align-items: center; gap: 8px; }
#hud-input::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--bone-3);
}
body.seeing #hud-input::before { background: var(--you); box-shadow: 0 0 0 3px rgba(120, 232, 255, 0.16); }

#sound-btn {
  pointer-events: auto;
  background: none;
  border: 0;
  padding: 10px 0;
  cursor: pointer;
  text-align: left;
}
body.muted #sound-btn { text-decoration: line-through; }

.foot-left { display: flex; flex-direction: column; gap: 2px; }

/* the pulse: a ring that fills as you intercept */
#pulse-btn {
  pointer-events: auto;
  position: relative;
  width: 74px; height: 74px;
  border: 0;
  border-radius: 50%;
  background: rgba(5, 7, 10, 0.5);
  color: var(--bone-3);
  cursor: pointer;
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  transition: color 0.3s, transform 0.15s var(--ease);
}
#pulse-btn svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
#pulse-btn .track { fill: none; stroke: var(--bone-4); stroke-width: 1.5; }
#pulse-btn .charge {
  fill: none;
  stroke: var(--you);
  stroke-width: 2;
  stroke-dasharray: 213.6;
  stroke-dashoffset: 213.6;
  transition: stroke-dashoffset 0.25s var(--ease);
}
#pulse-btn span { position: relative; padding-left: 0.22em; }
#pulse-btn.ready { color: var(--you); animation: ready 1.4s ease-in-out infinite; }
#pulse-btn:active { transform: scale(0.94); }
@keyframes ready {
  50% { box-shadow: 0 0 0 7px rgba(120, 232, 255, 0.12); }
}

#fist-hint { display: none; text-align: right; }
body.mode-hand #pulse-btn { display: none; }
body.mode-hand #fist-hint { display: block; }
#fist-hint.ready { color: var(--you); }

/* ── screens ── */

.screen {
  position: fixed; inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(var(--pad-t) + 16px) var(--pad-r) max(28px, env(safe-area-inset-bottom)) var(--pad-l);
  text-align: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s var(--ease), visibility 0.6s;
}
body[data-screen="intro"] #intro,
body[data-screen="calibrate"] #calibrate,
body[data-screen="over"] #over,
body.paused #paused { opacity: 1; visibility: visible; }

#intro { background: linear-gradient(to bottom, rgba(5, 7, 10, 0.2), rgba(5, 7, 10, 0.66) 70%); }

.kicker { margin-bottom: 26px; }

.title {
  font-weight: 300;
  font-size: clamp(60px, 17vw, 150px);
  letter-spacing: 0.42em;
  margin-right: -0.42em;
  line-height: 0.92;
}
body[data-screen="intro"] .title { animation: rise 1.6s var(--ease) both; }
@keyframes rise {
  from { opacity: 0; letter-spacing: 0.7em; filter: blur(10px); }
}

.line {
  margin-top: 22px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--bone-2);
}

.modes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 236px));
  gap: 12px;
  margin-top: 46px;
}
body.touch-first .mode[data-mode="touch"] { order: -1; }

.mode {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 16px 18px;
  text-align: left;
  background: rgba(5, 7, 10, 0.6);
  border: 1px solid var(--bone-4);
  cursor: pointer;
  transition: border-color 0.25s, background 0.25s;
}
.mode::before {
  /* the corner of a target bracket */
  content: "";
  position: absolute;
  top: -1px; left: -1px;
  width: 10px; height: 10px;
  border-top: 1px solid var(--you);
  border-left: 1px solid var(--you);
}
.mode:hover, .mode:focus-visible { border-color: var(--bone-3); background: rgba(5, 7, 10, 0.8); outline: none; }
.mode-name {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--you);
}
.mode-name::after { content: "\2192"; letter-spacing: 0; transition: transform 0.25s var(--ease); }
.mode:hover .mode-name::after { transform: translateX(4px); }
.mode-desc { font-size: 12px; line-height: 1.6; color: var(--bone-2); }

.inks {
  display: flex;
  gap: 22px;
  margin-top: 42px;
  flex-wrap: wrap;
  justify-content: center;
}
.inks span { display: flex; align-items: center; gap: 8px; }
.inks i { width: 14px; height: 2px; display: block; }

.best { margin-top: 18px; }
.best b { font-weight: 400; color: var(--bone-2); }

/* calibration: an empty ring the open hand fills */
#calibrate { background: rgba(5, 7, 10, 0.32); gap: 22px; }
.cal-ring { width: 150px; height: 150px; position: relative; }
.cal-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.cal-ring .track { fill: none; stroke: var(--bone-4); stroke-width: 1; }
.cal-ring .fill {
  fill: none;
  stroke: var(--you);
  stroke-width: 2;
  stroke-dasharray: 289;
  stroke-dashoffset: 289;
}
.cal-ring .tick { stroke: var(--bone-3); stroke-width: 1; }
#cal-status { min-height: 1.4em; }
#cal-status.threat { color: var(--threat); }
.cal-line { font-size: clamp(20px, 5vw, 30px); font-weight: 300; letter-spacing: 0.14em; }

.btn {
  margin-top: 8px;
  padding: 16px 34px;
  background: transparent;
  border: 1px solid var(--you);
  color: var(--you);
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  transition: background 0.2s;
}
.btn:hover { background: rgba(120, 232, 255, 0.08); }
.btn.ghost { border-color: var(--bone-4); color: var(--bone-2); }
.btn.ghost:hover { border-color: var(--bone-3); background: rgba(232, 228, 218, 0.04); }

/* the debrief */
#over { background: rgba(5, 7, 10, 0.74); }
.over-title {
  margin-top: 14px;
  font-size: clamp(34px, 8vw, 64px);
  font-weight: 300;
  letter-spacing: 0.08em;
}
.stats {
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: 10px 34px;
  margin: 44px 0 40px;
}
.stats div { display: flex; flex-direction: column-reverse; gap: 8px; }
.stats dd { font-size: clamp(22px, 4.6vw, 32px); font-weight: 300; }
.stats .score dd { color: var(--you); }
.actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
#over-best { margin-top: 26px; min-height: 1.2em; }
#over-best.new { color: var(--you); }

#paused { background: rgba(5, 7, 10, 0.78); cursor: pointer; gap: 16px; z-index: 10; }

#inset-probe {
  position: fixed;
  visibility: hidden;
  pointer-events: none;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── narrow screens ── */
@media (max-width: 560px) {
  .title { font-size: 15vw; letter-spacing: 0.3em; margin-right: -0.3em; }
  .modes { grid-template-columns: minmax(0, 1fr); width: 100%; max-width: 330px; margin-top: 38px; }
  .stats { grid-template-columns: repeat(2, auto); gap: 18px 40px; }
  .stats .score { grid-column: 1 / -1; }
  .inks { gap: 16px; margin-top: 34px; }
  .line { font-size: 12px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .modes { margin-top: 22px; }
  .inks { margin-top: 18px; }
  .kicker { margin-bottom: 12px; }
  .stats { margin: 22px 0; }
}

@media (prefers-reduced-motion: reduce) {
  #grain, #scan { animation: none; }
  #scan { display: none; }
  .title, #hud-msg.show { animation-duration: 0.01s; }
}
