/* Багровая Луна — оформление интерфейса.
   Все экраны лежат в одной сетке и переключаются классом, поэтому
   перекрыть друг друга они не могут: активен всегда ровно один. */

:root {
  --ink: #0b0810;
  --ink-2: #140f1c;
  --ink-3: #1e1729;
  --line: #38294c;
  --text: #efe6f5;
  --muted: #a294b8;
  --crimson: #d33350;
  --crimson-dim: #8e2038;
  --gold: #e8b451;
  --moon: #cbb6ff;
  --ok: #58c98a;
  --radius: 14px;
  --gap: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --font: "Trebuchet MS", "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template: 1fr / 1fr;
  isolation: isolate;
}

.screen {
  grid-area: 1 / 1;
  display: none;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.screen--active { display: flex; flex-direction: column; }

/* --------------------------------- Загрузка -------------------------------- */

.boot {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
}

.boot__moon {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: radial-gradient(circle at 62% 38%, #ff5a75, var(--crimson) 45%, #5c0f22 100%);
  box-shadow: 0 0 60px rgba(211, 51, 80, 0.45);
  animation: pulse 2.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.92; }
  50% { transform: scale(1.06); opacity: 1; }
}

.boot__title {
  margin: 0;
  font-size: clamp(28px, 7vw, 46px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 0 24px rgba(211, 51, 80, 0.55);
}

.boot__bar {
  width: min(320px, 70vw);
  height: 8px;
  border-radius: 999px;
  background: var(--ink-3);
  overflow: hidden;
}

.boot__bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--crimson-dim), var(--crimson));
  transition: width 0.25s ease;
}

.boot__hint { margin: 0; color: var(--muted); font-size: 14px; min-height: 20px; }

/* ---------------------------------- Меню ----------------------------------- */

#screen-menu { position: relative; }

.menu__scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.menu {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(11, 8, 16, 0.86) 0%, rgba(11, 8, 16, 0.5) 40%, rgba(11, 8, 16, 0.9) 100%);
}

.menu__head { text-align: center; max-width: 560px; }

