:root {
  --bg: #15121f;
  --card: #fff8f0;
  --ink: #2a2033;
  --accent: #ff6b8b;
  --w: min(92vw, 400px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: #fff;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; overscroll-behavior: none;
}
#app {
  height: var(--tg-viewport-stable-height, 100dvh);   /* в Telegram — его высота окна */
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 16px 20px; gap: 12px;
}
body.menu-open #app { filter: blur(3px) brightness(.6); }

/* ——— HUD ——— */
.hud {
  width: var(--w); display: flex; justify-content: space-between; align-items: center;
  gap: 8px; font-size: 14px; min-height: 30px;
}
.hud .title { font-weight: 700; letter-spacing: .04em; flex: 1; opacity: .9; }
.hud .meter { color: var(--accent); font-size: 18px; letter-spacing: 2px; }
.hudbtn {
  font: inherit; font-size: 13px; color: #fff; background: rgba(255,255,255,.1);
  border: 0; border-radius: 10px; padding: 5px 10px; cursor: pointer;
}
.hudbtn.back.off { opacity: .2; pointer-events: none; }
.hud { flex-wrap: wrap; }
.hud .day { font-size: 13px; opacity: .75; white-space: nowrap; }

/* Шкалы колоды: круг-иконка, заливка снизу показывает уровень, точка — «это изменится» */
.metersrow { width: 100%; display: flex; justify-content: center; gap: 16px; padding: 6px 0 2px; }
.mi {
  --accent: #ff6b8b;
  position: relative; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-size: 21px; line-height: 1;
  background: linear-gradient(to top, var(--accent) var(--p), rgba(255,255,255,.14) var(--p));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18);
  transition: background .3s;
}
.mi em { font-style: normal; }
.mi.warn { --accent: #ffb020; box-shadow: inset 0 0 0 2px #ffb020; }
.mi .dot {
  position: absolute; top: -9px; left: 50%; width: 9px; height: 9px; margin-left: -4.5px;
  border-radius: 50%; background: #fff; opacity: 0; transition: opacity .12s, transform .12s;
}
.mi.hit .dot { opacity: 1; }
.mi.hit.big .dot { transform: scale(1.5); }
.mbtn small { display: block; font-weight: 500; font-size: 12px; opacity: .85; }

/* ——— Карточка ——— */
.stage { position: relative; flex: 1; width: var(--w); max-height: 700px; min-height: 0; }
.stage::before, .stage::after {
  content: ""; position: absolute; inset: 0; border-radius: 22px; background: #e9ddd0;
}
.stage::before { transform: translateY(16px) scale(.88); opacity: .35; }
.stage::after  { transform: translateY(8px) scale(.94); opacity: .6; }

#card {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: 22px; background: var(--card); color: var(--ink);
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: grab; will-change: transform;
}
#card.dragging { cursor: grabbing; }
#card.enter { animation: enter .25s ease-out; }
@keyframes enter { from { transform: scale(.94); opacity: .4; } to { transform: none; opacity: 1; } }

.tint { position: absolute; inset: 0; z-index: 3; pointer-events: none; opacity: 0; }
.tint[data-dir="left"]  { background: rgba(70,130,255,.28); }
.tint[data-dir="right"] { background: rgba(255,90,130,.28); }
.tint[data-dir="up"]    { background: rgba(255,190,60,.30); }
.tint[data-dir="down"]  { background: rgba(110,110,110,.30); }

.peek {
  position: absolute; z-index: 4; top: 14px; left: 50%; transform: translateX(-50%);
  max-width: 88%; padding: 9px 16px; border-radius: 14px; opacity: 0; pointer-events: none;
  background: rgba(21,18,31,.9); color: #fff; font-weight: 600; font-size: 16px; text-align: center;
}

