@font-face {
  font-family: "Kaisotai Next UP";
  src: url("fonts/Kaisotai-Next-UP-B.otf") format("opentype"),
    url("fonts/Kaisotai-Next-UP-B.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --purity-ratio: 1;
  --purity-lock: 0;
  --purity-lock-width: 0%;
  --purity-whiteout: 0;
  --white: #f4f4f2;
  --paper: #e9e9e6;
  --surface: #efefec;
  --surface-soft: #f2f2ef;
  --surface-panel: rgba(239, 239, 236, 0.94);
  --pale: #d9d9d6;
  --line: #9d9d99;
  --dim: #686865;
  --ink: #111;
  --soft-ink: #2b2b2b;
  --warning: #4a4a4a;
  font-family: "Kaisotai Next UP", "Yu Gothic", "Hiragino Kaku Gothic ProN", "Meiryo", system-ui, sans-serif;
}

:where(.monitor-strip, .art-readout, .eyebrow, .status-grid strong, .upgrade em, .disconnect-overlay, .log-list) {
  font-family: "Kaisotai Next UP", Consolas, "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-size: 16px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(0, 0, 0, 0.035) 1px, transparent 1px),
    var(--white);
  background-size: 34px 34px;
}

body.disconnect-active {
  overflow: auto;
}

button {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 16px;
  min-height: 44px;
  transition: background 140ms ease, color 140ms ease, transform 140ms ease;
}

button::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--purity-lock-width);
  pointer-events: none;
  opacity: calc(var(--purity-lock) * 0.36);
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.9) 0 2px, rgba(17, 17, 17, 0.18) 2px 3px, transparent 3px 8px),
    rgba(247, 247, 245, 0.78);
  transition: width 420ms ease, opacity 420ms ease;
}

button:hover:not(:disabled) {
  background: var(--ink);
  color: var(--white);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.app {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: minmax(380px, 1.15fr) minmax(320px, 0.88fr) minmax(280px, 0.7fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 16px;
  height: 100vh;
  min-height: 100vh;
  padding: 16px;
}

.app::before,
.app::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}

.app::before {
  z-index: 11;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, calc(var(--purity-whiteout) * 0.58)), rgba(255, 255, 255, calc(var(--purity-whiteout) * 0.9))),
    radial-gradient(ellipse at 18% 34%, rgba(17, 17, 17, 0.13), transparent 34%),
    radial-gradient(ellipse at 88% 58%, rgba(17, 17, 17, 0.1), transparent 38%),
    linear-gradient(180deg, rgba(247, 247, 245, 0.15), transparent 28%, rgba(17, 17, 17, 0.1));
  filter: blur(0.2px);
  mix-blend-mode: multiply;
}

.app::after {
  z-index: 12;
  background:
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.045) 0 1px, transparent 1px 9px),
    linear-gradient(90deg, transparent, rgba(17, 17, 17, 0.08), transparent);
  mix-blend-mode: multiply;
}

.encounter-active .room-panel,
.encounter-active .control-panel,
.encounter-active .log-panel {
  filter: contrast(1.08) brightness(0.96);
}

.encounter-active .app::after {
  animation: encounter-field-drift 1.8s linear infinite;
}

.encounter-active .app::before {
  animation: anomaly-vignette-breathe 3.4s ease-in-out infinite;
}

.encounter-active[data-anomaly-effect="veil"] .app::after {
  background:
    linear-gradient(90deg, rgba(247, 247, 245, 0.32), transparent 28%, rgba(247, 247, 245, 0.24)),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.035) 0 1px, transparent 1px 10px);
}

.encounter-active[data-anomaly-effect="echo"] .app::after {
  background:
    linear-gradient(90deg, transparent 0 12px, rgba(17, 17, 17, 0.04) 12px 14px, transparent 14px 28px),
    linear-gradient(0deg, transparent, rgba(17, 17, 17, 0.06), transparent);
  animation-name: anomaly-echo-drift;
}

.encounter-active[data-anomaly-effect="route"] .app::after {
  background:
    radial-gradient(ellipse at 72% 44%, transparent 0 30%, rgba(17, 17, 17, 0.12) 31%, transparent 33%),
    linear-gradient(115deg, transparent 0 45%, rgba(17, 17, 17, 0.16) 46%, transparent 48%),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.035) 0 1px, transparent 1px 8px);
}

.encounter-active[data-anomaly-effect="afterimage"] .app::after {
  background:
    linear-gradient(90deg, transparent 0 38%, rgba(17, 17, 17, 0.1) 39%, transparent 40%),
    linear-gradient(90deg, transparent 0 58%, rgba(17, 17, 17, 0.07) 59%, transparent 60%),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.035) 0 1px, transparent 1px 9px);
  animation-name: anomaly-afterimage-shift;
}

