@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/plex-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/plex-500.woff2") format("woff2");
}
@font-face {
  font-family: "Syne";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/syne-700.woff2") format("woff2");
}

:root {
  --ice: #e7eefc;
  --dim: #93a6c4;
  --line: rgba(215, 228, 255, 0.28);
  --warn: #ffd7b0;
  --bg: #04060c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ice);
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 400;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  background: var(--bg);
}

button, a { font: inherit; }

button {
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

::selection {
  background: var(--ice);
  color: var(--bg);
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.frame {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.frame i {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 1px solid rgba(231, 238, 252, 0.45);
}

.frame i:nth-child(1) { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); border-right: 0; border-bottom: 0; }
.frame i:nth-child(2) { top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); border-left: 0; border-bottom: 0; }
.frame i:nth-child(3) { bottom: max(12px, env(safe-area-inset-bottom)); left: max(12px, env(safe-area-inset-left)); border-right: 0; border-top: 0; }
.frame i:nth-child(4) { bottom: max(12px, env(safe-area-inset-bottom)); right: max(12px, env(safe-area-inset-right)); border-left: 0; border-top: 0; }

#hud {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  padding:
    max(22px, calc(env(safe-area-inset-top) + 14px))
    max(26px, calc(env(safe-area-inset-right) + 16px))
    max(20px, calc(env(safe-area-inset-bottom) + 12px))
    max(26px, calc(env(safe-area-inset-left) + 16px));
  animation: hudIn 1.5s ease both;
}

#hud button, #hud a { pointer-events: auto; }

@keyframes hudIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.brand { display: flex; gap: 12px; align-items: flex-start; }

.mark {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  border-radius: 50%;
  flex: none;
  background:
    radial-gradient(circle at 50% 50%, #04060c 0 38%, transparent 39%),
    conic-gradient(from 30deg, #f4f7ff, #7ea6ff 35%, #e7c2a4 52%, #9ebfff 78%, #f4f7ff);
  box-shadow: 0 0 18px rgba(150, 180, 255, 0.45);
  animation: spin 16s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

h1 {
  margin: 0;
  font-family: Syne, "Avenir Next", "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1;
}

.brand p {
  margin: 0.38rem 0 0;
  color: var(--dim);
  letter-spacing: 0.3em;
  font-size: 10px;
}

.telem {
  margin: 0.45rem 0 0;
  color: #7d91ae;
  font-size: 10px;
  letter-spacing: 0.14em;
}

.telem b {
  font-weight: 500;
  color: #c5d3e8;
}

.telem span { margin-left: 0.75rem; }

.head-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.55rem;
}

.status {
  margin: 0;
  letter-spacing: 0.26em;
  font-size: 10px;
  color: #c5d4ea;
  text-align: right;
}

#sound {
  border: 1px solid var(--line);
  padding: 0.45rem 0.6rem;
  letter-spacing: 0.2em;
  font-size: 10px;
  color: rgba(231, 238, 252, 0.72);
}

#sound[aria-pressed="true"] {
  color: var(--bg);
  background: var(--ice);
  border-color: var(--ice);
}

.hint {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  margin: 0;
  letter-spacing: 0.42em;
  font-size: 10px;
  color: rgba(231, 238, 252, 0.78);
  white-space: nowrap;
  opacity: 0;
  animation: hint 7.5s ease 1.1s forwards;
  pointer-events: none;
}

@keyframes hint {
  0% { opacity: 0; }
  12% { opacity: 0.85; }
  68% { opacity: 0.85; }
  100% { opacity: 0; }
}

.readout {
  position: relative;
  align-self: center;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(920px, 100%);
  isolation: isolate;
}
.readout::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8%;
  width: min(820px, 108%);
  height: 150%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at 50% 60%, rgba(4, 6, 12, 0.78), rgba(4, 6, 12, 0.42) 48%, transparent 72%);
  z-index: -1;
  pointer-events: none;
}

.kicker {
  margin: 0;
  letter-spacing: 0.34em;
  font-size: 11px;
  color: #d5e0f4;
}

.count {
  margin: 0.15rem 0 0;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-size: clamp(4.6rem, 16vw, 8.4rem);
  line-height: 0.86;
  letter-spacing: -0.045em;
  color: var(--ice);
}

