:root {
  --night: #0d151a;
  --panel: #15232c;
  --text: #eef4f5;
  --muted: #a7bcc8;
  --ice: #b9dfef;
  --line: #49616e;
  --control-line: #72919f;
  --signal: #a51b2c;
  --left-gutter: max(1rem, env(safe-area-inset-left, 0px));
  --right-gutter: max(1rem, env(safe-area-inset-right, 0px));
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: var(--text);
  background: var(--night);
  line-height: 1.55;
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; overflow-wrap: anywhere; }
h1, h2, h3 { line-height: 1.12; }
p:last-child { margin-bottom: 0; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.shell {
  max-width: calc(44rem + var(--left-gutter) + var(--right-gutter));
  margin-inline: auto;
  padding: calc(2.5rem + env(safe-area-inset-top, 0px))
    var(--right-gutter) calc(2.5rem + env(safe-area-inset-bottom, 0px)) var(--left-gutter);
}

.system-label {
  font-family: ui-monospace, Menlo, monospace;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ice);
}

.login {
  display: grid;
  align-content: center;
  min-height: 100vh;
  min-height: 100svh;
  max-width: calc(25rem + var(--left-gutter) + var(--right-gutter));
}
.login-header { text-align: center; }
.login-header > p:last-child { color: var(--muted); }
.login-logo {
  display: block;
  width: 7rem;
  height: auto;
  margin: 0 auto .85rem;
  filter: drop-shadow(0 0 .85rem #ff862e45);
}

.login-form {
  margin-top: 1.5rem;
  padding: clamp(.9rem, 4vw, 1.5rem);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .3rem;
}

.login label { display: block; margin-bottom: .3rem; font-weight: 600; }
.login button { width: 100%; }
.login .errorlist { padding-inline-start: 1.25rem; color: var(--text); }

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--control-line);
  border-radius: .25rem;
  background: var(--night);
  color: var(--text);
  padding: .65rem .75rem;
  font: inherit;
  font-size: max(16px, 1rem);
}

button, .button {
  border: 1px solid transparent;
  border-radius: .25rem;
  background: var(--ice);
  color: var(--night);
  min-height: 48px;
  max-width: 100%;
  padding: .55rem .85rem;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.button { display: inline-flex; align-items: center; text-decoration: none; }
.secondary { background: var(--panel); border-color: var(--control-line); color: var(--ice); }
:is(button, .button, input, [tabindex="-1"]):focus-visible {
  outline: 3px solid var(--ice);
  outline-offset: 3px;
}

#play-content { padding-top: calc(.5rem + env(safe-area-inset-top, 0px)); }

.profile-logout { display: flex; justify-content: flex-end; margin-bottom: .4rem; }
.profile-logout button { min-height: 36px; padding: .2rem .6rem; font-size: .8rem; }

.profile-mirror {
  display: grid;
  justify-items: center;
  gap: .65rem;
  text-align: center;
}

.profile-avatar {
  width: min(100%, 48vh);
  width: min(100%, 48svh);
}
.profile-avatar img { display: block; width: 100%; height: auto; }
.pixel-avatar { display: none; width: 100%; height: auto; }
[data-animated-avatar="true"] .mirror-static { display: none; }
[data-animated-avatar="true"] .pixel-avatar { display: block; }

.portrait-avatar {
  display: none;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--control-line);
  border-radius: .3rem;
  background: var(--night);
}
[data-portrait-avatar="true"] .mirror-static,
[data-portrait-avatar="true"] .pixel-avatar { display: none; }
[data-portrait-avatar="true"] .portrait-avatar { display: block; }
[data-portrait-avatar="true"] .portrait-frames {
  width: 100%;
  height: 100%;
  background: var(--portrait-image) 0% 0% / 600% 600% no-repeat;
}

.pixel-mouth-talking, .is-speaking .pixel-mouth-rest { display: none; }
.is-speaking .pixel-mouth-talking { display: inline; }

@media (prefers-reduced-motion: no-preference) {
  .pixel-character { animation: pixel-arrive .6s steps(2, end) both; }
  .pixel-eyes, .pixel-mouth-talking {
    transform-box: fill-box;
    transform-origin: center;
  }
  .pixel-eyes { animation: pixel-blink 5.4s steps(1, end) infinite; }
  .is-speaking .pixel-mouth-talking { animation: pixel-talk .42s steps(1, end) infinite; }
  .portrait-frames { animation: portrait-idle 5s ease-in-out infinite; }
  .is-speaking .portrait-frames {
    animation: portrait-idle 5s ease-in-out infinite,
      portrait-columns .5s steps(6, end) infinite,
      portrait-rows 3s steps(6, end) infinite;
  }
}

@keyframes portrait-idle {
  0%, 100% { transform: scale(1.012); }
  50% { transform: scale(1.018) translateY(-.25%); }
}

/* The six visible steps span positions 0% through 100%. */
@keyframes portrait-columns {
  from { background-position-x: 0%; }
  to { background-position-x: 120%; }
}

@keyframes portrait-rows {
  from { background-position-y: 0%; }
  to { background-position-y: 120%; }
}

@keyframes pixel-arrive {
  from { transform: translateY(2px); }
  to { transform: translateY(0); }
}

