/* ═══ FIRST FLIGHT — Pocket Dragons fan tribute ═══
   Визуальная система выверена по материалам проекта: почти чёрная ночь,
   латунь #d9a441, пергамент #f4ead7, янтарный ключевой свет, белый фосфор цифр. */
:root {
  --ink: #05070a;
  --amber: #ffb54d;
  --amber-bright: #ffc66e;
  --cream: #f4ead7;
  --cream-dim: #c8b79a;
  --brass: #d9a441;
  --brass-deep: #8a621c;
  --phos: #f2f7ff;
  --danger: #ff4d3d;
  --serif: "Cinzel", "Palatino Linotype", Georgia, serif;
  --mono: "JetBrains Mono", "Consolas", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; background: var(--ink); }

body {
  font-family: var(--mono);
  color: var(--cream);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

#app { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }

#game {
  width: 100vw; height: 100vh;
  object-fit: cover;
  display: block;
}
/* мобильные браузеры: динамическая высота — низ игрового окна не уезжает под адресную строку */
@supports (height: 100dvh) {
  #game { height: 100dvh; }
}

/* ── atmosphere ── */
#vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 40;
  background: radial-gradient(ellipse at 50% 42%, transparent 44%, rgba(2,3,5,.7) 100%);
}
/* плёночное зерно: SVG-шум тайлом (repeating-conic давал радиальный муар) */
#grain {
  position: fixed; inset: -50%; pointer-events: none; z-index: 41; opacity: .12;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.32'/%3E%3C/svg%3E");
  background-size: 160px 160px;
  /* сдвиг в px внутри тайла 160px: зерно живёт, но не «прыгает» картинкой.
     Раньше % от 200%-слоя давал рывки ±77px на 3.3 Гц — читалось как дрожь фона */
  animation: grainShift 1.8s steps(3) infinite;
}
@keyframes grainShift {
  0% { transform: translate(0,0); } 33% { transform: translate(-6px,4px); }
  66% { transform: translate(5px,-5px); } 100% { transform: translate(0,0); }
}
#flash {
  position: fixed; inset: 0; background: #fff3e0; opacity: 0;
  pointer-events: none; z-index: 60;
}

/* латунная рамка-витрина поверх всего — музейная витрина Хэтчери */
#app::after {
  content: ""; position: fixed; inset: 10px; z-index: 45; pointer-events: none;
  border: 1px solid rgba(217,164,65,.22);
  outline: 1px solid rgba(217,164,65,.07); outline-offset: 4px;
}

/* ── overlays ── */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  overflow-y: auto;
  transition: opacity .45s ease, visibility 0s;
  visibility: visible;
}
/* visibility: hidden — скрытые кнопки выпадают из tab-порядка и не ловят Enter */
.overlay.hidden { opacity: 0; pointer-events: none; visibility: hidden; transition: opacity .45s ease, visibility 0s .45s; }

/* ══ title ═ */
#screen-title {
  /* градиенты поверх официального постера Хэтчери (инкубатор с яйцом) */
  background:
    radial-gradient(ellipse at 50% 55%, rgba(5,7,10,.42) 0%, rgba(5,7,10,.86) 80%),
    linear-gradient(180deg, rgba(5,7,10,.55) 0%, rgba(5,7,10,.18) 30%, rgba(5,7,10,.28) 62%, rgba(5,7,10,.72) 100%),
    radial-gradient(ellipse at 50% 40%, #182230 0%, #05070a 80%);
}
/* постер живёт своим слоем: медленный кен-бёрнс — титул дышит, как кадр тизера.
   position: fixed (не absolute) — постер не создаёт прокручиваемого переполнения
   внутри .overlay, иначе титул «тянулся» пальцем на телефоне */
.poster {
  position: fixed; inset: -6%;
  background: url("../assets/poster.jpg") center 38% / cover no-repeat;
  animation: kenburns 46s ease-in-out infinite alternate;
  will-change: transform;
}
@keyframes kenburns {
  from { transform: scale(1) translate3d(0, 0, 0); }
  to { transform: scale(1.08) translate3d(-1.4%, -1.2%, 0); }
}
.title-block { position: relative; text-align: center; padding: 20px; animation: rise .9s ease both; max-height: 100vh; max-height: 100dvh; }
@keyframes rise { from { opacity: 0; transform: translateY(26px); } }

