@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url("fonts/inter-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url("fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #eeeeee;
  --text: #111111;
  --muted: #666666;
  --faint: #999999;
  --line: #8a8a8a;
  --tile-border: #666666;
  --hit: #f3a683;
  --key: #aaaaaa;
  --key-text: #111111;
  --modal: #eeeeee;
  --track: #e2e2e2;
  --bar: #666666;
  --accent: #5b7cf7;
  --len: 4;
  --tile: min(58px, calc((100vw - 56px) / var(--len)));
  --key-gap: 5px;
  --key-w: min(34px, calc((100vw - 12px - 11 * var(--key-gap)) / 12));
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --text: #ececec;
    --muted: #a8a8a8;
    --faint: #8a8a8a;
    --line: #555555;
    --tile-border: #7a7a7a;
    --hit: #e0916c;
    --key: #5e5e5e;
    --key-text: #f2f2f2;
    --modal: #242424;
    --track: #303030;
    --bar: #6c6c6c;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Шапка */
.top {
  flex: none;
  text-align: center;
  padding: 18px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.top h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: -0.01em;
}
.top .poo { font-size: 0.9em; }
.sub {
  margin: 10px 0 0;
  font-size: 16px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

/* Поле */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}
#board-wrap {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 44px 16px 24px;
  scrollbar-width: thin;
}
#board {
  display: grid;
  gap: 6px;
  justify-content: center;
}
.row {
  display: grid;
  grid-template-columns: repeat(var(--len), var(--tile));
  gap: 6px;
}
.tile {
  width: var(--tile);
  height: var(--tile);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--tile-border);
  font-size: calc(var(--tile) * 0.55);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}
.tile.hit {
  background: var(--hit);
  color: #111111;
}
.row[data-word] { cursor: pointer; }
@media (hover: hover) {
  .row[data-word]:hover .tile { border-color: var(--text); }
}
.row.input .tile:empty { border-color: color-mix(in srgb, var(--tile-border) 55%, transparent); }
.row.shake { animation: shake 0.4s; }
.row.fresh .tile { animation: pop 0.18s ease-out; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}
@keyframes pop {
  from { transform: scale(0.9); }
  to { transform: scale(1); }
}

#toast {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
#toast span {
  padding: 7px 14px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  max-width: calc(100vw - 32px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

/* Клавиатура */
#keyboard {
  flex: none;
  width: 100%;
  max-width: 484px;
  margin: 0 auto;
  padding: 0 6px;
  display: grid;
  gap: 7px;
  touch-action: manipulation;
}
.krow {
  display: flex;
  justify-content: center;
  gap: var(--key-gap);
}
.key {
  flex: 0 0 var(--key-w);
  min-width: 0;
  height: 46px;
  border-radius: 4px;
  background: var(--key);
  color: var(--key-text);
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  user-select: none;
  touch-action: manipulation;
}
.key.wide {
  flex: 1 1 0;
  max-width: 62px;
  font-size: 12px;
  text-transform: none;
  font-weight: 700;
}
.key:active { filter: brightness(0.85); }
.key svg { display: block; margin: 0 auto; }

/* Ссылки внизу */
.links {
  flex: none;
  display: flex;
  justify-content: center;
  gap: clamp(14px, 6vw, 46px);
  padding: 14px 10px calc(12px + env(safe-area-inset-bottom));
}
.links button {
  color: var(--faint);
  font-size: 16px;
  white-space: nowrap;
}
.links button:hover { color: var(--text); }

/* Окна */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.5);
}
#overlay[hidden] { display: none; }
.modal {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow-y: auto;
  padding: 34px 26px 26px;
  border-radius: 12px;
  background: var(--modal);
  animation: rise 0.18s ease-out;
}
.modal.wide { max-width: 640px; }
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
.close {
  position: absolute;
  top: 6px;
  right: 10px;
  width: 36px;
  height: 36px;
  font-size: 30px;
  font-weight: 300;
  line-height: 1;
  color: var(--muted);
}
.close:hover { color: var(--text); }

