/* Mini App MemeGarden — каркас (MVP).
 *
 * Цвета только из палитр STYLE.md. Свет сверху слева: у кнопок и карточек
 * верхний и левый край светлее, правый и нижний темнее. Тени — сдвиг цвета
 * без размытия, никакого серого и чёрного. Тема (светлая/тёмная) берётся из
 * Telegram: app.js ставит <html data-theme="...">.
 */

:root {
  --bg: #f4efe6;          /* бумага васи */
  --surface: #fff4f7;     /* сакура, блик */
  --line: #fde0e8;        /* сакура, светлый */
  --text: #3e2524;        /* кора, контур */
  --text-soft: #744640;   /* кора, основной */
  --accent: #f7c3d3;      /* сакура, средний */
  --accent-light: #fde0e8;
  --accent-shade: #d88ba8;
  --accent-contour: #c2779a;
  --on-accent: #3e2524;   /* текст на розовом — всегда тёмная кора, в обеих темах */
  --garden: #eef5dc;      /* листва, блик */
  --garden-edge: #cfe3a8;
  --ok: #5f8a4e;          /* листва, тень */
  --warn: #9e4540;        /* клён, тень */
  --gold: #c9973d;        /* золото, тень */

  --safe-top: var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-left: var(--tg-safe-area-inset-left, env(safe-area-inset-left, 0px));
  --safe-right: var(--tg-safe-area-inset-right, env(safe-area-inset-right, 0px));
  --content-top: var(--tg-content-safe-area-inset-top, 0px);
  --content-bottom: var(--tg-content-safe-area-inset-bottom, 0px);

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #3e2524;          /* кора, контур — тёмный, но не чёрный */
  --surface: #4f2f2c;     /* кора, тень */
  --line: #583431;        /* кора, полоски */
  --text: #f4efe6;
  --text-soft: #fde0e8;
  --accent: #eea3bb;
  --accent-light: #f7c3d3;
  --accent-shade: #c2779a;
  --accent-contour: #3e2524;
  --garden: #4a6b3d;      /* листва, контур */
  --garden-edge: #587a46;
  --ok: #cfe3a8;
  --warn: #f6b48f;
  --gold: #f7df9a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: var(--tg-viewport-stable-height, 100dvh);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ------------------------------------------------------------ шапка */

.top {
  padding: calc(var(--safe-top) + var(--content-top) + 8px) 16px 0;
}

.stats {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.stat {
  flex: 1;
  text-align: center;
  padding: 7px 4px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 2px 2px 0 var(--accent-shade);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  line-height: 21px;   /* строка не зависит от эмодзи: картинка вместо него высоту не меняет */
}

.status {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 18px;
  margin: 8px 2px 4px;
  font-size: 12px;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------ содержимое */

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 16px 16px;
}

.view > * { flex-shrink: 0; }

.note { color: var(--text-soft); text-align: center; margin: 32px 0; }

/* ----------------------------------------------------------- ферма */

.farm-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 44px;
  margin-bottom: 4px;
}

.farm-note { margin: 6px 0 0; font-size: 12px; color: var(--text-soft); text-align: center; }
.farm-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.garden {
  /* сад занимает всё свободное место экрана, ряды расходятся по высоте */
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  align-content: space-evenly;
  gap: 4px 8px;
  overflow: hidden;
  padding: 12px 4px 20px;
  background: var(--garden);
  border-radius: 14px;
  box-shadow: inset -3px -3px 0 var(--garden-edge);
}

.plot {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.plot svg {
  /* 32×32 увеличивается только целым числом: ×4, на узких экранах ×3 */
  width: 128px;
  height: 128px;
  image-rendering: pixelated;
}

.plot-label {
  margin-top: -6px;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  box-shadow: 1px 1px 0 var(--accent-shade);
}

.plot-title { font-size: 11px; color: var(--text-soft); margin-top: 3px; }

/* Полоса редкости над деревом и свечение кроны (web/rarity-fx.js). Полоса — холст
   64x24 шириной с рисунок дерева (масштаб тот же, что у спрайта), свечение — холст
   64x64 поверх дерева. Обе накладки пропускают нажатия сквозь себя: тап по ним —
   тап по грядке. Свечение абсолютное и места не занимает. */
.plot-art { display: flex; flex-direction: column; align-items: stretch; }
.plot-strip { display: block; position: relative; z-index: 1; width: 100%; height: auto; image-rendering: pixelated; pointer-events: none; }
.plot-tree { position: relative; display: block; }
.plot-glow {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  pointer-events: none;
}
.plot--ready .plot-label { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.plot--wilted .plot-label { color: var(--warn); }
.plot--empty .plot-label { color: var(--text-soft); }

/* крупнее, если ширина позволяет: ×5 */
@media (min-width: 370px) {
  .plot svg { width: 160px; height: 160px; }
}

@media (max-width: 330px) {
  .plot svg { width: 96px; height: 96px; }
}

/* ---------------------------------------------------------- кнопки */

.btn {
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--accent);
  box-shadow: inset 2px 2px 0 var(--accent-light), 2px 2px 0 var(--accent-contour);
  cursor: pointer;
  touch-action: manipulation;
}

.btn:active { transform: translate(1px, 1px); box-shadow: inset 2px 2px 0 var(--accent-light), 1px 1px 0 var(--accent-contour); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-quiet { background: var(--surface); color: var(--text); box-shadow: 2px 2px 0 var(--accent-shade); }
.btn-wide { width: 100%; }

/* ------------------------------------------------- простые разделы */

.section { margin: 8px 0 18px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); margin: 0 0 6px; }

.item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.item:first-of-type { border-top: 0; }
.item-text { flex: 1; min-width: 0; }
.item-sub { font-size: 12px; color: var(--text-soft); }
.item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.item-actions .btn { min-height: 34px; padding: 6px 10px; font-size: 13px; }

/* --------------------------------------------- иконки предметов (item-icons.js) */

.item-icon { flex-shrink: 0; image-rendering: pixelated; }
.seed-icon { flex-shrink: 0; image-rendering: pixelated; }
.seed-icon--emoji { display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.item-name-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.item-name-row .rarity { image-rendering: pixelated; }

.herbarium-new { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.herbarium-new .rarity { image-rendering: pixelated; }

.herbarium-slots { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 14px; }
.herbarium-slot {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line);
}
.herbarium-slot canvas { image-rendering: pixelated; }
.herbarium-slot-missing { opacity: .35; }

/* ------------------------------------------------ нижняя навигация */

.tabs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  padding: 4px 4px calc(var(--safe-bottom) + var(--content-bottom) + 4px);
  background: var(--surface);
  box-shadow: 0 -2px 0 var(--line);
}

.tabs button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-soft);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  touch-action: manipulation;
}