.encounter-active[data-anomaly-effect="frost"] .app::after {
  background:
    radial-gradient(circle at 0% 100%, rgba(247, 247, 245, 0.84), transparent 42%),
    radial-gradient(circle at 100% 0%, rgba(247, 247, 245, 0.76), transparent 36%),
    linear-gradient(90deg, transparent 0 44%, rgba(17, 17, 17, 0.12) 45%, transparent 47%),
    repeating-linear-gradient(45deg, rgba(17, 17, 17, 0.055) 0 1px, transparent 1px 8px);
}

.encounter-active[data-anomaly-effect="blank"] .app::after {
  background:
    linear-gradient(180deg, transparent 0 22%, rgba(247, 247, 245, 0.68) 22% 31%, transparent 31% 100%),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.045) 0 1px, transparent 1px 12px);
  animation-name: anomaly-blank-breathe;
}

.encounter-active[data-anomaly-effect="pulse"] .app::after {
  background:
    radial-gradient(ellipse at 50% 52%, transparent 0 24%, rgba(17, 17, 17, 0.11) 25%, transparent 27%),
    repeating-linear-gradient(90deg, rgba(17, 17, 17, 0.04) 0 1px, transparent 1px 11px);
  animation-name: anomaly-pulse-field;
}

.encounter-active[data-anomaly-effect="grain"] .app::after {
  background:
    repeating-radial-gradient(circle at 30% 40%, rgba(17, 17, 17, 0.055) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.035) 0 1px, transparent 1px 8px);
  animation-name: anomaly-grain-shift;
}

.encounter-active[data-anomaly-effect="miscount"] .app::after {
  background:
    linear-gradient(90deg, transparent 0 18%, rgba(17, 17, 17, 0.1) 18% 19%, transparent 19% 36%, rgba(17, 17, 17, 0.07) 36% 37%, transparent 37%),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.04) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(90deg, transparent 0 23px, rgba(17, 17, 17, 0.045) 23px 24px, transparent 24px 31px);
  animation-name: anomaly-miscount-drift;
}

.encounter-active[data-anomaly-effect="mirror"] .app::after {
  background:
    linear-gradient(90deg, rgba(247, 247, 245, 0.56), transparent 20%, rgba(17, 17, 17, 0.08) 49% 51%, transparent 80%, rgba(247, 247, 245, 0.48)),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.04) 0 1px, transparent 1px 10px);
  animation-name: anomaly-mirror-drift;
}

.encounter-active[data-anomaly-effect="redact"] .app::after {
  background:
    linear-gradient(180deg, transparent 0 15%, rgba(17, 17, 17, 0.2) 15% 18%, transparent 18% 42%, rgba(17, 17, 17, 0.16) 42% 46%, transparent 46% 72%, rgba(17, 17, 17, 0.18) 72% 74%, transparent 74%),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.035) 0 1px, transparent 1px 9px);
  animation-name: anomaly-redact-slide;
}

.encounter-active[data-anomaly-effect="return"] .app::after {
  background:
    repeating-linear-gradient(135deg, transparent 0 18px, rgba(17, 17, 17, 0.08) 18px 20px, transparent 20px 34px),
    repeating-linear-gradient(45deg, transparent 0 26px, rgba(17, 17, 17, 0.055) 26px 28px, transparent 28px 42px),
    linear-gradient(90deg, rgba(247, 247, 245, 0.28), transparent 45%, rgba(17, 17, 17, 0.1), transparent);
  animation-name: anomaly-return-loop;
}

.encounter-active[data-anomaly-effect="lull"] .app::after {
  background:
    radial-gradient(ellipse at 50% 72%, rgba(247, 247, 245, 0.72), transparent 38%),
    linear-gradient(180deg, rgba(247, 247, 245, 0.42), transparent 40%, rgba(17, 17, 17, 0.08)),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.025) 0 1px, transparent 1px 14px);
  animation-name: anomaly-lull-sink;
}

.encounter-active[data-anomaly-effect="needle"] .app::after {
  background:
    repeating-linear-gradient(100deg, transparent 0 15px, rgba(17, 17, 17, 0.08) 15px 16px, transparent 16px 30px),
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(17, 17, 17, 0.07) 23px 24px, transparent 24px 39px),
    linear-gradient(180deg, rgba(247, 247, 245, 0.2), transparent 42%, rgba(17, 17, 17, 0.1));
  animation-name: anomaly-needle-rain;
}

.encounter-active[data-encounter-severity="low"] .app::after {
  opacity: 0.36;
}

.encounter-active[data-encounter-severity="low"] .app::before {
  opacity: 0.26;
}

.encounter-active[data-encounter-severity="mid"] .app::after {
  opacity: 0.48;
}

.encounter-active[data-encounter-severity="mid"] .app::before {
  opacity: 0.38;
}

.encounter-active[data-encounter-severity="high"] .app::after {
  opacity: 0.62;
}

.encounter-active[data-encounter-severity="high"] .app::before {
  opacity: 0.52;
}

.purity-low .room-panel,
.purity-low .control-panel,
.purity-low .log-panel {
  box-shadow:
    inset 0 0 0 999px rgba(255, 255, 255, 0.08),
    inset 1px 0 0 rgba(255, 255, 255, 0.82),
    inset -1px 0 0 rgba(17, 17, 17, 0.1),
    2px 0 0 rgba(17, 17, 17, 0.12);
  transform: translateX(1px);
}

