:root {
  color-scheme: dark;
  --ink: #070809;
  --panel: rgba(13, 15, 16, 0.92);
  --panel-solid: #101213;
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.24);
  --muted: #a9adb0;
  --paper: #f4f3ef;
  --red: #dc2638;
  --red-hot: #ff4052;
  --green: #53e07d;
  --amber: #ffc857;
  --cyan: #45c9da;
  font-family: "Cairo", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app,
#scene {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--ink);
  color: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

button {
  font: inherit;
}

.language-gate {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 6, 7, 0.9);
  backdrop-filter: blur(18px);
  transition: opacity 280ms ease, visibility 280ms ease;
}

.language-gate.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.language-dialog {
  width: min(680px, 100%);
  padding: 32px;
  border: 1px solid var(--line-strong);
  border-top: 3px solid var(--red);
  background: rgba(13, 15, 16, 0.98);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.72);
}

.language-brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.language-edition {
  margin-inline-start: auto;
  padding: 7px 9px;
  border: 1px solid var(--line);
  color: var(--muted);
  font: 500 8px/1 "Oswald", sans-serif;
}

.language-brand > div {
  display: grid;
  gap: 5px;
}

.language-brand strong {
  font: 600 23px/1 "Oswald", sans-serif;
}

.language-brand small {
  color: var(--muted);
  font: 500 9px/1 "Oswald", sans-serif;
}

.language-heading {
  margin: 30px 0 24px;
  text-align: center;
}

.language-heading > span {
  color: var(--red-hot);
  font: 600 9px/1 "Oswald", sans-serif;
}

.language-heading h2 {
  margin: 11px 0 6px;
  font-size: 24px;
  line-height: 1.35;
}

.language-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.language-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.language-options button {
  min-width: 0;
  min-height: 92px;
  padding: 17px;
  border: 1px solid var(--line);
  display: grid;
  grid-template-columns: 42px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 13px;
  color: var(--paper);
  background: #121415;
  text-align: start;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.language-options button:hover,
.language-options button:focus-visible {
  border-color: var(--red-hot);
  background: #181214;
  outline: 0;
}

.language-options button:active {
  transform: translateY(1px);
}

.language-options button > span {
  grid-row: 1 / 3;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #1c1f20;
  font: 600 15px/1 "Oswald", sans-serif;
}

.language-options button strong {
  align-self: end;
  font-size: 15px;
}

.language-options button small {
  align-self: start;
  color: var(--muted);
  font-size: 10px;
}

#scene canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: 0;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background:
    radial-gradient(circle at 52% 42%, transparent 34%, rgba(0, 0, 0, 0.28) 73%, rgba(0, 0, 0, 0.76) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.32), transparent 21%, transparent 72%, rgba(0, 0, 0, 0.58));
}

.topbar {
  position: fixed;
  z-index: 10;
  inset: 0 0 auto 0;
  height: 86px;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(5, 6, 7, 0.94), rgba(5, 6, 7, 0));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: auto;
}

.brand-mark,
.loading-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: var(--red);
  font: 600 18px/1 "Oswald", sans-serif;
  box-shadow: 0 0 26px rgba(220, 38, 56, 0.24);
}

.brand h1 {
  margin: 0;
  font: 600 23px/1 "Oswald", sans-serif;
  letter-spacing: 0;
}

.brand p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0;
}

.brand p span {
  color: var(--red-hot);
  margin: 0 4px;
}

.mode-control {
  display: flex;
  gap: 5px;
  padding: 4px;
  pointer-events: auto;
  background: rgba(10, 12, 13, 0.84);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(16px);
}

.icon-button,
.route-arrow,
.popover-close {
  width: 40px;
  height: 40px;
  border: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease;
}

.icon-button:hover,
.route-arrow:hover,
.popover-close:hover,
.icon-button.active {
  color: #fff;
  background: rgba(220, 38, 56, 0.94);
}

