/* ---------- Токены ---------- */
:root {
  --light: #F1F7FA;
  --blue: #08B7F4;
  --dark: #020205;
  --gray: #D2D9DF;

  --blue-hover: #3CC8F8;
  --blue-press: #0599CE;
  --muted: #5A646C;
  --line: rgba(2, 2, 5, .12);

  --r-s: 10px;
  --r-m: 16px;
  --r-l: 24px;
  --shadow: 0 1px 2px rgba(2, 2, 5, .04), 0 10px 28px rgba(2, 2, 5, .07);

  --font: 'Magistral', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: var(--font);
}

/* ---------- База ---------- */
* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--dark);
  font: 400 16px/1.45 var(--font);
  background:
    radial-gradient(60rem 36rem at 90% -10%, rgba(8, 183, 244, .16), transparent 60%),
    radial-gradient(48rem 30rem at -10% 110%, rgba(210, 217, 223, .7), transparent 60%),
    var(--light);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 500; line-height: 1.1; }
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

/* ---------- Каркас ---------- */
.app {
  width: min(100vw, 760px, max(360px, 80dvh));
  height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  flex: none;
  height: 56px;
  padding: 0 14px 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, .85);
  border-radius: var(--r-m);
  box-shadow: var(--shadow);
}
.brand { height: 20px; width: auto; display: block; }

.hud { display: flex; align-items: center; gap: 8px; }
.timer {
  min-width: 64px;
  font: 500 20px/1 var(--font-head);
  font-variant-numeric: tabular-nums;
  text-align: right;
  transition: opacity .2s;
}
.timer.is-paused { opacity: .4; }

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 12px;
  background: transparent;
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--light); }

/* штриховые иконки; у иллюстраций шагов цвета заданы атрибутами */
.icon-btn svg, .tool svg, .key svg, .arrow { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.screens { flex: 1; min-height: 0; position: relative; }
.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  scrollbar-width: none;
  animation: enter .35s ease-out;
}
.screen::-webkit-scrollbar { display: none; }
@keyframes enter { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Кнопки ---------- */
.actions { display: flex; gap: 12px; flex: none; }
.actions .btn { flex: 1; }

.btn {
  min-height: 60px;
  padding: 0 24px;
  border: 0;
  border-radius: var(--r-m);
  font: 500 19px/1 var(--font);
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-primary { background: var(--blue); color: var(--dark); box-shadow: 0 6px 18px rgba(8, 183, 244, .35); }
.btn-primary:active:not(:disabled) { background: var(--blue-press); }
.btn-secondary { background: #fff; box-shadow: inset 0 0 0 2px var(--gray); }
.btn-secondary:active { background: var(--light); }
.btn:disabled { background: var(--gray); color: var(--muted); box-shadow: none; cursor: default; }

@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: var(--blue-hover); }
  .btn-secondary:hover { box-shadow: inset 0 0 0 2px var(--blue); }
  .icon-btn:hover { background: var(--light); }
}

/* ---------- Меню ---------- */
.hero { padding: 16px 4px 0; display: grid; gap: 12px; }
.hero h1 { font-size: clamp(34px, 8vw, 52px); }
.lead { max-width: 34em; color: var(--muted); font-size: 18px; }

.steps {
  list-style: none;
  margin: auto 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.step {
  position: relative;
  padding: 18px 10px 16px;
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
  background: #fff;
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
}
.step svg:not(.arrow) { width: 100%; max-width: 160px; height: auto; overflow: visible; }
.step p { font-size: clamp(13px, 2.3vw, 16px); text-wrap: balance; font-weight: 500; line-height: 1.25; }
.step-n {
  position: absolute; top: 10px; left: 10px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--dark); color: #fff;
  font: 500 14px/1 var(--font-head);
}
.arrow {
  position: absolute; z-index: 1; top: 40%; right: -23px;
  width: 28px; height: 14px;
  padding: 0;
  color: var(--blue);
  stroke-width: 2.5;
  stroke-dasharray: 5 4;
  animation: flow 1s linear infinite;
}
@keyframes flow { to { stroke-dashoffset: -9; } }

/* анимации шагов */
.float { animation: float 3s ease-in-out infinite alternate; }
@keyframes float { to { transform: translateY(-4px); } }
.ghost { animation: flow 1.4s linear infinite; }


.scanline { animation: scan-x 2.4s ease-in-out infinite alternate; opacity: .75; }
@keyframes scan-x { to { transform: translateX(84px); } }
.badge { transform-box: fill-box; transform-origin: center; animation: pop 2.4s ease-in-out infinite; }
@keyframes pop { 0%, 45% { transform: scale(0); } 60%, 100% { transform: scale(1); } }

.bar { transform-box: fill-box; transform-origin: bottom; animation: rise 3.6s ease-out infinite; }
.bar-1 { animation-delay: .5s; }
.bar-2 { animation-delay: .25s; }
@keyframes rise { 0% { transform: scaleY(0); } 30%, 85% { transform: scaleY(1); } 100% { transform: scaleY(0); } }
.star { transform-box: fill-box; transform-origin: center; animation: star 3.6s ease-out infinite; }
@keyframes star { 0%, 30% { transform: translateY(40px) scale(0); } 45%, 85% { transform: none; } 100% { transform: translateY(40px) scale(0); } }

/* ---------- Игра ---------- */
.screen-game { overflow: hidden; gap: 12px; }

.task { display: flex; align-items: center; gap: 14px; flex: none; }
.task h2 { font-size: clamp(22px, 5vw, 30px); }
.task h2 b { color: var(--blue-press); font-weight: 500; }
.hint { color: var(--muted); margin-top: 4px; }
.chip {
  flex: none;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--dark); color: #fff;
  font: 500 22px/1 var(--font-head);
  font-variant-numeric: tabular-nums;
}