.menu__title {
  margin: 0;
  font-size: clamp(30px, 8vw, 56px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-shadow: 0 2px 0 #000, 0 0 30px rgba(211, 51, 80, 0.6);
}

.menu__sub { margin: 8px 0 0; color: var(--muted); font-size: clamp(13px, 3.4vw, 15px); }

.menu__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.menu__nav {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  width: min(340px, 88vw);
}

.menu__promo {
  width: min(420px, 92vw);
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(211, 51, 80, 0.18), rgba(20, 15, 28, 0.9));
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.menu__promo h3 { margin: 0; font-size: 16px; }
.menu__promo p { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }

.menu__foot { color: var(--muted); font-size: 11px; text-align: center; max-width: 520px; line-height: 1.5; }

/* -------------------------------- Панели ----------------------------------- */

.screen--panel { background: radial-gradient(120% 80% at 50% 0%, #1b1426 0%, var(--ink) 70%); }

.panel__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(12px + var(--safe-t)) calc(14px + var(--safe-r)) 12px calc(14px + var(--safe-l));
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.panel__head h2 { margin: 0; font-size: clamp(17px, 4.6vw, 22px); flex: 1; letter-spacing: 0.06em; }

.panel__lead,
.panel__note {
  margin: 12px calc(14px + var(--safe-r)) 0 calc(14px + var(--safe-l));
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  flex: 0 0 auto;
}

.panel__note { margin-bottom: calc(14px + var(--safe-b)); font-size: 11px; }

.purse {
  font-size: 13px;
  color: var(--gold);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  grid-auto-rows: max-content;
  gap: var(--gap);
  padding: var(--gap) calc(14px + var(--safe-r)) calc(14px + var(--safe-b)) calc(14px + var(--safe-l));
  align-content: start;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px calc(14px + var(--safe-r)) 0 calc(14px + var(--safe-l));
  overflow-x: auto;
  flex: 0 0 auto;
}

.tab {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--ink-2);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.tab[aria-selected="true"] { background: var(--crimson-dim); color: #fff; border-color: var(--crimson); }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(160deg, var(--ink-3), var(--ink-2));
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.card--locked { opacity: 0.55; }
.card--done { border-color: var(--ok); }
.card--best { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(232, 180, 81, 0.35) inset; }

.card__row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.card__icon { flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center; color: var(--crimson); }
.card__title { margin: 0; font-size: 15px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.card__desc { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.card__level { font-size: 12px; color: var(--moon); white-space: nowrap; }
.card__foot { margin-top: auto; display: flex; align-items: center; gap: 8px; }
.card__price { font-size: 13px; color: var(--gold); white-space: nowrap; font-variant-numeric: tabular-nums; }

.pips { display: flex; gap: 3px; }
.pips i { width: 12px; height: 5px; border-radius: 2px; background: var(--ink); border: 1px solid var(--line); }
.pips i.on { background: var(--crimson); border-color: var(--crimson); }

/* -------------------------------- Кнопки ----------------------------------- */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--ink-3), var(--ink-2));
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 11px 16px;
  border-radius: 11px;
  cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
  min-height: 44px;
  text-align: center;
}

.btn:hover:not(:disabled) { border-color: var(--crimson); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn--primary {
  background: linear-gradient(180deg, var(--crimson), var(--crimson-dim));
  border-color: var(--crimson);
  font-weight: 700;
  letter-spacing: 0.05em;
}

.btn--gold { background: linear-gradient(180deg, #c9962f, #8a6415); border-color: var(--gold); color: #fff8e6; }
.btn--ghost { background: transparent; }
.btn--small { font-size: 13px; padding: 8px 12px; min-height: 38px; }

.btn--icon {
  width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  flex: 0 0 auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(20, 15, 28, 0.82);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.chip--shard { color: var(--moon); }
.chip--gold { color: var(--gold); }

/* --------------------------------- Забег ----------------------------------- */

#screen-run { position: relative; background: #05040a; }

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

.hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  pointer-events: none;
  z-index: 2;
}

.hud__top { display: flex; align-items: flex-start; gap: 12px; }
.hud__vitals { display: flex; flex-direction: column; gap: 6px; width: min(230px, 45vw); }
.hud__meta { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.hud__pause { pointer-events: auto; background: rgba(20, 15, 28, 0.82); }

.bar {
  position: relative;
  height: 18px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(11, 8, 16, 0.8);
  overflow: hidden;
}

.bar i {
  position: absolute;
  inset: 0;
  width: 100%;
  transform-origin: left;
  transition: transform 0.16s ease;
}

.bar--hp i { background: linear-gradient(90deg, #ff5570, var(--crimson-dim)); }
.bar--moon { height: 12px; }
.bar--moon i { background: linear-gradient(90deg, #b39bff, #6d4fd6); }

.bar span {
  position: relative;
  display: block;
  text-align: center;
  font-size: 11px;
  line-height: 16px;
  text-shadow: 0 1px 2px #000;
  font-variant-numeric: tabular-nums;
}

.bar--moon span { line-height: 10px; font-size: 9px; letter-spacing: 0.14em; }

.boss {
  align-self: center;
  width: min(360px, 78%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.boss[hidden] { display: none; }
.boss b { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; text-shadow: 0 1px 3px #000; }
.boss .bar { width: 100%; height: 12px; }
.bar--boss i { background: linear-gradient(90deg, #ff4a68, #7a1428); }

.hud__spells { display: flex; gap: 8px; }

.slot {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(11, 8, 16, 0.78);
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.slot img { width: 32px; height: 32px; image-rendering: pixelated; }
.slot--empty { opacity: 0.4; }
.slot__key { position: absolute; right: 3px; bottom: 1px; font-size: 9px; color: var(--muted); }
.slot__cd { position: absolute; inset: 0; background: rgba(5, 4, 10, 0.7); transform-origin: bottom; }

.hud__relics { display: flex; flex-wrap: wrap; gap: 6px; max-width: 60%; }

.relic {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(20, 15, 28, 0.8);
  color: var(--moon);
}

.hud__toast {
  margin: 6px auto auto;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(11, 8, 16, 0.9);
  border: 1px solid var(--crimson);
  font-size: 14px;
  text-align: center;
  animation: toast 0.3s ease;
  max-width: 90%;
}

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

/* --------------------------- Сенсорное управление -------------------------- */

.touch {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 calc(14px + var(--safe-r)) calc(14px + var(--safe-b)) calc(14px + var(--safe-l));
  pointer-events: none;
}

.touch__pad, .touch__acts { display: flex; gap: 10px; align-items: flex-end; pointer-events: none; }
.touch__acts { display: grid; grid-template-columns: repeat(2, auto); gap: 10px; }

.touch__btn {
  pointer-events: auto;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(20, 15, 28, 0.66);
  color: var(--text);
  font-size: 20px;
  display: grid;
  place-items: center;
  touch-action: none;
  backdrop-filter: blur(2px);
}

.touch__btn:active, .touch__btn[data-down="1"] { background: rgba(211, 51, 80, 0.55); }
.touch__btn--attack { width: 72px; height: 72px; font-size: 26px; border-color: var(--crimson); }
.touch__btn--jump { border-color: var(--moon); }

/* -------------------------------- Модалки ---------------------------------- */

.modal {
  grid-area: 1 / 1;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: rgba(5, 4, 10, 0.82);
  backdrop-filter: blur(3px);
}

.modal[hidden] { display: none; }

.modal__box {
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(160deg, #201830, var(--ink-2));
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.modal__title { margin: 0; font-size: clamp(18px, 5vw, 22px); letter-spacing: 0.05em; }
.modal__text { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.55; }
.modal__body { display: grid; gap: 10px; }
.modal__body:empty { display: none; }
.modal__actions { display: grid; gap: 8px; }
.modal__actions:empty { display: none; }

.choice {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
}

.choice strong { font-size: 15px; }
.choice span { font-size: 12.5px; color: var(--muted); line-height: 1.45; }

.stats-list { display: grid; gap: 6px; font-size: 13px; }
.stats-list div { display: flex; justify-content: space-between; gap: 12px; }
.stats-list dt { color: var(--muted); }
.stats-list dd { margin: 0; font-variant-numeric: tabular-nums; }

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

.settings {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px calc(14px + var(--safe-r)) 14px calc(14px + var(--safe-l));
}

.setting {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink-2);
}

.setting__label { flex: 1; min-width: 0; }
.setting__label b { display: block; font-size: 14px; font-weight: 600; }
.setting__label span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

.switch {
  flex: 0 0 auto;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--ink);
  position: relative;
  cursor: pointer;
}

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

.switch[aria-checked="true"] { background: var(--crimson-dim); border-color: var(--crimson); }
.switch[aria-checked="true"]::after { transform: translateX(22px); background: #fff; }

.range { flex: 0 0 120px; }

/* --------------------------------- Вспышка --------------------------------- */

.flash {
  grid-area: 1 / 1;
  z-index: 20;
  pointer-events: none;
  background: #fff;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.flash[hidden] { display: none; }
.flash.on { opacity: 0.85; transition: opacity 0.05s ease; }

/* ------------------------------- Адаптивность ------------------------------ */

@media (max-height: 520px) {
  .menu { gap: 10px; justify-content: flex-start; padding-top: calc(10px + var(--safe-t)); }
  .menu__sub { display: none; }
  .menu__nav { width: min(300px, 80vw); }
  .btn { min-height: 40px; padding: 8px 14px; }
  .touch__btn { width: 52px; height: 52px; }
  .touch__btn--attack { width: 62px; height: 62px; }
}

@media (min-width: 720px) {
  .menu__nav { grid-template-columns: 1fr 1fr; width: min(460px, 90vw); }
  .menu__nav .btn--primary { grid-column: 1 / -1; }
}
