/* Кроссворд «о нас». Цвета взяты с фотографии: река (фон), рубашка и здания (клетки), платье (акцент). */

@font-face {
  font-family: "Playfair Display";
  src: url("fonts/playfair-display-cyrillic-wght-normal.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Playfair Display";
  src: url("fonts/playfair-display-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122;
}
@font-face {
  font-family: "Inter";
  src: url("fonts/inter-cyrillic-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  src: url("fonts/inter-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122;
}

:root {
  --ink: #0b1626;          /* вода на фото */
  --ink-2: #13223a;
  --ink-3: #1d3050;
  --cream: #f5efe4;        /* рубашка, здания */
  --cream-dim: #c9c1b3;
  --red: #c8282e;          /* платье */
  --red-soft: #f3c9c1;
  --key: #24375a;
  --key-down: #3a5182;

  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --fast: 140ms;
  --base: 240ms;
  --slow: 600ms;

  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--ink);
  color: var(--cream);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--cream); outline-offset: 2px; }
svg { display: block; }

main {
  position: relative;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--slow) var(--ease-out), visibility 0s linear var(--slow);
}
.screen.is-active {
  visibility: visible;
  opacity: 1;
  transition: opacity var(--slow) var(--ease-out), visibility 0s;
}

/* ── Кнопки ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 0 28px;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  transition: transform var(--fast) var(--ease-out), background-color var(--base) var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--cream); color: var(--ink); }
.btn-primary:hover { background: #fff; }
.btn-ghost { color: var(--cream); background: rgba(245, 239, 228, 0.12); }
.btn-ghost:hover { background: rgba(245, 239, 228, 0.2); }

/* ── Заставка ───────────────────────────── */
.intro { display: flex; flex-direction: column; justify-content: space-between; }
.intro-photo {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: 50% 40%;
  transform: scale(1.08);
  animation: drift 14s var(--ease-out) forwards;
}
/* Нейтральные затемнения под текстом — единственное место с переходом цвета. */
.intro::before, .intro::after {
  content: ""; position: absolute; left: 0; right: 0; pointer-events: none; z-index: 1;
}
.intro::before { top: 0; height: 42%; /* taste-skill-ignore: нейтральный скрим под текстом на фото */ background: linear-gradient(rgba(6, 14, 28, 0.62), rgba(6, 14, 28, 0)); }
.intro::after { bottom: 0; height: 46%; /* taste-skill-ignore: скрим */ background: linear-gradient(rgba(6, 14, 28, 0), rgba(6, 14, 28, 0.82)); }

.intro-top, .intro-bottom { position: relative; z-index: 2; padding: 0 24px; }
.intro-top { padding-top: calc(var(--safe-t) + 56px); }
.intro-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(52px, 16vw, 76px);
  line-height: 0.95;
  letter-spacing: -0.03em;
}
.intro-sub { margin-top: 14px; font-size: 18px; line-height: 1.4; max-width: 18em; color: var(--cream); }
.intro-bottom { padding-bottom: calc(var(--safe-b) + 28px); display: flex; flex-direction: column; gap: 18px; }
.intro-lead { font-size: 18px; line-height: 1.45; max-width: 20em; }
.intro-bottom .btn { width: 100%; }
.intro-note { font-size: 14px; color: var(--cream-dim); text-align: center; }

.intro .rise { opacity: 0; transform: translateY(24px); animation: rise 900ms var(--ease-out) forwards; }

/* ── Игра ───────────────────────────────── */
.play { display: flex; flex-direction: column; }
.play-bg { position: absolute; inset: 0; overflow: hidden; }
.play-bg img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.15); }
.play-bg::after { content: ""; position: absolute; inset: 0; background: rgba(8, 17, 32, 0.6); }

.bar {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-t) + 10px) var(--pad) 6px;
}
.bar-title { font-family: var(--serif); font-size: 22px; font-weight: 500; letter-spacing: -0.02em; flex: 1; }
.bar-progress { font-size: 15px; font-variant-numeric: tabular-nums; color: var(--cream-dim); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 999px;
  display: grid; place-items: center;
  background: rgba(245, 239, 228, 0.1);
  transition: transform var(--fast) var(--ease-out), background-color var(--base);
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--cream); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn .i-speaker { fill: var(--cream); }
.icon-btn .i-off { display: none; }
.icon-btn[aria-pressed="false"] .i-wave { display: none; }
.icon-btn[aria-pressed="false"] .i-off { display: block; }

.board-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px var(--pad);
}
.board {
  --cell: 30px;
  --gap: 3px;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: var(--gap);
}
.cell {
  position: relative;
  display: grid; place-items: center;
  border-radius: calc(var(--cell) * 0.16);
  background: var(--cream);
  color: var(--ink);
  font-weight: 650;
  font-size: calc(var(--cell) * 0.56);
  line-height: 1;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  transition: background-color var(--base) var(--ease-out), transform var(--base) var(--ease-out);
  opacity: 0;
  transform: scale(0.6);
}
.board.is-in .cell { opacity: 1; transform: scale(1); transition-delay: var(--d, 0ms); transition-property: opacity, transform, background-color; transition-duration: 520ms, 520ms, var(--base); }
.board.is-settled .cell { transition-delay: 0ms; }
.cell.is-spine { color: var(--red); }
/* Клетки главного слова помечены красной полоской снизу */
.cell.is-spine::after {
  content: ""; position: absolute; left: 18%; right: 18%; bottom: 12%;
  height: max(2px, calc(var(--cell) * 0.08)); border-radius: 2px;
  background: var(--red); opacity: 0.85;
}
.cell.is-spine.is-solved::after { background: var(--cream); opacity: 0.6; }
.cell.in-word { background: var(--red-soft); }
.cell.is-cursor { background: var(--cream); outline: 2.5px solid var(--red); outline-offset: -2.5px; }
.cell.is-solved { background: var(--cream); color: var(--ink); }
.cell.is-spine.is-solved { background: var(--red); color: var(--cream); }
.cell .num {
  position: absolute; top: 2px; left: 3px;
  font-size: max(8px, calc(var(--cell) * 0.24));
  font-weight: 600;
  color: rgba(11, 22, 38, 0.55);
  pointer-events: none;
}
.cell.is-spine.is-solved .num { color: rgba(245, 239, 228, 0.7); }
.cell .ch { display: block; }
.cell .ch.pop { animation: pop 200ms var(--ease-out); }
.cell.wave { animation: wave 520ms var(--ease-out) both; animation-delay: var(--w, 0ms); }
.cell.shake { animation: shake 360ms var(--ease-in-out); }
.cell.is-wrong { color: var(--red); }