.progress { flex: none; display: flex; gap: 6px; }
.progress i { flex: 1; height: 6px; border-radius: 3px; background: var(--gray); transition: background .3s; }
.progress i.is-done { background: var(--blue); }
.progress i.is-current { background: var(--dark); }

.stage {
  flex: 1;
  min-height: 200px;
  display: grid;
  place-items: center;
  container-type: size;
}

.board {
  --bg: var(--light);
  position: relative;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  overflow: hidden;
  background: var(--bg);
  border-radius: var(--r-l);
  box-shadow: var(--shadow), inset 0 0 0 2px var(--line);
  transition: background .3s;
}
.board canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;
  cursor: crosshair;
}
.board.is-shaking { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* сканирование */
.scan {
  position: absolute; inset: 0;
  display: grid; place-items: end center;
  padding-bottom: 5%;
  animation: grid-in .4s ease-out;
}
@keyframes grid-in { from { opacity: 0; } }
.scan::after {
  content: '';
  position: absolute; inset: 0;
  background:
    linear-gradient(rgba(255, 255, 255, .3) 1px, transparent 1px) 0 0 / 8.333% 8.333%,
    linear-gradient(90deg, rgba(255, 255, 255, .3) 1px, transparent 1px) 0 0 / 8.333% 8.333%;
  mix-blend-mode: difference;
}
.scan::before {
  content: '';
  position: absolute; left: 0; right: 0; top: -24%;
  height: 24%;
  background: linear-gradient(transparent, rgba(8, 183, 244, .55));
  border-bottom: 3px solid var(--blue);
  box-shadow: 0 8px 24px rgba(8, 183, 244, .7);
  animation: scan-y 2s cubic-bezier(.45, 0, .55, 1) forwards;
}
@keyframes scan-y { 50% { top: 100%; } to { top: -24%; } }
.scan span {
  position: relative; z-index: 1;
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--dark); color: #fff;
  font-weight: 500;
}
.scan span::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* результат проверки */
.review { --side: min(47cqw, calc(100cqh - 38px - 110px)); display: grid; gap: 16px; justify-items: center; width: 100%; }
.compare {
  display: grid;
  grid-template-columns: repeat(2, var(--side));
  gap: 3cqw;
  justify-content: center;
}
.compare figure { margin: 0; display: grid; gap: 8px; }
.frame {
  aspect-ratio: 1;
  background: var(--bg, var(--light));
  border-radius: var(--r-l);
  box-shadow: var(--shadow), inset 0 0 0 2px var(--line);
  overflow: hidden;
}
.frame img { width: 100%; height: 100%; display: block; object-fit: contain; }
.compare figure:last-child .frame img { padding: 8%; animation: wipe .9s .15s cubic-bezier(.6, 0, .2, 1) backwards; }
@keyframes wipe { from { clip-path: inset(0 100% 0 0); } }
figcaption { text-align: center; color: var(--muted); font-weight: 500; }

/* панель под холстом */
.dock { flex: none; display: grid; gap: 12px; }

