:root {
  color-scheme: dark;
  --ink: #10121f;
  --paper: #fff5d6;
  --muted: #abb7c7;
  --panel: rgba(20, 23, 38, 0.78);
  --panel-strong: rgba(13, 16, 30, 0.9);
  --line: #29324f;
  --accent: #ffcf58;
  --accent-2: #6df0c2;
  --danger: #f05a63;
  --button-size: 38px;
  font-family: "Press Start 2P", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  height: 100%;
  background: #080a14;
  scroll-behavior: smooth;
  overflow: hidden;
}

body {
  margin: 0;
  width: 100%;
  height: 100dvh;
  background:
    linear-gradient(180deg, #080a14 0%, #11172a 46%, #161927 100%);
  color: var(--paper);
  overflow: hidden;
  overscroll-behavior: none;
}

button,
a {
  font: inherit;
}

.site-header {
  position: fixed;
  z-index: 20;
  top: max(10px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
  isolation: isolate;
}

.site-header::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: -12px;
  left: -12px;
  right: -12px;
  height: 96px;
  background:
    linear-gradient(180deg, rgba(7, 10, 20, 0.76), rgba(7, 10, 20, 0.28) 70%, rgba(7, 10, 20, 0));
  pointer-events: none;
}

.brand {
  display: grid;
  gap: 4px;
  width: max-content;
  max-width: min(206px, calc(100vw - 24px));
  padding: 6px 8px;
  color: var(--paper);
  text-decoration: none;
  background: var(--panel);
  border: 2px solid rgba(255, 245, 214, 0.2);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.35), inset 0 0 0 2px rgba(109, 240, 194, 0.06);
  pointer-events: auto;
  backdrop-filter: blur(8px);
  image-rendering: pixelated;
}

.brand-title {
  font-size: clamp(9px, 1.1vw, 12px);
  line-height: 1.3;
}

.brand-subtitle {
  color: var(--muted);
  font-size: clamp(6px, 0.72vw, 7px);
  line-height: 1.4;
}

.world-controls {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
  max-width: calc(100vw - 278px);
  flex-wrap: wrap;
  pointer-events: auto;
  padding: 5px;
  background: rgba(9, 12, 22, 0.62);
  border: 2px solid rgba(255, 245, 214, 0.12);
  border-radius: 9px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(6px);
}

.control-button {
  display: inline-grid;
  place-items: center;
  min-width: var(--button-size);
  max-width: 82px;
  height: var(--button-size);
  padding: 0 7px;
  color: var(--paper);
  background: var(--panel-strong);
  border: 2px solid rgba(255, 245, 214, 0.22);
  border-radius: 7px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.42), inset 0 0 0 2px rgba(255, 207, 88, 0.04);
  cursor: pointer;
  font-size: 8px;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.control-button-wide {
  min-width: 64px;
  padding: 0 6px;
}

.language-switch {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.control-button-lang {
  min-width: 34px;
  padding: 0 6px;
}

.control-button-lang.is-active {
  color: #10121f;
  background: var(--accent);
  border-color: #fff2b4;
}

.control-button:hover {
  border-color: rgba(255, 207, 88, 0.8);
  background: #1d2642;
}

.control-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
}

.main-demo-shell {
  height: 100dvh;
  overflow: hidden;
}

.world-shell {
  position: relative;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: #10182c;
}

#hospital-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #11172a;
}

#hospital-canvas.is-dragging {
  cursor: grabbing;
}

.world-vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 7, 14, 0.55) 0%, rgba(5, 7, 14, 0) 16%, rgba(5, 7, 14, 0) 72%, rgba(5, 7, 14, 0.5) 100%),
    radial-gradient(circle at center, rgba(255, 255, 255, 0) 42%, rgba(4, 6, 13, 0.2) 100%);
  mix-blend-mode: multiply;
}

.boot-loading,
.boot-error,
.first-run-hint,
.small-viewport-fallback {
  position: absolute;
  z-index: 31;
  color: var(--paper);
  background:
    linear-gradient(180deg, rgba(17, 22, 39, 0.94), rgba(12, 16, 30, 0.88));
  border: 2px solid rgba(255, 245, 214, 0.24);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.38), inset 0 0 0 2px rgba(109, 240, 194, 0.055);
  image-rendering: pixelated;
  backdrop-filter: blur(6px);
}

.boot-loading {
  left: 50%;
  top: 50%;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  transform: translate(-50%, -50%);
  font-size: 9px;
  line-height: 1.5;
}

.is-demo-ready .boot-loading {
  display: none;
}