.purity-low button::after {
  opacity: calc(0.14 + var(--purity-lock) * 0.48);
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0 2px, rgba(17, 17, 17, 0.2) 2px 3px, transparent 3px 7px),
    linear-gradient(90deg, rgba(247, 247, 245, 0.86), rgba(247, 247, 245, 0.58));
}

.purity-low .log-list li:nth-child(4n + 2) {
  color: color-mix(in srgb, var(--ink) 78%, var(--surface));
  text-shadow: 1px 0 rgba(255, 255, 255, 0.72);
}

.purity-low .status-grid article:nth-child(2) {
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.96) 0 5px, rgba(17, 17, 17, 0.05) 5px 6px),
    var(--surface-soft);
}

.purity-low .app::before {
  opacity: calc(var(--purity-whiteout) * 0.36);
  mix-blend-mode: normal;
}

.purity-critical .app::after {
  opacity: 0.46;
  background:
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.075) 0 1px, transparent 1px 8px),
    linear-gradient(90deg, transparent 0 36%, rgba(17, 17, 17, 0.08) 37%, transparent 39%),
    linear-gradient(180deg, rgba(247, 247, 245, 0.18), transparent 48%, rgba(247, 247, 245, 0.22));
  animation: purity-scan-drift 2.4s linear infinite;
}

.purity-critical .app::before {
  opacity: calc(0.18 + var(--purity-whiteout) * 0.52);
  mix-blend-mode: normal;
}

.purity-critical .status-grid strong,
.purity-critical .art-readout,
.purity-critical .monitor-strip {
  animation: purity-value-flicker 3.2s steps(1, end) infinite;
}

.purity-critical .room-panel,
.purity-critical .control-panel,
.purity-critical .log-panel {
  border-color: rgba(17, 17, 17, 0.72);
  box-shadow:
    inset 0 0 0 999px rgba(255, 255, 255, 0.18),
    3px 0 0 rgba(17, 17, 17, 0.22),
    -2px 0 0 rgba(255, 255, 255, 0.9);
}

.purity-critical .status-grid article,
.purity-critical .upgrade,
.purity-critical .actions button {
  transform: translateX(calc(var(--purity-lock) * 3px));
}

.purity-critical .log-list li:nth-child(3n) .log-text {
  color: transparent;
  text-shadow: 0 0 0 rgba(17, 17, 17, 0.36);
}

.purity-zero .app::before {
  opacity: 0.7;
  background:
    radial-gradient(ellipse at 50% 52%, rgba(247, 247, 245, 0.72), rgba(247, 247, 245, 0.22) 42%, transparent 68%),
    linear-gradient(180deg, rgba(247, 247, 245, 0.5), transparent 34%, rgba(247, 247, 245, 0.46));
  animation: purity-whiteout-breathe 2.2s ease-in-out infinite;
  mix-blend-mode: normal;
}

.purity-zero .app::after {
  opacity: 0.62;
  background:
    linear-gradient(90deg, transparent 0 18%, rgba(17, 17, 17, 0.1) 18.5%, transparent 19%),
    linear-gradient(90deg, transparent 0 63%, rgba(17, 17, 17, 0.08) 63.5%, transparent 64%),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.04) 0 1px, transparent 1px 10px);
  animation: purity-line-drift 2.8s linear infinite;
}

.purity-zero .control-panel {
  filter: contrast(0.78) brightness(1.2);
}

.purity-zero .room-panel,
.purity-zero .control-panel,
.purity-zero .log-panel {
  background: rgba(255, 255, 255, 0.88);
  box-shadow:
    inset 0 0 0 999px rgba(255, 255, 255, 0.28),
    0 0 0 2px rgba(255, 255, 255, 0.9);
}

.purity-zero .actions button {
  transition-duration: 320ms;
}

.purity-zero .status-grid span,
.purity-zero .art-readout span {
  animation: purity-label-drop 4s steps(1, end) infinite;
}

.disconnect-active[data-disconnect-reason="sterility"] .app::before {
  opacity: 0.96;
  background:
    radial-gradient(ellipse at 50% 48%, rgba(255, 255, 255, 0.98) 0 32%, rgba(247, 247, 245, 0.94) 58%, rgba(247, 247, 245, 1) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(247, 247, 245, 1) 52%, rgba(255, 255, 255, 1));
  animation: sterility-whiteout 2.2s ease-out both;
  mix-blend-mode: normal;
}

.disconnect-active[data-disconnect-reason="sterility"] .app::after {
  opacity: 0.56;
  background:
    linear-gradient(90deg, transparent 0 9%, rgba(17, 17, 17, 0.16) 9.2%, transparent 9.7%),
    linear-gradient(90deg, transparent 0 48%, rgba(17, 17, 17, 0.1) 48.3%, transparent 48.8%),
    linear-gradient(90deg, transparent 0 84%, rgba(17, 17, 17, 0.14) 84.2%, transparent 84.8%),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.05) 0 1px, transparent 1px 18px);
  animation: purity-line-drift 2.2s linear infinite;
}

