/*
 * game.css — вёрстка и компоненты. Все размеры здесь, только здесь.
 * Цвета приходят из theme.css переменными.
 */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  transition: background var(--anim) ease, color var(--anim) ease;
  user-select: none;
}

body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
  animation-duration: 1ms !important;
  transition-duration: 1ms !important;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
  min-height: var(--tap);
  min-width: var(--tap);
}

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

.screen {
  width: 100%;
  max-width: var(--max-w);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    calc(12px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
  gap: 12px;
  min-width: 0;
}

/* ------------------------------- шапки ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}

.topbar__title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: .2px;
  flex: 1;
  text-align: center;
  line-height: 1.1;
}

.topbar__title small {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.iconbtn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  border-radius: var(--r-chip);
  display: grid;
  place-items: center;
  padding: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: transform var(--anim) ease;
}

.iconbtn:active { transform: scale(.92); }

.iconbtn--ghost {
  background: transparent;
  box-shadow: none;
}

.iconbtn svg { display: block; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 8px;
  border-radius: var(--r-chip);
  background: var(--panel);
  box-shadow: var(--shadow);
  font-weight: 800;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.pill__ico {
  width: 22px;
  height: 22px;
  color: #E9A93B;
  flex: 0 0 auto;
}

/* ------------------------------ главный ------------------------------ */

.brand {
  text-align: center;
  padding: 6px 0 2px;
}

.brand__title {
  margin: 0;
  font-size: 30px;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -.4px;
}

.brand__sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.carousel {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: min(78vw, 300px);
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding: 0 2px;
  padding: 4px 2px 14px;
  scrollbar-width: none;
  max-width: 100%;
}

.carousel::-webkit-scrollbar { display: none; }

.world-card {
  scroll-snap-align: center;
  background: var(--panel);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
  text-align: left;
  min-height: 318px;
  transition: transform var(--anim) ease;
}

.world-card:active { transform: scale(.985); }

.world-card__art {
  height: 150px;
  border-radius: calc(var(--r-card) - 8px);
  display: grid;
  place-items: center;
  position: relative;
  background: var(--world-tint, var(--bg));
  overflow: hidden;
}

.world-card__art .hero__base {
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, .16));
}

.world-card__name {
  font-size: 20px;
  font-weight: 900;
  margin: 0;
}

.world-card__tag {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  margin: -6px 0 0;
  line-height: 1.35;
}

.world-card__progress {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}

.bar {
  flex: 1;
  height: 8px;
  border-radius: var(--r-chip);
  background: var(--line);
  overflow: hidden;
}

.bar__fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width var(--anim) ease;
}

.world-card--locked .world-card__art { filter: saturate(.35); opacity: .8; }

.lock-note {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 18px;
  border-radius: var(--r-chip);
  background: var(--panel);
  font-weight: 800;
  font-size: 15px;
  box-shadow: var(--shadow);
  transition: transform var(--anim) ease, filter var(--anim) ease;
}

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

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn--warm {
  background: var(--highlight);
  color: #5B4438;
}

.btn--block { width: 100%; }

.btn--sm {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 13px;
}

.btn--flat {
  box-shadow: none;
  background: var(--line);
}

.btn[disabled] {
  opacity: .45;
  pointer-events: none;
}

.btn__ico { width: 20px; height: 20px; flex: 0 0 auto; }

/* -------------------------------- игра ------------------------------- */

.statbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.counter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 6px;
  border-radius: var(--r-chip);
  background: var(--panel);
  box-shadow: var(--shadow);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.counter__face {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--highlight);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: 0 0 auto;
}

.counter__face .hero { width: 30px; height: 30px; }

.hearts {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.hearts__i {
  width: 26px;
  height: 26px;
  color: var(--heart);
  opacity: 1;
  transition: transform var(--anim) ease, opacity var(--anim) ease;
}

.hearts__i--off { color: var(--line); }

.hearts__i--lost { animation: heart-pop var(--anim) ease; }

@keyframes heart-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Три правила в один ряд: компактные чипы одинаковой ширины. */
.chips--row {
  flex-wrap: nowrap;
  gap: 6px;
}

.chips--row > .chip--rule {
  flex: 1 1 0;
  min-width: 0;
  max-width: none;
  justify-content: center;
  padding: 6px 7px;
  font-size: 11.5px;
  line-height: 1.15;
  text-align: center;
}

.chips--row .chip--rule .chip__dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  font-size: 9px;
}

.chip__text {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: normal;
  text-align: center;
}