.pixel-loader {
  width: 22px;
  height: 22px;
  background:
    linear-gradient(90deg, var(--accent) 0 45%, transparent 45% 55%, var(--accent-2) 55% 100%);
  box-shadow: 0 0 0 2px rgba(255, 245, 214, 0.22);
  animation: pixel-loader-step 900ms steps(2, end) infinite;
}

@keyframes pixel-loader-step {
  0% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
  100% { transform: translateY(0); }
}

.boot-error {
  left: 50%;
  top: 50%;
  display: grid;
  gap: 10px;
  width: min(440px, calc(100vw - 32px));
  padding: 14px;
  transform: translate(-50%, -50%);
  font-size: 9px;
  line-height: 1.6;
}

.boot-error strong,
.small-viewport-fallback strong {
  color: var(--accent);
  font-weight: 400;
}

.first-run-hint {
  left: max(14px, env(safe-area-inset-left));
  top: 104px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 26px;
  gap: 10px;
  width: min(420px, calc(100vw - 28px));
  padding: 10px 10px 10px 12px;
  font-size: 8px;
  line-height: 1.65;
  pointer-events: auto;
}

.hint-close,
.small-viewport-continue {
  color: var(--paper);
  background: rgba(18, 24, 42, 0.92);
  border: 2px solid rgba(255, 245, 214, 0.24);
  cursor: pointer;
  font: inherit;
}

.hint-close {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  font-size: 12px;
  line-height: 1;
}

.small-viewport-fallback {
  left: 50%;
  top: 50%;
  display: grid;
  gap: 12px;
  width: min(480px, calc(100vw - 28px));
  padding: 14px;
  transform: translate(-50%, -50%);
  font-size: 9px;
  line-height: 1.7;
  pointer-events: auto;
}

.is-small-viewport-fallback .world-controls {
  visibility: hidden;
  pointer-events: none;
}

.small-viewport-continue {
  justify-self: start;
  min-height: 34px;
  padding: 0 12px;
  color: #10121f;
  background: var(--accent);
  border-color: #fff2b4;
  font-size: 8px;
}

.boot-error.is-hidden,
.first-run-hint.is-hidden,
.small-viewport-fallback.is-hidden {
  display: none;
}