@keyframes pixel-blink {
  0%, 94%, 100% { transform: scaleY(1); }
  96% { transform: scaleY(.3); }
}

@keyframes pixel-talk {
  0%, 66% { transform: scaleY(.45); }
  33% { transform: scaleY(1); }
}

.profile-name h1 { font-size: clamp(1.5rem, 5vw, 2rem); margin-bottom: .15rem; }
.profile-name > p:last-child { color: var(--muted); }

.conversation { margin-top: 1.25rem; }
.conversation h2 { font-size: 1.3rem; margin-bottom: .65rem; }
#connection { margin-top: 1rem; color: var(--ice); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: .3rem;
  padding: clamp(.9rem, 4vw, 1.25rem);
  margin-bottom: .65rem;
}

.card .system-label { margin-bottom: .6rem; }
.text { white-space: pre-wrap; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: .6rem; }

.conversation-turn { margin-bottom: 1rem; }

.speech-bubble, .reply-bubble {
  padding: clamp(.85rem, 4vw, 1.25rem);
  border: 1px solid var(--line);
}

.speech-bubble {
  position: relative;
  margin: 0 .75rem .65rem .5rem;
  background: var(--panel);
  border-radius: .75rem .75rem .75rem .2rem;
}

.speech-bubble::before {
  content: "";
  position: absolute;
  top: 1.05rem;
  left: -.34rem;
  width: .6rem;
  height: .6rem;
  background: var(--panel);
  border: solid var(--line);
  border-width: 0 0 1px 1px;
  transform: rotate(45deg);
}

.speech-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: .25rem .75rem;
  margin-bottom: .45rem;
}
.speech-meta .system-label { min-width: 0; margin-bottom: 0; }
.read-receipt { color: var(--muted); font-size: .8rem; }
.reply-bubble .system-label { margin-bottom: .45rem; }
.player-composer { margin-bottom: 1rem; }
.player-composer label { display: block; margin-bottom: .35rem; }
.player-composer textarea {
  display: block;
  width: 100%;
  margin-bottom: .5rem;
  padding: .65rem .75rem;
  border: 1px solid var(--control-line);
  border-radius: .25rem;
  background: var(--night);
  color: var(--text);
  font: inherit;
  font-size: max(16px, 1rem);
  resize: vertical;
}
.player-composer textarea:focus-visible {
  outline: 3px solid var(--ice);
  outline-offset: 3px;
}
.composer-hint, .composer-status { font-size: .875rem; color: var(--muted); }
.composer-hint { margin-block: .5rem 0; }
.composer-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.composer-actions button:disabled { opacity: .6; cursor: default; }
.composer-status:not(:empty) { margin: .6rem 0 0; }
.composer-status:empty { margin: 0; }
.speech-bubble .text { margin-bottom: .65rem; }
.speech-button { display: none; }
.speech-ready .speech-button { display: inline-flex; align-items: center; gap: .5rem; }
.speech-button svg { flex: none; }
.speech-status { margin: .6rem 0 0; color: var(--muted); }
.speech-status:empty { margin: 0; }
.reply-bubble {
  width: fit-content;
  max-width: calc(100% - 1.25rem);
  margin-left: auto;
  background: #213b48;
  border-radius: .75rem .75rem .2rem .75rem;
}
.conversation-turn .choices { margin-left: clamp(.75rem, 4vw, 2rem); }

:root:has(#check:not([hidden])) { background: var(--signal); }

.check {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 36rem);
  align-content: center;
  justify-content: center;
  text-align: center;
  padding: calc(1.5rem + env(safe-area-inset-top, 0px))
    var(--right-gutter) calc(1.5rem + env(safe-area-inset-bottom, 0px)) var(--left-gutter);
  background: var(--signal);
  color: white;
}

.check .system-label { color: inherit; margin-bottom: .65rem; }
.check h1 { font-size: clamp(2.25rem, 9vw, 5rem); margin-bottom: 1rem; }
.check form { width: min(100%, 22rem); justify-self: center; }
.check button { width: 100%; background: white; color: #68101d; }
.check :is(h1, button):focus-visible { outline-color: white; }

.hunt-live { max-width: 28rem; }
.hunt-live-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .65rem;
  margin-bottom: 1.3rem;
}
.hunt-live-header :is(h1, p) { margin-bottom: 0; }
.hunt-live-header h1 { margin-top: .25rem; font-size: 1.7rem; }
.hunt-live .card h2 { font-size: 1.2rem; margin-bottom: .6rem; }
.hunt-live .card .text { margin-bottom: 0; }
.hunt-live-send { margin-top: .75rem; }
.hunt-live-send button { width: 100%; min-height: 60px; }
.hunt-live-feedback { color: var(--ice); margin-bottom: .85rem; }
.hunt-live-preview summary {
  display: list-item;
  min-height: 48px;
  padding-block: .7rem;
  cursor: pointer;
  color: var(--ice);
}
.hunt-live-history {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.hunt-live-history .system-label { margin-bottom: .35rem; }

@media (max-width: 36rem) {
  .shell { padding-top: calc(1.25rem + env(safe-area-inset-top, 0px)); }
  .choices { grid-template-columns: minmax(0, 1fr); }
  .card button { width: 100%; }
  .composer-actions button { width: auto; flex: 1 1 auto; }
}
