/* MazeRoo Play — app styles. Tokens and fonts come from /css/tokens.css,
   shared with the site; components follow the site's look (2px ink outline,
   hard sticker shadow, crayon-yellow main button, squared-paper desk). */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  height: 100%;
  font-family: var(--body);
  font-size: var(--step-0);
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--desk);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: -1px -1px;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
/* The bundled display font (Archivo Black) has Latin letters only. Other scripts
   would mix fonts inside one word ("Получилось" + "!"), so they use a bold
   system font for headings instead. */
:root { --display-weight: 400; }
html:is(:lang(ru), :lang(uk), :lang(el), :lang(ar), :lang(zh), :lang(ja), :lang(ko), :lang(pl), :lang(tr)) {
  --display: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display-weight: 800;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
svg { display: block; }

.screen {
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- shared controls ---------- */
.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--tap); height: var(--tap);
  border: 2px solid var(--ink); border-radius: 50%;
  background: var(--paper);
  transition: background-color var(--dur-ui);
}
.icon-btn:hover { background: var(--paper-hover); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#openSettings svg { stroke-width: 1.9; }
.icon-btn-q { font-family: 'Archivo Black', var(--display); font-size: var(--step-1); line-height: 1; }
.icon-btn[aria-pressed=true] { background: var(--ink); color: var(--paper); }

.btn-make {
  display: block; width: 100%;
  min-height: var(--tap-kid);
  padding: var(--s-3) var(--s-4);
  border: 2px solid var(--ink);
  border-radius: var(--r-lg);
  background: var(--crayon);
  font-family: var(--display);
  font-weight: var(--display-weight);
  font-size: var(--step-2);
  box-shadow: var(--shadow-press);
  transition: transform var(--dur-press), box-shadow var(--dur-press), background-color var(--dur-ui);
}
.btn-make:hover { background: var(--crayon-deep); }
.btn-make:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn-make.quiet { background: var(--paper); font-size: var(--step-1); min-height: 52px; }
.btn-make.quiet:hover { background: var(--paper-hover); }

.btn {
  min-height: var(--tap);
  padding: var(--s-2) var(--s-4);
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--ink); color: var(--paper);
  font-weight: 700;
}
.btn:hover { background: var(--ink-hover); }

.link-btn {
  min-height: var(--tap);
  padding: var(--s-2) var(--s-3);
  border: 0; background: none;
  font-weight: 700; text-decoration: underline; text-underline-offset: 3px;
}

/* ---------- start screen ---------- */
.start { display: flex; flex-direction: column; overflow-y: auto; }
.start-top {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-4) var(--s-4) var(--s-2);
}
.brand { display: inline-flex; align-items: center; gap: var(--s-3); }
.brand-mark { width: 40px; height: 40px; color: var(--ink); }
.brand-name { margin: 0; font-family: 'Archivo Black', 'Arial Black', sans-serif; font-weight: 400; font-size: var(--step-2); line-height: 1; letter-spacing: -0.01em; }

.start-body {
  width: 100%; max-width: 520px; margin: auto;
  display: grid; gap: var(--s-4);
  padding: var(--s-2) var(--s-4) var(--s-6);
}
.card {
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--r-xl);
  padding: var(--s-4);
  box-shadow: var(--shadow-sticker-sm);
}
[dir=rtl] .card { box-shadow: -4px 4px 0 var(--ink); }
.card-title { margin: 0 0 var(--s-3); font-family: var(--display); font-weight: var(--display-weight); font-size: var(--step-1); line-height: 1.2; }

.tiles { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--s-2); }
.tile {
  min-height: var(--tap-kid);
  display: grid; place-items: center;
  padding: var(--s-1);
  border: 2px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--paper);
  font-family: var(--display); font-weight: var(--display-weight); font-size: var(--step-1); line-height: 1.1;
  text-align: center; overflow-wrap: break-word; hyphens: auto;
  transition: border-color var(--dur-ui), background-color var(--dur-ui);
}
.tile.small-text { font-family: var(--body); font-weight: 800; font-size: var(--step--1); }
.tile[aria-checked=true] { border-color: var(--ink); background: var(--ink); color: var(--paper); }

