/* Урожай — тёплый «дачный» стиль в духе claymorphism: мягкие объёмные
   плитки, деревянное поле, крупные тап-таргеты, двойные тени без резких линий.
   Аудитория 50+ в браузере соцсети — читаемость и крупные зоны нажатия важнее
   модных трюков; интерактивные состояния без сдвига макета.

   Палитра: крафт-бумага #F6F1E0 / зелень #3E7B3F / томатный акцент #E8572A.
   Каждому виду «урожая» — своя пастельная подложка: вид различается и формой
   эмодзи, и цветом плашки (не только цветом — против дальтонизма). */

:root {
  --bg: #F6F1E0;
  --bg-deep: #EFE7CE;
  --paper: #FFFDF4;
  --paper-deep: #FBF2D6;
  --ink: #2B2117;
  --ink-dim: #6E5F4C;
  --green: #4C8A4D;
  --green-dark: #2F6230;
  --tomato: #E8572A;
  --tomato-dark: #C43D14;
  --wood: #C99A5B;
  --wood-deep: #A87B42;
  --wood-rim: #8A6233;
  --gold: #E9B44C;
  --pink: #E5637E;
  --cuke: #6FA96A;
  --spice: #D98E4A;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'M PLUS Rounded 1c', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ---------- Десктоп: компактная колонка ---------- */
/* На широких окнах игра не растягивается бесформенно: колонка остаётся
   «телефонной» (560px) и по центру, с мягкой тенью «карточки на столе»,
   а сцена на весь экран деликатно виньетируется по краям. Никаких
   фальш-рамок: у поля уже есть своя деревянная фактура. */
/* ---------- Десктоп: компактное меню-окно ---------- */
/* Первое окно (меню) на широких экранах выглядит слишком большим —
   жмём его до компактной карточки: narrower панель, меньше маскот и кегли.
   Телефоны (окна < 700px) не трогаем. */
@media (min-width: 700px) {
  body { max-width: 560px; margin: 0 auto; }

  #menu .menu-inner { width: min(88vw, 330px); padding: 20px 18px; }
  .menu-inner .mascot { max-width: 92px; margin: 0 auto 6px; }
  .menu-inner h1 { font-size: 38px; }
  .menu-inner .tagline { margin: 8px 0 10px; font-size: 14px; }
  .menu-inner p.hint { font-size: 13px; line-height: 1.4; margin: 5px 0 0; }
  .menu-inner .hint.total { margin-top: 5px; }
  .menu-inner .btn.big { margin-top: 6px; }
  .menu-inner .btn-row { margin-top: 10px; }
}

/* ---------- Фон: небо, солнце, грядка у горизонта ---------- */
#sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1150px 460px at 50% -160px, rgba(76, 138, 77, .16), transparent 72%),
    radial-gradient(760px 300px at 12% 108%, rgba(232, 87, 42, .09), transparent 70%),
    linear-gradient(180deg, #FBF7EA 0%, #F6F1E0 55%, var(--bg-deep) 100%);
}

#sky::before { /* мягкое «солнце» слева вверху */
  content: '';
  position: absolute;
  top: -60px;
  left: -40px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(233, 180, 76, .35) 0%, rgba(233, 180, 76, .12) 46%, transparent 70%);
}

#sky::after { /* грядка-полоса у нижнего края */
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 120px;
  background: linear-gradient(180deg, transparent 0%, rgba(76, 138, 77, .15) 62%, rgba(47, 98, 48, .18) 100%);
}

.deco {
  position: relative; /* устаревший класс — на случай эмодзи-сцены */
}

/* Листья-углы: рамка «сада» вокруг поля — приглушённые, и сезонно
   подкрашиваются (hue-rotate из палитры сезона — осень «желтеет», мороз «синеет») */
.leaf {
  position: fixed;
  z-index: 0;
  pointer-events: none;
  opacity: .88;
  filter: saturate(.7) hue-rotate(var(--leaf-rot, 0deg));
}

.leaf-tl {
  left: -18px;
  top: -16px;
  width: 110px;
}

.leaf-br {
  right: -20px;
  bottom: -14px;
  width: 124px;
  transform: rotate(160deg);
}

.tile .glyph { display: inline-block; pointer-events: none; }

.tile .glyph svg {
  width: 78%;
  height: 78%;
  display: block;
  filter: drop-shadow(0 1.5px 1px rgba(43, 33, 23, .28));
}

.chip .chip-ic {
  width: 30px;
  height: 30px;
  vertical-align: -8px;
  margin-right: 3px;
}

