/* «Кубічні Глибини» — ландшафтний шелл на один екран телефона.
   Базовий шар: скидання, шелл, кнопки, сцена, бійці, трей, оверлеї, шторка й тост.
   Токени й спільні деталі оправи — в ui/theme.css; кубик як предмет — die.css; кубик як
   інформація — ui/dice-ui.css; окремі екрани — screens/*.css і meta/meta.css.

   Сторінка ніколи не скролиться; скролять лише внутрішні списки. Усі розміри ведуться від
   dvh, щоб верстка не залежала від того, згорнута адресна стрічка браузера чи ні. */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-ui);
  font-size: var(--fs);
  color: var(--ink);
  background: var(--wood-deep);
  display: grid;
  place-items: center;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* Гра — не сторінка з картинками: спрайт, витягнутий мишкою за межі сцени, ламає ілюзію
   й лишає по собі привида на курсорі. Webkit-правило вимикає перетяг у Chrome і Safari,
   Firefox добиває обробник dragstart у app.js. */
img, canvas { -webkit-user-drag: none; }

/* Зерно на весь екран. Гра зіткана з темних градієнтів, а плавний темний перехід лягає
   рівними сходинками по 30-40 px (виміряно на сцені: 60 унікальних кольорів у рядку).
   Таку сходинку 6-бітна панель відтворює часовим дизерингом — швидким перемиканням між
   двома сусідніми відтінками, що на 60 Гц читається як мерехтіння. Статичний шум ламає
   сходинку, і дизерити стає нічого. Сам шум нерухомий: жодної анімації, жодного JS. */
body::after {
  content: "";
  position: fixed; inset: 0; z-index: 60;
  pointer-events: none;
  opacity: 0.05;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='140' height='140' filter='url(%23n)'/></svg>") 0 0 / 140px 140px repeat;
}

#app {
  width: 100vw;
  height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
@supports (height: 100dvh) { #app { width: 100dvw; height: 100dvh; } }

/* На великому екрані шелл не розтягується на весь монітор, а стає «пристроєм» 16:9 —
   так видно рівно те саме кадрування, що й на телефоні. */
@media (min-width: 1000px) and (min-height: 660px) {
  #app {
    width: min(1120px, 94vw);
    height: min(630px, 94vh);
    border: 1px solid var(--edge);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 30px 70px -24px #000, 0 0 0 1px #0006 inset;
  }
}

.shell { position: relative; display: flex; flex-direction: column; height: 100%; overflow: hidden; }

.muted { color: var(--ink-muted); }
.hidden { display: none !important; }

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