.start-actions { display: grid; gap: var(--s-3); padding-top: var(--s-2); }

.install {
  position: relative;
  background: var(--paper);
  border: 2px dashed var(--ink);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-8) var(--s-4) var(--s-4);
}
[dir=rtl] .install { padding: var(--s-4) var(--s-4) var(--s-4) var(--s-8); }
.install-title { margin: 0 0 var(--s-1); font-size: var(--step-0); font-weight: 800; }
.install-text { margin: 0 0 var(--s-2); color: var(--ink-soft); font-size: var(--step--1); }
.install-text:last-child { margin: 0; }
.install-close {
  position: absolute; top: 2px; inset-inline-end: 2px;
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  border: 0; background: none;
}
.install-close svg { width: 18px; height: 18px; fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; }

.site-link { margin: 0; text-align: center; font-size: var(--step--1); }
.site-link a { color: var(--ink-soft); }

/* ---------- play screen ---------- */
.play { display: grid; grid-template-rows: auto 1fr; overflow: hidden; }
.bar {
  display: flex; align-items: center; gap: var(--s-2);
  min-height: 60px;
  padding: var(--s-2) var(--s-3);
}
.bar-gap { flex: 1; }
.segmented {
  display: inline-flex;
  border: 2px solid var(--ink); border-radius: var(--r-pill);
  background: var(--paper);
  padding: 2px;
}
.segmented button {
  display: inline-flex; align-items: center; gap: var(--s-1);
  min-height: 38px;
  padding: 0 var(--s-3);
  border: 0; border-radius: var(--r-pill);
  background: none;
  font-weight: 700; font-size: var(--step--1);
}
.segmented svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.segmented button[aria-checked=true] { background: var(--ink); color: var(--paper); }
@media (max-width: 400px) { .segmented span { display: none; } .segmented button { padding: 0 var(--s-2); } }

.stage { position: relative; min-height: 0; }
.stage-canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  touch-action: none;
  outline-offset: -4px;
}
.minimap {
  position: absolute; top: var(--s-2); inset-inline-end: var(--s-3);
  /* size is set by stage.js from the maze's proportions */
  border: 2px solid var(--ink); border-radius: var(--r-sm);
  background: var(--desk);
  box-shadow: var(--shadow-sticker-sm);
  cursor: zoom-out;
}
.minimap.at-bottom { top: auto; bottom: var(--s-3); }
.zoom { position: absolute; top: var(--s-2); inset-inline-end: var(--s-3); display: grid; gap: var(--s-2); }
.play-here {
  position: absolute; bottom: var(--s-3); left: 50%; transform: translateX(-50%);
  box-shadow: var(--shadow-press);
  white-space: nowrap;
}

/* phones on their side: the bar becomes a rail at the start edge */
@media (orientation: landscape) and (max-height: 520px) {
  .play { grid-template-rows: 1fr; grid-template-columns: auto 1fr; }
  .bar { flex-direction: column; min-height: 0; padding: var(--s-2); }
  .segmented { flex-direction: column; border-radius: var(--r-lg); }
  .segmented span { display: none; }
  .segmented button { padding: var(--s-2); border-radius: var(--r-md); }
}

/* ---------- sheets (dialogs) ---------- */
.sheet {
  width: min(100vw, 520px);
  max-width: none; max-height: 88dvh;
  margin: auto auto 0;
  padding: var(--s-4) var(--s-4) calc(var(--s-4) + env(safe-area-inset-bottom));
  border: 2px solid var(--ink); border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: var(--paper);
  color: var(--ink);
  overflow-y: auto;
}
.sheet[open] { animation: sheet-up var(--dur-enter) ease-out; }
.sheet::backdrop { background: var(--scrim); }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }
@media (min-width: 600px) and (min-height: 600px) {
  .sheet { margin: auto; border-bottom: 2px solid var(--ink); border-radius: var(--r-xl); box-shadow: var(--shadow-sticker); }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-3); }