.count.tick { animation: tick 0.38s ease; }

@keyframes tick {
  from { transform: translateY(6px); opacity: 0.45; }
  to { transform: none; opacity: 1; }
}

.sub {
  margin: 0.2rem 0 0;
  letter-spacing: 0.2em;
  font-size: 12px;
  color: var(--dim);
}

.bar {
  width: min(440px, 78vw);
  height: 1px;
  margin-top: 0.85rem;
  background: rgba(215, 228, 255, 0.16);
}

.bar span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--ice);
  transform-origin: left center;
  transform: scaleX(1);
}

#now {
  margin-top: 0.95rem;
  border: 1px solid var(--line);
  padding: 0.85rem 1.15rem;
  letter-spacing: 0.28em;
  font-size: 11px;
}

#now:hover, #sound:hover { background: rgba(231, 238, 252, 0.08); }
#sound[aria-pressed="true"]:hover { background: var(--ice); }

body.critical .count,
body.critical .kicker { color: var(--warn); }
body.critical .bar span { background: var(--warn); }
body.critical .mark { animation-duration: 2.4s; }

body.dying #hud {
  opacity: 0;
  transition: opacity 0.7s ease;
}
body.dying .frame { opacity: 0.2; transition: opacity 0.7s ease; }
body.dying #hud button { pointer-events: none; }

#end {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.55rem;
  padding: 28px;
  background: radial-gradient(ellipse at 50% 45%, rgba(4, 6, 12, 0.15), rgba(4, 6, 12, 0.78) 70%);
  animation: endIn 1.1s ease both;
}

#end[hidden] { display: none; }

@keyframes endIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.end-kicker {
  margin: 0;
  letter-spacing: 0.42em;
  font-size: 11px;
  color: var(--dim);
}

#end h2 {
  margin: 0.2rem 0 0;
  font-family: Syne, "Avenir Next", sans-serif;
  font-weight: 700;
  font-size: clamp(2.4rem, 8vw, 5.4rem);
  letter-spacing: 0.045em;
  line-height: 0.95;
}

.end-note {
  margin: 0.35rem 0 0;
  max-width: 34rem;
  color: #b7c6de;
  letter-spacing: 0.06em;
  font-size: 13px;
  line-height: 1.55;
}

#endLink {
  margin-top: 0.6rem;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--ice);
  text-underline-offset: 0.35em;
}

#end.blocked #endLink {
  margin-top: 1.15rem;
  text-decoration: none;
  color: var(--bg);
  background: var(--ice);
  padding: 1.05rem 1.35rem;
  letter-spacing: 0.22em;
  font-size: 13px;
  font-weight: 500;
}

#end.blocked #endLink:hover { background: white; }

.noscript {
  position: fixed;
  inset: auto 0 18px;
  z-index: 5;
  text-align: center;
}

.noscript a { color: var(--ice); }

.glerr {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 6;
  margin: 0;
  color: #ffb4a8;
  font-size: 12px;
  white-space: pre-wrap;
  pointer-events: none;
}

:focus-visible {
  outline: 1px solid var(--ice);
  outline-offset: 4px;
}

@media (hover: hover) and (pointer: fine) {
  body { cursor: crosshair; }
  button, a { cursor: pointer; }
}

@media (max-width: 720px) {
  h1 { font-size: 12px; letter-spacing: 0.12em; }
  .kicker { letter-spacing: 0.16em; font-size: 9px; }
  .sub { letter-spacing: 0.1em; font-size: 10px; }
  .hint { letter-spacing: 0.22em; font-size: 9px; }
  #now { letter-spacing: 0.16em; }
  .status { letter-spacing: 0.14em; }
}

@media (max-width: 420px) {
  header { flex-wrap: wrap; }
  .head-right { flex-direction: row; align-items: center; width: 100%; justify-content: space-between; }
}

@media (max-height: 520px) {
  .count { font-size: 3.1rem; }
  .hint { display: none; }
  .telem { display: none; }
  .readout { gap: 0; }
  #now { margin-top: 0.4rem; padding: 0.45rem 0.7rem; }
  .bar { margin-top: 0.4rem; }
  .brand p { display: none; }
}

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