.tabs button span { font-size: 20px; line-height: 1; }

/* ------------------------------------------ иконки интерфейса (web/ui-icons.js) */

/* PNG с прозрачным фоном: лежат на любой поверхности как есть. Пока картинка не загрузилась,
   в <span> эмодзи; место под иконку вкладки занято заранее, полоса вкладок не растёт. */
.ui-icon { display: inline-flex; align-items: center; justify-content: center; line-height: 1; vertical-align: middle; margin: 0 2px; }
.ui-icon img { display: block; image-rendering: pixelated; }
.tabs button .tab-icon { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; margin: 0; vertical-align: top; }
.tabs button[aria-current="page"] { color: var(--on-accent); font-weight: 700; background: var(--accent-light); }

/* ------------------------------------------------ нижний лист, тост */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  background: rgba(60, 40, 40, 0.10);
  z-index: 10;
}

.sheet-backdrop[hidden], .toast[hidden], .tabs[hidden], .top[hidden] { display: none; }

.sheet {
  width: 100%;
  max-height: 80%;
  overflow-y: auto;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -3px 0 var(--accent-shade);
}

.sheet h2 { margin: 0 0 10px; font-size: 17px; }
.sheet p { margin: 6px 0; line-height: 1.4; }
#sheet-close { width: 100%; margin-top: 14px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--safe-bottom) + 76px);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 2px 2px 0 var(--accent-contour);
  line-height: 1.35;
  white-space: pre-line;
  z-index: 20;
  /* Тост — только сообщение: нажатия проходят сквозь него к кнопкам под
     ним (раньше строка о посадке на 3,5 с закрывала «Посадить» внизу сада). */
  pointer-events: none;
}

.toast.is-error { box-shadow: 2px 2px 0 var(--warn); }

.problem { margin: 32px 16px; line-height: 1.45; }
.problem b { display: block; margin-bottom: 6px; font-size: 17px; }
.problem .btn { margin-top: 14px; }