.toast {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: 26px;
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 14px;
  color: #09101d;
  background: var(--accent-2);
  border: 2px solid #d8fff1;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.38);
  opacity: 0;
  transform: translateX(-50%) translateY(16px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
  font-size: 9px;
  line-height: 1.6;
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.activity-feed,
.hospital-inspector,
.hospital-tooltip {
  position: absolute;
  z-index: 12;
  color: var(--paper);
  background: rgba(13, 16, 30, 0.88);
  border: 2px solid rgba(255, 245, 214, 0.22);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.38), inset 0 0 0 2px rgba(109, 240, 194, 0.055);
  image-rendering: pixelated;
  backdrop-filter: blur(6px);
}

.activity-feed {
  left: max(14px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(276px, calc(100vw - 28px));
  max-height: min(86px, calc(100dvh - 132px));
  padding: 6px 8px 7px;
  overflow: hidden;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(17, 22, 39, 0.9), rgba(12, 16, 30, 0.82));
}

.activity-feed-title,
.inspector-kicker {
  color: var(--accent-2);
  font-size: 7px;
  line-height: 1.5;
}

.activity-feed-list {
  display: grid;
  gap: 3px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.activity-feed-list li {
  color: #e7edf7;
  font-size: 7px;
  line-height: 1.3;
}

.activity-feed-list li:nth-child(n + 5) {
  display: none;
}

.is-fit-all-view .activity-feed {
  width: min(236px, calc(100vw - 28px));
  max-height: 66px;
  padding: 5px 7px 6px;
  opacity: 0.9;
}

.is-fit-all-view .activity-feed-list li:nth-child(n + 5) {
  display: none;
}

@media (max-height: 760px) {
  .site-header::before {
    height: 88px;
  }

  .activity-feed {
    width: min(236px, calc(100vw - 28px));
    max-height: 70px;
    padding: 5px 7px 6px;
  }

  .activity-feed-list li:nth-child(n + 5) {
    display: none;
  }

  .first-run-hint {
    top: 92px;
    width: min(360px, calc(100vw - 28px));
    font-size: 7px;
  }
}

.hospital-inspector {
  right: max(14px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: min(342px, calc(100vw - 28px));
  max-height: min(500px, calc(100svh - 110px));
  padding: 12px;
  overflow: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
  background:
    linear-gradient(180deg, rgba(17, 22, 39, 0.92), rgba(12, 16, 30, 0.86));
}

.hospital-inspector.is-hidden,
.hospital-tooltip.is-hidden {
  display: none;
}

.inspector-close {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: var(--paper);
  background: rgba(18, 24, 42, 0.92);
  border: 2px solid rgba(255, 245, 214, 0.24);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}

.inspector-title {
  margin: 7px 34px 10px 0;
  color: #fff6cf;
  font-size: 10px;
  line-height: 1.5;
}

.inspector-body {
  display: grid;
  gap: 8px;
}

.inspector-row {
  display: grid;
  grid-template-columns: minmax(88px, 0.9fr) minmax(0, 1.1fr);
  gap: 8px;
  align-items: start;
  color: #b9c7d8;
  font-size: 8px;
  line-height: 1.65;
}

.inspector-row strong {
  color: #eef5ff;
  font-weight: 400;
  overflow-wrap: anywhere;
}

.inspector-events {
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 245, 214, 0.18);
}

.inspector-events-title {
  margin-bottom: 6px;
  color: var(--accent-2);
  font-size: 8px;
  line-height: 1.4;
}

.inspector-events ol {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.inspector-events li {
  color: #e7edf7;
  font-size: 8px;
  line-height: 1.5;
}

.hospital-tooltip {
  max-width: 280px;
  min-width: 96px;
  padding: 8px 9px;
  pointer-events: none;
  transform: translateZ(0);
  color: #fff6cf;
  font-size: 9px;
  line-height: 1.55;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.hospital-tooltip::after {
  content: "";
  position: absolute;
  left: 10px;
  bottom: -6px;
  width: 10px;
  height: 6px;
  background: rgba(13, 16, 30, 0.88);
  border-left: 2px solid rgba(255, 245, 214, 0.22);
  border-bottom: 2px solid rgba(255, 245, 214, 0.22);
}

.support-section {
  display: none;
  position: relative;
  padding: clamp(42px, 8vw, 92px) 20px clamp(54px, 8vw, 104px);
  background:
    linear-gradient(180deg, #141927 0%, #0d111d 100%);
  border-top: 4px solid #28304c;
}

.support-inner {
  width: min(920px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 18px;
  align-items: start;
}

.support-kicker {
  margin: 0;
  color: var(--accent-2);
  font-size: 8px;
  line-height: 1.6;
}

.support-inner h1 {
  margin: 0;
  max-width: 820px;
  color: var(--paper);
  font-size: clamp(18px, 3.2vw, 34px);
  line-height: 1.35;
  letter-spacing: 0;
}

.support-inner p {
  margin: 0;
  max-width: 780px;
  color: #d7dfeb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(15px, 1.6vw, 18px);
  line-height: 1.75;
}

.support-mail {
  display: inline-grid;
  place-items: center;
  justify-self: start;
  min-height: 46px;
  padding: 0 16px;
  color: #161314;
  text-decoration: none;
  background: var(--accent);
  border: 2px solid #fff2b4;
  border-radius: 8px;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.4);
  font-size: 9px;
  line-height: 1.4;
}

.support-mail:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
}

.mail-address {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.4;
}

@media (max-width: 820px) {
  .site-header {
    align-items: flex-start;
  }

  .brand {
    padding: 6px 8px;
  }

  .world-controls {
    position: fixed;
    left: 50%;
    right: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
    justify-content: center;
    gap: 6px;
    padding: 8px;
    overflow-x: auto;
    flex-wrap: nowrap;
    transform: translateX(-50%);
    background: rgba(9, 12, 22, 0.74);
    border: 2px solid rgba(255, 245, 214, 0.12);
    border-radius: 8px;
    backdrop-filter: blur(8px);
  }

  .control-button {
    flex: 0 0 auto;
    min-width: 38px;
    height: 38px;
    padding: 0 8px;
    font-size: 7px;
  }

  .control-button-wide {
    min-width: 66px;
    padding: 0 6px;
  }

  .control-button-lang {
    min-width: 34px;
  }

  .world-shell {
    height: 100dvh;
    min-height: 0;
  }

  .toast {
    bottom: 86px;
  }

  .activity-feed {
    width: min(236px, calc(100vw - 24px));
    max-height: 72px;
    padding: 6px 8px;
    bottom: 90px;
  }

  .first-run-hint {
    top: 74px;
    width: min(360px, calc(100vw - 24px));
  }

  .hospital-inspector {
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: 90px;
    width: auto;
    max-height: 44svh;
  }
}

@media (max-width: 480px) {
  .brand-title {
    font-size: 9px;
  }

  .brand-subtitle {
    font-size: 6px;
  }

  .world-shell {
    min-height: 0;
  }

  .support-mail {
    justify-self: stretch;
    text-align: center;
  }
}