/* Подсказка */
.clue {
  position: relative;
  display: flex; align-items: stretch; gap: 4px;
  margin: 4px var(--pad) 10px;
  min-height: 92px;
  border-radius: 18px;
  background: var(--ink-2);
}
.clue-nav {
  width: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 18px;
  transition: background-color var(--base), transform var(--fast) var(--ease-out);
}
.clue-nav:active { transform: scale(0.9); background: var(--ink-3); }
.clue-nav svg { width: 22px; height: 22px; fill: none; stroke: var(--cream); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.clue-body { flex: 1; min-width: 0; padding: 12px 0; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.clue-meta { font-size: 14px; color: var(--cream-dim); display: flex; gap: 10px; align-items: baseline; }
.clue-meta .hint-btn { margin-left: auto; font-size: 14px; color: var(--cream); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(245, 239, 228, 0.4); padding: 4px 0; }
.clue-text { font-size: 17px; line-height: 1.35; font-weight: 500; }
.clue-body.swap { animation: swap 280ms var(--ease-out); }
.clue.is-spine { background: #5a1418; }

/* Клавиатура */
.keys {
  position: relative;
  background: var(--ink);
  padding-top: 10px !important;
  display: flex; flex-direction: column; gap: 7px;
  padding: 2px 4px calc(var(--safe-b) + 8px);
}
.key-row { display: flex; gap: 5px; justify-content: center; }
.key {
  flex: 1 1 0;
  max-width: 40px;
  height: 46px;
  border-radius: 8px;
  background: var(--key);
  color: var(--cream);
  font-size: 19px;
  font-weight: 500;
  transition: transform 90ms var(--ease-out), background-color 90ms;
}
.key:active, .key.is-down { transform: scale(0.9); background: var(--key-down); }
.key-wide { max-width: 64px; flex-grow: 1.6; display: grid; place-items: center; }
.key-wide svg { width: 24px; height: 24px; fill: none; stroke: var(--cream); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }

/* ── Финал ──────────────────────────────── */
.finale { display: flex; flex-direction: column; justify-content: flex-end; }
.finale-photo {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: 50% 40%;
  transform: scale(1.12);
  filter: blur(14px) brightness(0.7);
  transition: transform 3.5s var(--ease-out), filter 1.6s var(--ease-out);
}
.finale.is-active .finale-photo { transform: scale(1); filter: none; }
.finale::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 62%;
  background: linear-gradient(rgba(6, 14, 28, 0), rgba(6, 14, 28, 0.88) 55%); /* taste-skill-ignore: скрим под текстом финала */
  pointer-events: none;
}
.hearts { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.finale-body { position: relative; z-index: 3; padding: 0 24px calc(var(--safe-b) + 28px); }
.finale-word {
  display: flex; gap: 2px;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(54px, 17vw, 84px);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--cream);
}
.finale-word span { display: inline-block; opacity: 0; transform: translateY(40px) scale(0.8); }
.finale.is-playing .finale-word span { animation: letter 900ms var(--ease-out) forwards; animation-delay: var(--d); }
.finale-title { margin-top: 18px; font-family: var(--serif); font-weight: 500; font-size: 30px; line-height: 1.1; letter-spacing: -0.02em; }
.finale-text { margin-top: 10px; font-size: 17px; line-height: 1.5; max-width: 22em; }
.finale-actions { margin-top: 26px; display: flex; flex-direction: column; gap: 10px; }
.finale .later { opacity: 0; transform: translateY(18px); }
.finale.is-playing .later { animation: rise 800ms var(--ease-out) forwards; animation-delay: var(--d); }

/* ── Движения ───────────────────────────── */
@keyframes drift { to { transform: scale(1); } }
@keyframes rise { to { opacity: 1; transform: none; } }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes wave {
  0% { transform: none; }
  40% { transform: translateY(-6px) scale(1.12); }
  100% { transform: none; }
}
@keyframes shake {
  0%, 100% { transform: none; }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}
@keyframes swap { from { opacity: 0; transform: translateX(var(--from, 12px)); } to { opacity: 1; transform: none; } }
@keyframes letter { to { opacity: 1; transform: none; } }

.board.is-out .cell {
  opacity: 0; transform: scale(0.4) translateY(-10px);
  transition: opacity 420ms var(--ease-in-out), transform 420ms var(--ease-in-out);
  transition-delay: var(--d, 0ms);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; transition-duration: 1ms !important; transition-delay: 0ms !important; }
}

/* Невысокие телефоны (iPhone SE): ужимаем подсказку и клавиши */
@media (max-height: 700px) {
  .key { height: 40px; font-size: 17px; }
  .keys { gap: 6px; }
  .clue { min-height: 76px; margin-bottom: 8px; }
  .clue-text { font-size: 16px; }
  .intro-top { padding-top: calc(var(--safe-t) + 32px); }
}
