/* Цвета берём из темы Telegram (светлая/тёмная у каждого своя); запасные значения — для открытия в обычном браузере */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --muted: var(--tg-theme-hint-color, #707579);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f1f3f5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { max-width: 520px; margin: 0 auto; padding: 16px; }

h1 { font-size: 24px; margin: 8px 0 12px; }
.muted { color: var(--muted); }

.card {
  background: var(--card);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 12px 0;
}

button {
  font: inherit;
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
}

/* Доска: квадрат на всю ширину, фигуры — символами */
.board { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); width: 100%; aspect-ratio: 1; border-radius: 8px; overflow: hidden; margin: 8px 0; }
.sq { min-width: 0; min-height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: min(9vw, 46px); line-height: 1; }
.sq.light { background: #f0d9b5; }
.sq.dark { background: #b58863; }
.pw { color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 0 2px #000; }
.pb { color: #111; }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.options button { font-size: 22px; padding: 16px 8px; }
button:disabled { opacity: 0.5; }
#next { width: 100%; margin: 8px 0; }
.card.ok { border-left: 5px solid #2e9e4f; }
.card.bad { border-left: 5px solid #d64545; }

/* Нижняя панель вкладок и экран «День» */
#app { padding-bottom: 80px; }
#nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--card); }
#nav .tab { flex: 1; background: var(--card); color: var(--text); }
#nav .tab.on { background: var(--accent); color: var(--accent-text); }
h2 { font-size: 18px; margin: 18px 0 6px; }
.row { display: flex; justify-content: space-between; gap: 8px; }
.bar { height: 8px; background: var(--bg); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.bar div { height: 100%; background: var(--accent); }
.strip { display: flex; gap: 6px; justify-content: space-between; }
.dayc { display: flex; flex-direction: column; align-items: center; flex: 1; background: var(--card); border-radius: 10px; padding: 8px 0; }

/* Доигрывание: выбранная клетка, возможные ходы, последний ход */
.sq { position: relative; cursor: pointer; }
.sq.sel { box-shadow: inset 0 0 0 4px #3b82f6; }
.sq.last { background-image: linear-gradient(rgba(255, 220, 0, 0.35), rgba(255, 220, 0, 0.35)); }
.sq.dot::after { content: ""; position: absolute; width: 28%; height: 28%; border-radius: 50%; background: rgba(40, 160, 80, 0.6); }
.sq.cap { box-shadow: inset 0 0 0 4px rgba(214, 69, 69, 0.8); }
button.secondary { background: var(--card); color: var(--text); width: 100%; margin: 4px 0; }
#pnext { width: 100%; margin: 8px 0; }

/* Крафт: инвентарь сеткой, рецепты списком, заглушки вместо картинок */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.cell { display: flex; flex-direction: column; align-items: center; background: var(--card); border-radius: 12px; padding: 8px 4px; text-align: center; }
.cell small { font-size: 11px; color: var(--muted); line-height: 1.15; margin-top: 2px; }
.icon { width: 40px; height: 40px; border-radius: 8px; image-rendering: pixelated; flex: none; }
.icon.ph { display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 15px; text-shadow: 0 0 3px rgba(0,0,0,.6); }
.recipe .row { align-items: center; gap: 12px; }
.recipe .grow { flex: 1; min-width: 0; }
.recipe.ready { border-left: 5px solid #2e9e4f; }
.small { font-size: 13px; }
.okn { color: #2e9e4f; }
.lack { color: #d64545; }
button.make { padding: 10px 12px; flex: none; }

/* Сезон, бой, трофеи */
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.seg button { flex: 1 1 30%; padding: 9px 4px; font-size: 14px; background: var(--card); color: var(--text); }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.bar.big { height: 14px; border-radius: 7px; margin: 10px 0; }
.bar.big div { transition: width .6s; }
.big { font-size: 20px; }
.huge { font-size: 28px; font-weight: 700; margin: 8px 0; }
.when { margin-top: 8px; font-weight: 600; }
.boss-now { border: 2px solid var(--accent); }
.boss.off { opacity: .5; }
.check { display: flex; gap: 8px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid var(--bg); }
.check:last-child { border-bottom: 0; }
.check .grow { flex: 1; }
button.pick { padding: 8px 14px; }
.big-btn { width: 100%; font-size: 22px; padding: 18px; margin: 8px 0; background: #d64545; color: #fff; }
.arena { text-align: center; padding: 24px 12px; }
.arena .fighters { display: flex; justify-content: center; align-items: center; gap: 18px; font-size: 56px; }
.arena .vs { animation: clash .5s infinite alternate; }
.arena .hero { animation: lunge .6s infinite alternate; display: inline-block; }
.arena .boss-big { display: inline-flex; width: 72px; height: 72px; border-radius: 12px; align-items: center; justify-content: center; background: #6a1b9a; color: #fff; font-size: 40px; animation: shake .25s infinite; }
@keyframes clash { from { transform: scale(1) rotate(-12deg); } to { transform: scale(1.4) rotate(12deg); } }
@keyframes lunge { from { transform: translateX(-6px); } to { transform: translateX(14px); } }
@keyframes shake { 0% { transform: translateX(-3px); } 100% { transform: translateX(3px); } }
.trophy .row { align-items: baseline; }

/* Сундуки и награды (4.5d) */
.badge { background: #e53935; color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; }
.chest-row { display: flex; align-items: center; gap: 10px; }
.chest-ico { font-size: 28px; }
.chest-ico.big { font-size: 36px; filter: drop-shadow(0 0 6px gold); }
.chest-big { font-size: 72px; line-height: 1.2; }
.chest-big.shake { animation: shake 0.25s infinite; }
.chest-big.pop { animation: pop 0.5s ease-out; }
@keyframes pop { 0% { transform: scale(0.3); } 70% { transform: scale(1.3); } 100% { transform: scale(1); } }
.loot-list { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.loot { opacity: 0; animation: lootin 0.4s forwards; padding: 6px 10px; border-radius: 8px; background: var(--card); }
.loot.bonus { box-shadow: inset 0 0 0 2px gold; }
@keyframes lootin { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.award.todo { opacity: 0.65; }
.award.got { box-shadow: inset 4px 0 0 #43a047; }

/* Аватар и мастерская (4.5e) */
.hero-card { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 8px 0; }
.paperdoll { display: grid; grid-template-columns: 56px 72px 56px; grid-template-areas: ". head ." "weapon chest offhand" ". legs ." ". boots ." ". tool ."; gap: 4px; justify-content: center; }
.piece { display: flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 26px; min-height: 40px; box-shadow: inset 0 0 0 2px rgba(0,0,0,0.25); }
.piece img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.piece.empty { background: transparent; border: 2px dashed rgba(128,128,128,0.45); box-shadow: none; opacity: 0.45; }
.a-helmet { grid-area: head; border-radius: 16px 16px 8px 8px; min-height: 52px; }
.a-chestplate { grid-area: chest; min-height: 72px; }
.a-leggings { grid-area: legs; min-height: 52px; }
.a-boots { grid-area: boots; min-height: 36px; }
.a-weapon { grid-area: weapon; min-height: 72px; }
.a-offhand { grid-area: offhand; min-height: 72px; }
.a-tool { grid-area: tool; min-height: 36px; }
.legend { width: 100%; }
.hero-card.mini .paperdoll { grid-template-columns: 22px 28px 22px; gap: 2px; }
.hero-card.mini .piece { font-size: 11px; min-height: 16px; }
.hero-card.mini .a-helmet, .hero-card.mini .a-leggings { min-height: 20px; }
.hero-card.mini .a-chestplate, .hero-card.mini .a-weapon, .hero-card.mini .a-offhand { min-height: 30px; }
.snap { align-items: center; gap: 10px; margin-top: 6px; }
.cell.ghost { opacity: 0.4; }

/* 5.3: четыре вкладки внизу — на узком телефоне без переноса */
#nav { gap: 6px; padding-left: 8px; padding-right: 8px; }
#nav .tab { padding-left: 2px; padding-right: 2px; font-size: 12px; white-space: nowrap; }
/* 5.4: вкладка «Разбор» — кнопки уроков в программе */
button.wide { width: 100%; margin: 6px 0; }
.lessons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
h3.small { margin: 12px 0 4px; font-weight: 600; }
