/* ============ Базовые стили ============ */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%;
  background: radial-gradient(120% 100% at 50% 0%, #1f2a48 0%, #0c1220 100%);
  color: #fff;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 8px;
}

/* ============ HUD ============ */
#hud {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
}
.hud-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.hud-row--small { font-size: 12px; opacity: 0.75; }
.hud-item { display: flex; flex-direction: column; align-items: center; flex: 1; }
.hud-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.6; }
.hud-value { font-size: 20px; font-weight: 700; }
.progress {
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f7c948, #f09819, #ff5858);
  border-radius: 99px;
  transition: width 0.35s ease-out;
}

/* ============ Поле ============ */
#board-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
#board {
  --cols: 8;
  --rows: 8;
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: min(100%, 480px);
  max-height: 100%;
  background: rgba(255,255,255,0.035);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 16px;
  touch-action: none; /* важно для drag на мобильных */
  overflow: hidden;
}

/* Купюра */
.bill {
  position: absolute;
  top: 0; left: 0;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  padding: 3px;
  font-size: clamp(16px, 5.2vw, 32px);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: transform 0.28s cubic-bezier(.34,1.3,.64,1), opacity 0.22s, filter 0.22s;
  will-change: transform, opacity;
  cursor: pointer;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.35));
}
.bill > span { pointer-events: none; }

/* Фон купюры (для эффекта «карточки») */
.bill::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 8px;
  background: var(--bill-color, #555);
  opacity: 0.28;
  z-index: -1;
  transition: opacity 0.15s;
}
.bill.selected::before { opacity: 0.9; }
.bill.selected { filter: drop-shadow(0 0 8px #fff) brightness(1.2); }

.bill.hint { animation: hintPulse 0.6s ease-in-out 3; }
@keyframes hintPulse {
  0%, 100% { transform: translate(var(--tx,0), var(--ty,0)) scale(1); }
  50%      { transform: translate(var(--tx,0), var(--ty,0)) scale(1.15); }
}

.bill.removing {
  opacity: 0 !important;
  transform: scale(0.2) rotate(20deg) !important;
  transition: opacity 0.25s, transform 0.25s !important;
  pointer-events: none;
}

/* Бонусные купюры */
.bill.bonus-bomb::before {
  background: linear-gradient(135deg, #ff5500, #ff0055);
  opacity: 0.85;
  box-shadow: 0 0 12px #ff5500 inset, 0 0 8px #ff5500;
}
.bill.bonus-gold::before {
  background: linear-gradient(135deg, #ffd700, #ff9500);
  opacity: 0.95;
  box-shadow: 0 0 14px #ffd700 inset, 0 0 12px #ffd700;
  animation: goldShine 1.6s linear infinite;
}
@keyframes goldShine {
  0%,100% { filter: hue-rotate(0deg); }
  50%     { filter: hue-rotate(25deg) brightness(1.2); }
}

/* ============ Кнопки ============ */
#controls {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}
.btn {
  flex: 1;
  padding: 12px 8px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.btn:hover { background: rgba(255,255,255,0.12); }
.btn:active { transform: scale(0.97); }
.btn-accent {
  background: linear-gradient(135deg, #f7c948, #f09819);
  border-color: transparent;
  color: #221600;
}
.btn-accent:hover { filter: brightness(1.08); }

/* ============ Экраны ============ */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 20, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
  transition: opacity 0.25s;
}
#overlay.hidden { display: none; }

.screen {
  background: #1a2138;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 28px 22px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  animation: popIn 0.3s cubic-bezier(.34,1.5,.64,1);
}
.screen.hidden { display: none; }
.screen h2 { font-size: 22px; margin-bottom: 14px; }
.screen p  { margin-bottom: 10px; opacity: 0.85; font-size: 15px; }
.screen b  { color: #f7c948; }
.screen .btn { margin-top: 16px; }

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

/* ============ Всплывающие эффекты ============ */
.score-popup {
  position: fixed;
  transform: translate(-50%, -50%);
  color: #ffe066;
  font-size: 26px;
  font-weight: 800;
  text-shadow: 0 2px 8px rgba(0,0,0,0.75);
  pointer-events: none;
  z-index: 100;
  animation: floatUp 0.9s ease-out forwards;
}
@keyframes floatUp {
  0%   { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  20%  { transform: translate(-50%, -70%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -140%) scale(1); opacity: 0; }
}

.flash {
  position: fixed; inset: 0; pointer-events: none; z-index: 90;
  animation: flashFade 0.45s ease-out forwards;
}
.flash-bomb { background: radial-gradient(circle at 50% 50%, rgba(255,80,0,0.55), transparent 70%); }
.flash-gold { background: radial-gradient(circle at 50% 50%, rgba(255,215,0,0.6), transparent 70%); }
@keyframes flashFade { to { opacity: 0; } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 25, 40, 0.95);
  border: 1px solid #f7c948;
  color: #f7c948;
  padding: 10px 18px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  z-index: 200;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Узкие экраны — компактнее */
@media (max-height: 640px) {
  .hud-value { font-size: 17px; }
  .btn { padding: 10px 6px; font-size: 13px; }
  #hud { padding: 8px 10px; }
}