:root {
  --ink: #071018;
  --paper: #d7e7f2;
  --muted: #8ea4b5;
  --cyan: #7ee7ff;
  --amber: #ffc14a;
  --line: rgba(126, 231, 255, 0.38);
  --danger: #ff8d86;
  --panel: rgba(7, 16, 28, 0.88);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен скрывать элемент даже при display: flex/grid в правилах ниже. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
  font-family: Bahnschrift, "Segoe UI", sans-serif;
}

body {
  overflow: hidden;
}

canvas {
  /* Холст закреплён за окном: его размер в пикселях (PixiJS, autoDensity) не влияет на вёрстку. */
  position: fixed;
  top: 0;
  left: 0;
  display: block;
  touch-action: none;
  width: 100%;
  height: 100%;
  /* Сцену рисует PixiJS (WebGL2); фон холста виден только до первого кадра. */
  background: #05080f;
}

.gfx-error h2 { margin: 0 0 12px; font-size: 20px; letter-spacing: 0.08em; color: var(--danger); }
.gfx-error p { margin: 0 0 10px; line-height: 1.5; }
.gfx-error .gfx-error-hint { color: var(--muted); font-size: 13px; }

.panel {
  position: fixed;
  z-index: 3;
  top: 50%;
  left: 50%;
  width: min(420px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  padding: 28px 28px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--cyan);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 11px;
}

h1 {
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.04em;
  font-size: 34px;
}

.lead, .form-title {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

input {
  border: 1px solid rgba(126, 231, 255, 0.25);
  background: rgba(3, 8, 14, 0.75);
  color: var(--paper);
  padding: 10px 12px;
  font: 16px/1.2 Consolas, "Cascadia Mono", monospace;
  letter-spacing: 0.04em;
  text-transform: none;
}

input:focus {
  outline: 1px solid var(--cyan);
  border-color: var(--cyan);
}

button {
  border: 0;
  background: var(--cyan);
  color: #042028;
  font: 600 14px/1 Bahnschrift, "Segoe UI", sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 12px 14px;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }

button.ghost {
  background: transparent;
  color: var(--amber);
  border: 1px solid rgba(255, 193, 74, 0.7);
}

.portal-actions {
  display: grid;
  gap: 10px;
  margin: 18px 0 6px;
}

.ghost-link {
  display: block;
  padding: 11px 14px;
  border: 1px solid rgba(255, 193, 74, 0.7);
  color: var(--amber);
  font: 600 13px/1.2 Bahnschrift, "Segoe UI", sans-serif;
  letter-spacing: 0.08em;
  text-align: center;
  text-decoration: none;
  text-transform: uppercase;
}

.ghost-link:hover { background: rgba(255, 193, 74, 0.08); }

#auth .form-title { margin: 18px 0 0; }

#auth-error {
  min-height: 1.2em;
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 14px;
}

#hud, #roster, #hint, #nav {
  position: fixed;
  z-index: 2;
}

#hud {
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 14px;
  background: rgba(6, 12, 20, 0.72);
  border: 1px solid var(--line);
}

#hud strong {
  letter-spacing: 0.16em;
  font-size: 13px;
}

#callsign { margin-left: 12px; color: var(--amber); }

#coords, #link {
  font-family: Consolas, "Cascadia Mono", monospace;
  color: var(--cyan);
  font-size: 13px;
}

#hud button {
  margin-left: auto;
  padding: 8px 12px;
  background: transparent;
  color: var(--paper);
  border: 1px solid rgba(215, 231, 242, 0.35);
}

#roster {
  top: 76px;
  right: 16px;
  width: 200px;
  padding: 12px 14px;
  background: rgba(6, 12, 20, 0.72);
  border: 1px solid var(--line);
}

#roster p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

#pilots {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

#pilots li {
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 13px;
}

#hint {
  left: 16px;
  bottom: 16px;
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.04em;
  font-size: 13px;
}

