:root {
  --ink: #0f0a06;
  --ink-deep: #0a0704;
  --stone: #4a3f33;
  --bone: #e9dfcc;
  --bone-dim: rgba(233, 223, 204, 0.7);
  --amber: #d97a2b;
  --amber-deep: #8a4a16;
  --cold: #b9c9da;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink-deep);
}

body {
  color: var(--bone);
  font-family: "IM Fell English", Georgia, serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0.06;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 46%, transparent 58%, rgba(18, 11, 5, 0.12) 88%, rgba(18, 11, 5, 0.28) 100%);
}

.page {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-width: 1640px;
  margin: 0 auto;
  padding: 0;
  overflow: hidden;
}

/* ---------------------------------------------------------------- head */

.head {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: min(100%, var(--stage-w, 100%));
  padding: clamp(7px, 1.3vh, 16px) clamp(12px, 2vw, 30px) 0;
  pointer-events: none;
}

.head::before {
  content: "";
  position: absolute;
  inset: -2px -30px 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(14, 9, 5, 0.72) 0%, rgba(14, 9, 5, 0.28) 55%, rgba(14, 9, 5, 0) 100%);
}

.head-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 14px;
}

.head-side {
  min-width: 0;
  padding-bottom: 5px;
  font-family: "Azeret Mono", monospace;
  font-weight: 300;
  font-size: clamp(7px, 0.72vw, 10px);
  letter-spacing: 0.1em;
  color: var(--bone-dim);
}

.head-left { justify-self: start; }

.head-right {
  justify-self: end;
  text-align: right;
  font-family: "IM Fell English", Georgia, serif;
  font-size: clamp(7px, 0.78vw, 11px);
  letter-spacing: 0.24em;
  line-height: 1.45;
  color: rgba(231, 225, 212, 0.8);
}

.listener-tag {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.listener-tag img {
  display: block;
  height: clamp(18px, 2.2vh, 28px);
  width: auto;
  border: 1px solid rgba(231, 225, 212, 0.28);
  padding: 1px;
  background: rgba(231, 225, 212, 0.08);
}

.listener-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.25;
}

.listener-tag.alert img {
  border-color: var(--amber);
  box-shadow: 0 0 10px rgba(217, 122, 43, 0.4);
}

.listener-tag.alert .plate-name { color: var(--amber); }

.best-line { display: flex; gap: 8px; align-items: baseline; }
.best-label { opacity: 0.78; letter-spacing: 0.16em; }
.best-value { color: var(--bone); letter-spacing: 0.08em; }
.attempt-line { margin-top: 2px; opacity: 0.72; }

h1 {
  margin: 0;
  font-family: "Big Shoulders Stencil", Impact, sans-serif;
  font-weight: 500;
  font-size: clamp(21px, 2.9vw, 46px);
  line-height: 0.92;
  letter-spacing: 0.145em;
  text-indent: 0.145em;
  white-space: nowrap;
  color: var(--bone);
  text-align: center;
  text-shadow: 0 1px 14px rgba(0, 0, 0, 0.6);
}

.sound-word { transition: color 500ms ease; }
.hunting .sound-word { color: var(--amber); }

.head-rule {
  height: 1px;
  margin-top: 7px;
  background: linear-gradient(90deg, rgba(231, 225, 212, 0.12), rgba(231, 225, 212, 0.5) 12%, rgba(231, 225, 212, 0.5) 88%, rgba(231, 225, 212, 0.12));
}

.hint {
  margin: 6px 0 0;
  text-align: center;
  font-family: "IM Fell English", Georgia, serif;
  font-style: italic;
  font-size: clamp(10.5px, 1.12vw, 14px);
  line-height: 1.35;
  letter-spacing: 0.035em;
  color: rgba(240, 235, 224, 0.94);
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.95), 0 0 2px rgba(0, 0, 0, 0.95);
}

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