.modal h2 {
  margin: 0 0 6px;
  font-size: 23px;
  font-weight: 400;
  text-align: center;
}
.modal h3 {
  margin: 18px 0 10px;
  font-size: 16px;
  font-weight: 700;
}
.modal p {
  margin: 0 0 6px;
  font-size: 16px;
  line-height: 1.45;
}
.modal .route {
  margin: 0 0 20px;
  font-size: 30px;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.01em;
}
.route small {
  font-size: 0.7em;
  font-weight: 700;
}
.link {
  color: var(--muted);
  font-size: 16px;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.link:hover { color: var(--text); }

.stats {
  display: grid;
  grid-template-columns: repeat(4, auto);
  justify-content: space-between;
  gap: 10px;
  text-align: center;
}
.stats b {
  display: block;
  font-size: 32px;
  font-weight: 300;
  line-height: 1.25;
}
.stats span {
  font-size: 13px;
  line-height: 1.25;
  display: block;
}

.dist {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
}
.dist-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
}
.dist-rows { display: grid; }
.dist-row {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  height: 22px;
  font-size: 13px;
}
.dist-row > span {
  text-align: right;
  padding-right: 6px;
}
.dist-track { height: 20px; }
.dist-row:nth-child(odd) .dist-track { background: var(--track); }
.dist-bar {
  height: 100%;
  width: max-content;
  min-width: 18px;
  padding: 0 5px;
  background: var(--bar);
  color: #ffffff;
  font-weight: 700;
  font-size: 13px;
  line-height: 20px;
}
.dist-bar.now { background: var(--accent); }

.modal .next {
  margin: 20px 0 0;
  text-align: center;
}
.next b { font-variant-numeric: tabular-nums; }

/* Как играть */
.modal .lead {
  margin: 14px 0 16px;
  color: var(--muted);
  font-style: italic;
}
.modal .goal {
  margin: 0 0 14px;
  font-size: 19px;
  font-weight: 700;
}
.example {
  width: max-content;
  margin: 14px auto 16px;
  padding: 4px;
  display: grid;
  gap: 4px;
  background: #1f1f1f;
}
.example div {
  display: grid;
  grid-template-columns: repeat(var(--len), 46px);
  gap: 4px;
}
.example i {
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #777777;
  color: #dddddd;
  font-style: normal;
  font-size: 24px;
  font-weight: 700;
}
.example i.diff {
  background: #343e55;
  border-color: #7384ad;
  box-shadow: 0 0 0 4px #343e55;
}
.play {
  display: block;
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 20px;
}
.play:hover { color: var(--text); }

/* Вчерашний ответ */
.path {
  margin: 16px auto 14px;
  display: grid;
  gap: 4px;
  justify-content: center;
}
.path .row { grid-template-columns: repeat(var(--len), 38px); gap: 4px; }
.path .tile { width: 38px; height: 38px; font-size: 20px; }
.center { text-align: center; }
.modal .muted { color: var(--muted); font-size: 14px; }

/* Значение слова */
.modal .word {
  margin-bottom: 14px;
  font-size: 28px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.defs {
  margin: 0 0 14px;
  padding-left: 22px;
  font-size: 16px;
  line-height: 1.45;
}
.defs li { margin-bottom: 8px; }
.defs li:only-child { list-style: none; margin-left: -22px; }
.modal .src {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}
.src a { color: inherit; }
.back {
  display: block;
  margin-top: 16px;
}

.noscript { text-align: center; padding: 20px; }

@media (max-width: 420px) {
  .top { padding-top: 12px; }
  .top h1 { font-size: 32px; }
  .sub { margin-top: 6px; }
  #board-wrap { padding-top: 22px; }
  :root { --key-gap: 4px; }
  #keyboard { gap: 6px; }
  .key { height: 52px; font-size: 16px; }
  .links button { font-size: 15px; }
  #toast span { font-size: 13px; }
  .modal { padding: 30px 18px 22px; }
  .modal .route { font-size: 25px; }
  .stats b { font-size: 28px; }
  .stats span { font-size: 12px; }
  .example div { grid-template-columns: repeat(var(--len), 40px); }
  .example i { height: 40px; font-size: 21px; }
}
@media (max-height: 620px) {
  .top { padding: 8px 16px 6px; }
  .top h1 { font-size: 28px; }
  .sub { margin-top: 4px; font-size: 14px; }
  #board-wrap { padding-top: 16px; padding-bottom: 12px; }
  .key { height: 42px; }
  .links { padding-top: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .row.shake, .row.fresh .tile, .modal { animation: none; }
}