#nav {
  left: 16px;
  bottom: 44px;
  width: 280px;
  padding: 10px 14px 12px;
  background: rgba(6, 12, 20, 0.78);
  border: 1px solid var(--line);
  font-size: 13px;
}

#nav p { margin: 0; }

#nav .nav-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.nav-row {
  display: flex;
  gap: 10px;
  line-height: 1.6;
}

.nav-row > span:last-child,
.nav-row > strong {
  font-family: Consolas, "Cascadia Mono", monospace;
  color: var(--cyan);
  overflow-wrap: anywhere;
}

.nav-row > strong { color: var(--amber); font-weight: 500; }

.nav-key {
  flex: 0 0 78px;
  color: var(--muted);
}

.nav-selected {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(126, 231, 255, 0.16);
}

.nav-meta {
  padding-left: 88px;
  color: var(--muted);
  font-size: 12px;
}

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

.nav-actions:not(:has(button:not([hidden]))) { display: none; }

.nav-actions button {
  padding: 6px 10px;
  background: transparent;
  color: var(--paper);
  border: 1px solid rgba(215, 231, 242, 0.35);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.nav-actions button:hover { border-color: var(--cyan); color: var(--cyan); }

#nav-fly { color: var(--amber); border-color: rgba(255, 193, 74, 0.6); }

@media (max-width: 720px) {
  #nav { width: auto; right: 160px; bottom: 16px; font-size: 12px; }
  #hint { display: none; }
  .nav-key { flex-basis: 64px; }
  .nav-meta { padding-left: 74px; }
}

@media (max-width: 720px) {
  #roster { display: none; }
  #hud { gap: 8px; }
  #coords { display: none; }
}

/* ---------- Миссии ---------- */

#hud .hud-accent {
  margin-left: auto;
  color: var(--amber);
  border-color: rgba(255, 193, 74, 0.6);
}

#hud .hud-accent ~ button { margin-left: 0; }

#quest-overlay, #settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: start center;
  padding: 48px 16px;
  overflow-y: auto;
  background: rgba(3, 7, 13, 0.72);
  backdrop-filter: blur(6px);
}

.quest-shell {
  width: min(1040px, 100%);
  padding: 22px 26px 18px;
  background: rgba(7, 16, 28, 0.94);
  border: 1px solid var(--line);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
}

.quest-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(126, 231, 255, 0.16);
}

.quest-top h2 {
  margin: 0;
  font-weight: 600;
  font-size: 26px;
  letter-spacing: 0.02em;
}

.quest-icon {
  padding: 6px 10px;
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(215, 231, 242, 0.25);
}

.quest-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.quest-card {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 16px;
  border: 1px solid rgba(126, 231, 255, 0.2);
  background: rgba(3, 8, 14, 0.6);
}

.quest-card h3 { margin: 0; font-size: 19px; font-weight: 600; }
.quest-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.quest-card button { justify-self: start; }
.quest-card button:disabled { opacity: 0.45; cursor: default; filter: none; }

.quest-badge {
  justify-self: start;
  padding: 3px 8px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cyan);
  border: 1px solid rgba(126, 231, 255, 0.35);
}

