/* Космосим: Вход — квест. Стиль зеркалит основную игру: темная палуба,
   скошенные панели, угловые скобы, янтарно-циановые акценты, CRT-эффекты.
   Палитра продублирована в js/art.js (Art.C). */

:root {
  --bg: #070a10;
  --panel: #121a28;
  --panel-hi: #1a2434;
  --edge: #26344a;
  --edge-hi: #3d5470;
  --ink: #dce6f2;
  --ink-dim: #8a97a8;
  --ink-faint: #5a6675;
  --good: #57f2a0;
  --warn: #ffd166;
  --bad: #ff5c7a;
  --cyan: #6ee0f2;
  --blue: #7aa2ff;
  --zill: #9fd8b0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  touch-action: manipulation;
  background:
    radial-gradient(1100px 600px at 50% -100px, #101828 0%, transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  min-height: 100vh;
}

#game-wrap {
  position: relative;
  width: min(960px, 100%);
  margin: 64px auto 16px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  box-shadow: 0 0 0 1px var(--edge), 0 0 44px rgba(0, 0, 0, 0.6);
}

#game-wrap::before,
#game-wrap::after {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  pointer-events: none;
  z-index: 60;
}
#game-wrap::before {
  top: -5px; left: -5px;
  border-top: 2px solid var(--cyan);
  border-left: 2px solid var(--cyan);
}
#game-wrap::after {
  bottom: -5px; right: -5px;
  border-bottom: 2px solid var(--cyan);
  border-right: 2px solid var(--cyan);
}

#stage { position: relative; }

#canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  background: #0d1117;
}

#fx-scan, #fx-vig {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 55;
}
#fx-scan {
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.028) 0px,
    rgba(255, 255, 255, 0.028) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
}
#fx-vig {
  background: radial-gradient(120% 120% at 50% 45%, transparent 62%, rgba(2, 4, 8, 0.5) 100%);
}

.hidden { display: none !important; }

/* ---------- Терминал сеанса (HUD) ---------- */

#hud {
  position: absolute;
  top: -8px; left: 0; right: 0;
  transform: translateY(-100%);
  display: flex;
  gap: 8px;
  padding: 6px 0;
}

.hud-item {
  flex: 1 1 0;
  min-width: 0;
  background: linear-gradient(180deg, #16202f 0%, #101826 100%);
  border: 1px solid var(--edge);
  border-bottom: 2px solid var(--edge);
  padding: 5px 10px 4px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.hud-item::before {
  content: '';
  position: absolute;
  left: 0; top: -1px; bottom: -2px;
  width: 2px;
  background: var(--edge-hi);
}
.hud-item.good::before { background: var(--good); box-shadow: 0 0 8px rgba(87, 242, 160, 0.7); }
.hud-item.warn::before { background: var(--warn); box-shadow: 0 0 8px rgba(255, 209, 102, 0.7); }
.hud-item.cyan::before { background: var(--cyan); box-shadow: 0 0 8px rgba(110, 224, 242, 0.7); }
.hud-item.blue::before { background: var(--blue); box-shadow: 0 0 8px rgba(122, 162, 255, 0.7); }
.hud-item.bad::before { background: var(--bad); box-shadow: 0 0 8px rgba(255, 92, 122, 0.7); }

.hud-label { color: var(--ink-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; }
.hud-value {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-item.good .hud-value { color: var(--good); }
.hud-item.warn .hud-value { color: var(--warn); }
.hud-item.cyan .hud-value { color: var(--cyan); }
.hud-item.blue .hud-value { color: var(--blue); }
.hud-item.bad .hud-value { color: var(--bad); }

/* ---------- Инвентарь ---------- */

#inv {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 8px 0 2px;
}

.inv-label {
  align-self: center;
  color: var(--ink-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  padding: 0 4px;
}

#inv-slots { display: flex; gap: 6px; flex-wrap: wrap; flex: 1 1 auto; }

.inv-slot {
  font-family: inherit;
  font-size: 12px;
  color: var(--ink);
  background: linear-gradient(180deg, #16202f 0%, #101826 100%);
  border: 1px solid var(--edge);
  border-left: 3px solid var(--edge-hi);
  padding: 6px 10px;
  cursor: pointer;
}
.inv-slot:hover { border-color: var(--edge-hi); background: linear-gradient(180deg, #1c2838 0%, #141d2b 100%); }
.inv-slot.selected { border-color: var(--warn); border-left-color: var(--warn); color: var(--warn); box-shadow: 0 0 10px rgba(255, 209, 102, 0.25); }

#btn-hint { margin-left: auto; }
#btn-hint.active {
  border-color: var(--cyan);
  border-left-color: var(--cyan);
  color: var(--cyan);
  box-shadow: 0 0 12px rgba(110, 224, 242, 0.3);
}
#btn-terminal { margin-left: 0; }

/* ---------- Подсказка наведения ---------- */

#interact-hint {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(13, 19, 30, 0.92);
  border: 1px solid var(--edge-hi);
  border-left: 3px solid var(--warn);
  padding: 6px 14px;
  font-size: 13px;
  letter-spacing: 0.02em;
  pointer-events: none;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}

/* ---------- Тосты ---------- */

#toasts {
  position: absolute;
  right: 12px; top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  max-width: 360px;
  z-index: 20;
}

.toast {
  background: linear-gradient(180deg, rgba(22, 32, 47, 0.96), rgba(14, 21, 32, 0.96));
  border: 1px solid var(--edge-hi);
  border-left: 3px solid var(--cyan);
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.4;
  animation: toast-in 0.18s ease-out;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
}
.toast.session { font-family: "Consolas", "Courier New", monospace; font-size: 12px; color: var(--cyan); }
.toast.zill {
  border-left-color: var(--zill);
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
  color: var(--zill);
  background: linear-gradient(180deg, rgba(20, 30, 26, 0.96), rgba(12, 20, 16, 0.96));
}
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--bad); }
.toast.kira { border-left-color: var(--warn); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Оверлеи ---------- */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 12, 0.72);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.dialog-box, .choice-box, .menu-box {
  position: relative;
  background: linear-gradient(180deg, #141d2c 0%, #0f1622 100%);
  border: 1px solid var(--edge);
}
.dialog-box::before, .choice-box::before, .menu-box::before,
.dialog-box::after, .choice-box::after, .menu-box::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  pointer-events: none;
}
.dialog-box::before, .choice-box::before, .menu-box::before {
  top: -1px; left: -1px;
  border-top: 2px solid var(--cyan);
  border-left: 2px solid var(--cyan);
}
.dialog-box::after, .choice-box::after, .menu-box::after {
  bottom: -1px; right: -1px;
  border-bottom: 2px solid var(--cyan);
  border-right: 2px solid var(--cyan);
}

/* ---------- Диалог (визуальная новелла: строка внизу экрана) ---------- */

#dialog {
  background: none;
  backdrop-filter: none;
  align-items: flex-end;
  pointer-events: none;
}

.dialog-box {
  width: min(920px, 100%);
  border: 1px solid var(--edge);
  border-top: 2px solid var(--cyan);
  background: linear-gradient(180deg, rgba(16, 24, 38, 0.94) 0%, rgba(10, 15, 24, 0.94) 100%);
  backdrop-filter: blur(3px);
  box-shadow: 0 0 34px rgba(110, 224, 242, 0.1), 0 -12px 40px rgba(0, 0, 0, 0.55);
  padding: 14px 22px 12px;
  margin: 0 14px 14px;
  cursor: pointer;
  pointer-events: auto;
}

.dialog-name {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--cyan);
  margin-bottom: 6px;
}

