/* Gramagochi — экран варианта E.

   Две зоны с разными визуальными языками (GDD §6.4):
     .lcd      — пиксель-арт, сегментные бары, скан-линии
     всё вне   — плоский цифровой UI, без градиентов и фальшивого пластика

   Правило: пиксельная стилистика не выходит за пределы .lcd, плоская не
   заходит внутрь. Иначе два языка смешиваются в кашу.

   Ни один цвет не задан литералом по месту — только токены. Это условие
   для будущего выбора палитры игроком (GDD §5).
*/

:root {
  /* Комната и корпус — не зависят от режима экрана: пластик не меняет
     цвет от того, какой на нём дисплей. */
  --room: #191722;
  --room-glow: #2b2739;
  --case: #3b3457;
  --case-deep: #2c2743;
  --bezel: #211d33;
  --tile: #282341;
  --tile-line: #3b3459;
  --tile-deep: #322b4f;
  --chrome-text: #d7d0ee;
  --chrome-dim: #8f86b2;
  --accent: #a2be69;

  /* Экран: переключается режимом ЧБ / ЦВЕТ */
  --bg: #a2be69;
  --glow: #b4cd7d;
  --panel: #94b05b;
  --ink: #1a2810;
  --dim: rgba(26, 40, 16, 0.45);
  --bar-a: var(--ink);
  --bar-b: var(--ink);
  --bar-c: var(--ink);

  /* Pixelify Sans заменён 10.09.2026 (живой тест): его кириллица на мелких
     размерах ломалась — разная толщина букв, "С" читалась почти как "О".
     Silkscreen проверен вживую рядом с пятью другими кандидатами
     (screenshot в комментарии к коммиту) — ровная толщина, ничего не
     ломается. */
  --pixel: 'Silkscreen', 'Courier New', monospace;
  --mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;

  /* Плавающие "Закрыть"/"⌄ •••" Telegram в fullscreen — не вырез устройства
     (тот уже в env(safe-area-inset-top) ниже), джаваскрипт держит актуальное
     значение (app.js, syncSafeArea). 0 по умолчанию — вне Telegram ничего
     не двигается. */
  --tg-safe-top: 0px;
}

:root[data-mode="color"] {
  --bg: #f3ecd9;
  --glow: #fbf6e8;
  --panel: #e9dfc6;
  --ink: #221d18;
  --dim: rgba(34, 29, 24, 0.45);
  --bar-a: #c8502f;
  --bar-b: #217a63;
  --bar-c: #b07a1c;
}

* { box-sizing: border-box; }

/* Собственный display у класса перебивает браузерный [hidden],
   поэтому скрытие приходится усиливать. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--room);
  font-family: var(--mono);
  color: var(--chrome-text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.room {
  min-height: 100dvh;
  padding-top: calc(8px + env(safe-area-inset-top) + var(--tg-safe-top));
  padding-right: calc(8px + env(safe-area-inset-right));
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  padding-left: calc(8px + env(safe-area-inset-left));
  display: flex;
  justify-content: center;
  background: radial-gradient(ellipse 85% 45% at 50% 34%, var(--room-glow) 0%, var(--room) 72%);
}

.case {
  flex: 1;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 34px;
  background: linear-gradient(168deg, var(--case) 0%, var(--case-deep) 100%);
  box-shadow: 0 22px 48px -20px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* --- Экран ---------------------------------------------------------------- */

.bezel {
  flex: 1;
  min-height: 0;
  padding: 8px;
  /* Концентрика: радиус корпуса минус толщина рамки, иначе углы «спорят». */
  border-radius: 22px;
  background: var(--bezel);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.6);
}

.lcd {
  /* Экраны онбординга кладутся поверх ЭКРАНА, а не поверх всего приложения:
     без этого overlay цепляется за вьюпорт и закрывает корпус. */
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  transition: background 0.2s ease;
}

.lcd-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 13px;
  background: var(--panel);
  border-bottom: 2px solid var(--ink);
}

.ident { display: flex; align-items: baseline; gap: 7px; min-width: 0; }

.name {
  font-family: var(--pixel);
  font-size: 15px;
  letter-spacing: 0.04em;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage, .age { font-size: 10px; color: var(--dim); }
.age { font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* Иконки-бары: плитка не меняет размер, фон тает влево (GDD §9.4) */

.bars {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 11px 13px 9px;
}

.bar {
  position: relative;
  flex: 1;
  height: 36px;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  background: var(--panel);
}

.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--bar-c);
  transition: width 0.35s ease;
}

.bar svg {
  position: relative;
  width: 19px;
  height: 19px;
  /* Иконка инвертируется над заливкой и над пустой частью одновременно —
     так она читается на любом уровне бара без второй копии в разметке. */
  mix-blend-mode: difference;
}

.bar.is-low { animation: blink 1.1s steps(1) infinite; }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }

.scene {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse 72% 60% at 50% 46%, var(--glow) 0%, var(--bg) 72%);
  overflow: hidden;
}

.scene::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 3px);
}