/* ---------- Экран правил ---------- */
.rules-panel {
  width: min(94vw, 420px);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rules-panel h2 { margin-bottom: 2px; }

.rules-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: grid;
  gap: 12px;
  padding-right: 4px;
  margin-bottom: 12px;
}

.rule-p { margin: 0; color: var(--ink-dim); font-size: 15px; line-height: 1.5; text-align: left; }
.rule-p b { color: var(--ink); }

.rule-row {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
}

.rule-row b { color: var(--green-dark); }

.rule-ic {
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: var(--paper-deep);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), 0 2px 0 rgba(43, 33, 23, .1);
  display: grid;
  place-items: center;
}

.rule-ic svg { width: 36px; height: 36px; display: block; }

/* ---------- Маскот и сцена ---------- */
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* приглушённый фон: сатурация и яркость вниз, лёгкий блюр — поле читается
     само, но сцена не выбелена в ноль и остаётся дачной подложкой */
  filter: saturate(.78) opacity(.8) blur(1px);
}

.mascot {
  width: 112px;
  margin: -4px auto 4px;
}

.mascot.small {
  width: 74px;
  margin: -2px auto 0;
}

.mascot svg {
  width: 100%;
  height: auto;
  display: block;
  filter: drop-shadow(0 3px 4px rgba(43, 33, 23, .2));
  animation: mascot-bob 2.6s ease-in-out infinite alternate;
}

@keyframes mascot-bob {
  from { transform: translateY(0) rotate(-2deg); }
  to   { transform: translateY(-5px) rotate(2deg); }
}

/* ---------- HUD ---------- */
#hud {
  width: min(100%, 560px);
  /* «чёлка»/статус-бар: блок заметно ниже прежних 10px — в предпросмотре и
     в живом webview счёт не под чёлкой (body сверху ещё добавит env()) */
  padding: 44px 12px 0;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.icon-btn {
  min-width: 46px;
  min-height: 46px;
  border: none;
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink-dim);
  box-shadow: 0 3px 0 rgba(43, 33, 23, .14), inset 0 2px 0 rgba(255, 255, 255, .9);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(43, 33, 23, .14), inset 0 2px 0 rgba(255, 255, 255, .9);
}

.icon-btn .ic-off { display: none; }
.icon-btn.is-muted .ic-on { display: none; }
.icon-btn.is-muted .ic-off { display: block; }

.hud-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 32px;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--tomato-dark);
}

.hud-score::after {
  content: 'очки';
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-top: 3px;
}

.hud-score.bump { animation: bump .28s ease; }

@keyframes bump {
  30%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.hud-sub {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.chip {
  background: var(--paper);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(43, 33, 23, .12), inset 0 2px 0 rgba(255, 255, 255, .9);
  white-space: nowrap;
}

.chip.accent { color: var(--green-dark); }

/* две кнопки в ряд (Правила | Рейтинг) — компактнее вертикали */
.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-row .btn { flex: 1; margin-top: 0; }

/* сезон — тихая метка прогресса, не соперник игровым чипам */
.chip.season {
  color: var(--ink-dim);
  font-weight: 600;
  border: 1px dashed rgba(43, 33, 23, .22);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .7);
}

.chip.low {
  background: var(--tomato);
  color: #FFF6EC;
  box-shadow: 0 3px 0 var(--tomato-dark), inset 0 2px 0 rgba(255, 255, 255, .35);
}

.chip.tomato {
  background: var(--gold);
  color: #40300A;
  box-shadow: 0 3px 0 #C08A2B, inset 0 2px 0 rgba(255, 255, 255, .45);
  animation: chip-in .18s ease;
}

/* чип каскада всегда держит своё место в HUD (visibility, а не display):
   когда «каскад ×N» появляется/исчезает, высота HUD и позиция доски
   не прыгают (жалоба: поле дёргается, когда надпись не влезает в строку) */
#combo-chip { visibility: hidden; }
#combo-chip.on { visibility: visible; }

@keyframes chip-in {
  from { transform: scale(.6); }
  to   { transform: scale(1); }
}

.hidden { display: none !important; }

/* ---------- Поле: деревянный ящик ---------- */
#board {
  position: relative;
  /* центрируем доску целиком (и по вертикали в свободном месте под HUD —
     «пальцевая» зона на телефоне, и по горизонтали при окнах шире 494px,
     где квадрат поля ограничен потолком 470 и прежние 12px уводили его влево) */
  margin: auto;
  border-radius: 22px;
  background:
    /* пазы между досками */
    repeating-linear-gradient(90deg, rgba(47, 30, 12, .10) 0 2px, transparent 2px 62px),
    linear-gradient(180deg, var(--wood) 0%, var(--wood-deep) 100%);
  box-shadow:
    inset 0 0 0 4px var(--wood-rim),
    inset 0 4px 10px rgba(43, 33, 23, .3),
    inset 0 -2px 0 rgba(255, 240, 200, .34),
    0 12px 26px -10px rgba(43, 33, 23, .45);
  touch-action: none; /* свайпы обрабатываем сами */
}

