/* «Каскадёр» — стили: тёмная тема, адаптив, анимации. Без внешних ресурсов. */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #14121f;
  --panel: #1f1b2e;
  --panel2: #2a2440;
  --text: #efeaff;
  --muted: #9a91b8;
  --accent: #ffb02e;
  --accent2: #7c5cff;
  --danger: #ff5c7a;
  --ok: #4ade80;
  --radius: 14px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

#app { min-height: 100%; display: flex; justify-content: center; }

/* ---------- экраны ---------- */
.screen { display: none; width: 100%; max-width: 640px; padding: 12px; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

.menu-box, .shop-box {
  width: 100%;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 24px 20px;
  margin-top: 4vh;
  text-align: center;
}
.logo { font-size: 2.4rem; margin-bottom: 8px; }
.tagline { color: var(--muted); margin-bottom: 20px; }

.rules { text-align: left; margin-top: 24px; background: var(--panel2); border-radius: var(--radius); padding: 16px; }
.rules h2 { font-size: 1rem; margin-bottom: 10px; color: var(--accent); }
.rules li { margin: 6px 0 6px 18px; color: var(--muted); font-size: .92rem; }

/* ---------- кнопки (тач ≥44px) ---------- */
.btn {
  display: inline-block;
  min-height: 44px;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--panel2);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  transition: transform .1s, filter .15s;
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { filter: brightness(1.2); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-big { display: block; width: 100%; margin: 10px 0; font-size: 1.15rem; padding: 14px; }
.btn-accent { background: linear-gradient(135deg, var(--accent2), #5636d6); }
.btn-small { min-height: 44px; min-width: 44px; padding: 6px 12px; font-size: .9rem; }

/* ---------- HUD ---------- */
.hud {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 10px 12px;
  flex-wrap: wrap;
}
.hud-item { display: flex; flex-direction: column; align-items: center; min-width: 52px; }
.hud-goal { flex: 1; min-width: 120px; }
.hud-label { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.hud-value { font-size: 1.1rem; font-weight: 700; }
.hud-value.danger { color: var(--danger); }
.hud-bar-track { width: 100%; height: 8px; background: var(--panel2); border-radius: 4px; margin-top: 4px; overflow: hidden; }
.hud-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent2), var(--accent)); border-radius: 4px; transition: width .4s ease; }

/* ---------- панель джокеров ---------- */
.jokers-panel {
  width: 100%;
  display: flex;
  gap: 8px;
  padding: 8px 2px;
  min-height: 52px;
  flex-wrap: wrap;
}
.jokers-empty { color: var(--muted); font-size: .85rem; align-self: center; }
.joker-chip {
  position: relative;
  width: 44px; height: 44px;
  background: var(--panel2);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  cursor: help;
}
.joker-tip {
  display: none;
  position: absolute;
  bottom: 110%; left: 0;
  z-index: 30;
  width: 210px;
  background: #0d0b16;
  border: 1px solid var(--accent2);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .78rem;
  line-height: 1.35;
  text-align: left;
}
.joker-chip:hover .joker-tip, .joker-chip:active .joker-tip { display: block; }
.joker-tip i { color: var(--muted); }

/* ---------- игровое поле ---------- */
#board-wrap { position: relative; width: min(90vw, 76vh, 560px); margin: 4px auto; }
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--panel);
  border-radius: var(--radius);
  overflow: hidden;
  touch-action: none;
  user-select: none;
}
.tile {
  position: absolute;
  top: 0; left: 0;
  width: 12.5%; height: 12.5%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform .22s ease;
  will-change: transform;
  z-index: 1;
}
/* круглый аватар героя: портрет в кольце цвета фишки + мягкая подсветка */
.tile-avatar {
  position: relative;
  width: 86%; height: 86%;
  border-radius: 50%;
  overflow: hidden;
  background: var(--ring-bg, #2a2440);
  border: 2.5px solid var(--ring, #888);
  box-shadow: 0 0 0 1px rgba(0,0,0,.35),
              0 2px 6px rgba(0,0,0,.45),
              0 0 10px 1px var(--glow, transparent);
  transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}
.tile-face {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  -webkit-user-drag: none;
  user-select: none;
  pointer-events: none;
}
/* фолбэк-эмодзи, если портрет не загрузился */
.tile-avatar.tile-fallback { display: flex; align-items: center; justify-content: center; }
.tile-emoji { font-size: clamp(15px, 4vmin, 32px); line-height: 1; }

/* цвет кольца/подсветки/фолбэк-фона по цвету фишки */
.c-red    { --ring: #ff5252; --glow: rgba(255, 82,  82, .55); --ring-bg: rgba(255, 82,  82, .18); }
.c-blue   { --ring: #4096ff; --glow: rgba(64, 150, 255, .55); --ring-bg: rgba(64, 150, 255, .18); }
.c-green  { --ring: #4ade80; --glow: rgba(74, 222, 128, .50); --ring-bg: rgba(74, 222, 128, .16); }
.c-yellow { --ring: #facc15; --glow: rgba(250, 204,  21, .50); --ring-bg: rgba(250, 204,  21, .16); }
.c-purple { --ring: #a855f7; --glow: rgba(168,  85, 247, .55); --ring-bg: rgba(168,  85, 247, .18); }
.c-orange { --ring: #fb923c; --glow: rgba(251, 146,  60, .55); --ring-bg: rgba(251, 146,  60, .18); }

/* наведение — усиленная подсветка */
@media (hover: hover) {
  .tile:hover { z-index: 5; }
  .tile:hover .tile-avatar {
    transform: scale(1.06);
    box-shadow: 0 0 0 1px rgba(0,0,0,.35), 0 2px 8px rgba(0,0,0,.5), 0 0 16px 3px var(--glow);
  }
}
/* выбранная — пульсация кольца */
.tile.selected { z-index: 6; }
.tile.selected .tile-avatar {
  border-color: var(--accent);
  animation: ringPulse 1s ease-in-out infinite;
}
@keyframes ringPulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent), 0 0 10px 2px var(--glow); transform: scale(1.02); }
  50%      { box-shadow: 0 0 0 4px var(--accent), 0 0 22px 6px var(--glow); transform: scale(1.1); }
}

.tile.pop { z-index: 4; }
.tile.pop .tile-avatar { animation: pop .28s ease forwards; }
@keyframes pop {
  0%   { opacity: 1; transform: scale(1); }
  45%  { opacity: 1; transform: scale(1.32); box-shadow: 0 0 24px 8px var(--glow); }
  100% { opacity: 0; transform: scale(.15); }
}
.tile.shake { animation: shake .32s ease; }
@keyframes shake {
  0%, 100% { translate: 0 0; }
  25% { translate: -6% 0; }
  75% { translate: 6% 0; }
}

/* ---------- всплывающие очки и разбор ---------- */
.float-score {
  position: absolute;
  top: 40%; left: 50%;
  transform: translateX(-50%);
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 2px 8px rgba(0,0,0,.6);
  pointer-events: none;
  animation: floatUp 1s ease forwards;
  z-index: 20;
}
@keyframes floatUp {
  0%   { opacity: 0; translate: 0 20px; }
  20%  { opacity: 1; }
  100% { opacity: 0; translate: 0 -60px; }
}
.breakdown {
  width: 100%;
  min-height: 40px;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-radius: 10px;
  font-size: .85rem;
  color: var(--muted);
  opacity: 0;
  transition: opacity .3s;
  text-align: center;
}
.breakdown.show { opacity: 1; color: var(--text); }

/* ---------- итог раунда ---------- */
.reward-detail { font-size: 1.2rem; margin: 16px 0 24px; }
.reward-detail .muted { font-size: .85rem; color: var(--muted); }

/* ---------- магазин ---------- */
.shop-balance { color: var(--muted); margin-bottom: 14px; }
.shop-stock { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.shop-card {
  background: var(--panel2);
  border-radius: var(--radius);
  padding: 14px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.shop-icon { font-size: 2rem; }
.shop-name { font-weight: 700; }
.shop-effect { font-size: .8rem; color: var(--ok); min-height: 2.2em; }
.shop-desc { font-size: .75rem; color: var(--muted); font-style: italic; min-height: 2.6em; }
.shop-warn { font-size: .72rem; color: var(--danger); }
.buy-btn { width: 100%; }
.shop-actions { display: flex; gap: 10px; justify-content: center; margin: 18px 0; flex-wrap: wrap; }
.owned-title { font-size: 1rem; color: var(--accent); margin: 8px 0; }
.shop-owned { display: flex; flex-direction: column; gap: 8px; }
.owned-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2); border-radius: 10px; padding: 8px 12px;
}
.owned-icon { font-size: 1.3rem; }
.owned-name { flex: 1; text-align: left; font-size: .95rem; }

/* ---------- статистика ---------- */
.stats { margin: 18px 0; text-align: left; }
.stat-row {
  display: flex; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--panel2);
  color: var(--muted);
}
.stat-row b { color: var(--text); }
.muted { color: var(--muted); }

/* ---------- адаптив ---------- */
@media (max-width: 480px) {
  .screen { padding: 8px; }
  .logo { font-size: 1.9rem; }
  .hud { gap: 6px; padding: 8px; }
  .hud-value { font-size: 1rem; }
  .shop-stock { grid-template-columns: 1fr; }
}
@media (orientation: landscape) and (max-height: 520px) {
  #board-wrap { width: min(60vh, 90vw); }
  .menu-box, .shop-box { margin-top: 8px; }
}

/* ---------- FX-оверлей: частицы, флеш, множитель ---------- */
.fx-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 15;
}
.fx-flash {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
  z-index: 16;
  mix-blend-mode: screen;
}
.fx-flash.fx-flash-on { animation: fxFlash .42s ease-out; }
@keyframes fxFlash {
  0%   { opacity: .9; }
  100% { opacity: 0; }
}
.fx-mult {
  position: absolute;
  top: 34%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(1.6rem, 8vmin, 3.4rem);
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 2px 12px rgba(0,0,0,.7), 0 0 22px currentColor;
  pointer-events: none;
  z-index: 18;
  animation: fxMult .95s cubic-bezier(.2,.9,.25,1) forwards;
}
@keyframes fxMult {
  0%   { opacity: 0; transform: translate(-50%,-50%) scale(.4) rotate(-6deg); }
  25%  { opacity: 1; transform: translate(-50%,-50%) scale(1.15) rotate(2deg); }
  55%  { opacity: 1; transform: translate(-50%,-60%) scale(1); }
  100% { opacity: 0; transform: translate(-50%,-120%) scale(.9); }
}

/* ---------- аудио-контроль ---------- */
.audio-bar {
  position: fixed;
  bottom: 10px; right: 10px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 18, 31, .82);
  border: 1px solid var(--panel2);
  border-radius: 22px;
  padding: 4px 8px;
  backdrop-filter: blur(4px);
}
.audio-btn {
  min-width: 34px; min-height: 34px;
  border: none; border-radius: 50%;
  background: var(--panel2); color: var(--text);
  font-size: 1.05rem; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: filter .15s, transform .1s;
  touch-action: manipulation;
}
.audio-btn:hover { filter: brightness(1.25); }
.audio-btn:active { transform: scale(.92); }
.audio-btn-amb.off { opacity: .4; }
.vol-slider {
  width: 84px; height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}
@media (max-width: 480px) {
  .vol-slider { width: 56px; }
}

/* ---------- плавные переходы между экранами ---------- */
.screen.active { animation: screenIn .34s ease both; }
@keyframes screenIn {
  0%   { opacity: 0; transform: translateY(14px) scale(.99); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- уважение к prefers-reduced-motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .screen.active { animation-duration: .12s; }
  .tile.selected .tile-avatar { animation: none; border-color: var(--accent); }
  .fx-mult { animation-duration: .5s; }
  .float-score { animation-duration: .6s; }
  * { scroll-behavior: auto !important; }
}