.icon-button svg,
.route-arrow svg,
.trigger-button svg,
.legend-toggle svg,
.dimension-line svg {
  width: 18px;
  height: 18px;
  stroke-width: 1.8;
}

.scene-panel {
  position: fixed;
  z-index: 8;
  top: 102px;
  right: 24px;
  width: min(356px, calc(100vw - 48px));
  padding: 23px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--red);
  box-shadow: 0 22px 68px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(18px);
}

.panel-kicker {
  display: flex;
  align-items: center;
  gap: 10px;
  direction: ltr;
  color: var(--muted);
  font: 500 10px/1 "Oswald", sans-serif;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-kicker span:first-child {
  color: var(--red-hot);
  font-size: 18px;
}

.scene-panel h2 {
  margin: 16px 0 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

.scene-en {
  direction: ltr;
  margin: 3px 0 10px;
  color: var(--muted);
  font: 500 13px/1.4 "Oswald", sans-serif;
  text-align: right;
}

.dimension-line {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--amber);
  direction: ltr;
  justify-content: flex-end;
  font: 500 12px/1 "Oswald", sans-serif;
}

.scene-copy {
  margin: 16px 0 19px;
  color: #d4d3cf;
  font-size: 12px;
  line-height: 1.8;
}

.scene-meta {
  display: grid;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.scene-meta > div {
  padding: 11px 12px;
  background: rgba(9, 10, 11, 0.9);
}

.meta-label {
  color: var(--muted);
  font-size: 9px;
}

.scene-meta p {
  margin: 4px 0 0;
  color: #e8e6e0;
  font-size: 10px;
  line-height: 1.65;
}

.trigger-button {
  width: 100%;
  min-height: 46px;
  margin-top: 15px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: white;
  background: var(--red);
  cursor: pointer;
  font-weight: 700;
  font-size: 11px;
  transition: background 160ms ease, transform 160ms ease;
}

.trigger-button:hover {
  background: var(--red-hot);
}

.trigger-button:active {
  transform: translateY(1px);
}

.legend {
  position: fixed;
  z-index: 8;
  left: 24px;
  bottom: 102px;
  display: flex;
  align-items: center;
  gap: 14px;
  direction: ltr;
  padding: 6px;
  padding-right: 13px;
  background: rgba(10, 12, 13, 0.86);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(16px);
  color: var(--muted);
  font: 500 9px/1 "Oswald", sans-serif;
}

.legend span {
  white-space: nowrap;
}

.legend-toggle {
  height: 34px;
  padding: 0 11px;
  border: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 10px;
}

.legend-toggle[aria-pressed="false"] {
  color: var(--muted);
  background: transparent;
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 4px;
  border-radius: 50%;
  box-shadow: 0 0 9px currentColor;
}

.beam { color: var(--cyan); background: var(--cyan); }
.pir { color: var(--green); background: var(--green); }
.pressure { color: var(--amber); background: var(--amber); }
.manual { color: var(--red-hot); background: var(--red-hot); }
.speaker { color: #ff78b8; background: #ff78b8; }

.route {
  position: fixed;
  z-index: 9;
  left: 24px;
  right: 24px;
  bottom: 20px;
  height: 68px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: stretch;
  direction: ltr;
  background: rgba(10, 12, 13, 0.9);
  border: 1px solid var(--line-strong);
  backdrop-filter: blur(18px);
}

.route-arrow {
  width: 42px;
  height: 66px;
}

.route-scroll {
  min-width: 0;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}

.route-scroll::-webkit-scrollbar {
  display: none;
}

.route-step {
  position: relative;
  min-width: 124px;
  padding: 12px 14px;
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.route-step::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  transform: scaleX(0);
  background: var(--red);
  transform-origin: left;
  transition: transform 180ms ease;
}

.route-step.active {
  color: white;
  background: rgba(220, 38, 56, 0.11);
}

.route-step.active::after {
  transform: scaleX(1);
}

.route-step small,
.route-step strong {
  display: block;
  letter-spacing: 0;
}

.route-step small {
  color: var(--red-hot);
  font: 500 9px/1 "Oswald", sans-serif;
}

.route-step strong {
  margin-top: 6px;
  font-size: 10px;
  white-space: nowrap;
}

.sensor-label {
  position: fixed;
  z-index: 7;
  min-width: 27px;
  height: 27px;
  padding: 0 6px;
  border: 1px solid currentColor;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--cyan);
  background: rgba(7, 8, 9, 0.88);
  box-shadow: 0 0 15px rgba(69, 201, 218, 0.24);
  cursor: pointer;
  font: 600 9px/1 "Oswald", sans-serif;
  transform: translate(-50%, -50%);
}

.sensor-label.type-pir { color: var(--green); }
.sensor-label.type-pressure { color: var(--amber); }
.sensor-label.type-manual { color: var(--red-hot); }
.sensor-label.type-speaker {
  color: #ff78b8;
  border-radius: 5px;
  box-shadow: 0 0 15px rgba(255, 120, 184, 0.26);
}
.sensor-label.offscreen { display: none; }

.sensor-popover {
  position: fixed;
  z-index: 20;
  left: 50%;
  top: 50%;
  width: min(330px, calc(100vw - 40px));
  padding: 20px;
  transform: translate(-50%, -50%);
  background: #121415;
  border: 1px solid var(--line);
  border-right: 3px solid var(--cyan);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.64);
}

.sensor-popover[hidden] { display: none; }

.sensor-popover > span {
  color: var(--cyan);
  font: 600 11px/1 "Oswald", sans-serif;
}

.sensor-popover h3 {
  margin: 9px 0 7px;
  font-size: 18px;
}

.sensor-popover p {
  color: #d7d5d0;
  font-size: 11px;
  line-height: 1.8;
}

.sensor-popover small {
  display: block;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
  line-height: 1.7;
}

.popover-close {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 32px;
  height: 32px;
}

dialog {
  width: min(820px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line);
  color: var(--paper);
  background: #101213;
  box-shadow: 0 28px 100px rgba(0, 0, 0, 0.72);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(8px);
}

.dialog-top {
  min-height: 70px;
  padding: 14px 16px 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  direction: ltr;
  border-bottom: 1px solid var(--line);
}

.dialog-top span {
  color: var(--red-hot);
  font: 500 9px/1 "Oswald", sans-serif;
}

.dialog-top h2 {
  margin: 5px 0 0;
  font-size: 17px;
}

dialog img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 170px);
  object-fit: contain;
  background: #050607;
}