.stage-wrap {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.stage {
  position: relative;
  width: var(--stage-w, 100%);
  aspect-ratio: 2 / 1;
  max-height: 100%;
  overflow: hidden;
  background: var(--ink);
  container-type: size;
  box-shadow:
    0 22px 70px rgba(0, 0, 0, 0.62),
    0 0 0 1px rgba(231, 225, 212, 0.1);
}

.stage-canvas { position: absolute; inset: 0; z-index: 0; }
.stage-canvas canvas { display: block; width: 100% !important; height: 100% !important; }

.warm {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  mix-blend-mode: soft-light;
  background:
    radial-gradient(ellipse at 74% 15%, rgba(255, 208, 142, 0.38), rgba(255, 208, 142, 0) 56%),
    radial-gradient(ellipse at 22% 70%, rgba(255, 200, 132, 0.13), rgba(255, 200, 132, 0) 62%),
    linear-gradient(180deg, rgba(170, 118, 64, 0.15), rgba(128, 86, 44, 0.08) 55%, rgba(86, 56, 28, 0.15));
}

.creature-glow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 17cqw;
  height: 17cqw;
  margin: -8.5cqw 0 0 -8.5cqw;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: screen;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(217, 122, 43, 0.62) 0%, rgba(217, 122, 43, 0.22) 34%, rgba(217, 122, 43, 0) 70%);
  transition: opacity 320ms ease;
}

.grain {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.6'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}

.vignette {
  position: absolute;
  inset: 0;
  z-index: 7;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 46%, transparent 60%, rgba(0, 0, 0, 0.08) 88%, rgba(0, 0, 0, 0.22) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.05), transparent 20%, transparent 80%, rgba(0, 0, 0, 0.12));
}

.frame {
  position: absolute;
  inset: 9px;
  z-index: 8;
  pointer-events: none;
  border: 1px solid rgba(231, 225, 212, 0.42);
}

i.tick {
  position: absolute;
  z-index: 9;
  width: 17px;
  height: 17px;
  pointer-events: none;
  border-color: rgba(231, 225, 212, 0.82);
  border-style: solid;
  border-width: 0;
}
.tick.tl { top: 9px; left: 9px; border-top-width: 1.5px; border-left-width: 1.5px; }
.tick.tr { top: 9px; right: 9px; border-top-width: 1.5px; border-right-width: 1.5px; }
.tick.bl { bottom: 9px; left: 9px; border-bottom-width: 1.5px; border-left-width: 1.5px; }
.tick.br { bottom: 9px; right: 9px; border-bottom-width: 1.5px; border-right-width: 1.5px; }