.disconnect-active[data-disconnect-reason="sterility"] .room-panel,
.disconnect-active[data-disconnect-reason="sterility"] .control-panel,
.disconnect-active[data-disconnect-reason="sterility"] .log-panel {
  border-color: rgba(17, 17, 17, 0.18);
  background: rgba(255, 255, 255, 0.96);
  color: color-mix(in srgb, var(--ink) 26%, var(--white));
  filter: contrast(0.62) brightness(1.34);
}

.disconnect-active[data-disconnect-reason="sterility"] button,
.disconnect-active[data-disconnect-reason="sterility"] .status-grid article,
.disconnect-active[data-disconnect-reason="sterility"] .stage-hud,
.disconnect-active[data-disconnect-reason="sterility"] .subject-card,
.disconnect-active[data-disconnect-reason="sterility"] .audio-panel {
  border-color: rgba(17, 17, 17, 0.12);
  background: rgba(255, 255, 255, 0.9);
  color: color-mix(in srgb, var(--ink) 18%, var(--white));
}

.disconnect-active[data-disconnect-reason="sterility"] .mio-line,
.disconnect-active[data-disconnect-reason="sterility"] .log-list,
.disconnect-active[data-disconnect-reason="sterility"] .art-readout,
.disconnect-active[data-disconnect-reason="sterility"] .monitor-strip {
  opacity: 0.18;
}

.sterility-lost .room-panel,
.sterility-lost .control-panel,
.sterility-lost .log-panel {
  pointer-events: none;
}

.room-panel,
.control-panel,
.log-panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--ink);
  background: var(--surface-panel);
}

.room-panel::after,
.control-panel::after,
.log-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
  background:
    repeating-linear-gradient(90deg, rgba(17, 17, 17, 0.04) 0 1px, transparent 1px 12px),
    linear-gradient(180deg, transparent, rgba(17, 17, 17, 0.06), transparent);
  transition: opacity 180ms ease;
}

.encounter-active .room-panel::after,
.encounter-active .control-panel::after,
.encounter-active .log-panel::after {
  opacity: 0.2;
  animation: encounter-field-drift 1.8s linear infinite;
}

.encounter-active[data-encounter-severity="high"] .room-panel::after,
.encounter-active[data-encounter-severity="high"] .control-panel::after,
.encounter-active[data-encounter-severity="high"] .log-panel::after {
  opacity: 0.32;
}

.room-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  height: 100%;
}

.room-grid {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 42%, transparent 0 20%, rgba(0, 0, 0, 0.04) 42%, transparent 64%),
    linear-gradient(0deg, transparent 0 82%, rgba(0, 0, 0, 0.11) 82% 82.4%, transparent 82.4%);
}

.monitor-strip {
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--ink);
  padding: 10px 12px;
  background: rgba(242, 242, 239, 0.96);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.monitor-controls {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  white-space: nowrap;
}

.audio-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  min-width: 28px;
  min-height: 28px;
  height: 28px;
  padding: 0;
  border-color: var(--dim);
  border-radius: 4px;
  background: var(--surface-soft);
  font-size: 15px;
  line-height: 1;
  text-align: center;
}

.audio-toggle::after {
  content: none;
}

.audio-toggle.is-muted {
  color: var(--dim);
}

.audio-toggle.is-muted::before {
  content: "";
  position: absolute;
  inset: 5px 13px;
  width: 1px;
  background: currentColor;
  transform: rotate(-38deg);
}

.audio-next {
  font-size: 16px;
}

.audio-settings {
  font-size: 16px;
}

.audio-settings::before {
  content: none;
}

.audio-panel {
  position: absolute;
  z-index: 8;
  top: 48px;
  right: 18px;
  display: grid;
  gap: 12px;
  border: 1px solid var(--ink);
  width: min(340px, calc(100vw - 36px));
  padding: 12px;
  background: color-mix(in srgb, var(--surface) 94%, var(--white));
  box-shadow: 0 12px 24px rgb(0 0 0 / 16%);
}

.audio-panel[hidden] {
  display: none;
}

.audio-panel-actions {
  display: grid;
  grid-template-columns: repeat(3, 28px);
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.audio-now-playing {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.audio-now-playing span {
  color: var(--dim);
  font-size: 11px;
}

.audio-now-playing strong {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.audio-seek-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.audio-seek-row span {
  color: var(--dim);
  text-align: center;
}

.audio-volume-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 30px auto 16px;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.audio-mute-label {
  color: var(--dim);
  font-size: 11px;
  line-height: 1;
}

.audio-panel input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--ink);
}

.audio-panel input[type="range"] {
  width: 100%;
  accent-color: var(--ink);
}

.audio-panel output {
  color: var(--dim);
  font-size: 12px;
  text-align: right;
}

.subject-stage {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

.stage-hud-stack {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
  gap: 8px;
  border-bottom: 1px solid var(--ink);
  padding: 6px;
  background: rgba(239, 239, 236, 0.92);
}

.art-frame {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
}

.art-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background:
    linear-gradient(90deg, transparent 0 48%, rgba(17, 17, 17, 0.18) 49%, transparent 50%),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.08) 0 1px, transparent 1px 7px);
}

