@font-face {
  font-family: "Metel Sans";
  src: url("../vendor/roboto-cyrillic.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "Metel Sans";
  src: url("../vendor/roboto-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+2113, U+2191, U+2193, U+FFFD;
}

:root {
  color-scheme: dark;
  font-family: "Metel Sans", Roboto, Arial, sans-serif;
  --ink: #f0f6ff;
  --soft: #b9cddd;
  --muted: #8ba3b6;
  --amber: #f5cf91;
  --amber-strong: #ffb75e;
  --ice: #d4edfd;
  --line: #3d566c;
  --line-soft: #2b3f52;
  --bg: #0a121c;
  --panel: #152438;
  --panel-deep: #101c2b;
  --ok: #9ddfb0;
  --warn: #ffbf80;
  --shadow: 0 20px 60px #00000066;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 0%, #16283d, var(--bg) 62%);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  overflow: hidden;
}

/* ---------- top bar ---------- */

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: calc(8px + var(--safe-top)) clamp(10px, 2.4vw, 22px) 8px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #122135f2, #0d1928e6);
  backdrop-filter: blur(12px);
}

.brand {
  min-width: 0;
  margin-right: auto;
}

.brand-name {
  margin: 0 0 1px;
  color: var(--amber);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-title {
  margin: 0;
  font-size: clamp(1.05rem, 2.6vw, 1.45rem);
  font-weight: 650;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #1b3047d9;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.control:hover {
  background: #25405c;
  border-color: #5c7f9a;
}

.control:active {
  transform: translateY(1px);
}

.control[aria-pressed="true"] {
  border-color: var(--amber);
  background: #3c3a2f99;
  color: var(--amber);
}

.control.primary {
  border-color: #b98b4e;
  background: linear-gradient(180deg, #efc27f, #d9a258);
  color: #241809;
  font-weight: 650;
}

.control.primary:hover {
  background: linear-gradient(180deg, #ffd596, #e7b268);
}

.control.ghost {
  background: transparent;
}

.control.icon {
  width: 40px;
  padding: 0;
}

.control:disabled {
  opacity: 0.5;
  cursor: default;
}

.control .icon-glyph {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 180px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: #0f1c2ccc;
  color: var(--soft);
  font-size: 0.8rem;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.user-chip.is-guest::before {
  background: var(--muted);
}

.user-chip.is-auth {
  color: var(--ok);
  border-color: #3c644c;
}

.user-chip.is-auth::before {
  background: var(--ok);
  box-shadow: 0 0 8px #9ddfb088;
}

/* ---------- stage ---------- */

.stage-wrap {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
  padding: 8px clamp(8px, 1.6vw, 18px);
  overflow: hidden;
}

.stage-wrap::before {
  content: "";
  position: absolute;
  inset: -48px;
  z-index: 0;
  background-image: var(--backdrop);
  background-size: cover;
  background-position: center;
  filter: blur(26px) brightness(0.34) saturate(0.9);
  opacity: 0.52;
  pointer-events: none;
}

@media (max-width: 720px) {
  .stage-wrap::before {
    filter: blur(22px) brightness(0.42) saturate(0.95);
    opacity: 0.6;
  }
}

.stage {
  position: relative;
  z-index: 1;
  isolation: isolate;
  overflow: hidden;
  width: 100%;
  background: #000;
  border-radius: 12px;
  box-shadow: var(--shadow), 0 0 0 1px #2f485f88;
  touch-action: manipulation;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background:
    radial-gradient(ellipse 88% 76% at 52% 45%, transparent 40%, #050a1173 100%),
    linear-gradient(180deg, #050a1126, transparent 14% 84%, #050a1159);
}

.layer {
  position: absolute;
  display: block;
}

.layer > img,
.layer > canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.layer.image {
  object-fit: fill;
}

.layer.pixelated > img {
  image-rendering: pixelated;
}

.layer-clip {
  overflow: hidden;
}

.stage[data-hints="true"] .hotspot-shape {
  opacity: 1;
}

/* ---------- hotspots ---------- */

.hotspots {
  position: absolute;
  inset: 0;
  z-index: 60;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.hotspot {
  pointer-events: none;
}

.hotspot-shape {
  pointer-events: fill;
  cursor: pointer;
  opacity: 0;
  fill: #b9e4ff12;
  stroke: #d0edff;
  stroke-width: 1.35;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: opacity 160ms ease;
  filter: drop-shadow(0 0 2px #8dcfffed) drop-shadow(0 0 5px #8dcfffad);
}

.hotspot[data-pressed] .hotspot-shape,
.hotspot:focus-visible .hotspot-shape {
  opacity: 1;
}

@media (hover: hover) {
  .hotspot-shape:hover {
    opacity: 1;
  }
}

/* ---------- talk ---------- */

.talk-trigger {
  position: absolute;
  z-index: 70;
  left: clamp(8px, 2.2%, 24px);
  bottom: clamp(8px, 3%, 24px);
  min-height: 38px;
  border-color: #8f6c42;
  background: #1e2a37e8;
  color: var(--amber);
  box-shadow: 0 6px 22px #0009;
}

.talk-trigger:hover {
  background: #2a3a4b;
}

/* ---------- narration ---------- */

.narration-panel {
  position: relative;
  z-index: 8;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex: 0 0 auto;
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 10px clamp(12px, 3vw, 26px) calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #0d1928, #0b1522);
}

.narration-text {
  flex: 1 1 auto;
  min-height: 3.1em;
  max-height: 28dvh;
  overflow-y: auto;
  font-size: clamp(1rem, 1.9vw, 1.16rem);
  line-height: 1.45;
  scrollbar-width: thin;
}

.narration-text p {
  margin: 0;
}

.narration-text p + p {
  margin-top: 0.45em;
}

.narration-text .text-unit {
  opacity: 0;
}

.narration-text .text-unit.is-visible {
  opacity: 1;
}

.narration-panel .control {
  flex: 0 0 auto;
  margin-bottom: 2px;
}

/* ---------- overlay sheets ---------- */

dialog.sheet {
  width: min(560px, calc(100vw - 24px));
  max-height: min(760px, calc(100dvh - 40px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(160deg, #1a2d43, #101c2b 74%);
  color: var(--ink);
  box-shadow: 0 30px 100px #000b;
  overflow: hidden;
}

dialog.sheet::backdrop {
  background: #050a11b8;
  backdrop-filter: blur(4px);
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.sheet-head h2 {
  margin: 0;
  margin-right: auto;
  font-size: 1.15rem;
  font-weight: 650;
}

.sheet-body {
  max-height: calc(100dvh - 190px);
  padding: 16px 18px calc(18px + var(--safe-bottom));
  overflow-y: auto;
}

.sheet-body p {
  margin: 0 0 0.6em;
  color: var(--soft);
  line-height: 1.5;
}

.sheet-body p:last-child {
  margin-bottom: 0;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.sheet-close {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 10px;
  font-size: 1.2rem;
}

/* settings */

.settings-group {
  padding: 12px 0;
  border-bottom: 1px solid var(--line-soft);
}

.settings-group:last-child {
  border-bottom: 0;
}

.settings-group h3 {
  margin: 0 0 10px;
  color: var(--amber);
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(100px, 0.9fr) minmax(120px, 1.4fr) 56px;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.setting-row label {
  color: var(--soft);
  font-size: 0.9rem;
}

.setting-row output {
  color: var(--ice);
  font-size: 0.82rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  accent-color: var(--amber-strong);
}

select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #0f1c2c;
  color: var(--ink);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  color: var(--soft);
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0d1824;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 160ms ease, background 160ms ease;
}

.switch[aria-pressed="true"] {
  background: #40552f;
  border-color: #8a9c52;
}

.switch[aria-pressed="true"]::after {
  transform: translateX(20px);
  background: var(--amber);
}

/* auth */

.auth-state {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: #0d1928;
}

.auth-state strong {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
}

.auth-state span {
  color: var(--muted);
  font-size: 0.88rem;
}

.auth-qr {
  display: grid;
  place-items: center;
  width: max-content;
  margin: 12px auto 6px;
  padding: 10px;
  border-radius: 12px;
  background: #f3f7fb;
}

.auth-qr:empty {
  display: none;
}

.auth-qr svg {
  display: block;
  width: 176px;
  height: 176px;
}

.auth-qr-caption {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.auth-link {
  display: block;
  margin: 10px 0;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #0b1522;
  color: var(--ice);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
  user-select: all;
}

.auth-steps {
  margin: 14px 0;
  padding-left: 20px;
  color: var(--soft);
  font-size: 0.9rem;
  line-height: 1.55;
}

.auth-steps li + li {
  margin-top: 6px;
}

.auth-status {
  min-height: 1.3em;
  color: var(--amber);
  font-size: 0.88rem;
}

/* detail dialog */

.detail {
  width: min(620px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #0f1b2a;
  color: var(--ink);
  box-shadow: 0 30px 100px #000b;
}

.detail::backdrop {
  background: #050a11b8;
  backdrop-filter: blur(5px);
}

.detail .sheet-body {
  font-size: 1.06rem;
  line-height: 1.55;
}

/* conversation */

.conversation {
  position: absolute;
  z-index: 80;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(640px, calc(100% - 24px));
  padding: 14px 16px;
  border: 1px solid #5c7f9a;
  border-radius: 14px;
  background: linear-gradient(160deg, #1b2e44f2, #0e1a29f5);
  box-shadow: 0 18px 50px #000a;
  backdrop-filter: blur(10px);
}

.conversation[hidden] {
  display: none;
}

.speaker {
  margin: 0 0 5px;
  color: var(--amber);
  font-size: 0.82rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.speech {
  margin: 0 0 12px;
  min-height: 2.9em;
  font-size: 1.02rem;
  line-height: 1.5;
}

.speech p {
  margin: 0;
}

.speech p + p {
  margin-top: 0.4em;
}

.speech .text-unit {
  opacity: 0;
}

.speech .text-unit.is-visible {
  opacity: 1;
}

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

/* ---------- loader ---------- */

.loader {
  position: absolute;
  inset: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 35%, #1a2d43, #0a121c 70%),
    #0a121c;
  transition: opacity 320ms ease, visibility 320ms ease;
}

.loader[hidden] {
  display: none;
}

.loader.is-done {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-brand {
  margin: 0;
  color: var(--amber);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.loader-title {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.loader-bar {
  width: min(340px, 80vw);
  height: 5px;
  border-radius: 999px;
  background: #22344a;
  overflow: hidden;
}

.loader-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #d9a258, var(--amber));
  transition: width 180ms ease;
}

.loader-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  z-index: 300;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #16283df2;
  color: var(--ink);
  font-size: 0.88rem;
  text-align: center;
  box-shadow: 0 12px 34px #0008;
  opacity: 0;
  visibility: hidden;
  transition: opacity 180ms ease, transform 180ms ease, visibility 180ms ease;
}

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

/* ---------- debug ---------- */

.debug {
  position: fixed;
  z-index: 250;
  top: 70px;
  right: 10px;
  max-width: 260px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #050a11e6;
  color: #9ddfb0;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  pointer-events: none;
}

/* ---------- responsive ---------- */

@media (max-width: 720px) {
  .auth-qr,
  .auth-qr-caption {
    display: none;
  }

  .topbar {
    gap: 6px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .topbar-actions .label {
    display: none;
  }

  .control {
    padding: 0 10px;
  }

  .control.icon {
    width: 38px;
  }

  .user-chip {
    max-width: 120px;
    font-size: 0.74rem;
    padding: 0 9px;
  }

  .brand-name {
    font-size: 0.64rem;
  }

  .narration-panel {
    gap: 8px;
    padding-top: 8px;
  }

  .narration-text {
    min-height: 2.9em;
    max-height: 30dvh;
    font-size: 0.98rem;
  }

  .setting-row {
    grid-template-columns: 92px 1fr 48px;
  }

  dialog.sheet {
    width: 100vw;
    max-width: 100vw;
    max-height: 88dvh;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
  }

  .sheet-body {
    max-height: calc(88dvh - 66px);
  }
}

@media (max-width: 420px) {
  .brand-title {
    font-size: 1rem;
  }

  .user-chip {
    max-width: 96px;
  }

  .user-chip .chip-text {
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .narration-panel {
    padding-top: 6px;
    padding-bottom: calc(8px + var(--safe-bottom));
  }

  .narration-text {
    max-height: 22dvh;
  }

  .topbar {
    padding-top: calc(5px + var(--safe-top));
    padding-bottom: 5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .narration-text .text-unit,
  .speech .text-unit {
    opacity: 1 !important;
  }

  .sash-panel {
    animation: none !important;
  }
}

/* ---------- sash animation ---------- */

.sash-panel {
  transform-origin: 1.65% 50%;
  animation: sash-sway var(--sash-period, 2600ms) step-end infinite;
}

@keyframes sash-sway {
  0%,
  49%,
  100% {
    transform: scaleX(1);
  }
  9%,
  37% {
    transform: scaleX(calc(1 + 0.026 * var(--sash-amount, 1)));
  }
  20% {
    transform: scaleX(calc(1 + 0.052 * var(--sash-amount, 1)));
  }
  59%,
  87% {
    transform: scaleX(calc(1 - 0.026 * var(--sash-amount, 1)));
  }
  70% {
    transform: scaleX(calc(1 - 0.052 * var(--sash-amount, 1)));
  }
}

.sound-off {
  display: none;
}

#sound[aria-pressed="false"] .sound-wave {
  display: none;
}

#sound[aria-pressed="false"] .sound-off {
  display: inline;
}

.noscript {
  padding: 16px;
}