.stage-clock {
  position: absolute;
  top: 12.5%;
  right: 2.4%;
  z-index: 12;
  font-family: "Azeret Mono", monospace;
  font-weight: 300;
  font-size: clamp(7px, 0.86cqw, 13px);
  letter-spacing: 0.16em;
  color: rgba(231, 225, 212, 0.78);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.exit-label {
  position: absolute;
  top: 34%;
  right: 2.2%;
  z-index: 12;
  font-family: "IM Fell English", Georgia, serif;
  font-size: clamp(5px, 0.6cqw, 10px);
  letter-spacing: 0.24em;
  color: rgba(185, 201, 218, 0.78);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.callout {
  position: absolute;
  left: 50%;
  top: 39%;
  width: 92%;
  transform: translate(-50%, -50%);
  z-index: 20;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 360ms ease;
}
.callout.show { opacity: 1; }

.callout-main {
  font-family: "Big Shoulders Stencil", Impact, sans-serif;
  font-weight: 500;
  font-size: clamp(24px, 4.6cqw, 68px);
  letter-spacing: 0.12em;
  text-indent: 0.12em;
  line-height: 0.95;
  color: var(--bone);
  text-shadow: 0 2px 26px rgba(0, 0, 0, 0.85);
}
.callout.lost .callout-main { color: var(--amber); }

.callout-sub {
  margin-top: 1.2%;
  font-family: "IM Fell English", Georgia, serif;
  font-size: clamp(8px, 1.06cqw, 15px);
  letter-spacing: 0.14em;
  color: rgba(231, 225, 212, 0.88);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.95);
}

.flash {
  position: absolute;
  inset: 0;
  z-index: 30;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 66% 6%, #ffffff 0%, #e8f0fb 48%, #b9c9da 100%);
}

.stage-error {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  margin: 0;
  font-family: "IM Fell English", Georgia, serif;
  color: var(--bone-dim);
}

/* ---------------------------------------------------------------- foot */

.foot {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: min(100%, var(--stage-w, 100%));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: clamp(14px, 3vw, 44px);
  padding: clamp(7px, 1.2vh, 14px) clamp(12px, 2vw, 30px) clamp(10px, 1.6vh, 18px);
  border-top: 1px solid rgba(231, 225, 212, 0.16);
}

.foot::before {
  content: "";
  position: absolute;
  inset: 0 -30px -2px;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(0deg, rgba(14, 9, 5, 0.82) 0%, rgba(14, 9, 5, 0.45) 58%, rgba(14, 9, 5, 0) 100%);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: clamp(9px, 1.8vw, 24px);
  min-width: 0;
}

.ctrl { display: flex; flex-direction: column; gap: 3px; }

.caps { display: flex; gap: 4px; height: 38px; align-items: center; }

.cap-btn {
  display: flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 90ms ease, filter 90ms ease;
}
.cap-btn:active { transform: translateY(1px); filter: brightness(1.16); }
.cap-btn:focus-visible { outline: 1px solid var(--amber); outline-offset: 3px; }

.cap-img { display: block; height: 38px; width: auto; user-select: none; -webkit-user-drag: none; }
.cap-img.flip { transform: scaleX(-1); }
.cap-img.wide { height: 33px; }

.cap-drawn {
  width: 37px;
  height: 37px;
  justify-content: center;
  font-family: "Big Shoulders Stencil", Impact, sans-serif;
  font-weight: 600;
  font-size: 23px;
  line-height: 1;
  color: var(--bone);
  background: #140e08;
  border: 1px solid rgba(231, 225, 212, 0.62);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.75), inset 0 0 12px rgba(231, 225, 212, 0.06), 0 2px 0 rgba(0, 0, 0, 0.55);
  border-radius: 2px;
}

.ctrl-label {
  font-family: "IM Fell English", Georgia, serif;
  font-size: clamp(8px, 0.78vw, 11px);
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: rgba(231, 225, 212, 0.92);
  white-space: nowrap;
}
.ctrl-label em {
  font-family: "Azeret Mono", monospace;
  font-style: normal;
  letter-spacing: 0.03em;
  color: rgba(231, 225, 212, 0.6);
  margin-left: 3px;
}

.readouts {
  width: clamp(190px, 27vw, 380px);
  min-width: 160px;
  margin-left: auto;
  padding-bottom: 1px;
}

.gauge-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: "Azeret Mono", monospace;
  font-weight: 300;
  font-size: clamp(8px, 0.76vw, 11px);
  letter-spacing: 0.18em;
  color: rgba(231, 225, 212, 0.78);
}
.gauge-value { color: var(--amber); font-size: 1.12em; letter-spacing: 0.06em; }

.gauge { position: relative; height: 12px; margin-top: 1px; }
.gauge::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 6px;
  background: repeating-linear-gradient(90deg, rgba(231, 225, 212, 0.5) 0 1px, transparent 1px 3.448%);
}
.gauge::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 7px;
  height: 1px;
  background: rgba(231, 225, 212, 0.38);
}
.gauge-fill {
  position: absolute;
  left: 0;
  top: 5px;
  height: 4px;
  width: 0%;
  background: var(--amber);
  box-shadow: 0 0 8px rgba(217, 122, 43, 0.45);
  transition: width 80ms linear;
}
.gauge.masked .gauge-fill { width: 0% !important; box-shadow: none; }

.cover-line {
  margin-top: 3px;
  font-family: "Azeret Mono", monospace;
  font-weight: 300;
  font-size: clamp(7px, 0.7vw, 10px);
  letter-spacing: 0.1em;
  color: rgba(231, 225, 212, 0.7);
  white-space: nowrap;
}
.cover-line.active-thunder { color: var(--cold); }
.cover-line.active-flicker { color: var(--amber); }