.mio-illustration {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 58%;
  filter: grayscale(1) contrast(1.1) brightness(0.98);
}

.encounter-active .mio-illustration {
  animation: encounter-image-drift 760ms steps(2, end) infinite;
  filter: grayscale(1) contrast(1.12) brightness(0.98);
}

.encounter-active .art-frame::after {
  opacity: 0.18;
  animation: encounter-scan 620ms linear infinite;
}

.art-glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 32%, rgba(0, 0, 0, 0.08)),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.035) 0 1px, transparent 1px 5px);
  mix-blend-mode: multiply;
}

.encounter-active .art-glass {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 24%, rgba(0, 0, 0, 0.14)),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.07) 0 1px, transparent 1px 4px);
}

.disconnect-active .mio-illustration {
  animation: none;
  filter: grayscale(1) contrast(1.08) brightness(0.92);
}

.disconnect-active .art-frame::after {
  opacity: 0.16;
  animation: encounter-scan 900ms linear infinite;
}

.purity-critical .mio-illustration {
  filter: grayscale(1) contrast(0.9) brightness(1.12) saturate(0.4);
}

.purity-zero .mio-illustration,
.disconnect-active[data-disconnect-reason="sterility"] .mio-illustration {
  filter: grayscale(1) contrast(0.72) brightness(1.24) opacity(0.72);
}

.art-readout {
  position: absolute;
  left: 14px;
  top: 14px;
  display: grid;
  gap: 5px;
  border: 1px solid rgba(17, 17, 17, 0.72);
  padding: 9px 11px;
  background: rgba(247, 247, 245, 0.78);
  color: var(--ink);
  font-size: 12px;
  text-transform: uppercase;
}

.iv-stand {
  position: absolute;
  top: 50px;
  right: 16%;
  width: 90px;
  height: 370px;
}

.iv-bag {
  position: absolute;
  left: 7px;
  width: 40px;
  height: 74px;
  border: 2px solid var(--ink);
  border-radius: 4px 4px 12px 12px;
  background: linear-gradient(var(--surface-soft) 0 48%, var(--pale) 48% 100%);
}

.iv-pole {
  position: absolute;
  top: 0;
  right: 20px;
  width: 2px;
  height: 330px;
  background: var(--ink);
}

.black-route {
  position: absolute;
  top: 118px;
  right: 19%;
  width: 31%;
  height: 210px;
  border-top: 5px solid var(--ink);
  border-left: 5px solid var(--ink);
  border-radius: 80px 0 0 0;
  transform: rotate(-5deg);
  transform-origin: right top;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.35));
}

.chair {
  position: absolute;
  left: 50%;
  bottom: 52px;
  width: 280px;
  height: 330px;
  transform: translateX(-50%);
}

.chair-back,
.chair-seat {
  position: absolute;
  border: 2px solid var(--ink);
  background: linear-gradient(135deg, var(--paper), var(--surface-soft));
}

.chair-back {
  left: 66px;
  top: 16px;
  width: 150px;
  height: 210px;
  transform: skewX(-4deg);
}

.chair-seat {
  left: 40px;
  bottom: 46px;
  width: 200px;
  height: 74px;
}

.chair-base {
  position: absolute;
  left: 132px;
  bottom: 0;
  width: 18px;
  height: 68px;
  background: var(--ink);
}

.chair-base::after {
  content: "";
  position: absolute;
  left: -72px;
  bottom: 0;
  width: 160px;
  height: 2px;
  background: var(--ink);
}

.mio {
  position: absolute;
  left: 50%;
  bottom: 102px;
  width: 178px;
  height: 300px;
  margin: 0;
  transform: translateX(-50%);
}

.mio-hair {
  position: absolute;
  left: 34px;
  top: 0;
  width: 110px;
  height: 128px;
  border: 2px solid var(--ink);
  border-bottom: 0;
  border-radius: 52px 52px 34px 34px;
  background: linear-gradient(120deg, var(--surface-soft), #d8d8d8);
}

.mio-face {
  position: absolute;
  left: 48px;
  top: 46px;
  width: 82px;
  height: 86px;
  border: 2px solid var(--ink);
  border-radius: 44px 44px 38px 38px;
  background: #f4f4f2;
}

.eye {
  position: absolute;
  top: 38px;
  width: 12px;
  height: 5px;
  border-bottom: 2px solid var(--dim);
}

.eye-left {
  left: 18px;
}

.eye-right {
  right: 18px;
}

.mio-neck {
  position: absolute;
  left: 76px;
  top: 126px;
  width: 26px;
  height: 34px;
  border-left: 2px solid var(--ink);
  border-right: 2px solid var(--ink);
  background: var(--white);
}

.mio-gown {
  position: absolute;
  left: 18px;
  top: 154px;
  width: 142px;
  height: 138px;
  border: 2px solid var(--ink);
  border-radius: 42px 42px 8px 8px;
  background:
    linear-gradient(90deg, transparent 0 49%, rgba(0, 0, 0, 0.18) 49% 50.5%, transparent 50.5%),
    var(--surface-soft);
}

.route-pin {
  position: absolute;
  right: 28px;
  top: 34px;
  width: 10px;
  height: 10px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--ink);
}