button {
  font: inherit;
  color: var(--ink);
  background: var(--grad-wood);
  border: 1px solid var(--edge-lit);
  border-radius: 9px;
  padding: 6px 11px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 1px 0 rgba(255, 210, 150, 0.09) inset;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
@media (hover: hover) {
  button:hover:not(:disabled) { border-color: var(--brass); background: linear-gradient(180deg, #48311e, #2c1d13); }
}
button.primary {
  background: var(--grad-brass);
  border-color: var(--brass-lit);
  color: #1a1108;
  font-weight: 800;
  text-shadow: 0 1px 0 rgba(255, 235, 200, 0.35);
}
button.ghost { background: none; border-color: transparent; padding: 4px 7px; box-shadow: none; }
button.danger { border-color: #6d2a20; color: #e8b3a8; }

/* Головна дія екрана — пігулка: одна форма на «Спуститися», «Далі», «У бій». Гравець
   упізнає її як «крок уперед» раніше, ніж читає підпис. */
.act {
  min-width: clamp(64px, 20vw, 112px);
  height: clamp(38px, 12dvh, 52px);
  border-radius: 999px;
  font-size: 1.02em;
  letter-spacing: 0.03em;
}

/* ---------- Шар зображень (assets.js) ---------- */

.art {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--art-size, 1em);
  height: var(--art-size, 1em);
  flex: none;
  vertical-align: -0.18em;
}
.art img { width: 100%; height: 100%; object-fit: contain; display: block; }
.art-fb { display: none; font-size: calc(var(--art-size, 1em) * 0.8); line-height: 1; }
.art-missing img { display: none; }
.art-missing .art-fb { display: block; }

/* ---------- Сцена ---------- */

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: radial-gradient(88% 74% at 50% 12%, var(--loc-a, #2b1e15), var(--loc-b, #0b0705) 78%);
}
.stage[data-loc="corridor"] { --loc-a: #3a2415; --loc-b: #0e0906; --loc-glow: rgba(255, 150, 60, 0.20); }
.stage[data-loc="catacombs"] { --loc-a: #1e2430; --loc-b: #080a0d; --loc-glow: rgba(120, 180, 220, 0.14); }
.stage[data-loc="lair"] { --loc-a: #3b1d16; --loc-b: #0d0605; --loc-glow: rgba(255, 90, 50, 0.22); }
.stage[data-loc="throne"] { --loc-a: #251a33; --loc-b: #0a0710; --loc-glow: rgba(160, 110, 240, 0.22); }
.stage[data-loc="alcove"] { --loc-a: #3a2a14; --loc-b: #100b06; --loc-glow: rgba(255, 190, 90, 0.24); }

.bg-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  opacity: 0.85;
}
/* Затемнення поверх фону: сценою керує силует бійців, а не текстура стіни. */
.stage-tint {
  position: absolute; inset: 0;
  background:
    radial-gradient(60% 45% at 50% 4%, var(--loc-glow, transparent), transparent 70%),
    radial-gradient(120% 110% at 50% 58%, transparent 22%, rgba(0, 0, 0, 0.72) 100%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.55), transparent 26%, transparent 46%, rgba(0, 0, 0, 0.88));
  pointer-events: none;
}
/* Титульний екран сам малює своє затемнення (meta/meta.css) — спільне лише глушило б логотип. */
.title-shell .stage-tint { display: none; }

/* ---------- Бійці ---------- */

.fighter {
  position: absolute;
  bottom: 22%;
  display: flex;
  justify-content: center;
  max-width: 34%;
  z-index: 1;
}
.fighter.hero { left: 5%; }
.fighter.foe { right: 4%; }
/* Спрайт — квадратна коробка стороною --art-size (object-fit: contain усередині). Без
   height: 100%: у колонці аркуша персонажа спрайт із такою висотою забирав усе місце й
   виштовхував за край картки і смужку XP, і рядок статистики під ним. */
.sprite { --art-size: min(30vw, 62%); }
.fighter .sprite { --art-size: clamp(64px, 42dvh, 220px); }
/* Спрайти намальовані обличчям вліво (docs/ART.md), тож героя зліва треба віддзеркалити. */
.fighter.hero .sprite img, .fighter.hero .sprite .art-fb { transform: scaleX(-1); }
.fighter.foe .sprite img { filter: drop-shadow(0 14px 20px rgba(0, 0, 0, 0.8)); }
.fighter.hero .sprite img { filter: drop-shadow(0 14px 20px rgba(0, 0, 0, 0.8)); }
.fighter.foe.tier-elite .sprite img {
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.8)) drop-shadow(0 0 22px rgba(255, 110, 40, 0.42));
}
.fighter.foe.tier-boss .sprite img {
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.85)) drop-shadow(0 0 26px rgba(220, 60, 40, 0.5));
}
.fighter.hurt { animation: hurt 0.32s ease-out; }
@keyframes hurt {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  60% { transform: translateX(4px); }
}

/* Бейджі стану: пасивки ворога, отрута, бонуси ходу. Пояснюють себе тапом — на телефоні
   `title` недоступний. */
.badges { display: flex; gap: 4px; flex-wrap: wrap; }
.hud-foe .badges { justify-content: flex-end; }
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(6, 4, 3, 0.7); border: 1px solid #6d2a20;
  border-radius: 6px; padding: 2px 7px;
  font-size: 0.72em; white-space: nowrap;
  cursor: help;
}
.badge.info { background: rgba(6, 4, 3, 0.7); border-color: #35617f; }
.badge.soon { border-color: var(--brass); color: var(--brass-lit); }

/* Числа, що спливають над бійцем після резолву. */
.floater {
  position: absolute;
  font-family: var(--font-display);
  font-size: 1.7em; font-weight: 700;
  text-shadow: 0 2px 4px #000, 0 0 10px #000;
  pointer-events: none;
  z-index: 7;
  animation: float-up 1.1s ease-out forwards;
}
.floater.dmg { color: #ff7a5c; }
.floater.heal { color: #96e07a; }
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, 6px) scale(0.7); }
  18% { opacity: 1; transform: translate(-50%, -6px) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(1); }
}

/* ---------- Трей ---------- */

.tray {
  flex: none;
  height: var(--tray-h);
  display: flex;
  align-items: center;
  gap: var(--pad);
  padding: 0 var(--pad);
  background: linear-gradient(180deg, rgba(36, 24, 17, 0.95), rgba(13, 9, 6, 0.98));
  border-top: 1px solid var(--edge);
  box-shadow: 0 -3px 14px -6px #000;
}
.tray-dice {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.tray-dice::-webkit-scrollbar { display: none; }
.tray-side { display: flex; align-items: center; gap: var(--pad); flex: none; }

/* ---------- Кубик як предмет у розмітці ---------- */

/* Оправа навколо фігури: рідкість рамкою, мітка «можна перекинути / перекинуто» на ріжку.
   Сама фігура — окремий компонент (die.js / die.css). */
.die {
  position: relative;
  flex: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 2px;
  border-radius: 12px;
  border: 1px solid transparent;
}
.die.clickable { cursor: pointer; }
.die.uncommon { border-color: #2f4d63; }
.die.rare { border-color: #4b3573; }
.die.clickable.hot { border-color: var(--edge-lit); background: #ffffff08; }
@media (hover: hover) {
  .die.clickable.hot:hover { border-color: var(--brass-lit); background: #ffffff12; }
}
.die.clickable.hot::after {
  content: "↻";
  position: absolute; top: -2px; right: -1px;
  font-size: 0.8em; color: var(--brass-lit);
  text-shadow: 0 1px 3px #000;
}
/* Позначений на перекид: видно ще до підтвердження, що саме полетить назад у руку.
   Селектор мусить бути не слабшим за `.die.clickable.hot` — позначений кубик завжди й
   натисний, тож інакше та рамка перебивала б цю. */
.die.clickable.picked {
  border-color: var(--brass-lit);
  background: #f2cb8426;
  box-shadow: 0 0 12px -3px var(--brass-lit);
}
.die.clickable.picked::after { content: "✓"; color: #ffe3ae; }
.die-label {
  font-size: 0.68em; color: var(--ink-muted);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Оверлеї сцени ---------- */

/* Картка на всю сцену (знайомство з вузлом, перемога, підсумок рану). `.stage` не створює
   власного stacking context (position: relative без z-index), тож її діти конкурують
   номерами прямо з цією карткою — а вона мусить бути над усіма, включно з керуванням ходу. */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.66);
  padding: var(--pad);
  z-index: 7;
}
.card {
  background: var(--grad-panel-solid);
  border: 1px solid var(--edge-lit);
  border-radius: 16px;
  padding: calc(var(--pad) * 1.8);
  text-align: center;
  max-width: min(560px, 94%);
  max-height: 100%;
  overflow-y: auto;
  box-shadow: var(--shadow-card);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}

/* ---------- 3D-стіл ---------- */

.arena-slot, .arena-host { position: absolute; inset: 0; }
.arena-host canvas { display: block; touch-action: none; width: 100%; height: 100%; }

/* ---------- Шторка, тост, портрет ---------- */

#sheet-backdrop {
  position: fixed; inset: 0; background: #000d; z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: 10px;
}
#sheet {
  background: var(--grad-panel-solid);
  border: 1px solid var(--edge-lit); border-radius: 14px;
  padding: 14px; width: min(560px, 94vw); max-height: 92dvh; overflow-y: auto;
  box-shadow: 0 20px 50px -18px #000;
  display: flex; flex-direction: column; gap: 9px;
}
#sheet h2 { font-family: var(--font-display); font-size: 1.15em; font-weight: 400; color: var(--brass-lit); }
#sheet .row { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
#sheet .dice-row { display: flex; gap: 9px; flex-wrap: wrap; justify-content: center; }

.log { font-size: 0.86em; color: var(--ink-muted); max-height: 40dvh; overflow-y: auto; line-height: 1.5; }
.log .turn-mark { color: #6d5a45; }

#toast {
  position: fixed; top: calc(var(--bar-h) + 8px); left: 50%; transform: translateX(-50%);
  background: #2a1610f0; border: 1px solid var(--edge-lit); padding: 7px 14px;
  border-radius: 999px; z-index: 50; font-size: 0.92em; max-width: 86vw; text-align: center;
  box-shadow: 0 8px 20px -8px #000;
}

#rotate {
  display: none;
  position: fixed; inset: 0; z-index: 100;
  flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--wood-deep); color: var(--ink-muted); text-align: center; padding: 20px;
}
.rotate-icon { font-size: 60px; animation: tip 2.2s ease-in-out infinite; }
@keyframes tip {
  0%, 45%, 100% { transform: rotate(0deg); }
  65%, 90% { transform: rotate(-90deg); }
}
/* Лише сенсорні пристрої: на десктопі вузьке вікно — не привід ховати гру. */
@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  .fighter.hurt, .hp .seg, .hud-bar .seg { animation: none; }
}