/* -------------------------------------------------------------- narrow */

@media (max-width: 680px), (max-height: 520px) {
  .head { padding: 5px clamp(8px, 1.6vw, 14px) 0; }
  .head-row { gap: 5px; }
  h1 { font-size: clamp(16px, 4.2vw, 27px); letter-spacing: 0.1em; text-indent: 0.1em; }
  .head-side { font-size: 7px; padding-bottom: 2px; letter-spacing: 0.05em; }
  .head-right { font-size: 7px; letter-spacing: 0.14em; }
  .head-left .best-label { display: none; }
  .head-rule { margin-top: 4px; }
  .hint { font-size: 9.5px; margin-top: 3px; line-height: 1.22; }
  .foot { flex-direction: row; align-items: flex-end; gap: 9px; padding: 5px clamp(8px, 1.6vw, 14px) 13px; }
  .controls { flex: 1 1 auto; justify-content: flex-start; gap: clamp(6px, 1.3vw, 14px); flex-wrap: nowrap; }
  .caps { height: 31px; }
  .cap-img { height: 31px; }
  .cap-img.wide { height: 27px; }
  .cap-drawn { width: 30px; height: 30px; font-size: 19px; }
  .ctrl-label { font-size: 7.2px; letter-spacing: 0.08em; }
  .ctrl-label em { font-size: 0.9em; margin-left: 2px; }
  .readouts { width: clamp(104px, 27vw, 240px); min-width: 0; flex: 0 0 auto; }
  .gauge-value, .gauge-head { font-size: 8px; letter-spacing: 0.08em; }
  .cover-line { font-size: 6.8px; letter-spacing: 0.04em; }
  .stage-clock { font-size: 7px; top: 12%; }
  .exit-label { font-size: 5px; }
}

@media (pointer: coarse) {
  .caps { height: 44px; }
  .cap-img { height: 44px; }
  .cap-img.wide { height: 37px; }
  .cap-drawn { width: 42px; height: 42px; font-size: 26px; }
  .ctrl-label { font-size: 9px; }
  .cap-btn { padding: 2px; }
}

@media (max-width: 380px) {
  .foot { flex-wrap: wrap; align-items: flex-end; row-gap: 5px; }
  .controls { flex: 1 1 100%; justify-content: space-between; }
  .readouts { flex: 1 1 100%; width: 100%; margin-top: 2px; }
}

/* ------------------------------------------------------------ portrait */

@media (orientation: portrait) {
  .page {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 5px;
    padding: 6px 0;
    overflow: hidden;
  }

  .head {
    position: static;
    transform: none;
    width: 100%;
    padding: 0 clamp(8px, 2.4vw, 18px);
  }
  .head::before { display: none; }

  .stage-wrap {
    position: static;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0;
  }

  .stage {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    max-height: none;
    max-width: none;
  }

  .foot {
    position: static;
    transform: none;
    width: 100%;
    flex: 0 0 auto;
    flex-wrap: wrap;
    align-items: flex-end;
    row-gap: 5px;
    padding: 5px clamp(8px, 2.4vw, 18px) 14px;
    border-top: 1px solid rgba(231, 225, 212, 0.2);
  }
  .foot::before { display: none; }

  .controls {
    flex: 1 1 100%;
    justify-content: space-between;
    gap: clamp(5px, 1.4vw, 12px);
  }

  .readouts {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    margin-top: 2px;
    padding-bottom: 0;
  }

  .exit-label { display: none; }

  .stage-clock {
    top: 7px;
    right: 9px;
    left: auto;
    transform: none;
    font-size: 9px;
  }

  .frame { inset: 7px; }
  .tick.tl { top: 7px; left: 7px; }
  .tick.tr { top: 7px; right: 7px; }
  .tick.bl { bottom: 7px; left: 7px; }
  .tick.br { bottom: 7px; right: 7px; }
}