.quest-badge.is-active { color: var(--amber); border-color: rgba(255, 193, 74, 0.5); }
.quest-badge.is-completed { color: #c9f27a; border-color: rgba(201, 242, 122, 0.45); }
.quest-badge.is-failed, .quest-badge.is-abandoned { color: var(--danger); border-color: rgba(255, 141, 134, 0.45); }

.quest-empty, .quest-muted { color: var(--muted); }

.quest-play {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 28px;
  margin-top: 20px;
}

.quest-scene.is-entering { animation: quest-enter 0.35s ease-out; }

@keyframes quest-enter {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .quest-scene.is-entering { animation: none; }
}

.quest-speaker {
  margin: 0 0 6px;
  color: var(--amber);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.quest-title { margin: 0 0 14px; font-size: 24px; font-weight: 600; }

.quest-text p {
  margin: 0 0 14px;
  max-width: 68ch;
  font-family: "Segoe UI", Bahnschrift, sans-serif;
  font-size: 17px;
  line-height: 1.68;
  white-space: pre-line;
}

.quest-prompt { margin: 18px 0 10px; color: var(--cyan); font-size: 15px; }

.quest-options { display: grid; gap: 8px; margin-top: 8px; }

.quest-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  text-transform: none;
  letter-spacing: 0.01em;
  font: 500 15px/1.35 "Segoe UI", Bahnschrift, sans-serif;
  color: var(--paper);
  background: rgba(126, 231, 255, 0.06);
  border: 1px solid rgba(126, 231, 255, 0.28);
  transition: background 0.15s, border-color 0.15s;
}

.quest-option:hover:not(:disabled) {
  background: rgba(126, 231, 255, 0.14);
  border-color: var(--cyan);
  filter: none;
}

.quest-option:disabled { opacity: 0.55; cursor: progress; }

.quest-option-key {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font: 600 12px/1 Consolas, monospace;
  color: var(--cyan);
  border: 1px solid rgba(126, 231, 255, 0.4);
}

.quest-option.is-back { justify-content: center; color: var(--muted); background: transparent; }

.quest-ending {
  margin: 4px 0;
  color: #c9f27a;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
}

.quest-side {
  padding-left: 22px;
  border-left: 1px solid rgba(126, 231, 255, 0.16);
}

.quest-side-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.quest-stages, .quest-journal {
  margin: 0 0 20px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  font-size: 14px;
  line-height: 1.4;
}

.quest-stages li::before { content: "○ "; color: var(--muted); }
.quest-stages li.is-done { color: var(--muted); text-decoration: line-through; }
.quest-stages li.is-done::before { content: "● "; color: #c9f27a; }

.quest-journal { max-height: 220px; overflow-y: auto; color: var(--muted); }
.quest-journal li { padding-left: 10px; border-left: 2px solid rgba(255, 193, 74, 0.4); }

.quest-side-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.quest-side-actions button { padding: 8px 10px; font-size: 12px; }

.quest-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(255, 141, 134, 0.5);
}

.quest-error { min-height: 1.2em; margin: 12px 0 0; color: var(--danger); font-size: 14px; }

@media (max-width: 820px) {
  #quest-overlay { padding: 12px 8px; }
  .quest-shell { padding: 16px; }
  .quest-play { grid-template-columns: 1fr; }
  .quest-side { padding-left: 0; border-left: 0; border-top: 1px solid rgba(126, 231, 255, 0.16); padding-top: 16px; }
}

#hud .hud-link {
  padding: 8px 12px;
  color: var(--cyan);
  font: 600 14px/1 Bahnschrift, "Segoe UI", sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  border: 1px solid rgba(126, 231, 255, 0.45);
}

.quest-image {
  display: block;
  width: 100%;
  max-height: 300px;
  margin: 0 0 16px;
  object-fit: cover;
  border: 1px solid rgba(126, 231, 255, 0.2);
}

/* ---------- Бренд: RIO PRESENTS · SPACEVERSE: NOVA SECTOR ---------- */

.brand { margin-bottom: 4px; }

.brand-presents {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.32em;
}

/* Знак RIO читается вместе с соседним словом: «RIO PRESENTS». */
.rio-mark { flex: none; width: 66px; height: 28px; overflow: visible; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.rio-letters { fill: none; stroke: var(--paper); stroke-width: 2.6; stroke-linecap: square; stroke-linejoin: miter; }
.rio-orbit { fill: none; stroke: var(--cyan); stroke-width: 1.2; stroke-opacity: 0.75; }
.rio-star { fill: var(--amber); }

.brand-title {
  margin: 0;
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.16em;
  background: linear-gradient(180deg, #ffffff 0%, #bfefff 55%, var(--cyan) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 28px rgba(126, 231, 255, 0.18);
}

.brand-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 0;
  color: var(--cyan);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.46em;
}

/* Та же орбита, что у знака RIO: линия со «звездой» связывает бренд и название. */
.brand-orbit {
  position: relative;
  flex: none;
  width: 42px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cyan));
}

