:root {
  color-scheme: dark;
  --bg: #0c0b09;
  --paper: #f0e6d4;
  --dim: #a89880;
  --line: rgba(240, 230, 212, 0.18);
  --serif: "Source Serif 4", Palatino, "Palatino Linotype", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--paper);
  font-family: var(--serif);
}

body.match {
  --bg: #070208;
  --paper: #ffe4f0;
  --dim: #ff9bb8;
  --line: rgba(255, 180, 205, 0.2);
}

#app {
  height: 100%;
  position: relative;
  overflow: hidden;
  touch-action: none;
}

#view {
  width: 100%;
  height: 100%;
  display: block;
}

#hud, #caption, #toast, #hint, #keys, #touch, #menu {
  position: absolute;
  pointer-events: none;
}

#hud {
  top: 16px;
  left: 16px;
  right: 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: start;
}

body[data-mode="title"] #hud,
body[data-mode="ending"] #hud,
body[data-mode="gauge"] #objective {
  display: none;
}

#signal, #hearts {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
}

#hearts { justify-content: flex-end; }

#signal .track {
  width: min(28vw, 140px);
  height: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
}

#signal .fill { height: 100%; width: 100%; }

#flask {
  border: 1px solid var(--line);
  padding: 2px 6px;
}

#objective {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-align: center;
  color: #ffd0e2;
  text-shadow: 0 0 16px rgba(255, 59, 106, 0.8);
}

#hearts i {
  width: 14px;
  height: 10px;
  display: block;
  border: 1px solid var(--line);
  background: transparent;
}

#hearts i.on { background: var(--paper); }

#caption, #toast, #hint {
  left: 50%;
  transform: translateX(-50%);
  width: min(640px, calc(100% - 32px));
  text-align: center;
  margin: 0;
}

#caption {
  bottom: calc(108px + var(--safe-bottom));
  font-size: 1.15rem;
  line-height: 1.35;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.85);
}

#caption #who {
  display: block;
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

body.match #caption, #toast, #hint, #keys, .eyebrow, .title-keys {
  font-family: var(--mono);
}

#toast {
  top: 58px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

#hint {
  bottom: calc(64px + var(--safe-bottom));
  font-size: 13px;
  color: var(--dim);
}

#keys {
  bottom: calc(16px + var(--safe-bottom));
  left: 16px;
  right: 16px;
  margin: 0;
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.04em;
}

body[data-mode="title"] #keys,
body[data-mode="ending"] #keys,
body[data-mode="dead"] #keys,
body[data-mode="choice"] #keys,
body[data-mode="story"] #keys,
body[data-mode="gauge"] #keys-play,
body:not(.gauge) #keys-gauge {
  display: none;
}

#keys kbd {
  font-family: var(--mono);
  border: 1px solid var(--line);
  padding: 1px 5px;
}

body.match #keys .shoot {
  color: #fff;
  background: #ff3b6a;
  border-color: transparent;
}

#menu {
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
}

#menu:empty { display: none; }

.card {
  pointer-events: auto;
  width: min(460px, 100%);
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 28px 26px 22px;
  background: rgba(12, 11, 9, 0.88);
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}

body.match .card { background: rgba(18, 6, 16, 0.9); }

.eyebrow {
  margin: 0 0 8px;
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.card h1 {
  margin: 0 0 10px;
  font-size: clamp(2.2rem, 8vw, 4.2rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.lede {
  margin: 0;
  color: var(--paper);
  font-size: 1.05rem;
  line-height: 1.5;
}

.title-keys {
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  color: var(--paper);
  font-size: 15px;
  line-height: 1.4;
}

.title-keys li + li { margin-top: 6px; }

.title-keys kbd {
  font-family: var(--mono);
  font-size: 0.86em;
  border: 1px solid var(--line);
  padding: 1px 5px;
}

.story-log {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
  text-align: left;
}

.story-log p {
  margin: 0;
  color: var(--paper);
  line-height: 1.4;
}

.story-log .who {
  display: block;
  margin-bottom: 2px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
}

#story {
  position: absolute;
  top: 48px;
  right: 16px;
  z-index: 2;
  pointer-events: auto;
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

body[data-mode="title"] #story,
body[data-mode="ending"] #story,
body[data-mode="dead"] #story,
body[data-mode="choice"] #story,
body[data-mode="gauge"] #story,
body[data-mode="story"] #story,
body.gauge #actions [data-act="story"] {
  display: none;
}

.credit {
  margin: 8px 0 16px;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--paper);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

button {
  font: 600 14px/1 var(--mono);
  color: var(--paper);
  background: transparent;
  border: 1px solid var(--line);
  padding: 12px 14px;
  min-height: 44px;
  cursor: pointer;
}

button:hover, button:focus-visible {
  border-color: var(--paper);
  outline: none;
}

button[data-act="start"],
button[data-act="walk"],
button[data-act="retry"] {
  background: var(--paper);
  color: #16130f;
  border-color: transparent;
}

button[data-act="score"] {
  background: #ff3b6a;
  color: white;
  border-color: transparent;
}

#touch {
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  padding: 12px 12px var(--safe-bottom);
  pointer-events: none;
}

#stick, #actions button { pointer-events: auto; }

#stick {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  position: relative;
}

#nub {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(240, 230, 212, 0.85);
  position: absolute;
  left: 32px;
  top: 32px;
}

#actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#actions .shoot {
  color: var(--dim);
}

body.match #actions .shoot {
  background: #ff3b6a;
  color: white;
  border-color: transparent;
}

#actions .valve { display: none; }

body.gauge #actions .valve { display: block; }
body.gauge #actions .shoot,
body.gauge #actions [data-act="layer"] { display: none; }

body[data-mode="title"] #touch,
body[data-mode="ending"] #touch,
body[data-mode="dead"] #touch,
body[data-mode="choice"] #touch,
body[data-mode="story"] #touch {
  display: none;
}

@media (pointer: coarse), (max-width: 820px) {
  #hud {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "signal hearts"
      "objective objective";
    row-gap: 8px;
  }

  #signal { grid-area: signal; }
  #hearts { grid-area: hearts; }
  #objective { grid-area: objective; }

  #signal .track { width: 72px; }
  #story { display: none; }

  body[data-mode="play"] #touch,
  body[data-mode="gauge"] #touch,
  body[data-mode="vent"] #touch {
    display: flex;
  }

  #caption { bottom: calc(188px + var(--safe-bottom)); }
  #hint { bottom: calc(140px + var(--safe-bottom)); }
  #keys { display: none; }
}

[hidden] { display: none !important; }
