/* ==========================================================================
   Легенды Прод-Комитета — фэнтези-тема
   Структура: токены → база → фон → шапка → статы → карточка сцены →
   варианты выбора → кнопка «Назад» → тост → адаптив/анимации.
   ========================================================================== */

/* ------------------------------- Токены -------------------------------- */
:root {
  --bg: #0f0b1e;
  --bg-2: #1a1233;
  --panel: #1c1436;
  --panel-2: #241a45;
  --line: rgba(233, 196, 106, 0.28);
  --gold: #e9c46a;
  --gold-soft: #f2d99b;
  --accent: #a06bff;
  --accent-2: #6b4bff;
  --text: #ece7ff;
  --muted: #a99fd0;
  --danger: #ff7a7a;
  --ok: #7ee0a5;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);

  --font-serif: "Georgia", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Отступы с учётом «брови» iPhone */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* -------------------------------- База --------------------------------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(1200px 700px at 50% -10%, #2a1b52 0%, transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

/* Запрещаем случайный зум по двойному тапу */
button, a { touch-action: manipulation; }

/* ------------------------------ Фон-руны ------------------------------- */
.bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.bg__rune {
  position: absolute;
  font-family: var(--font-serif);
  color: rgba(160, 107, 255, 0.14);
  font-size: 120px;
  animation: float 14s ease-in-out infinite;
}
.bg__rune--1 { top: 8%; left: 6%; animation-delay: 0s; }
.bg__rune--2 { top: 60%; right: 8%; animation-delay: -5s; }
.bg__rune--3 { bottom: 6%; left: 40%; animation-delay: -9s; }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0.5; }
  50%      { transform: translateY(-24px) rotate(6deg); opacity: 0.9; }
}

/* ------------------------------- Каркас -------------------------------- */
.app {
  position: relative;
  z-index: 1;
  max-width: 620px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar__logo { font-size: 22px; }

.topbar__name {
  font-family: var(--font-serif);
  font-size: 15px;
  letter-spacing: 0.02em;
  color: var(--gold-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__reset {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.topbar__reset:active { transform: scale(0.92); background: rgba(255, 255, 255, 0.1); }

/* -------------------------------- Статы -------------------------------- */
.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.stat {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(233, 196, 106, 0.08);
  color: var(--gold-soft);
  white-space: nowrap;
}

.stat--coffee { background: rgba(233, 196, 106, 0.12); }
.stat--debt   { background: rgba(160, 107, 255, 0.14); border-color: rgba(160, 107, 255, 0.4); color: #d9c9ff; }

.stat--danger {
  color: #fff;
  background: rgba(255, 122, 122, 0.22);
  border-color: rgba(255, 122, 122, 0.6);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 122, 122, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 122, 122, 0); }
}

/* ------------------------------- Сцена --------------------------------- */
.scene {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  position: relative;
  padding: 20px 18px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(233, 196, 106, 0.06) 0%, transparent 30%),
    linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Тонкая «золотая» кромка сверху */
.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0.7;
}

.card--enter { animation: cardIn 0.35s cubic-bezier(0.2, 0.9, 0.3, 1); }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.99); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.card__icon {
  font-size: 44px;
  line-height: 1;
  margin-bottom: 10px;
  filter: drop-shadow(0 6px 16px rgba(160, 107, 255, 0.35));
}

.card__title {
  margin: 0 0 12px;
  font-family: var(--font-serif);
  font-size: 24px;
  line-height: 1.2;
  color: var(--gold-soft);
}

.card__text { color: var(--text); }
.card__text p { margin: 0 0 12px; }
.card__text p:last-child { margin-bottom: 0; }

.card__text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(160, 107, 255, 0.35);
  color: #d9c9ff;
}

.card__text strong { color: var(--gold-soft); }

.player-name {
  color: var(--gold);
  font-weight: 700;
}

/* Плашка с титулом в концовке */
.rank {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--line);
  background: rgba(233, 196, 106, 0.07);
}
.rank__label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.rank__value { font-family: var(--font-serif); font-size: 20px; color: var(--gold); }

/* ---------------------------- Варианты выбора --------------------------- */
.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice {
  position: relative;
  width: 100%;
  text-align: left;
  padding: 15px 44px 15px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(160, 107, 255, 0.12), rgba(160, 107, 255, 0.05));
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.35;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
  animation: choiceIn 0.3s ease both;
}
.choice:nth-child(1) { animation-delay: 0.02s; }
.choice:nth-child(2) { animation-delay: 0.06s; }
.choice:nth-child(3) { animation-delay: 0.10s; }
.choice:nth-child(4) { animation-delay: 0.14s; }
.choice:nth-child(5) { animation-delay: 0.18s; }

@keyframes choiceIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.choice:hover { border-color: var(--gold); background: linear-gradient(180deg, rgba(160, 107, 255, 0.2), rgba(160, 107, 255, 0.08)); }
.choice:active { transform: scale(0.985); }

.choice code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 5px;
}

.choice__key {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.choice--ghost {
  background: transparent;
  border-style: dashed;
  color: var(--gold-soft);
  text-align: center;
  padding-right: 16px;
}

/* ---------------------------- Кнопка «Назад» ---------------------------- */
.back {
  align-self: flex-start;
  margin-top: 2px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
.back:active { transform: scale(0.96); }

/* -------------------------------- Футер -------------------------------- */
.footer {
  margin-top: auto;
  padding-top: 8px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  opacity: 0.7;
}

/* -------------------------------- Тост --------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translate(-50%, 20px);
  max-width: min(92vw, 520px);
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(28, 20, 54, 0.96);
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------- Адаптив -------------------------------- */
@media (max-width: 380px) {
  .card { padding: 16px 14px 18px; }
  .card__title { font-size: 21px; }
  .card__icon { font-size: 38px; }
  .choice { font-size: 15px; }
}

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