.dialog-text { font-size: 16px; line-height: 1.5; }

.dialog-next {
  margin-top: 8px;
  font-size: 11px;
  color: var(--ink-faint);
  text-align: right;
  letter-spacing: 0.06em;
}

/* ---------- Модалка выбора ---------- */

.choice-box {
  width: 580px;
  padding: 20px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.choice-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--edge);
}
.choice-desc { font-size: 14px; color: var(--ink-dim); line-height: 1.5; margin: 12px 0 16px; white-space: pre-line; }

.choice-buttons { display: flex; flex-direction: column; gap: 8px; max-height: 440px; overflow-y: auto; padding-right: 2px; }

.btn {
  font-family: inherit;
  font-size: 14px;
  background: linear-gradient(180deg, #1e2a3c 0%, #182231 100%);
  color: var(--ink);
  border: 1px solid var(--edge);
  border-left: 3px solid var(--edge-hi);
  padding: 10px 16px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.12s ease, box-shadow 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #283953 0%, #1f2d42 100%);
  border-color: var(--edge-hi);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary { border-left-color: var(--good); }
.btn-primary:hover:not(:disabled) { border-color: var(--good); box-shadow: 0 0 16px rgba(87, 242, 160, 0.18), 0 4px 14px rgba(0, 0, 0, 0.4); }
.btn-danger { border-left-color: var(--bad); }

.btn .btn-sub { display: block; font-size: 12px; color: var(--ink-dim); margin-top: 2px; }

/* ---------- Наручный терминал ---------- */

.term-box { width: 620px; }

.term-tabs { display: flex; gap: 8px; margin: 14px 0 10px; }
.term-tabs .tab { flex: 0 0 auto; padding: 7px 18px; }
.term-tabs .tab.active { border-color: var(--cyan); border-left-color: var(--cyan); color: var(--cyan); }

.term-list {
  min-height: 240px;
  max-height: 340px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}

.term-task {
  font-size: 14px;
  line-height: 1.45;
  padding: 8px 12px;
  border: 1px solid var(--edge);
  border-left: 3px solid var(--warn);
  background: rgba(10, 15, 24, 0.6);
}
.term-task.done { border-left-color: var(--good); color: var(--ink-dim); }
.term-task.done .tt-text { text-decoration: line-through; }
.term-task .tt-mark { color: var(--ink-faint); font-size: 11px; display: block; margin-top: 2px; }

.term-doc {
  padding: 10px 12px;
  border: 1px solid var(--edge);
  border-left: 3px solid var(--blue);
  background: rgba(10, 15, 24, 0.6);
  font-size: 13px;
  line-height: 1.5;
}
.term-doc .td-kind {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--blue);
  display: block;
  margin-bottom: 3px;
}
.term-doc.zill { border-left-color: var(--zill); }
.term-doc.zill .td-kind { color: var(--zill); }

.term-close { margin-top: 12px; display: flex; justify-content: flex-end; }

/* ---------- Меню и финал ---------- */

/* рисованный фон экрана: титул в меню, стоянка в финале */
.screen-back {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  filter: brightness(0.62) saturate(0.92);
  /* без анимации появления: в фоновой панели она замирала на opacity 0
     и вместо иллюстрации был виден канвас под ней */
}

/* финальная стоянка сама по себе темная — гасим ее меньше */
#screen-end .screen-back { filter: brightness(0.8) saturate(0.95); }

.menu-box {
  width: 620px;
  padding: 30px 40px 26px;
  text-align: center;
  box-shadow: 0 0 44px rgba(110, 224, 242, 0.07), 0 14px 44px rgba(0, 0, 0, 0.65);
}

.menu-title {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  background: linear-gradient(180deg, #b8ffd9 0%, var(--good) 55%, #1f9e68 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 14px rgba(87, 242, 160, 0.35));
}
.menu-title.quest {
  background: linear-gradient(180deg, #c9f4ff 0%, var(--cyan) 55%, #2f8ba8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 14px rgba(110, 224, 242, 0.35));
}

.menu-subtitle { color: var(--ink-dim); margin-top: 6px; font-size: 14px; letter-spacing: 0.04em; }

.menu-goal {
  margin: 20px auto;
  padding: 13px 18px;
  background: rgba(9, 13, 20, 0.75);
  border: 1px dashed var(--edge-hi);
  font-size: 14px;
  line-height: 1.65;
  text-align: left;
}
.menu-goal b { color: var(--warn); }

.menu-buttons { display: flex; flex-direction: column; gap: 8px; margin: 0 auto 16px; width: 320px; }
.menu-buttons .btn { text-align: center; }

.menu-help {
  font-size: 12px;
  color: var(--ink-dim);
  line-height: 1.75;
  text-align: left;
  border-top: 1px solid var(--edge);
  padding-top: 12px;
}
.menu-help b { color: var(--cyan); font-family: "Consolas", "Courier New", monospace; }

/* экран выбора стартовой сцены */
.select-box { width: 680px; max-height: 94%; overflow-y: auto; overflow-x: hidden; }
.sel-title { font-size: 26px; letter-spacing: 0.2em; text-indent: 0.2em; }
.sel-back { margin-top: 14px; margin-bottom: 0; }
#select-list { text-align: left; margin-top: 10px; }
.sel-episode {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 12px 2px 6px;
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--edge);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
}
.sel-episode:first-child { margin-top: 2px; }
.sel-episode b { color: var(--cyan); font-size: 13px; }
.sel-scenes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.sel-scene {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 7px 11px;
  font-size: 13px;
  min-width: 0;
}
.sel-scene .ss-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-scene .ss-bal {
  color: var(--ink-dim);
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px;
  white-space: nowrap;
}
.sel-scene:hover:not(:disabled) .ss-bal { color: var(--warn); }

.choice-buttons::-webkit-scrollbar, .term-list::-webkit-scrollbar { width: 8px; }
.choice-buttons::-webkit-scrollbar-track, .term-list::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.04); }
.choice-buttons::-webkit-scrollbar-thumb, .term-list::-webkit-scrollbar-thumb { background: var(--edge-hi); }

@media (pointer: coarse) {
  #fx-scan { display: none; }
  .overlay { backdrop-filter: none; }
}

@media (max-width: 760px) {
  #game-wrap { margin-top: 10px; }
  #hud {
    position: static;
    transform: none;
    flex-wrap: wrap;
    gap: 5px;
    padding: 0 0 8px;
  }
  .hud-item { flex: 1 1 30%; min-width: 0; padding: 3px 7px; gap: 6px; }
  .hud-label { font-size: 8px; }
  .hud-value { font-size: 12px; }
  .overlay { padding: 8px; position: fixed; z-index: 70; }
  .dialog-box, .choice-box, .menu-box { max-width: 100%; }
  .dialog-box { width: auto; padding: 14px 16px; }
  .dialog-text { font-size: 15px; }
  .choice-box { width: auto; padding: 16px; }
  .choice-buttons { max-height: 56vh; }
  .menu-box { width: auto; max-height: 100%; overflow-y: auto; padding: 22px 16px 18px; }
  .menu-title { font-size: 28px; letter-spacing: 0.18em; text-indent: 0.18em; }
}