@media (max-width: 360px) {
  .chips--row .chip--rule { font-size: 11px; padding: 6px 5px; }
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 7px 11px;
  border-radius: var(--r-chip);
  background: var(--panel);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  box-shadow: var(--shadow);
  line-height: 1.15;
}

.chip__dot {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: var(--accent);
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  font-size: 10px;
  font-weight: 900;
}

.chip__dot--row { background: var(--highlight); color: #5B4438; }
.chip__dot--touch { background: var(--ink); color: var(--bg); }

.board-wrap {
  display: grid;
  place-items: center;
  padding: 2px;
  flex: 1;
}

.board {
  width: min(92vw, 430px);
  max-width: 100%;
  min-width: min-content;
  display: grid;
  gap: 2px;
  padding: 6px;
  border-radius: var(--r-card);
  background: var(--panel);
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.cell {
  position: relative;
  border-radius: var(--r-tile);
  border: 2px solid transparent;
  background: var(--cell-color, var(--c1));
  display: grid;
  place-items: center;
  min-height: 44px;
  min-width: 44px;
  transition: transform var(--anim) ease, filter var(--anim) ease;
  padding: 0;
  overflow: hidden;
}

.cell--bt { border-top-color: var(--line); }
.cell--br { border-right-color: var(--line); }
.cell--bb { border-bottom-color: var(--line); }
.cell--bl { border-left-color: var(--line); }

.cell--n1 { --cell-color: var(--c1); }
.cell--n2 { --cell-color: var(--c2); }
.cell--n3 { --cell-color: var(--c3); }
.cell--n4 { --cell-color: var(--c4); }
.cell--n5 { --cell-color: var(--c5); }
.cell--n6 { --cell-color: var(--c6); }

.cell--blocked { filter: saturate(.4); }

.cell__char {
  width: 84%;
  height: 84%;
  object-fit: contain;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .22));
  animation: char-in var(--anim) ease;
}

@keyframes char-in {
  from { transform: scale(.4); opacity: .2; }
  to { transform: scale(1); opacity: 1; }
}

.cell__fallback {
  width: 58%;
  height: 58%;
  border-radius: 50%;
  background: var(--panel);
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 900;
  color: var(--ink);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .5);
  animation: char-in var(--anim) ease;
}

.cell__sym {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .28);
  color: rgba(255, 255, 255, .95);
}

.cell__cross {
  width: 44%;
  height: 44%;
  position: relative;
  opacity: .38;
}

.cell__cross::before,
.cell__cross::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  width: 2.5px;
  height: 100%;
  border-radius: 2px;
  background: var(--ink);
  transform: translateX(-50%) rotate(45deg);
}

.cell__cross::after { transform: translateX(-50%) rotate(-45deg); }

.cell--hint { animation: hint-pulse 900ms ease 2; }

@keyframes hint-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 224, 122, .0); }
  50% { box-shadow: 0 0 0 6px rgba(255, 224, 122, .85); }
}

.cell--wrong { animation: wrong-shake 260ms ease; }

@keyframes wrong-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.cell--char-gold { box-shadow: inset 0 0 0 3px var(--highlight); }

.footbar {
  display: flex;
  gap: 10px;
}

.footbar .btn { flex: 1; }

.hint-badge {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: var(--r-chip);
  background: var(--highlight);
  color: #5B4438;
  font-weight: 900;
}

/* ------------------------------ оверлеи ------------------------------ */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--sheet);
  backdrop-filter: blur(3px);
  z-index: 20;
  animation: fade-in var(--anim) ease;
}

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

.sheet {
  width: min(92vw, 420px);
  max-width: 100%;
  box-sizing: border-box;
  background: var(--panel);
  border-radius: var(--r-card);
  padding: 22px 20px 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .25);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: sheet-up var(--anim) ease;
}

@keyframes sheet-up {
  from { transform: translateY(16px) scale(.97); opacity: .4; }
  to { transform: none; opacity: 1; }
}

.sheet__title {
  margin: 0;
  font-size: 24px;
  font-weight: 900;
}

.sheet__text {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.45;
}

.sheet__art {
  width: 112px;
  height: 112px;
  margin: 0 auto -4px;
  display: grid;
  place-items: center;
  font-size: 56px;
}

.sheet__art img { width: 112px; height: 112px; object-fit: contain; }

.reward {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: center;
  padding: 8px 15px;
  border-radius: var(--r-chip);
  background: var(--highlight);
  color: #5B4438;
  font-weight: 900;
  font-size: 17px;
}