/* ---------- Плитка: мягкая «прядёная» пуговица ---------- */
.tile {
  position: absolute;
  display: grid;
  place-items: center;
  border-radius: 24%;
  background: var(--paper);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .9),
    inset 0 -4px 0 rgba(43, 33, 23, .09),
    0 3px 0 rgba(43, 33, 23, .13),
    0 5px 10px rgba(43, 33, 23, .1);
  line-height: 1;
  transition: top 170ms cubic-bezier(.3, .8, .4, 1), left 170ms cubic-bezier(.3, .8, .4, 1),
              transform 150ms ease, opacity 150ms ease;
  cursor: pointer;
}

/* пастельные подложки «в честь вида» (тон каждого вида, гарантия
   различимости даже при расстройствах цветового восприятия) */
.tile.t0 { background: #FFE0D2; }  /* помидор   */
.tile.t1 { background: #E3EED6; }  /* огурец     */
.tile.t2 { background: #FBE2EF; }  /* клубника-малина */
.tile.t3 { background: #FFF3CB; }  /* подсолнух */
.tile.t4 { background: #EAF3D2; }  /* яблоко-антоновка */

.tile.sel {
  transform: scale(1.12);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .9),
    0 0 0 4px var(--tomato),
    0 6px 14px rgba(232, 87, 42, .4);
}

.tile.hint { animation: hint-dance .5s ease infinite alternate; }

/* ---------- Спецэлементы: ракета, бочка-бах, радуга ---------- */
.tile.sp {
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .95),
    inset 0 -4px 0 rgba(43, 33, 23, .09),
    0 0 0 2.5px rgba(43, 33, 23, .18),
    0 3px 0 rgba(43, 33, 23, .13),
    0 5px 10px rgba(43, 33, 23, .1);
}

.tile.sp-new {
  animation: sp-born .4s cubic-bezier(.3, 1.4, .6, 1);
}

@keyframes sp-born {
  0%   { transform: scale(.2) rotate(-30deg); }
  70%  { transform: scale(1.25); }
  100% { transform: scale(1); }
}

.tile .glyph { display: inline-block; pointer-events: none; }
.tile.sp-v .glyph { transform: rotate(90deg); }

.tile.sp-color {
  background: var(--paper);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .95),
    0 0 0 3px rgba(233, 180, 76, .55),
    0 3px 0 rgba(43, 33, 23, .13),
    0 5px 10px rgba(43, 33, 23, .1);
}

@keyframes hint-dance {
  from { transform: translateY(0) rotate(0deg); }
  to   { transform: translateY(-9%) rotate(-4deg); }
}

.tile.shake { animation: tile-shake .3s ease; }

@keyframes tile-shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-6%); }
  75%      { transform: translateX(6%); }
}

.tile.pop {
  animation: pop-out .19s ease forwards;
}

@keyframes pop-out {
  0%   { transform: scale(1); opacity: 1; }
  55%  { transform: scale(1.18); opacity: .95; }
  100% { transform: scale(.08) rotate(20deg); opacity: 0; }
}

/* ---------- Частицы и конфетти ---------- */
.fx {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  pointer-events: none;
  background: var(--c, var(--tomato));
  animation: fx-fly var(--d, .5s) ease-out forwards;
  z-index: 5;
}

@keyframes fx-fly {
  from { transform: translate(0, 0) scale(1); opacity: 1; }
  to   { transform: translate(var(--dx, 8px), var(--dy, -30px)) scale(.35); opacity: 0; }
}

.confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 9;
}

.confetti span {
  position: absolute;
  top: -6%;
  width: 10px;
  height: 15px;
  border-radius: 3px;
  background: var(--c, var(--tomato));
  opacity: .92;
  transform: rotate(var(--r, 0deg));
  animation: confetti-fall var(--d, 2.1s) ease-in var(--dl, 0s) forwards;
}

@keyframes confetti-fall {
  to { transform: translateY(112vh) rotate(560deg); opacity: .85; }
}