@keyframes encounter-image-drift {
  0%, 100% { transform: translate(0, 0); }
  33% { transform: translate(1px, -1px); }
  66% { transform: translate(-1px, 1px); }
}

@keyframes encounter-scan {
  from { background-position: 0 0, 0 0; }
  to { background-position: 18px 0, 0 14px; }
}

@keyframes encounter-field-drift {
  from { background-position: 0 0, -120px 0; }
  to { background-position: 0 18px, 120px 0; }
}

@keyframes anomaly-echo-drift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 28px 0, 0 18px; }
}

@keyframes anomaly-afterimage-shift {
  0%, 100% { background-position: 0 0, 0 0, 0 0; }
  50% { background-position: 10px 0, -8px 0, 0 12px; }
}

@keyframes anomaly-blank-breathe {
  0%, 100% { opacity: 0.12; }
  50% { opacity: 0.24; }
}

@keyframes anomaly-pulse-field {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.006); }
}

@keyframes anomaly-grain-shift {
  from { background-position: 0 0, 0 0; }
  to { background-position: 13px 7px, 0 16px; }
}

@keyframes anomaly-miscount-drift {
  0%, 100% { background-position: 0 0, 0 0, 0 0; }
  35% { background-position: 9px 0, 0 6px, 31px 0; }
  70% { background-position: -4px 0, 0 15px, 8px 0; }
}

@keyframes anomaly-mirror-drift {
  0%, 100% { background-position: 0 0, 0 0; }
  50% { background-position: 18px 0, 0 12px; }
}

@keyframes anomaly-redact-slide {
  from { background-position: 0 -12px, 0 0; }
  to { background-position: 0 24px, 0 18px; }
}

@keyframes anomaly-return-loop {
  from { background-position: 0 0, 0 0, -80px 0; }
  to { background-position: -34px 34px, 42px 42px, 80px 0; }
}

@keyframes anomaly-lull-sink {
  0%, 100% { transform: translateY(0); filter: blur(0.2px); }
  50% { transform: translateY(2px); filter: blur(0.9px); }
}

@keyframes anomaly-needle-rain {
  from { background-position: 0 -40px, 0 -20px, 0 0; }
  to { background-position: 18px 48px, 0 39px, 0 0; }
}

@keyframes anomaly-vignette-breathe {
  0%, 100% { transform: scale(1); filter: blur(0.2px); }
  50% { transform: scale(1.012); filter: blur(0.8px); }
}

@keyframes purity-scan-drift {
  from { background-position: 0 0, -36px 0, 0 0; }
  to { background-position: 0 18px, 36px 0, 0 0; }
}

@keyframes purity-value-flicker {
  0%, 88%, 100% { opacity: 1; transform: translateX(0); }
  89% { opacity: 0.72; transform: translateX(1px); }
  91% { opacity: 0.92; transform: translateX(-1px); }
}

@keyframes purity-whiteout-breathe {
  0%, 100% { filter: blur(0); }
  50% { filter: blur(0.7px); }
}

@keyframes purity-line-drift {
  from { background-position: -12px 0, 18px 0, 0 0; }
  to { background-position: 12px 0, -18px 0, 0 22px; }
}

@keyframes purity-label-drop {
  0%, 84%, 100% { opacity: 1; }
  85%, 87% { opacity: 0.08; }
  88% { opacity: 0.7; }
}

@keyframes sterility-whiteout {
  0% { opacity: 0; transform: scale(0.992); filter: blur(0); }
  42% { opacity: 0.72; filter: blur(0.4px); }
  100% { opacity: 0.96; transform: scale(1); filter: blur(1.1px); }
}

.subject-card {
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--ink);
  padding: 12px;
  background: rgba(239, 239, 236, 0.94);
}

.subject-card > div {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--dim);
  font-size: 13px;
  text-transform: uppercase;
  white-space: nowrap;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(20px, 2.5vw, 34px);
  font-weight: 500;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  font-weight: 500;
}

.mio-line {
  flex: 0 0 auto;
  max-width: none;
  margin: 0;
  color: var(--soft-ink);
  font-size: clamp(15px, 1.25vw, 17px);
  text-align: right;
  white-space: nowrap;
}

.control-panel,
.log-panel {
  padding: 14px;
}