.brand-orbit::after {
  content: "";
  position: absolute;
  right: -3px;
  top: -2.5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--amber);
}

#hud .hud-brand { white-space: nowrap; }
.hud-brand-sub { color: var(--cyan); font-weight: 500; }

@media (max-width: 720px) {
  .hud-brand-sub { display: none; }
  .brand-title { font-size: 32px; letter-spacing: 0.12em; }
}

/* ---------- Сюжетная сцена (игра и предпросмотр редактора) ---------- */

#quest-overlay.is-playing { place-items: stretch; padding: 16px; }

#quest-overlay.is-playing .quest-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1640px;
  min-height: calc(100vh - 32px);
  margin: 0 auto;
}

#quest-overlay.is-playing .quest-play { flex: 1; grid-template-columns: minmax(0, 1fr) 280px; align-items: start; }
/* Сцена с фоном занимает всю доступную высоту окна прохождения */
#quest-overlay.is-playing .scene-stage { min-height: calc(100vh - 170px); align-content: center; }

.scene-stage {
  position: relative;
  isolation: isolate;
  display: grid;
  gap: 18px;
  align-content: start;
  min-width: 0;
  min-height: 320px;
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(126, 231, 255, 0.14);
  background: radial-gradient(900px 420px at 20% 0%, rgba(56, 92, 140, 0.22), transparent 70%), #050a12;
}

.scene-stage.is-entering > * { animation: quest-enter 0.35s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .scene-stage.is-entering > * { animation: none; }
}

.scene-stage.has-art {
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  align-items: start;
}

.scene-backdrop {
  position: absolute;
  inset: -12px;
  z-index: -1;
  background-position: center;
  background-size: cover;
  filter: brightness(0.36) saturate(0.85) blur(1px);
}

.scene-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(5, 10, 18, 0.15), rgba(5, 10, 18, 0.75));
}

