:root {
  color-scheme: dark;
  --ink: #f2e8d5;
  --paper: #d8c4a1;
  --brass: #c99a49;
  --brass-bright: #f0c978;
  --night: #070b10;
  --header-h: 82px;
  font-family: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--night);
  overflow: hidden;
}

button {
  font: inherit;
}

.app {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 560px;
  color: var(--ink);
  isolation: isolate;
  background: #070b10;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  contain: layout paint;
}

.screen.is-active {
  display: block;
}

.screen-image,
.screen-shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.screen-image { object-fit: cover; }
.screen-shade { background: radial-gradient(circle at center, transparent 42%, rgba(1, 3, 6, 0.72)); pointer-events: none; }

.scene-back {
  position: fixed;
  z-index: 55;
  top: 22px;
  left: 24px;
  padding: 10px 14px;
  border: 1px solid rgba(240, 201, 120, 0.55);
  color: var(--ink);
  background: rgba(10, 9, 8, 0.78);
  cursor: pointer;
}

.scene-back:hover, .scene-back:focus-visible { color: var(--brass-bright); border-color: var(--brass-bright); }

.telegram-screen, .carriage-screen { z-index: 45; overflow: auto; }

.telegram-paper {
  position: relative;
  z-index: 2;
  width: min(780px, calc(100% - 40px));
  min-height: calc(100svh - 76px);
  margin: 38px auto;
  padding: 34px 42px 30px;
  color: #2a2117;
  background: rgba(213, 188, 143, 0.91);
  background-image: linear-gradient(rgba(239, 221, 185, 0.84), rgba(202, 174, 126, 0.9));
  border: 1px solid #d6b879;
  box-shadow: 0 25px 90px rgba(0,0,0,.75), inset 0 0 60px rgba(79, 47, 17, .18);
}

