/* ============================================================
   Мини-приложение «Три в ряд» для супераппа Домиленд
   Дизайн: mobile-first, светлая тема, фирменные скругления/тени
   ============================================================ */

:root {
  --bg: #eef1f7;
  --surface: #ffffff;
  --accent: #3661ff;
  --accent-soft: #e7edff;
  --text: #17233f;
  --text-muted: #7a8699;
  --danger: #ff4d6d;
  --success: #2ec4b6;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(23, 35, 63, 0.10);
  --board-size: min(92vw, 400px);
}

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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #e8edfb 0%, var(--bg) 45%);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow-x: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 16px 16px max(16px, safe-area-inset-bottom, 0px);
}

/* ---------- Шапка ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.greeting {
  font-size: 13px;
  color: var(--text-muted);
  min-height: 16px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}

.icon-btn:active {
  transform: scale(0.92);
}

/* ---------- Показатели ---------- */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.stat {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 10px;
  text-align: center;
}

.stat-accent {
  background: var(--accent);
  color: #fff;
}

.stat-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.75;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- Прогресс-бар к цели уровня ---------- */
.track-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.track-label {
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.track-label b {
  color: var(--accent);
  font-weight: 700;
}

.track {
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: rgba(23, 35, 63, 0.08);
  overflow: hidden;
}

.track-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #6b8aff);
  border-radius: 99px;
  transition: width 0.35s ease;
}

/* ---------- Панель инструментов ---------- */
.toolbar {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 10px;
}

.tb-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.tb-btn:active {
  transform: scale(0.95);
}

.tb-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- Игровое поле ---------- */
.board-wrap {
  display: flex;
  justify-content: center;
  position: relative; /* для float-score */
}

.board {
  width: var(--board-size);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
  padding: 8px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.board.shake {
  animation: shake 0.32s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

/* ---------- Элементы (гемы) ---------- */
.gem {
  border-radius: 26%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 5.4vw, 26px);
  cursor: pointer;
  border: 2px solid rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.12), 0 2px 4px rgba(0, 0, 0, 0.08);
  transition: transform 0.18s ease;
  will-change: transform;
  position: relative;
}

.gem.selected {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  z-index: 2;
  transform: scale(1.06);
}

.gem.pop {
  animation: pop 0.30s ease forwards;
}

@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.28) rotate(12deg); opacity: 1; }
  100% { transform: scale(0); opacity: 0; }
}

.gem.drop {
  animation: drop 0.32s ease;
}

/* --drop задаётся из JS: высота, с которой «падает» новый элемент */
@keyframes drop {
  from { transform: translateY(calc(var(--drop, 200px) * -1)); opacity: 0.25; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- Подсказка (hint) ---------- */
.gem.hint {
  animation: hint-pulse 0.8s ease 2;
  box-shadow: 0 0 0 5px rgba(54, 97, 255, 0.5), 0 0 18px rgba(54, 97, 255, 0.3);
  z-index: 3;
}

@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(54, 97, 255, 0.15); }
  50% { box-shadow: 0 0 0 7px rgba(54, 97, 255, 0.6), 0 0 24px rgba(54, 97, 255, 0.3); }
}

/* ---------- Всплывающие очки над полем ---------- */
.float-score {
  position: absolute;
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 1px 6px rgba(54, 97, 255, 0.3);
  pointer-events: none;
  z-index: 10;
  transform: translate(-50%, -100%);
  animation: float-up 0.9s ease forwards;
}

@keyframes float-up {
  0% { opacity: 1; transform: translate(-50%, -100%) scale(0.6); }
  25% { opacity: 1; transform: translate(-50%, -200%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -350%); }
}

/* ---------- Toast (комбо и сообщения) ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  background: rgba(23, 35, 63, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.25s ease, toast-out 0.3s ease 0.9s forwards;
  pointer-events: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(10px) scale(0.88); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(-50%) scale(1); }
  to { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(0.9); }
}

/* ---------- Оверлей ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 35, 63, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
  animation: fade-in 0.25s ease;
}

.overlay[hidden] {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 28px 24px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: card-in 0.3s ease;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(16px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.overlay-title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.overlay-sub {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 20px;
}

.overlay-score {
  font-size: 18px;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 700;
}

.overlay-best {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(54, 97, 255, 0.35);
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: none;
  margin-top: 10px;
}

.rules {
  text-align: left;
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 20px;
}

.rules li {
  margin-bottom: 4px;
}