dialog > p {
  margin: 0;
  padding: 10px 16px 12px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

.loading {
  position: fixed;
  z-index: 300;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 0;
  background: #070809;
  transition: opacity 500ms ease, visibility 500ms ease;
}

.loading.done {
  opacity: 0;
  visibility: hidden;
}

.loading-mark {
  margin-bottom: 17px;
  animation: pulse 1.4s ease-in-out infinite;
}

.loading-copy {
  display: grid;
  justify-items: center;
  gap: 7px;
}

.loading-copy strong {
  font: 600 18px/1 "Oswald", sans-serif;
}

.loading p {
  margin: 0;
  color: var(--muted);
  font: 500 8px/1 "Oswald", sans-serif;
}

.loading-line {
  position: relative;
  width: 150px;
  height: 1px;
  margin-top: 20px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.14);
}

.loading-line::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 44%;
  background: var(--red-hot);
  animation: loadingSweep 1.15s ease-in-out infinite;
}

.game-hud[hidden] {
  display: none;
}

.game-hud {
  position: fixed;
  z-index: 30;
  inset: 0;
  pointer-events: none;
}

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.22);
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: rgba(255, 255, 255, 0.8);
  transform: translate(-50%, -50%);
}

.crosshair::before { width: 5px; height: 1px; }
.crosshair::after { width: 1px; height: 5px; }

.crosshair.ready {
  border-color: var(--amber);
  box-shadow: 0 0 18px rgba(255, 200, 87, 0.52);
  transform: translate(-50%, -50%) scale(1.16);
}