.telegram-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; border-bottom: 3px double #765126; padding-bottom: 18px; }
.eyebrow { margin: 0 0 7px; color: #755329; font-family: Arial, sans-serif; font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.telegram-heading h1, .destination-card h1, .arrival-card h1 { margin: 0; font-size: clamp(36px, 6vw, 60px); font-weight: 400; line-height: 1; }
.ollama-status { display: flex; align-items: center; margin: 6px 0 0; color: #725f49; font: 10px Arial, sans-serif; text-transform: uppercase; }
.ollama-status span { width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #997542; }
.ollama-status.is-online span { background: #467542; box-shadow: 0 0 8px #6f9d5e; }
.ollama-status.is-offline span { background: #8b3b2c; }
.recipient-row { display: grid; grid-template-columns: 58px 1fr; align-items: center; gap: 12px; padding: 18px 0 14px; border-bottom: 1px solid rgba(91, 58, 27, .45); }
.recipient-row label, .telegram-form > label, .destination-card label { color: #5e421f; font: 700 11px Arial, sans-serif; letter-spacing: .12em; text-transform: uppercase; }
.recipient-row select, .destination-card input { width: 100%; padding: 10px 12px; border: 1px solid #8d6c3e; border-radius: 2px; color: #2d2114; background: rgba(246, 229, 194, .58); font: 16px Georgia, serif; }
.telegram-log { height: clamp(230px, 38vh, 390px); padding: 18px 2px; overflow-y: auto; scrollbar-color: #876335 transparent; }
.telegram-empty { display: grid; place-items: center; height: 100%; color: #715b40; text-align: center; }
.telegram-empty p { margin: 7px 0 3px; font-style: italic; }
.telegram-empty small { opacity: .72; }
.wire-mark { font-size: 32px; }
.wire-message { width: 86%; margin: 0 0 13px; padding: 12px 15px; border-left: 3px solid #8b642e; background: rgba(255, 239, 205, .32); box-shadow: 0 3px 10px rgba(75, 44, 16, .08); }
.wire-message.outgoing { margin-left: auto; border-right: 3px solid #5f4a32; border-left: 0; background: rgba(114, 88, 53, .14); }
.wire-message.system { width: 100%; border: 1px dashed #8b3b2c; color: #712f23; background: transparent; }
.wire-sender { margin: 0 0 5px; color: #765328; font: 700 10px Arial, sans-serif; letter-spacing: .08em; text-transform: uppercase; }
.wire-text { margin: 0; line-height: 1.45; white-space: pre-wrap; }
.telegram-form { padding-top: 14px; border-top: 1px solid rgba(91, 58, 27, .45); }
.message-compose { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 8px; }
.message-compose textarea { resize: none; width: 100%; padding: 11px 13px; border: 1px solid #8d6c3e; color: #2d2114; background: rgba(246, 229, 194, .55); font: 16px/1.4 Georgia, serif; }
.message-compose button, .destination-card button, .arrival-card button { align-self: stretch; padding: 0 20px; border: 1px solid #3c2915; color: #f3dfb8; background: #372617; cursor: pointer; font: 700 11px Arial, sans-serif; letter-spacing: .08em; text-transform: uppercase; }
.message-compose button:disabled { opacity: .55; cursor: wait; }
.form-note { margin: 7px 0 0; color: #755f44; font-size: 11px; }

.carriage-entry, .destination-scene { position: absolute; inset: 0; min-height: 100%; }
.destination-card, .arrival-card { position: relative; z-index: 2; width: min(500px, calc(100% - 40px)); padding: 34px 38px; color: #2a2117; background: rgba(220, 197, 155, .94); border: 1px solid #d6b879; box-shadow: 0 25px 90px rgba(0,0,0,.78), inset 0 0 50px rgba(79,47,17,.17); }
.destination-card { margin: max(110px, 16vh) auto 40px; }
.destination-card > p:not(.eyebrow), .arrival-card > p:not(.eyebrow) { color: #604c34; line-height: 1.5; }
.destination-card label { display: block; margin: 23px 0 8px; }
.destination-card button { width: 100%; margin-top: 12px; min-height: 44px; }
.destination-feedback { min-height: 44px; margin-bottom: 0 !important; color: #7d2f21 !important; font-size: 13px; }
.destination-shade { background: linear-gradient(180deg, rgba(2,5,9,.12), rgba(2,5,9,.74)); }
.arrival-card { position: absolute; bottom: 32px; left: 50%; transform: translateX(-50%); text-align: center; }
.arrival-card h1 { font-size: clamp(30px, 5vw, 48px); }
.arrival-card button { min-height: 44px; margin-top: 8px; }
[hidden] { display: none !important; }

.briefing-modal {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  overflow-y: auto;
  visibility: visible;
  opacity: 1;
  transition: opacity .28s ease, visibility .28s ease;
}

.briefing-modal[aria-hidden="true"] { visibility: hidden; opacity: 0; pointer-events: none; }
.briefing-backdrop { position: fixed; inset: 0; background: rgba(1, 3, 6, .88); }
.briefing-card {
  position: relative;
  width: min(720px, 100%);
  padding: 38px 44px 34px;
  color: #2a2117;
  background: linear-gradient(rgba(232, 212, 173, .97), rgba(202, 174, 126, .97));
  border: 1px solid #d6b879;
  box-shadow: 0 28px 100px rgba(0,0,0,.82), inset 0 0 60px rgba(79,47,17,.18);
}
.briefing-card::before { content: ""; position: absolute; inset: 10px; pointer-events: none; border: 1px solid rgba(112,76,35,.28); }
.briefing-card h1 { position: relative; margin: 0 0 18px; color: #2b1d10; font-size: clamp(34px, 6vw, 56px); font-weight: 400; line-height: 1; }
.briefing-copy { position: relative; color: #51402d; font-size: 15px; line-height: 1.55; }
.briefing-copy p { margin: 0 0 12px; }
.briefing-copy ul { margin: 0 0 15px; padding-left: 22px; }
.briefing-copy li { margin: 7px 0; }
.briefing-start { position: relative; width: 100%; min-height: 48px; margin-top: 8px; border: 1px solid #3c2915; color: #f3dfb8; background: #372617; cursor: pointer; font: 700 11px Arial, sans-serif; letter-spacing: .1em; text-transform: uppercase; }
.briefing-start:hover, .briefing-start:focus-visible, .arrival-card button:hover, .arrival-card button:focus-visible { color: #fff1cf; background: #52381f; outline: 2px solid rgba(240,201,120,.55); outline-offset: 2px; }
.completion-card { width: min(620px, calc(100% - 36px)); background: rgba(220, 197, 155, .96); }
.completion-card h1 { font-size: clamp(29px, 5vw, 48px); line-height: 1.05; }

.masthead {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: var(--header-h);
  padding: 16px 30px 14px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(3, 5, 8, 0.94), rgba(3, 5, 8, 0.54) 68%, transparent);
}

.identity {
  display: flex;
  align-items: baseline;
  gap: 11px;
  filter: drop-shadow(0 2px 6px #000);
}

.address {
  color: var(--brass-bright);
  font-size: 29px;
  line-height: 1;
}

.street {
  font-size: 17px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.case-status {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  color: rgba(242, 232, 213, 0.72);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.case-status span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c99a49;
  box-shadow: 0 0 12px #f0c978;
}

.viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #070b10;
}

.scene {
  position: relative;
  width: 100%;
  height: 100%;
  min-width: 1000px;
  transform-origin: center;
  animation: scene-arrive 1.1s cubic-bezier(0.2, 0.78, 0.2, 1) both;
}

.scene-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  user-select: none;
  transform: scale(1.015);
  filter: saturate(0.92) contrast(1.03) brightness(0.86);
}

.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  box-shadow: inset 0 0 130px 36px rgba(1, 4, 8, 0.82);
}

.vignette {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(3, 6, 9, 0.46), transparent 18%, transparent 82%, rgba(3, 6, 9, 0.52)),
    radial-gradient(circle at center, transparent 52%, rgba(2, 5, 8, 0.26) 100%);
}

.rain {
  position: absolute;
  z-index: 5;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: repeating-linear-gradient(108deg, transparent 0 25px, rgba(181, 208, 222, 0.42) 26px, transparent 27px 52px);
}

.room {
  position: absolute;
  z-index: 10;
  padding: 0;
  border: 0;
  color: var(--ink);
  cursor: pointer;
  background: transparent;
  outline: none;
}

.room-depth {
  position: absolute;
  inset: 5px;
  border: 1px solid transparent;
  background: radial-gradient(circle at 50% 72%, rgba(240, 194, 102, 0), transparent 58%);
  box-shadow: inset 0 0 0 0 rgba(240, 194, 102, 0);
  transition: border-color 0.28s ease, background 0.35s ease, box-shadow 0.35s ease, transform 0.35s ease;
}

.room-label {
  position: absolute;
  left: 50%;
  bottom: 8%;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 8px 13px 8px 9px;
  color: #f5ead7;
  white-space: nowrap;
  background: linear-gradient(180deg, rgba(42, 31, 22, 0.95), rgba(17, 13, 11, 0.97));
  border: 1px solid rgba(214, 170, 91, 0.7);
  border-radius: 3px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.58), inset 0 1px rgba(255, 234, 191, 0.12);
  transform: translate(-50%, 4px) perspective(100px) rotateX(-2deg);
  opacity: 0.8;
  transition: opacity 0.25s ease, transform 0.3s ease, border-color 0.25s ease, box-shadow 0.3s ease;
}

.index {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: #18110a;
  font-size: 11px;
  font-weight: 700;
  background: var(--brass);
  border: 1px solid var(--brass-bright);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(72, 45, 20, 0.35);
}

.room:hover .room-depth,
.room:focus-visible .room-depth,
.room.is-focused .room-depth {
  border-color: rgba(239, 194, 105, 0.64);
  background: radial-gradient(circle at 50% 70%, rgba(246, 194, 94, 0.13), transparent 62%);
  box-shadow: inset 0 0 40px rgba(241, 183, 72, 0.13), 0 0 26px rgba(241, 183, 72, 0.12);
  transform: translateY(-2px) scale(1.008);
}

.room:hover .room-label,
.room:focus-visible .room-label,
.room.is-focused .room-label {
  opacity: 1;
  border-color: var(--brass-bright);
  transform: translate(-50%, -2px) perspective(100px) rotateX(0);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.72), 0 0 16px rgba(224, 166, 66, 0.22), inset 0 1px rgba(255, 234, 191, 0.16);
}

.room-library {
  top: 5%;
  left: 2.5%;
  width: 37%;
  height: 44%;
}

.room-documents {
  top: 5%;
  right: 3.5%;
  width: 39%;
  height: 44%;
}

.room-laboratory {
  bottom: 3%;
  left: 2%;
  width: 36%;
  height: 46%;
}

.room-telegram {
  bottom: 3%;
  left: 37.5%;
  width: 18.5%;
  height: 46%;
}

.room-carriage {
  right: 2%;
  bottom: 3%;
  width: 34%;
  height: 46%;
}

.quick-nav {
  position: fixed;
  z-index: 24;
  right: 20px;
  bottom: 18px;
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(8, 9, 10, 0.72);
  border: 1px solid rgba(210, 167, 88, 0.24);
}

.quick-nav button {
  padding: 8px 10px;
  border: 0;
  color: rgba(244, 234, 216, 0.68);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10px;
  background: transparent;
  cursor: pointer;
}

.quick-nav button:hover,
.quick-nav button:focus-visible {
  color: var(--brass-bright);
  outline: 1px solid rgba(201, 154, 73, 0.6);
}

.modal {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: end center;
  pointer-events: none;
  visibility: hidden;
}

.modal[aria-hidden="false"] {
  pointer-events: auto;
  visibility: visible;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(2, 4, 7, 0.65);
  opacity: 0;
  transition: opacity 0.34s ease;
}

.modal-sheet {
  position: relative;
  z-index: 1;
  width: min(680px, calc(100% - 32px));
  margin-bottom: 26px;
  padding: 34px 40px 30px;
  color: #262016;
  background:
    linear-gradient(rgba(221, 204, 168, 0.93), rgba(202, 179, 136, 0.96)),
    repeating-linear-gradient(0deg, transparent 0 4px, rgba(97, 63, 31, 0.04) 5px);
  border: 1px solid #d7bd87;
  box-shadow: 0 24px 90px rgba(0, 0, 0, 0.7), inset 0 0 44px rgba(82, 50, 22, 0.16);
  transform: translateY(30px) scale(0.98);
  opacity: 0;
  transition: opacity 0.32s ease, transform 0.38s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal[aria-hidden="false"] .modal-backdrop,
.modal[aria-hidden="false"] .modal-sheet {
  opacity: 1;
}

.modal[aria-hidden="false"] .modal-sheet {
  transform: translateY(0) scale(1);
}

.modal-kicker {
  margin: 0 0 7px;
  color: #765326;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.modal h1 {
  margin: 0;
  color: #25190e;
  font-size: clamp(34px, 6vw, 58px);
  font-weight: 400;
  line-height: 1;
}

.modal p:not(.modal-kicker) {
  max-width: 540px;
  margin: 18px 0 0;
  color: #54432f;
  font-size: 16px;
  line-height: 1.55;
}

.modal-rule {
  width: 58px;
  height: 2px;
  margin: 24px 0 18px;
  background: #9e7537;
}

.close-button {
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid #725327;
  color: #3b2a17;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  font-weight: 700;
  background: transparent;
  cursor: pointer;
}

.close-button:hover,
.close-button:focus-visible {
  color: #8b5c1e;
  outline: none;
  border-bottom-color: #b5823c;
}

@keyframes scene-arrive {
  from {
    opacity: 0;
    transform: scale(1.035);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.is-paused *,
.is-paused *::before,
.is-paused *::after {
  animation-play-state: paused !important;
}

@media (max-width: 760px) {
  :root {
    --header-h: 66px;
  }

  .app {
    min-height: 520px;
  }

  .masthead {
    padding: 13px 18px;
  }

  .address {
    font-size: 24px;
  }

  .street {
    font-size: 13px;
  }

  .case-status {
    display: none;
  }

  .viewport {
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .viewport::-webkit-scrollbar {
    display: none;
  }

  .scene {
    width: 1100px;
    min-width: 1100px;
    scroll-snap-align: center;
  }

  .room-label {
    opacity: 0.94;
    min-height: 34px;
    font-size: 14px;
  }

  .quick-nav {
    right: 10px;
    bottom: 10px;
    left: 10px;
    justify-content: space-between;
    overflow-x: auto;
  }

  .quick-nav button {
    flex: 0 0 auto;
    padding: 9px 8px;
  }

  .modal {
    place-items: end stretch;
  }

  .modal-sheet {
    width: 100%;
    margin: 0;
    padding: 28px 24px 30px;
    border-width: 1px 0 0;
  }

  .telegram-paper { width: 100%; min-height: 100svh; margin: 0; padding: 78px 20px 24px; border: 0; }
  .telegram-heading { display: block; }
  .ollama-status { margin-top: 12px; }
  .message-compose { grid-template-columns: 1fr; }
  .message-compose button { min-height: 44px; }
  .telegram-log { height: 34vh; }
  .scene-back { top: 14px; left: 14px; }
  .destination-card { margin-top: 84px; padding: 28px 24px; }
  .arrival-card { bottom: 18px; padding: 24px 20px; }
  .briefing-modal { place-items: start center; padding: 14px; }
  .briefing-card { padding: 30px 24px 24px; }
  .briefing-card h1 { font-size: 36px; }
  .briefing-copy { font-size: 14px; }
  .completion-card { bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