.pet {
  width: min(52vw, 190px);
  height: min(52vw, 190px);
  image-rendering: pixelated;
  cursor: pointer;
  transform-origin: 50% 88%;
  /* GRA-8: в цветном режиме кремовый мех почти не отличим от кремового
     фона LCD (контраст ~1.05:1) — глобально перекрашивать экран рискованно
     (--ink/--bg завязаны на весь текст внутри LCD), поэтому вместо этого
     мягкий контактный ореол вокруг силуэта, по уже тематизированному
     var(--dim). В ЧБ-режиме тоже уместен — только тоньше, там и так
     контраст в порядке. */
  filter: drop-shadow(0 2px 0 var(--dim)) drop-shadow(0 0 4px var(--dim));
}

/* Тап по питомцу ("погладить", backend actions.pet_touch) — отклик мгновенно,
   не дожидаясь сервера: короткий приплюснутый "подпрыг", как будто и правда
   ткнули пальцем. Дольше wobble у яйца (1.2s) в разы, чтобы не путать одно
   с другим боковым зрением. */
@keyframes poke {
  0% { transform: scale(1, 1); }
  35% { transform: scale(0.9, 1.08); }
  65% { transform: scale(1.06, 0.94); }
  100% { transform: scale(1, 1); }
}
.pet.is-poked { animation: poke 260ms ease-out; }

/* Настоящий пиксель-арт (Фаза 2, пилот): спрайт-лист 4 кадра в ряд,
   background-size:400% сжимает его так, что один кадр = ровно размер
   контейнера, а background-position шагает по процентам 0/33/67/100 —
   не завязано на реальный пиксельный размер исходника. */
.pet-raster {
  background-repeat: no-repeat;
  background-size: 400% 100%;
  background-position-y: 0;
}

.scene.is-egg .pet { animation: wobble 1.2s ease-in-out infinite; transform-origin: 50% 88%; }

@keyframes wobble {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}

.poops {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  gap: 6px;
}

.poops svg { width: 30px; height: 30px; }

.scene-note {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  margin: 0;
  padding: 0 16px;
  text-align: center;
  font-size: 11px;
  line-height: 1.5;
  color: var(--dim);
}

/* --- Корпус: плоский UI --------------------------------------------------- */

.controls { display: flex; justify-content: space-between; gap: 5px; }

.action {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0;
  border: 1px solid var(--tile-line);
  border-radius: 12px;
  background: var(--tile);
  color: var(--chrome-dim);
  font-family: var(--pixel);
  font-size: 11px;
  cursor: pointer;
}

.action svg { width: 20px; height: 20px; }
.action.is-open { background: var(--accent); border-color: var(--accent); color: var(--bezel); }
.action:disabled { opacity: 0.35; }
.action:active { transform: translateY(1px); }
.action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.drawer {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 13px;
  border: 1px solid var(--tile-line);
  border-radius: 16px;
  background: var(--tile);
}

/* Уголок указывает на открывший ящик тайл: меню «растёт» из кнопки,
   а не появляется само по себе. */
.drawer::before {
  content: '';
  position: absolute;
  top: -7px;
  left: var(--arrow, 20px);
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
  background: var(--tile);
  border-left: 1px solid var(--tile-line);
  border-top: 1px solid var(--tile-line);
}

.drawer-title {
  font-family: var(--pixel);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--chrome-dim);
}

.drawer-items { display: flex; gap: 8px; }

.item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 6px;
  border: 0;
  border-radius: 10px;
  background: var(--tile-deep);
  color: var(--chrome-text);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.item svg { width: 24px; height: 24px; }
.item small { font-weight: 400; font-size: 10px; color: var(--chrome-dim); }
.item:active { transform: translateY(1px); }

.tabs {
  display: flex;
  gap: 5px;
  padding: 4px;
  border-radius: 14px;
  background: var(--bezel);
}

.tab {
  flex: 1;
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--chrome-dim);
  font-family: var(--pixel);
  font-size: 13px;
  cursor: pointer;
}

.tab.is-active { background: var(--case); color: var(--chrome-text); }

.plate { display: flex; align-items: center; justify-content: center; gap: 10px; }

.brand {
  font-family: var(--pixel);
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--chrome-dim);
}

.mode {
  padding: 5px 9px;
  border: 1px solid var(--tile-line);
  border-radius: 8px;
  background: transparent;
  color: var(--chrome-dim);
  font-family: var(--pixel);
  font-size: 12px;
  cursor: pointer;
}

/* --- Экраны онбординга и ухода питомца ------------------------------------ */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: var(--bg);
}

.overlay h1 {
  margin: 0;
  font-family: var(--pixel);
  font-size: 20px;
  line-height: 1.7;
  color: var(--ink);
}

.overlay p { margin: 0; font-size: 13px; line-height: 1.55; color: var(--ink); max-width: 26ch; }

.pips { display: flex; gap: 8px; }

.pip { width: 18px; height: 18px; border: 2px solid var(--dim); }
.pip.is-on { background: var(--ink); border-color: var(--ink); }

.field {
  width: 100%;
  max-width: 260px;
  padding: 14px;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  font-family: var(--pixel);
  font-size: 20px;
  text-align: center;
}

.field:focus { outline: 2px solid var(--ink); outline-offset: 2px; }

.primary {
  min-height: 52px;
  padding: 0 26px;
  border: 0;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--pixel);
  font-size: 15px;
  cursor: pointer;
}

.primary:disabled { opacity: 0.4; }

/* --- Тост ----------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  max-width: 88vw;
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--tile);
  border: 1px solid var(--tile-line);
  color: var(--chrome-text);
  font-size: 12px;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