.sheet-title { margin: 0; font-family: var(--display); font-weight: var(--display-weight); font-size: var(--step-2); line-height: 1.15; }

/* win */
.win { text-align: center; }
.win-question { margin: var(--s-1) 0 var(--s-4); font-weight: 700; font-size: var(--step-1); }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: var(--s-3); }
.choice {
  display: grid; justify-items: center; align-content: center; gap: var(--s-2);
  min-height: 112px;
  padding: var(--s-3) var(--s-2);
  border: 2px solid var(--ink); border-radius: var(--r-lg);
  color: #fff;
  font-weight: 800; font-size: clamp(0.95rem, 4.2vw, 1.25rem); line-height: 1.15;
  overflow-wrap: break-word; hyphens: auto;
  box-shadow: var(--shadow-press);
  transition: transform var(--dur-press), box-shadow var(--dur-press), filter var(--dur-ui);
}
.choice svg { width: 56px; height: 56px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.choice:hover { filter: brightness(1.08); }
.choice:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.choice:disabled { cursor: default; }
.choice-easier { background: var(--easier); }
.choice-same { background: var(--same); }
.choice-harder { background: var(--harder); }
.win .link-btn { margin-top: var(--s-3); }

/* settings */
.field-label { display: block; font-weight: 700; margin-bottom: var(--s-2); }
.select {
  width: 100%; min-height: 48px;
  padding: var(--s-2) var(--s-3);
  border: 2px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--paper);
  font-weight: 600;
}
.formats { border: 0; padding: 0; margin: var(--s-4) 0; display: grid; gap: var(--s-2); }
.formats legend { font-weight: 700; padding: 0; margin-bottom: var(--s-2); }
.format input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.format-face {
  display: grid; gap: 2px;
  padding-block: var(--s-3);
  padding-inline: 2.6rem var(--s-3);
  border: 2px solid var(--line-strong); border-radius: var(--r-md);
  cursor: pointer; position: relative;
}
.format-face::before {
  content: ''; position: absolute; inset-inline-start: 0.9rem; top: 50%; translate: 0 -50%;
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--line-strong); background: var(--paper);
}
.format-face span { font-size: var(--step--1); color: var(--ink-soft); }
.format input:checked + .format-face { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.format input:checked + .format-face::before { border-color: var(--ink); background: radial-gradient(var(--ink) 0 4px, var(--paper) 5px); }
.format input:focus-visible + .format-face { outline: 3px solid var(--focus); outline-offset: 2px; }

.switch { display: flex; align-items: center; gap: var(--s-3); min-height: var(--tap); font-weight: 700; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  width: 44px; height: 26px; border-radius: 13px; flex: none;
  background: var(--paper); position: relative;
  box-shadow: inset 0 0 0 2px var(--line-strong);
  transition: background-color var(--dur-ui);
}
.switch-track::after {
  content: ''; position: absolute; top: 4px; left: 4px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--line-strong);
  transition: transform var(--dur-ui), background-color var(--dur-ui);
}
.switch input:checked + .switch-track { background: var(--ink); box-shadow: none; }
.switch input:checked + .switch-track::after { background: var(--paper); transform: translateX(18px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }
.install-help { margin-top: var(--s-4); padding-top: var(--s-4); border-top: 2px solid var(--desk); }
.install-help .install-text { margin: 0 0 var(--s-2); }
.version { margin: var(--s-4) 0 0; color: var(--ink-soft); font-size: var(--step--1); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--s-4) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--s-2);
  max-width: calc(100vw - 2 * var(--s-4));
  padding: var(--s-1) var(--s-1) var(--s-1) var(--s-4);
  border: 2px solid var(--ink); border-radius: var(--r-pill);
  background: var(--ink); color: var(--paper);
  font-weight: 600;
  box-shadow: var(--shadow-press);
  z-index: 10;
}
[dir=rtl] .toast { padding: var(--s-1) var(--s-4) var(--s-1) var(--s-1); }
.toast .link-btn { color: var(--crayon); }

.noscript { padding: var(--s-6); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