.control-panel {
  overflow: auto;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.status-grid article {
  min-height: 52px;
  border: 1px solid var(--ink);
  padding: 8px 9px;
  background: var(--surface-soft);
}

.status-grid span {
  display: block;
  color: var(--dim);
  overflow: hidden;
  font-size: 12px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-grid strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  font-size: clamp(19px, 2.1vw, 26px);
  font-weight: 500;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dream-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
  border: 1px solid var(--ink);
  height: 86px;
  min-height: 0;
  padding: 9px 10px;
  background: var(--surface-soft);
}

.stage-hud {
  width: 100%;
  height: 86px;
  margin: 0;
  background: transparent;
}

.dream-panel.stage-hud,
.encounter-panel.stage-hud {
  margin-top: 0;
  background: var(--surface-soft);
}

.stage-hud h2 {
  overflow: hidden;
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-hud .eyebrow {
  margin: 0;
  font-size: 12px;
  line-height: 1.2;
}

.dream-panel p:last-child {
  max-width: none;
  margin: 0;
  color: var(--dim);
  overflow: hidden;
  font-size: 13px;
  line-height: 1.25;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.encounter-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
  border: 1px solid var(--ink);
  height: 86px;
  min-height: 0;
  padding: 9px 10px;
  background: var(--surface-soft);
}

.encounter-panel.is-active {
  background:
    repeating-linear-gradient(90deg, rgba(17, 17, 17, 0.035) 0 1px, transparent 1px 8px),
    var(--surface-soft);
  animation: encounter-panel-pulse 1.2s steps(2, end) infinite;
}

.encounter-panel p:not(.eyebrow) {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  margin: 0;
  color: var(--dim);
  overflow: hidden;
  font-size: 13px;
  line-height: 1.25;
  text-align: left;
  text-overflow: clip;
  white-space: normal;
}

@keyframes encounter-panel-pulse {
  0%, 100% { box-shadow: inset 0 0 0 0 rgba(17, 17, 17, 0); }
  50% { box-shadow: inset 0 0 0 2px rgba(17, 17, 17, 0.16); }
}

.disconnect-overlay {
  position: fixed;
  left: 50%;
  top: 16px;
  z-index: 20;
  display: grid;
  gap: 4px;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%);
  border: 1px solid var(--ink);
  padding: 10px 14px;
  background: rgba(247, 247, 245, 0.94);
  color: var(--ink);
  text-align: center;
  text-transform: uppercase;
  transition: opacity 180ms ease;
}

.disconnect-overlay span {
  font-size: 14px;
  letter-spacing: 0;
}

.disconnect-overlay small {
  font-size: 13px;
  letter-spacing: 0;
}

.disconnect-active .disconnect-overlay {
  opacity: 1;
}

.disconnect-active[data-disconnect-reason="sterility"] .disconnect-overlay {
  inset: 0;
  z-index: 24;
  place-content: center;
  justify-items: center;
  min-width: 0;
  pointer-events: auto;
  transform: none;
  border: 0;
  padding: clamp(26px, 5vw, 48px) clamp(20px, 6vw, 58px);
  background:
    radial-gradient(ellipse at 50% 46%, rgba(255, 255, 255, 0.9) 0 22%, rgba(247, 247, 245, 0.9) 60%, rgba(247, 247, 245, 0.96) 100%),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.045) 0 1px, transparent 1px 11px);
  box-shadow: none;
  isolation: isolate;
  animation: sterility-overlay-arrive 680ms ease-out both;
}

.disconnect-active[data-disconnect-reason="sterility"] .disconnect-overlay::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 0;
  width: min(680px, calc(100vw - 28px));
  height: min(380px, calc(100vh - 28px));
  transform: translate(-50%, -50%);
  border: 2px solid rgba(17, 17, 17, 0.9);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 247, 245, 0.96)),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.045) 0 1px, transparent 1px 11px);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.94),
    0 24px 72px rgba(17, 17, 17, 0.2);
}

.disconnect-active[data-disconnect-reason="sterility"] .disconnect-overlay > * {
  position: relative;
  z-index: 1;
}

.disconnect-active[data-disconnect-reason="sterility"] .disconnect-overlay span {
  font-size: clamp(38px, 8vw, 88px);
  line-height: 0.95;
  white-space: nowrap;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.86);
}

.disconnect-active[data-disconnect-reason="sterility"] .disconnect-overlay small {
  margin-top: 14px;
  font-size: clamp(16px, 2.4vw, 24px);
  line-height: 1.35;
  text-transform: none;
}

.sterility-restart {
  justify-self: center;
  margin-top: 24px;
  min-width: min(320px, 100%);
  min-height: 64px;
  padding: 0 34px;
  border-width: 3px;
  border-color: #000;
  background: #000;
  color: #fff;
  font-size: clamp(20px, 3.4vw, 32px);
  font-weight: 700;
  line-height: 1;
  opacity: 1;
  box-shadow:
    0 0 0 5px rgba(255, 255, 255, 0.98),
    0 0 0 8px rgba(17, 17, 17, 0.18),
    0 12px 34px rgba(0, 0, 0, 0.34);
  text-transform: uppercase;
}

.disconnect-active[data-disconnect-reason="sterility"] .sterility-restart {
  border-color: #000;
  background: #000;
  color: #fff;
  opacity: 1;
}

.sterility-restart::after {
  content: none;
}

.disconnect-active[data-disconnect-reason="sterility"] .sterility-restart:hover {
  background: var(--white);
  color: var(--ink);
}