.over {
  font-family: var(--mono); font-size: 10px; letter-spacing: .3em;
  color: var(--brass); margin-bottom: 16px; text-transform: uppercase;
}
h1 {
  font-family: var(--serif); font-weight: 700;
  font-size: clamp(30px, 9vw, 104px); letter-spacing: .14em;
  color: var(--cream);
  text-shadow: 0 0 38px rgba(255,181,77,.4), 0 3px 0 rgba(0,0,0,.65), 0 8px 34px rgba(0,0,0,.8);
}
.sub {
  margin-top: 12px; font-size: 12.5px; letter-spacing: .2em; color: var(--cream-dim);
}
.title-dragon {
  display: block; margin: 14px auto 0; width: clamp(104px, 13vw, 140px);
  height: auto; object-fit: contain;
  filter: drop-shadow(0 14px 30px rgba(0,0,0,.65)) drop-shadow(0 0 26px rgba(255,181,77,.22));
}
/* низкие экраны (лендскейп телефона): дракон и заголовок ужимаются, ничего не обрезается */
@media (max-height: 620px) {
  .title-dragon { width: clamp(72px, 9vw, 96px); margin-top: 8px; }
  h1 { font-size: clamp(28px, 7vw, 64px); }
  .over { margin-bottom: 8px; }
  .sub { margin-top: 8px; }
  .plate { margin-top: 12px; padding: 12px 30px; }
  .hint { margin-top: 10px; }
}
.hint { margin-top: 16px; font-size: 11px; letter-spacing: .22em; color: #8f8672; }
.best-line { margin-top: 8px; font-size: 11px; letter-spacing: .22em; color: var(--amber); min-height: 15px; font-variant-numeric: tabular-nums; }

/* плашка-ссылка на вторую игру Хэтчери: стрелка уезжает при наведении */
.link-plate {
  font-size: 10.5px; letter-spacing: .24em; padding: 10px 20px; margin-top: 20px;
  font-family: var(--mono); font-weight: 700; text-decoration: none;
}
.link-plate span { display: inline-block; transition: transform .25s ease; }
.link-plate:hover span { transform: translateX(4px); }

/* ── brass plate buttons ── */
.plate {
  display: inline-block; margin-top: 18px;
  font-family: var(--serif); font-weight: 700; font-size: 16px; letter-spacing: .2em;
  color: #1c1408;
  background: linear-gradient(180deg, #f2c46d 0%, #d9a441 46%, #b47e29 78%, #8a621c 100%);
  border: 1px solid #5d4520; border-radius: 5px;
  padding: 15px 40px; cursor: pointer;
  box-shadow:
    0 2px 0 #4a3517,
    0 12px 30px rgba(0,0,0,.6),
    inset 0 1px 0 rgba(255,255,255,.55),
    inset 0 -2px 0 rgba(0,0,0,.18);
  transition: transform .08s, filter .15s, box-shadow .15s;
}
.plate:hover {
  filter: brightness(1.1);
  box-shadow:
    0 2px 0 #4a3517,
    0 14px 38px rgba(255,181,77,.3),
    inset 0 1px 0 rgba(255,255,255,.55),
    inset 0 -2px 0 rgba(0,0,0,.18);
}
.plate:active { transform: translateY(2px); box-shadow: 0 0 0 #4a3517, 0 4px 12px rgba(0,0,0,.5); }
.plate.ghost {
  background: rgba(11,10,7,.5); color: var(--brass);
  border: 1px solid rgba(217,164,65,.45); box-shadow: none;
}
.plate.ghost:hover { color: var(--amber-bright); border-color: var(--brass); }

/* ══ death plaque — «музейная» плашка по рецепту проекта ══ */
#screen-dead { background: rgba(3,4,6,.52); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.plaque {
  position: relative;
  text-align: center; min-width: min(410px, 88vw);
  max-height: 92vh; max-height: 92dvh;
  overflow-y: auto;
  background: rgba(11,10,7,.92);
  border: 1px solid rgba(217,164,65,.42); border-radius: 8px;
  padding: 32px 36px 28px;
  box-shadow: 0 40px 90px rgba(0,0,0,.8), inset 0 1px 0 rgba(255,255,255,.04);
  animation: rise .5s cubic-bezier(.2, 1.5, .4, 1) both;
}
/* уголки-«заклёпки» плашки */
.plaque::before, .plaque::after {
  content: ""; position: absolute; width: 5px; height: 5px; border-radius: 50%;
  background: var(--brass-deep); box-shadow: 0 0 4px rgba(217,164,65,.5);
}
.plaque::before { left: 8px; top: 8px; }
.plaque::after { right: 8px; top: 8px; }
.plaque-head {
  font-family: var(--serif); font-size: 14px; letter-spacing: .32em; color: var(--brass);
  border-bottom: 1px solid rgba(217,164,65,.22); padding-bottom: 15px; margin-bottom: 20px;
}
.plaque-score {
  font-family: var(--mono); font-weight: 700; font-variant-numeric: tabular-nums;
  font-size: 68px; color: var(--phos);
  text-shadow: 0 0 18px rgba(210,232,255,.55), 0 0 64px rgba(160,200,255,.28);
}
.plaque-score .unit { font-size: 22px; color: #7d8fa5; margin-left: 4px; }
.plaque-medal {
  font-family: var(--serif); font-size: 19px; letter-spacing: .28em;
  color: var(--amber-bright); margin-top: 8px;
  text-shadow: 0 0 16px rgba(255,181,77,.45);
}
.plaque-best { margin-top: 12px; font-size: 11px; letter-spacing: .2em; color: #8f8672; font-variant-numeric: tabular-nums; }
/* прогресс к следующему рангу: видимая цель на следующий заход */
.rank { margin-top: 14px; }
.rank-bar {
  height: 5px; border-radius: 3px; overflow: hidden;
  background: rgba(217,164,65,.14);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.6);
}
.rank-bar i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, #8a621c 0%, #d9a441 55%, #f2c46d 100%);
  box-shadow: 0 0 10px rgba(217,164,65,.55);
  transition: width .7s cubic-bezier(.2,.9,.3,1);
}
.rank-note { margin-top: 8px; font-size: 9.5px; letter-spacing: .2em; color: #a2906d; }
.plaque-stats { margin-top: 7px; font-size: 10px; letter-spacing: .18em; color: #6f7d8e; font-variant-numeric: tabular-nums; }
.plaque-hint {
  margin-top: 15px; font-size: 9.5px; letter-spacing: .24em; color: rgba(217,164,65,.6);
  animation: hintPulse 2.4s ease-in-out infinite;
}
@keyframes hintPulse { 0%,100% { opacity: .45 } 50% { opacity: .95 } }
.plaque-actions { display: flex; gap: 10px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }
.plaque-actions .plate { font-size: 13px; padding: 12px 22px; }

@media (max-width: 560px) {
  .plaque { padding: 24px 18px 20px; }
  .plaque-score { font-size: 54px; }
  #app::after { inset: 6px; }
  .plaque-hint { margin-top: 12px; }
}

/* лендскейпный телефон: плашка компактнее, чтобы влезала вся */
@media (orientation: landscape) and (max-height: 480px) {
  .plaque { padding: 14px 22px 12px; max-height: 94vh; max-height: 94dvh; }
  .plaque-head { padding-bottom: 8px; margin-bottom: 10px; font-size: 12px; }
  .plaque-score { font-size: 40px; }
  .plaque-medal { font-size: 15px; margin-top: 4px; }
  .plaque-best { margin-top: 7px; }
  .rank { margin-top: 8px; }
  .plaque-actions .plate { padding: 9px 16px; font-size: 12px; }
  .plaque-hint { margin-top: 8px; animation: none; opacity: .8; }
}

@media (prefers-reduced-motion: reduce) {
  #grain { animation: none; }
  .title-block, .plaque, .title-dragon, .poster, .plaque-hint { animation: none; }
  .plaque-hint { opacity: .8; }
}