/* ---------- Оверлеи ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}

.overlay.dark { background: rgba(52, 38, 20, .55); }

.menu-inner,
.panel {
  background: var(--paper);
  border-radius: 26px;
  padding: 30px 24px;
  width: min(92vw, 380px);
  text-align: center;
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, .95),
    inset 0 -5px 0 rgba(43, 33, 23, .07),
    0 18px 40px rgba(43, 33, 23, .28);
}

/* Меню — прозрачное, поле просвечивает */
#menu { background: rgba(246, 241, 224, .22); }
#menu .menu-inner { box-shadow: 0 12px 30px rgba(43, 33, 23, .16); }

h1 {
  margin: 0 0 2px;
  font-size: 46px;
  font-weight: 800;
  letter-spacing: 2px;
  background: linear-gradient(180deg, var(--green-dark) 30%, var(--green) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--green-dark);
}

h1::after { /* «черешенка» под заголовком */
  content: '';
  display: block;
  height: 4px;
  width: 120px;
  margin: 8px auto 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--tomato));
}

.tagline {
  margin: 14px 0 18px;
  color: var(--ink-dim);
  font-size: 17px;
}

h2 { margin: 0 0 10px; font-size: 27px; }

.final {
  font-size: 50px;
  font-weight: 800;
  color: var(--tomato-dark);
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}

.win-bonus { color: var(--green-dark); font-weight: 700; margin-top: 4px; }
.win-stars {
  font-size: 40px;
  letter-spacing: 8px;
  animation: chip-in .32s ease;
  margin-bottom: 2px;
}
.win-total { color: var(--ink-dim); margin: 8px 0 16px; }
.fail-goal { font-size: 25px; font-weight: 700; margin-bottom: 16px; }
.fail-goal .chip-ic {
  width: 38px;
  height: 38px;
  vertical-align: -9px;
  margin-right: 4px;
}

.col { display: grid; gap: 12px; }

.btn {
  min-height: 56px;
  border: none;
  border-radius: 18px;
  padding: 13px 18px;
  font: inherit;
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
  background: var(--paper-deep);
  color: var(--ink);
  box-shadow: 0 4px 0 rgba(43, 33, 23, .16), inset 0 2px 0 rgba(255, 255, 255, .9);
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
}

.btn.primary {
  background: linear-gradient(180deg, var(--green) 0%, var(--green-dark) 100%);
  color: #FFF9EA;
  box-shadow: 0 5px 0 rgba(31, 70, 32, .95), inset 0 2px 0 rgba(255, 255, 255, .3);
}

.btn.ghost {
  background: transparent;
  color: var(--ink-dim);
  box-shadow: inset 0 0 0 2.5px #D9CFAF, 0 0 0 rgba(0, 0, 0, 0);
}

.btn.big {
  width: 100%;
  min-height: 64px;
  font-size: 23px;
}

.btn:hover { filter: brightness(1.03); }

.btn:active, .btn.primary:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(43, 33, 23, .16), inset 0 2px 0 rgba(255, 255, 255, .3);
}

.btn.primary:active { box-shadow: 0 2px 0 rgba(31, 70, 32, .95), inset 0 2px 0 rgba(255, 255, 255, .3); }

.btn:disabled { opacity: .55; cursor: default; }

.btn:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid var(--tomato);
  outline-offset: 2px;
}

p.hint { color: var(--ink-dim); font-size: 14px; line-height: 1.55; }
p.hint.total { margin-top: 8px; font-weight: 700; color: var(--green-dark); }

/* ---------- Демо-реклама ---------- */
.overlay.ad { background: rgba(36, 28, 16, .82); }

.ad-box {
  background: var(--paper);
  border-radius: 22px;
  padding: 32px 36px;
  text-align: center;
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, .95), 0 16px 36px rgba(0, 0, 0, .3);
}

.ad-title { font-weight: 700; color: var(--ink-dim); }
.ad-count { font-size: 48px; font-weight: 800; margin: 8px 0; color: var(--tomato-dark); }
.ad-note  { color: var(--ink-dim); font-size: 13px; }

/* ---------- Тост ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(43, 33, 23, .94);
  color: #FFF6EC;
  border-radius: 14px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 500;
  z-index: 40;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
}

/* ---------- Меньше движения ---------- */
@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  .tile.hint, .tile.shake, .tile.pop { animation: none; }
  .hud-score.bump, .chip.tomato, .confetti span, .fx, .tile.sp-new, .win-stars { animation: none; }
  .mascot svg { animation: none; }
}

/* ---------- Десктоп ---------- */
@media (min-width: 700px) {
  body { justify-content: center; }
  #hud { width: min(100%, 480px); }
}