.disconnect-active[data-disconnect-reason="sterility"] .sterility-restart:focus-visible {
  outline: 4px solid var(--ink);
  outline-offset: 6px;
}

@keyframes sterility-overlay-arrive {
  from { opacity: 0; }
  to { opacity: 1; }
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr minmax(150px, 1.25fr);
  gap: 8px;
  margin-top: 10px;
}

.actions button {
  padding-inline: 8px;
  line-height: 1.2;
}

.upgrade-list {
  margin-top: 14px;
}

.upgrade-list h2 {
  margin-bottom: 10px;
}

.upgrade {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.24), transparent 42%),
    var(--surface-soft);
  text-align: left;
}

.upgrade span {
  display: grid;
  gap: 5px;
}

.upgrade strong {
  font-size: 18px;
  line-height: 1.15;
}

.upgrade small {
  color: var(--dim);
  font-size: 16px;
  line-height: 1.2;
}

.upgrade em {
  min-width: 72px;
  font-size: 26px;
  line-height: 1;
  font-style: normal;
  text-align: right;
}

.log-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100%;
  min-height: 320px;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--ink);
  min-height: 44px;
  padding-bottom: 10px;
}

.log-header-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.save-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(247, 247, 245, 0.74), rgba(247, 247, 245, 0.86)),
    repeating-linear-gradient(0deg, rgba(17, 17, 17, 0.035) 0 1px, transparent 1px 12px);
}

.save-modal[hidden] {
  display: none;
}

.save-dialog {
  width: min(620px, 100%);
  border: 1px solid var(--ink);
  padding: 14px;
  background:
    repeating-linear-gradient(90deg, rgba(17, 17, 17, 0.025) 0 1px, transparent 1px 9px),
    var(--surface-panel);
  color: var(--ink);
  box-shadow: 0 20px 64px rgba(17, 17, 17, 0.2);
}

.save-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 10px;
}

.save-dialog-header h2 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 24px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-tools {
  display: grid;
  gap: 10px;
  padding-top: 12px;
}

.save-tools textarea {
  width: 100%;
  min-width: 0;
  min-height: 168px;
  resize: vertical;
  border: 1px solid var(--ink);
  border-radius: 4px;
  padding: 10px;
  background: var(--surface-soft);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  word-break: break-all;
}

.save-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.save-dialog-actions .ghost-button {
  min-width: 78px;
}

.reset-dialog {
  width: min(460px, 100%);
}

.reset-confirm-body {
  display: grid;
  gap: 16px;
  padding-top: 14px;
}

.reset-confirm-body p {
  margin: 0;
  color: var(--soft-ink);
  font-size: 15px;
  line-height: 1.5;
}

.danger-button {
  border-color: #000;
  background: #000;
  color: #fff;
}

.danger-button:hover:not(:disabled) {
  background: var(--ink);
  color: #fff;
}

.log-header h2 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 24px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ghost-button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  font-size: 14px;
}

.log-list {
  list-style: none;
  overflow: auto;
  min-height: 0;
  margin: 0;
  padding: 12px 0 0;
  font-size: 16px;
  line-height: 1.75;
}

.log-list li {
  margin-bottom: 12px;
}

.log-list li.is-fading {
  color: color-mix(in srgb, var(--ink) 42%, transparent);
  letter-spacing: 0;
}

.log-list time {
  display: block;
  color: var(--dim);
  font-size: 12px;
  line-height: 16px;
  margin-bottom: 7px;
}

.log-text {
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .purity-critical .app::after,
  .purity-critical .status-grid strong,
  .purity-critical .art-readout,
  .purity-critical .monitor-strip,
  .purity-zero .app::before,
  .purity-zero .app::after,
  .purity-zero .status-grid span,
  .purity-zero .art-readout span,
  .disconnect-active[data-disconnect-reason="sterility"] .app::before,
  .disconnect-active[data-disconnect-reason="sterility"] .app::after,
  .disconnect-active[data-disconnect-reason="sterility"] .disconnect-overlay {
    animation: none;
  }

  .disconnect-active[data-disconnect-reason="sterility"] .app::before {
    opacity: 0.94;
  }

  .purity-critical .app::after,
  .purity-zero .app::after {
    opacity: 0.16;
  }
}

@media (max-width: 1120px) {
  .app {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
    height: auto;
  }

  .room-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .room-panel {
    min-height: 540px;
  }

  .subject-stage {
    min-height: 390px;
  }

  .stage-hud-stack {
    grid-template-columns: 1fr;
  }

  .monitor-strip,
  .subject-card,
  .dream-panel {
    flex-direction: column;
    align-items: stretch;
  }

  .mio-line,
  .dream-panel p:last-child {
    max-width: none;
    text-align: left;
  }

  .encounter-panel {
    grid-template-columns: 1fr;
  }

  .encounter-panel p:not(.eyebrow) {
    text-align: left;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .iv-stand {
    right: 6%;
  }

  .black-route {
    right: 11%;
    width: 38%;
  }
}