/* ——— Арт: два слоя фона для плавной смены сцен ——— */
.art { flex: 0 0 44%; position: relative; display: grid; place-items: end center; overflow: hidden; background: #333; }
.bg { position: absolute; inset: 0; opacity: 0; transition: opacity .55s ease; }
.bg.on { opacity: 1; }
.deco {
  position: absolute; top: 12px; left: 0; right: 0; z-index: 50; text-align: center;
  font-size: 26px; letter-spacing: 8px; opacity: .85;
}
.who {
  position: relative; z-index: 60; height: 78%; margin-bottom: 8px;
  display: grid; place-items: center; font-size: 92px; line-height: 1;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); transform-origin: 50% 100%;
}
.who img { height: 100%; width: auto; display: block; }

.a-pop    { animation: a-pop .35s cubic-bezier(.2,1.6,.4,1); }
.a-shake  { animation: a-shake .45s ease; }
.a-bounce { animation: a-bounce .6s cubic-bezier(.3,1.5,.5,1); }
.a-wobble { animation: a-wobble .6s ease; }
@keyframes a-pop    { from { transform: scale(.5); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes a-shake  { 0%,100% { transform: none; } 15% { transform: translateX(-10px) rotate(-4deg); }
  35% { transform: translateX(9px) rotate(4deg); } 55% { transform: translateX(-7px); } 75% { transform: translateX(5px); } }
@keyframes a-bounce { 0% { transform: translateY(40px) scale(.9); opacity: 0; } 60% { transform: translateY(-10px); opacity: 1; } 100% { transform: none; } }
@keyframes a-wobble { 0%,100% { transform: none; } 25% { transform: rotate(-8deg); } 50% { transform: rotate(7deg); } 75% { transform: rotate(-4deg); } }

/* ——— Текст и подсказки ——— */
.body { flex: 1; padding: 16px 20px 6px; display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.name { font-weight: 800; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.text { font-size: 19px; line-height: 1.42; }
.text.narr { font-style: italic; opacity: .9; }
.endtitle { font-weight: 800; font-size: 22px; color: #c2447a; }

.chips {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px 12px 14px; align-items: end;
  grid-template-areas: "up up" "left right";
}
.chip {
  font-size: 12px; font-weight: 600; padding: 6px 10px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid rgba(42,32,51,.25); color: rgba(42,32,51,.7);
  min-width: 0; max-width: 100%; text-align: center; line-height: 1.25;
  transition: background .12s, color .12s, border-color .12s;
}
.chip.left  { grid-area: left;  justify-self: start; text-align: left; }
.chip.up    { grid-area: up;    justify-self: center; }
.chip.right { grid-area: right; justify-self: end; text-align: right; }
.chip.empty { display: none; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ——— Меню ——— */
#menu {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: rgba(15,12,25,.55); padding: 16px;
}
#menu[hidden] { display: none; }
.panel {
  width: min(92vw, 380px); max-height: 90dvh; overflow: auto;
  background: #231d33; border-radius: 22px; padding: 22px 20px 20px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 16px 50px rgba(0,0,0,.5);
}
.panel h2 { margin: 0 0 6px; text-align: center; font-size: 24px; letter-spacing: .03em; }
.mbtn {
  font: inherit; font-size: 17px; font-weight: 600; padding: 13px 16px; border: 0; border-radius: 14px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.mbtn.ghost { background: rgba(255,255,255,.1); }
.mbtn.small { font-size: 14px; padding: 8px 12px; }
.mbtn:active { transform: scale(.98); }

.slot { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: rgba(255,255,255,.06); border-radius: 14px; padding: 10px 12px; }
.slotinfo { display: flex; flex-direction: column; gap: 2px; font-size: 13px; min-width: 0; }
.slotinfo i { opacity: .55; font-size: 12px; }
.slotbtns { display: flex; flex-direction: column; gap: 6px; }

.logbox { max-height: 55dvh; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.logitem b { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.logitem p { margin: 2px 0 0; font-size: 15px; line-height: 1.4; }
.logitem p.narr { font-style: italic; opacity: .8; }

.vol { display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.vol input { width: 100%; accent-color: var(--accent); }

/* ——— Бесконечная новелла: live-режим, меню, ожидание ——— */
body.idle .stage { visibility: hidden; }
.hudbtn.bal { background: rgba(255,200,80,.18); color: #ffd980; font-weight: 700; }
.chip.premium {
  border-color: #e0a020; color: #8a5a00; background: linear-gradient(135deg, #fff0c0, #ffd36b);
  font-weight: 700; box-shadow: 0 2px 10px rgba(224,160,32,.45);
  animation: prem 1.8s ease-in-out infinite;
}
.chip.premium.on { background: #e0a020; color: #fff; }
@keyframes prem { 0%,100% { box-shadow: 0 2px 10px rgba(224,160,32,.35); } 50% { box-shadow: 0 2px 18px rgba(255,190,60,.9); } }

.panel .note { margin: 0; font-size: 14px; line-height: 1.45; opacity: .8; text-align: center; }
.panel textarea {
  font: inherit; font-size: 15px; color: #fff; background: rgba(255,255,255,.08);
  border: 1.5px solid rgba(255,255,255,.15); border-radius: 12px; padding: 10px 12px; resize: none; width: 100%;
}
.panel textarea:focus { outline: none; border-color: var(--accent); }
.exs { display: flex; flex-direction: column; gap: 6px; }
.ex {
  font: inherit; font-size: 12.5px; text-align: left; color: rgba(255,255,255,.75);
  background: rgba(255,255,255,.05); border: 0; border-radius: 10px; padding: 7px 10px; cursor: pointer;
}
.tog { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.tog input { width: 18px; height: 18px; accent-color: var(--accent); }
.err { background: rgba(255,80,100,.15); color: #ffb0bb; border-radius: 10px; padding: 8px 10px; font-size: 13.5px; }
.err a, .note a { color: #ffd980; }

#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); z-index: 400;
  background: #000c; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 86vw;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Экран ожидания: пока ИИ пишет продолжение */
#wait {
  position: fixed; inset: 0; z-index: 300; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px; text-align: center;
  background: radial-gradient(circle at 50% 38%, #3a2466 0%, #1a1230 55%, #0d0919 100%);
}
#wait[hidden] { display: none; }
#wait .wtitle { font-size: 22px; font-weight: 700; letter-spacing: .03em; }
#wait .wmsg { font-size: 15px; opacity: .8; min-height: 22px; max-width: 300px; transition: opacity .3s; }
#wait .wmsg.out { opacity: 0; }
#wait .mbtn { min-width: 220px; }
.orb { position: relative; width: 120px; height: 120px; display: grid; place-items: center; }
.orb b { font-size: 34px; color: #ffd980; text-shadow: 0 0 18px #ffb84a; animation: spark 2.4s ease-in-out infinite; }
.orb i {
  position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(255,140,190,.55);
  animation: ring 2.8s ease-out infinite;
}
.orb i:nth-child(2) { animation-delay: .9s; border-color: rgba(140,170,255,.5); }
.orb i:nth-child(3) { animation-delay: 1.8s; border-color: rgba(255,217,128,.5); }
.orb.dead i { display: none; } .orb.dead b { color: #ff8a9a; text-shadow: none; animation: none; }
@keyframes ring { 0% { transform: scale(.35); opacity: .9; } 100% { transform: scale(1.35); opacity: 0; } }
@keyframes spark { 0%,100% { transform: scale(.9) rotate(0); } 50% { transform: scale(1.25) rotate(20deg); } }
.wbar { width: 200px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.12); overflow: hidden; }
.wbar u { display: block; height: 100%; width: 40%; border-radius: 4px; background: linear-gradient(90deg, #ff6b8b, #ffd980); animation: bar 1.6s ease-in-out infinite; }
@keyframes bar { 0% { transform: translateX(-110%); } 100% { transform: translateX(300%); } }
body.idle .hud { visibility: hidden; }

/* юридические тексты */
.legal { font-size: 13px; line-height: 1.5; opacity: .85; text-align: left; max-height: 58vh; overflow-y: auto; margin-bottom: 12px; }