.reward__ico { width: 22px; height: 22px; color: #D99B27; }

.tagline-ok {
  font-size: 13px;
  font-weight: 800;
  color: var(--accent);
}

/* --------------------------- магазин/настройки ------------------------ */

.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--panel);
  border-radius: var(--r-chip);
  box-shadow: var(--shadow);
}

.tabs__btn {
  flex: 1;
  border-radius: var(--r-chip);
  min-height: 40px;
  font-weight: 800;
  font-size: 13px;
  color: var(--muted);
}

.tabs__btn--active {
  background: var(--accent);
  color: var(--accent-ink);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 14px;
  text-align: left;
  width: 100%;
}

.row__ico { width: 22px; height: 22px; color: var(--muted); flex: 0 0 auto; }
.row__grow { flex: 1; }
.row__note { font-size: 12px; color: var(--muted); font-weight: 600; }

.switch {
  width: 48px;
  height: 28px;
  border-radius: var(--r-chip);
  background: var(--line);
  position: relative;
  flex: 0 0 auto;
  transition: background var(--anim) ease;
}

.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--panel);
  box-shadow: 0 2px 5px rgba(0, 0, 0, .2);
  transition: transform var(--anim) ease;
}

.switch--on { background: var(--accent); }
.switch--on::after { transform: translateX(20px); }

.note {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  font-weight: 600;
  padding: 4px 2px;
  margin: 0;
}

.footer-badges {
  margin-top: auto;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

.spacer { flex: 1; }

.loading {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: var(--muted);
}

/* ------------- персонаж: базовый спрайт + слои одежды ------------- */
.hero {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.hero__base {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.hero__layer {
  position: absolute;
  height: auto;
  pointer-events: none;
}

.js-char-fb {
  display: none;
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: var(--panel);
  place-items: center;
  font-weight: 900;
  color: var(--ink);
  box-shadow: inset 0 0 0 3px var(--line);
}

.world-card__art .hero { width: 132px; height: 132px; margin: 0 auto; }
.counter__face .hero { width: 30px; height: 30px; }
.sheet__art .hero { width: 140px; height: 140px; margin: 0 auto 6px; }

/* ------------- точки-индикаторы карусели миров ------------- */
.dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: -6px 0 0;
}

.dots__i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  transition: width var(--anim) ease, background var(--anim) ease;
}

.dots__i--on {
  width: 18px;
  border-radius: 999px;
  background: var(--accent);
}

/* ------------- чипы правил: кнопки ------------- */
button.chip {
  border: 0;
  font: inherit;
  cursor: pointer;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .06);
}

button.chip:active { transform: scale(.97); }

/* подсветка клеток, которые запрещает выбранное правило */
.cell--rule-hit {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  filter: brightness(1.08);
}

/* тонкая обводка клетки: границы регионов читаются и без цвета */
.cell {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
}

/* ------------- тап-зона клетки >= 44px ------------- */
.board {
  display: grid;
  min-width: min-content;
  gap: 2px;
}

.board-wrap {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-bottom: 2px;
  justify-items: center;
}

.cell {
  min-width: 44px;
  min-height: 44px;
  aspect-ratio: 1;
}

/* ------------- персонаж в клетке: 78% (на 8x8 — не меньше 72%) ------------- */
.cell .hero {
  width: 78%;
  height: 78%;
}

.cell--n8 .hero { width: 72%; height: 72%; }

/* ------------- PNG-иконки из art/icons ------------- */
.ico-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.coin-pill__img { width: 26px; height: 26px; }

/* ------------- крест в клетке: PNG icon_x_mark ------------- */
.cell__cross-img { width: 62%; height: 62%; opacity: .55; }


/* ------------------------- режимы на главном -------------------------- */
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 14px;
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: left;
  min-height: 0;
  color: var(--ink);
}

.mode:active { transform: scale(.985); }

.mode__ico {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--highlight);
  color: var(--ink);
  margin-bottom: 4px;
}

.mode__name { font-size: 14px; font-weight: 800; }
.mode__note { font-size: 11.5px; font-weight: 600; color: var(--muted); }

/* --------------------------- палитра в настройках --------------------- */
.theme-dots {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.theme-dot {
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 3px var(--line);
}

.theme-dot--on {
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ink);
}

/* Переключатель языка в настройках (i18n) */
.lang {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-chip);
  background: var(--panel);
  box-shadow: inset 0 0 0 1px var(--line);
  flex: 0 0 auto;
}

.lang__btn {
  min-width: 46px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: var(--r-chip);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--muted);
}

.lang__btn--on {
  background: var(--accent);
  color: var(--accent-ink);
}