.scene-art {
  display: grid;
  place-items: center;
  min-width: 0;
  margin: 0;
  background: rgba(2, 6, 12, 0.6);
  border: 1px solid rgba(126, 231, 255, 0.22);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

/* contain: картинка видна целиком, важные части не обрезаются и не прячутся под текст */
.scene-art-img {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(66vh, 640px);
  object-fit: contain;
}

.scene-dialog {
  min-width: 0;
  padding: 18px 20px 16px;
  background: rgba(6, 13, 24, 0.88);
  border: 1px solid rgba(126, 231, 255, 0.22);
  backdrop-filter: blur(4px);
}

.scene-stage:not(.has-art) .scene-dialog { justify-self: center; width: min(780px, 100%); }

.scene-speaker { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }

.scene-portrait {
  flex: none;
  width: 76px;
  height: 76px;
  object-fit: cover;
  border: 1px solid rgba(255, 193, 74, 0.6);
  background: #0b1522;
}

.scene-speaker-name {
  color: var(--amber);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.scene-title { margin: 0 0 12px; font-size: 24px; font-weight: 600; overflow-wrap: anywhere; }

.scene-text p {
  margin: 0 0 14px;
  max-width: 68ch;
  font-family: "Segoe UI", Bahnschrift, sans-serif;
  font-size: 17px;
  line-height: 1.68;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.scene-prompt { margin: 16px 0 10px; color: var(--cyan); font-size: 15px; }
.scene-options { display: grid; gap: 8px; margin-top: 8px; }
.scene-options .quest-option span:last-child { overflow-wrap: anywhere; }

@media (max-width: 1100px) {
  .scene-stage.has-art { grid-template-columns: 1fr; }
  .scene-art-img { max-height: 46vh; }
}

@media (max-width: 820px) {
  #quest-overlay.is-playing { padding: 0; }
  #quest-overlay.is-playing .quest-shell { min-height: 100vh; padding: 12px; border: 0; }
  #quest-overlay.is-playing .quest-play { grid-template-columns: 1fr; }
  #quest-overlay.is-playing .scene-stage { min-height: 0; align-content: start; }
  .scene-stage { padding: 10px; gap: 12px; min-height: 0; }
  .scene-dialog { padding: 14px; }
  .scene-portrait { width: 56px; height: 56px; }
  .scene-title { font-size: 20px; }
  .scene-text p { font-size: 16px; line-height: 1.6; }
  .scene-art-img { max-height: 38vh; }
}

/* ---------- Посещение планеты ---------- */

.planet {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  /* Прозрачный слой: под ним сцена PixiJS (зал, персонаж, переходы). */
  background: transparent;
  animation: planet-in 0.35s ease-out;
}

/* Во время снижения виден только переход; интерфейс проявляется вместе с залом. */
.planet .planet-top,
.planet .planet-body { transition: opacity 0.45s ease; }
.planet.is-descending .planet-top,
.planet.is-descending .planet-body { opacity: 0; pointer-events: none; }
.planet.is-descending { cursor: pointer; }

/* На планете космический интерфейс скрыт: он относится к другой сцене. */
body.on-planet #hud,
body.on-planet #nav,
body.on-planet #roster,
body.on-planet #hint { visibility: hidden; }

.planet.is-closing { animation: planet-out 0.32s ease-in forwards; }

.planet-top {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 28px 0;
}

.planet-top h2 {
  margin: 2px 0 4px;
  font-size: 40px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

.planet-place { margin: 0; color: var(--cyan); letter-spacing: 0.08em; font-size: 14px; }

.planet-leave,
.nav-visit button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  font: 500 13px/1 Bahnschrift, "Segoe UI", sans-serif;
  letter-spacing: 0.06em;
  color: var(--paper);
  background: rgba(6, 12, 20, 0.6);
  border: 1px solid rgba(215, 231, 242, 0.35);
  cursor: pointer;
}

.planet-leave:hover { border-color: var(--cyan); color: var(--cyan); }

.planet kbd,
.nav-visit kbd {
  padding: 2px 5px;
  font: 600 11px/1 Consolas, monospace;
  color: var(--muted);
  border: 1px solid rgba(142, 164, 181, 0.5);
}

.planet-body {
  position: relative;
  display: grid;
  grid-template-columns: minmax(200px, 290px) minmax(0, 780px);
  justify-content: center;
  align-items: end;
  gap: 32px;
  min-height: 0;
  padding: 16px 28px 32px;
}

.planet-speaker {
  margin: 0;
  animation: planet-rise 0.6s ease-out both;
}

/* Место под анимированного персонажа: его рисует PixiJS, подпись остаётся в HTML. */
.planet-figure-slot {
  width: 100%;
  height: min(58vh, 540px);
}

.planet-speaker.is-animated { animation: none; }
.planet-speaker.is-animated figcaption { text-shadow: 0 1px 8px rgba(0, 0, 0, 0.85); }

/* Рамка портрета с «уголками» — как экран связи на пульте. */
.planet-portrait-frame {
  position: relative;
  aspect-ratio: 4 / 5;
  background: #0b1522;
  border: 1px solid rgba(126, 231, 255, 0.35);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 0 0 6px rgba(6, 12, 20, 0.55);
}

.planet-portrait-frame::before,
.planet-portrait-frame::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  border: 2px solid var(--amber);
  pointer-events: none;
}

.planet-portrait-frame::before { top: -7px; left: -7px; border-right: 0; border-bottom: 0; }
.planet-portrait-frame::after { right: -7px; bottom: -7px; border-left: 0; border-top: 0; }

.planet-portrait-frame img { display: block; width: 100%; height: 100%; object-fit: cover; }

.planet-speaker figcaption { display: grid; gap: 4px; margin-top: 14px; }

#planet-speaker-name {
  color: var(--amber);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

#planet-speaker-role { color: var(--muted); font-size: 13px; }

.planet-talk {
  min-width: 0;
  max-height: calc(100vh - 170px);
  overflow-y: auto;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.planet-talk.is-narration { grid-column: 1 / -1; justify-self: center; width: min(780px, 100%); }
.planet-talk.is-leaving { opacity: 0; transform: translateY(-8px); }

.planet .scene-stage {
  min-height: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  background: none;
}

.planet .scene-dialog {
  justify-self: stretch;
  width: 100%;
  padding: 22px 26px 20px;
  background: rgba(5, 12, 22, 0.86);
  border: 1px solid rgba(126, 231, 255, 0.2);
  border-left: 3px solid var(--amber);
  clip-path: polygon(0 0, calc(100% - 18px) 0, 100% 18px, 100% 100%, 0 100%);
  backdrop-filter: blur(8px);
}

.planet-talk.is-narration .scene-dialog { border-left-color: var(--cyan); }
.planet-talk.is-narration .scene-text p { font-style: italic; color: #c3d6e2; }

.planet .scene-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--cyan);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.planet-echo {
  display: flex;
  gap: 10px;
  margin: 0 0 10px;
  padding-left: 12px;
  color: #b9cad6;
  font-size: 14px;
  border-left: 2px solid rgba(255, 193, 74, 0.5);
}

.planet-echo-who { color: var(--amber); letter-spacing: 0.14em; text-transform: uppercase; font-size: 11px; padding-top: 2px; }

/* Реплика раскрывается по абзацам; щелчок или пробел показывают её сразу. */
.planet-talk.is-revealing .scene-title,
.planet-talk.is-revealing .scene-text p,
.planet-talk.is-revealing .scene-prompt,
.planet-talk.is-revealing .scene-options {
  animation: planet-line 0.55s ease-out both;
  animation-delay: calc(var(--i, 0) * 0.42s);
}

.planet-talk.is-instant .scene-title,
.planet-talk.is-instant .scene-text p,
.planet-talk.is-instant .scene-prompt,
.planet-talk.is-instant .scene-options { animation: none; }

.planet .quest-option { transition: background 0.15s, border-color 0.15s, opacity 0.25s, transform 0.25s; }
.planet .quest-option:hover:not(:disabled) { transform: translateX(4px); }
.planet .quest-option.is-chosen,
.planet .quest-option.is-chosen:disabled {
  opacity: 1;
  color: #fff;
  background: rgba(255, 193, 74, 0.16);
  border-color: var(--amber);
  transform: translateX(8px);
}
.planet .quest-option.is-chosen .quest-option-key { color: var(--amber); border-color: var(--amber); }
.planet .quest-option.is-dimmed:disabled { opacity: 0.28; }
.planet .planet-return { margin-top: 14px; color: var(--cyan); border-color: rgba(126, 231, 255, 0.5); }

.planet-journal {
  margin: 12px 0 0;
  padding: 8px 12px;
  color: #c9f27a;
  font-size: 13px;
  background: rgba(6, 12, 20, 0.7);
  border-left: 2px solid #c9f27a;
}

/* Кнопка посещения в панели навигации */
.nav-visit {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(126, 240, 195, 0.25);
  animation: planet-line 0.4s ease-out both;
}

#nav .nav-visit-place { margin: 0 0 6px; color: #7ef0c3; font-size: 12px; letter-spacing: 0.06em; }
.nav-visit button { color: #7ef0c3; border-color: rgba(126, 240, 195, 0.6); }
.nav-visit button:hover { background: rgba(126, 240, 195, 0.12); }

@keyframes planet-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes planet-out { to { opacity: 0; } }
@keyframes planet-rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes planet-line { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .planet, .planet.is-closing, .planet-speaker, .nav-visit { animation: none; }
  .planet-talk.is-revealing .scene-title,
  .planet-talk.is-revealing .scene-text p,
  .planet-talk.is-revealing .scene-prompt,
  .planet-talk.is-revealing .scene-options { animation: none; }
}

@media (max-width: 820px) {
  .planet { overflow-x: hidden; overflow-y: auto; grid-template-rows: auto auto; }
  .planet-top { padding: 14px 16px 0; }
  .planet-top h2 { font-size: 28px; }
  .planet-leave { padding: 8px 10px; }
  .planet-leave kbd { display: none; }
  .planet-body { grid-template-columns: 1fr; align-items: start; gap: 14px; padding: 12px 16px 20px; }
  .planet-speaker { display: flex; align-items: center; gap: 14px; }
  .planet-portrait-frame { flex: none; width: 92px; }
  .planet-figure-slot { flex: none; width: 116px; height: 210px; }
  .planet-speaker figcaption { margin-top: 0; }
  .planet-talk { max-height: none; overflow: visible; }
  .planet .scene-dialog { padding: 16px 16px 14px; }
}

/* ---------- Настройки ---------- */

.settings-shell { width: min(640px, 100%); }

.settings-tabs {
  display: flex;
  gap: 6px;
  margin-top: 16px;
  border-bottom: 1px solid rgba(126, 231, 255, 0.16);
}

.settings-tabs [role=tab] {
  padding: 10px 14px;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: 0;
  margin-bottom: -1px;
}

.settings-tabs [role=tab][aria-selected=true] {
  color: var(--cyan);
  border-color: rgba(126, 231, 255, 0.3);
  background: rgba(7, 16, 28, 0.94);
}

.settings-pane { padding-top: 16px; }

.settings-lead { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.5; }

.settings-table { width: 100%; border-collapse: collapse; }

.settings-table th,
.settings-table td {
  padding: 6px 8px 6px 0;
  text-align: left;
  border-bottom: 1px solid rgba(126, 231, 255, 0.08);
}

.settings-table thead th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.settings-table tbody th { font-weight: 500; font-size: 15px; }

.settings-key {
  width: 100%;
  min-width: 96px;
  padding: 8px 10px;
  background: rgba(3, 8, 14, 0.75);
  color: var(--paper);
  border: 1px solid rgba(126, 231, 255, 0.25);
  font: 15px/1.2 Consolas, "Cascadia Mono", monospace;
  letter-spacing: 0.02em;
  text-transform: none;
}

.settings-key:hover { border-color: var(--cyan); }
.settings-key.is-empty { color: var(--muted); }
.settings-key.is-waiting { color: var(--amber); border-color: var(--amber); }

.settings-note { min-height: 1.4em; margin: 12px 0 0; color: var(--amber); font-size: 14px; }

.settings-actions { display: flex; justify-content: flex-end; margin-top: 8px; }

.settings-check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--paper);
  cursor: pointer;
}

.settings-check input { width: 18px; height: 18px; accent-color: var(--cyan); }

.settings-range {
  display: grid;
  grid-template-columns: auto 1fr 48px;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
  font-size: 14px;
  color: var(--paper);
}

.settings-range input { padding: 0; accent-color: var(--cyan); }
.settings-range input:disabled { opacity: 0.4; }
.settings-range output { font-family: Consolas, "Cascadia Mono", monospace; color: var(--cyan); text-align: right; }

@media (max-width: 560px) {
  .settings-range { grid-template-columns: 1fr 48px; }
  .settings-range span { grid-column: 1 / -1; }
  .settings-key { min-width: 0; }
}

/* Кнопок в панели много: на узком экране они компактнее и не переносят подписи. */
@media (max-width: 1100px) {
  #hud { gap: 10px; }
  #hud button, #hud .hud-link { padding: 6px 8px; font-size: 12px; letter-spacing: 0.04em; white-space: nowrap; }
  .hud-brand-sub { display: none; }
}
