/* Космосим: Скребок — визуальный слой HUD.
   «Рабочий космос»: темная палуба, скошенные панели, угловые скобы,
   янтарно-циановые акценты, легкие 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;
}

* { 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;
}

/* рамка игры: вписывается в окно и по ширине, и по высоте (канвас 3:2),
   на большом экране масштабируется вверх; канвас тянется вместе с ней */
#game-wrap {
  position: relative;
  width: min(100%, calc((100vh - 88px) * 1.5));
  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);
}

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

/* CRT-эффекты поверх всего: сетка развертки и виньетка */
#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;
  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;
}

/* цветной ключ по левому краю чипа */
.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-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: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.hud-sub { color: var(--ink-dim); font-size: 10px; font-variant-numeric: tabular-nums; }
.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-ячейки */
.hud-bar {
  flex: 1 1 auto;
  min-width: 40px;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--edge);
  align-self: center;
}

.hud-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #b8860b, var(--warn));
  box-shadow: 0 0 8px rgba(255, 209, 102, 0.5);
  transition: width 0.3s ease-out;
}

/* ---------- Подсказка взаимодействия ---------- */

#interact-hint {
  position: absolute;
  bottom: 64px;
  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: 7px 16px;
  font-size: 14px;
  letter-spacing: 0.02em;
  pointer-events: none;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5);
}

/* ---------- Реплика Киры ---------- */

#kira-line {
  position: absolute;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  max-width: 70%;
  background: rgba(22, 18, 10, 0.92);
  border: 1px solid rgba(255, 209, 102, 0.75);
  border-left: 3px solid var(--warn);
  padding: 8px 14px;
  font-size: 14px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 0 24px rgba(255, 209, 102, 0.12), 0 4px 18px rgba(0, 0, 0, 0.5);
}
#kira-line b { color: var(--warn); }

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

#toasts {
  position: absolute;
  right: 12px; bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  max-width: 340px;
}

.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(--good);
  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.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--bad); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: translateX(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-box {
  width: 640px;
  border-top: 2px solid var(--cyan);
  box-shadow: 0 0 34px rgba(110, 224, 242, 0.1), 0 12px 40px rgba(0, 0, 0, 0.6);
  padding: 18px 22px;
  cursor: pointer;
}

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

.dialog-text { font-size: 17px; line-height: 1.55; }

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

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

.choice-box {
  width: 560px;
  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; }

/* подсказка поворота на телефоне: поверх всех оверлеев */
#rotate { z-index: 80; }
.rotate-box { width: min(560px, 92%); text-align: center; }

.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-danger:hover:not(:disabled) { border-color: var(--bad); box-shadow: 0 0 16px rgba(255, 92, 122, 0.18), 0 4px 14px rgba(0, 0, 0, 0.4); }

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

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

.menu-box {
  width: 620px;
  max-height: 100%;
  overflow-y: auto;
  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-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; }

#end-title.win { color: var(--good); background: linear-gradient(180deg, #b8ffd9, var(--good)); }
#end-title.lose {
  color: var(--bad);
  background: linear-gradient(180deg, #ffc2d0, var(--bad));
  filter: drop-shadow(0 0 14px rgba(255, 92, 122, 0.35));
}
#end-title.early { color: var(--warn); background: linear-gradient(180deg, #ffe9b8, var(--warn)); }

/* ---------- скроллбар ---------- */

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

/* ---------- мобильная верстка ---------- */

/* тач-устройства: дорогое сглаживание канвас-эффектами смягчаем */
@media (pointer: coarse) {
  #fx-scan { display: none; }
  .overlay { backdrop-filter: none; }
}

/* узкий экран: HUD перестраивается сеткой над канвасом, панели вписываются в ширину */
@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-item.hud-wide { flex: 1 1 100%; }
  .hud-label { font-size: 8px; }
  .hud-value { font-size: 12px; }
  .hud-sub { font-size: 8px; }
  .hud-bar { min-width: 24px; }

  .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; }
  .menu-goal { font-size: 13px; margin: 14px auto; }
  .menu-help { font-size: 11px; }
  #kira-line { max-width: 94%; font-size: 13px; }
  #toasts { max-width: 72vw; }
}

/* низкий экран (телефон в альбомной): канвас занимает почти всю высоту, HUD одна строка */
@media (orientation: landscape) and (max-height: 520px) {
  #game-wrap {
    width: min(100%, calc((100vh - 40px) * 1.5));
    margin: 6px auto;
  }
  #hud { position: static; transform: none; flex-wrap: nowrap; gap: 3px; padding: 0 0 2px; }
  .hud-item { padding: 1px 5px; min-width: 0; overflow: hidden; gap: 4px; }
  .hud-label, .hud-sub { display: none; }
  .hud-value { font-size: 10px; }
  .hud-bar { min-width: 14px; height: 4px; }
  .menu-box { max-width: 100%; max-height: 100%; overflow-y: auto; padding: 12px 14px; }
}