.game-status {
  position: absolute;
  left: 50%;
  bottom: 92px;
  max-width: min(360px, calc(100vw - 120px));
  min-height: 26px;
  padding: 5px 10px;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(8, 9, 10, 0.78);
  border-inline-start: 2px solid var(--red-hot);
  font-size: 10px;
  text-align: center;
  opacity: 0;
  transition: opacity 160ms ease;
}

.game-status.visible { opacity: 1; }

.game-icon {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(8, 9, 10, 0.72);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  cursor: pointer;
  touch-action: none;
}

.game-icon:active {
  color: #fff;
  background: var(--red);
}

.game-icon svg { width: 21px; height: 21px; }

.game-exit {
  position: absolute;
  left: 24px;
  top: 104px;
}

.game-action {
  position: absolute;
  right: 32px;
  bottom: 32px;
  width: 58px;
  height: 58px;
  border-color: rgba(255, 200, 87, 0.5);
  color: var(--amber);
}

.touch-pad {
  position: absolute;
  left: 24px;
  bottom: 24px;
  width: 150px;
  height: 150px;
  display: none;
  grid-template: repeat(3, 48px) / repeat(3, 48px);
  gap: 3px;
  direction: ltr;
}

.move-up { grid-area: 1 / 2; }
.move-left { grid-area: 2 / 1; }
.move-down { grid-area: 2 / 2; }
.move-right { grid-area: 2 / 3; }

body.game-mode .scene-panel,
body.game-mode .legend,
body.game-mode .route,
body.game-mode .brand {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.game-mode .mode-control {
  opacity: 0.3;
}

body.game-mode #vignette {
  background:
    radial-gradient(circle at 50% 48%, transparent 48%, rgba(0, 0, 0, 0.28) 78%, rgba(0, 0, 0, 0.72) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.2), transparent 24%, transparent 76%, rgba(0, 0, 0, 0.5));
}

@keyframes pulse {
  50% { box-shadow: 0 0 38px rgba(220, 38, 56, 0.6); }
}

@keyframes loadingSweep {
  0% { transform: translateX(-110%); }
  100% { transform: translateX(340%); }
}

@media (max-width: 860px) {
  .topbar {
    height: 74px;
    padding: 12px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .brand h1 { font-size: 19px; }
  .brand p { display: none; }
  .mode-control { gap: 1px; }
  .icon-button { width: 35px; height: 35px; }

  .scene-panel {
    top: auto;
    right: 12px;
    left: 12px;
    bottom: 92px;
    width: auto;
    max-height: 34vh;
    overflow-y: auto;
    padding: 14px;
  }

  .scene-panel h2 { font-size: 19px; }
  .scene-copy { display: none; }
  .scene-meta { grid-template-columns: repeat(3, 1fr); }
  .scene-meta > div { padding: 8px; }
  .meta-label { font-size: 8px; }
  .scene-meta p { font-size: 8px; line-height: 1.55; }
  .trigger-button { min-height: 40px; margin-top: 9px; }

  .legend {
    left: 12px;
    bottom: auto;
    top: 80px;
    gap: 8px;
  }

  .legend > span { display: none; }
  .route { left: 12px; right: 12px; bottom: 12px; height: 68px; }
  .route-step { min-width: 104px; }

  .touch-pad { display: grid; }
  .game-exit { left: 12px; top: 78px; }
  .game-action { right: 18px; bottom: 25px; }
  .game-status { bottom: 188px; }
}

@media (max-width: 540px) {
  .brand-mark { display: none; }
  .mode-control { margin-right: auto; }
  .scene-panel { max-height: 38vh; }
  .scene-meta { display: none; }

  .language-gate { padding: 14px; }
  .language-dialog { padding: 20px; }
  .language-brand .brand-mark { display: grid; }
  .language-edition { display: none; }
  .language-heading h2 { font-size: 20px; }
  .language-options { grid-template-columns: 1fr; }
  .language-options button { min-height: 78px; }
}