.tools { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.group {
  display: flex; align-items: center; gap: 8px;
  padding: 6px;
  background: #fff;
  border-radius: var(--r-m);
  box-shadow: var(--shadow);
}
.tool, .swatch {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  padding: 0;
  border: 0; border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: transform .1s, background .15s, box-shadow .15s;
}
.tool svg { width: 24px; height: 24px; }
.tool:active:not(:disabled) { background: var(--gray); }
.tool[aria-pressed="true"] { background: var(--dark); color: #fff; }
.tool:disabled { opacity: .3; cursor: default; }
.tool i { width: var(--d); height: var(--d); border-radius: 50%; background: currentColor; }

.swatch { background: var(--c); box-shadow: inset 0 0 0 2px var(--line); }
.swatch[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--line), 0 0 0 3px #fff, 0 0 0 6px var(--dark); transform: scale(.92); }
.group:has(.swatch) { gap: 12px; padding: 8px 12px; }

.verdict {
  width: calc(var(--side) * 2 + 3cqw);
  display: flex; align-items: center; gap: 18px;
  padding: 14px 20px;
  background: #fff;
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
}
.pct { font: 500 52px/1 var(--font-head); font-variant-numeric: tabular-nums; min-width: 3.2ch; }
.verdict-body { flex: 1; display: grid; gap: 10px; font: 500 20px/1.2 var(--font-head); }
.meter { height: 10px; border-radius: 5px; background: var(--gray); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; border-radius: 5px; background: var(--blue); transition: width .9s cubic-bezier(.2, .7, .2, 1); }

/* ---------- Итоги ---------- */
.screen-result { gap: 14px; padding-bottom: 4px; }
.screen-result h2, .board-head h2 { font-size: clamp(30px, 7vw, 40px); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; flex: none; }
.stat { padding: 14px 18px; display: grid; gap: 4px; background: #fff; border-radius: var(--r-m); box-shadow: var(--shadow); }
.stat span { color: var(--muted); }
.stat strong { font: 500 clamp(32px, 7vw, 44px)/1 var(--font-head); font-variant-numeric: tabular-nums; }
.stat:first-child strong { color: var(--blue-press); }

.gallery {
  list-style: none; margin: 0; padding: 0; flex: none;
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
}
.thumb { display: grid; gap: 4px; text-align: center; font-size: 13px; }
.thumb .frame { position: relative; border-radius: 12px; box-shadow: inset 0 0 0 2px var(--line); }
.thumb b {
  position: absolute; right: 4px; bottom: 4px;
  padding: 2px 6px; border-radius: 6px;
  background: var(--dark); color: #fff;
  font: 500 12px/1.3 var(--font-head);
}
.thumb span { color: var(--muted); }

.name-block { flex: none; display: grid; gap: 6px; }
.label { color: var(--muted); font-weight: 500; }
.name-field {
  min-height: 60px;
  padding: 0 18px;
  display: flex; align-items: center;
  background: #fff;
  border-radius: var(--r-m);
  box-shadow: inset 0 0 0 2px var(--blue);
  font: 500 26px/1 var(--font-head);
  white-space: nowrap; overflow: hidden;
}
.caret { width: 2px; height: 1.2em; margin-left: 2px; background: var(--blue); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.placeholder { margin-left: -2px; color: #99A3AB; font-weight: 500; }
.name-field:not(:has(#name-text:empty)) .placeholder { display: none; }

.keyboard {
  flex: none;
  display: grid; gap: 6px;
  padding: 8px;
  background: #fff;
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
}
.kb-row { display: flex; justify-content: center; gap: 6px; }
.key {
  flex: 1 1 0; max-width: 64px;
  min-height: 52px;
  padding: 0;
  border: 0; border-radius: var(--r-s);
  background: var(--light);
  box-shadow: 0 2px 0 var(--gray);
  font: 500 21px/1 var(--font);
  cursor: pointer;
}
.key:active { background: var(--blue); transform: translateY(1px); box-shadow: none; }
.key-wide { flex: 1.5 1 0; max-width: none; font-size: 16px; font-weight: 500; background: var(--gray); box-shadow: none; }
.key-space { flex: 5 1 0; max-width: none; background: var(--light); box-shadow: 0 2px 0 var(--gray); }
.key[aria-pressed="true"] { background: var(--dark); color: #fff; }
.key svg { width: 22px; height: 22px; }

/* ---------- Лидерборд ---------- */
.board-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex: none; padding: 4px 4px 0; }
.board-head .muted { margin-top: 6px; }
.muted { color: var(--muted); }

.rows { flex: 1; min-height: 0; margin: 0; padding: 0 0 2px; list-style: none; display: grid; align-content: start; gap: 8px; overflow-y: auto; scrollbar-width: none; }
.rows::-webkit-scrollbar { display: none; }
.row {
  display: grid; grid-template-columns: 44px 1fr auto auto; align-items: center; gap: 14px;
  padding: 10px 18px 10px 10px;
  background: #fff;
  border-radius: var(--r-m);
  box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums;
}
.row .place {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 12px; background: var(--light);
  font: 500 20px/1 var(--font-head);
}
.row:nth-child(1) .place { background: var(--blue); }
.row:nth-child(2) .place { background: var(--dark); color: #fff; }
.row:nth-child(3) .place { background: var(--gray); }
.row .name { font: 500 20px/1.2 var(--font-head); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .score { font: 500 22px/1 var(--font-head); }
.row .time { min-width: 3.6em; text-align: right; color: var(--muted); }
.row.is-me { box-shadow: inset 0 0 0 3px var(--blue), var(--shadow); }
.rows .gap { text-align: center; color: var(--muted); line-height: .6; }

.empty { margin: auto; padding: 24px; text-align: center; color: var(--muted); font-size: 18px; }
.note { flex: none; font-size: 14px; }

/* ---------- Диалог и тост ---------- */
.btn-small { min-height: 44px; padding: 0 16px; font-size: 16px; background: #fff; box-shadow: inset 0 0 0 2px var(--gray); color: var(--muted); }
.btn-small:active { background: var(--light); }
.input {
  width: 100%; min-height: 56px; padding: 0 16px;
  border: 0; border-radius: var(--r-m);
  background: var(--light); box-shadow: inset 0 0 0 2px var(--gray);
  font: 500 20px/1 var(--font);
  -webkit-user-select: text; user-select: text;
}
.input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--blue); }
.error { color: #C4321A; font-weight: 500; margin: 0 0 6px; }
.dialog-body, .dialog form { display: grid; gap: 10px; align-content: start; }

.dialog {
  width: min(92vw, 420px);
  padding: 24px;
  border: 0; border-radius: var(--r-l);
  box-shadow: 0 20px 60px rgba(2, 2, 5, .3);
  color: var(--dark);
}
.dialog::backdrop { background: rgba(2, 2, 5, .45); }
.dialog p { color: var(--muted); margin-bottom: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 10;
  max-width: 90vw;
  padding: 12px 20px;
  transform: translateX(-50%);
  border-radius: var(--r-m);
  background: var(--dark); color: #fff;
  font-weight: 500;
  animation: enter .25s ease-out;
}

/* ---------- Адаптив ---------- */
@media (max-width: 560px) {
  .steps { grid-template-columns: 1fr 1fr; }
  .step:nth-child(2) .arrow { display: none; }
  .gallery { grid-template-columns: repeat(4, 1fr); }
  .btn { min-height: 56px; }
  .row { grid-template-columns: 40px 1fr auto; }
  .row .time { display: none; }
}

@media (max-height: 760px) {
  .steps { margin: 0; }
  .step svg:not(.arrow) { max-width: 84px; }
  .key { min-height: 46px; }
}

/* Высокие экраны (планшет/телефон вертикально): шаги — вертикальный список, пустого места нет */
@media (orientation: portrait) and (min-height: 1000px) {
  .hero { padding-top: 20px; gap: 14px; }
  .hero h1 { font-size: clamp(40px, 9vw, 60px); }
  .lead { font-size: 21px; }
  .steps { --ill: clamp(80px, 10vh, 140px); grid-template-columns: 1fr; gap: 28px; margin: auto 0; }
  .step { grid-template-columns: calc(var(--ill) * 1.25) 1fr; justify-items: start; align-items: center; gap: 28px; padding: 16px 28px 16px 20px; text-align: left; }
  .step svg:not(.arrow) { width: calc(var(--ill) * 1.25); height: var(--ill); max-width: none; }
  .step p { font-size: clamp(20px, 3.2vw, 28px); }
  .step-n { top: 10px; left: 10px; }
  .arrow { top: calc(100% + 3px); right: auto; left: calc(20px + var(--ill) * .625); transform: translateX(-50%) rotate(90deg); }
  .step:nth-child(2) .arrow { display: block; }
}

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