/* Страница игры «Свет в окне напротив» — Telegram Mini App и обычный браузер (запасной вход).
   Стиль заставки — «Дневник» (BRIEF.md, раздел 2): кремовая бумага, лаванда, персик, книжный шрифт. */
:root {
  --paper: #FBF4E9;
  --paper-edge: #D9C3A5;
  --ink: #4A3B2E;
  --ink-soft: #7A6650;
  --lavender: #CDBFF0;
  --lavender-ink: #3D2F6B;
  --peach: #F6C9A8;
  --light: #FFD98A;
  /* отступы под вырез и кнопки Telegram: Telegram задаёт --tg-*, браузер — env() */
  --inset-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px));
  --inset-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px));
  --inset-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --inset-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1b1512;
  color: var(--ink);
  font-family: "Lora", Georgia, "Times New Roman", serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

/* Игра — на весь экран; холст не заходит под вырез камеры, полоску «Домой» и кнопки Telegram («Закрыть», «…» сверху
   в полном экране). Прототип: просто поля; потом — холст на весь экран, а HUD сдвигается сам (tgGame.insets) */
#game {
  position: fixed;
  inset: 0;
  padding: calc(var(--inset-top) + var(--tg-content-safe-area-inset-top, 0px))
           calc(var(--inset-right) + var(--tg-content-safe-area-inset-right, 0px))
           calc(var(--inset-bottom) + var(--tg-content-safe-area-inset-bottom, 0px))
           calc(var(--inset-left) + var(--tg-content-safe-area-inset-left, 0px));
  background: #1b1512;
}

#frame {
  position: relative;
  width: 100%;
  height: 100%;
}

#unity-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #1b1512;
  outline: none;
}

/* ------------------------------------------------------------- заставка загрузки */
#loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  background: var(--paper);
  transition: opacity 0.6s ease;
  z-index: 2;
}

#loading.done {
  opacity: 0;
  pointer-events: none;
}

#label {
  font-style: italic;
  font-size: 14px;
  color: var(--lavender-ink);
  background: var(--lavender);
  padding: 2px 12px;
  border-radius: 3px;
  transform: rotate(-2deg);
}

#window-art {
  width: 72px;
  height: 72px;
}

#window-art .glow {
  animation: glow 2.4s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

#title {
  margin: 0;
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 500;
  font-style: italic;
  text-align: center;
  color: var(--ink);
}

#bar {
  position: relative;
  width: min(320px, 70vw);
  height: 6px;
  border-radius: 3px;
  background: #EFE3D2;
  border: 1px solid var(--paper-edge);
  overflow: hidden;
}

#bar-fill {
  width: 0%;
  height: 100%;
  background: var(--ink-soft);
  transition: width 0.25s ease;
}

#status {
  font-size: 14px;
  color: var(--ink-soft);
}

#age {
  position: absolute;
  right: calc(var(--inset-right) + 14px);
  bottom: calc(var(--inset-bottom) + 12px);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 12px;
  color: var(--ink-soft);
  border: 1px solid var(--paper-edge);
  border-radius: 4px;
  padding: 1px 6px;
}

/* ------------------------------------------------------------- «поверни телефон» */
#rotate {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px;
  background: var(--paper);
  color: var(--ink);
  text-align: center;
  font-size: 18px;
  font-style: italic;
  z-index: 5;
}

#rotate small {
  font-style: normal;
  font-size: 14px;
  color: var(--ink-soft);
}

body.mobile.portrait #rotate {
  display: flex;
}

#rotate svg {
  width: 84px;
  height: 84px;
}

#rotate .phone {
  transform-origin: 32px 32px;
  animation: turn 2.6s ease-in-out infinite;
}

@keyframes turn {
  0%, 25% { transform: rotate(0deg); }
  55%, 85% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

/* ------------------------------------------------------------- браузер: кнопка «во весь экран» */
#fullscreen {
  position: absolute;
  right: calc(var(--inset-right) + 10px);
  bottom: calc(var(--inset-bottom) + 10px);
  width: 44px;
  height: 44px;
  border: 1px solid var(--paper-edge);
  border-radius: 50%;
  background: var(--paper) center / 22px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234A3B2E' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5'/%3E%3C/svg%3E");
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 3;
}

#fullscreen.ready {
  opacity: 0.85;
  pointer-events: auto;
}

body.telegram #fullscreen,
body.fullscreen #fullscreen {
  display: none;
}

/* ------------------------------------------------------------- сообщения Unity и ?debug */
#banner {
  position: fixed;
  left: 50%;
  top: calc(var(--inset-top) + 10px);
  transform: translateX(-50%);
  display: none;
  max-width: 90vw;
  z-index: 6;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
}

#banner div {
  margin-bottom: 6px;
  padding: 8px 12px;
  border-radius: 6px;
  background: #FFF4D6;
  color: #6B4F0B;
}

#banner div.error {
  background: #FCE3E3;
  color: #7A1F1F;
}

#debug {
  position: absolute;
  left: 50%;
  bottom: calc(var(--inset-bottom) + 4px);
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
}
