:root {
  --paper: #fdfcf6;
  --grid: rgba(96, 150, 206, 0.30);
  --ink: #1f3a9c;
  --ink-soft: rgba(31, 58, 156, 0.6);
  --red: #d42f2f;
  --font: "Marker Felt", "Segoe Print", "Comic Sans MS", "Chalkboard SE", "Arial Hebrew", "Noto Sans Hebrew", cursive;
  --hud-top: 60px;
  --hud-bottom: 84px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--paper); color: var(--ink);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }

#stage {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; display: block; cursor: crosshair;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; gap: 10px;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  pointer-events: none;
}
.hud[hidden] { display: none; }
.hud > * { pointer-events: auto; }
#hud-top {
  top: 0; height: calc(var(--hud-top) + env(safe-area-inset-top));
  padding-top: calc(8px + env(safe-area-inset-top));
  background: linear-gradient(var(--paper) 75%, rgba(253, 252, 246, 0));
}
#hud-bottom {
  bottom: 0; height: calc(var(--hud-bottom) + env(safe-area-inset-bottom));
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  justify-content: center;
  background: linear-gradient(rgba(253, 252, 246, 0), var(--paper) 25%);
}

.level-name { display: flex; flex-direction: column; line-height: 1.05; min-width: 0; flex: 1; }
.level-name span { font-size: 13px; color: var(--ink-soft); }
.level-name b {
  font-size: 20px; font-weight: normal; line-height: 1.05;
  /* длинные названия (на любом языке) переносятся на вторую строку, а не обрезаются */
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.tools { display: flex; gap: 4px; align-items: center; }
.tools canvas { width: 46px; height: 30px; }

/* ---------- кнопки «от руки» ---------- */
.pen-btn {
  font-family: var(--font); color: var(--ink); background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 255px 18px 225px 18px / 18px 225px 18px 255px;
  padding: 8px 18px; font-size: 19px; cursor: pointer;
  box-shadow: 2px 3px 0 rgba(31, 58, 156, 0.25);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  touch-action: manipulation;
}
.pen-btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 4px 0 rgba(31, 58, 156, 0.3); }
.pen-btn:active { transform: translate(1px, 2px); box-shadow: 0 0 0 rgba(31, 58, 156, 0.3); }
.pen-btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.pen-btn:focus-visible { outline: 3px dashed var(--red); outline-offset: 3px; }
.pen-btn.icon { width: 44px; height: 44px; padding: 0; font-size: 22px; flex: none; }
.site-back:not([hidden]) { display: inline-flex; align-items: center; margin-top: 18px; font-size: 18px; text-decoration: none; }
.pen-btn.big { font-size: 24px; padding: 10px 30px; min-height: 56px; }
.pen-btn.primary { border-color: var(--red); color: var(--red); box-shadow: 2px 3px 0 rgba(212, 47, 47, 0.3); }

/* ---------- меню ---------- */
.screen {
  position: absolute; inset: 0; z-index: 5; overflow-y: auto;
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent calc(100% - 46px), rgba(222, 72, 72, 0.5) calc(100% - 46px), rgba(222, 72, 72, 0.5) calc(100% - 44px), transparent calc(100% - 44px)),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 100% 100%, 22px 22px, 22px 22px;
}
.screen[hidden] { display: none; }
.menu-inner {
  max-width: 440px; margin: 0 auto; text-align: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}
h1 { font-weight: normal; font-size: 50px; line-height: 1; margin: 12px 0 2px; }
.tagline { margin: 0 0 4px; font-size: 18px; color: var(--ink-soft); }

/* переключатель языка */
.lang-switch { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.lang-switch .pen-btn { font-size: 16px; padding: 4px 12px; min-height: 36px; box-shadow: none; }
.lang-switch .pen-btn[aria-pressed="true"] { border-color: var(--red); color: var(--red); box-shadow: 2px 2px 0 rgba(212, 47, 47, 0.25); }
#menu-art { width: 320px; max-width: 100%; height: auto; display: block; margin: 0 auto; }
.lead { font-size: 18px; line-height: 1.35; margin: 4px 0 18px; }
h2 { font-weight: normal; font-size: 26px; margin: 26px 0 10px; }
.level-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.level-grid .pen-btn { padding: 8px 4px; font-size: 18px; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 84px; }
.level-grid .num { font-size: 24px; line-height: 1; }
.level-grid small { font-size: 13px; color: var(--ink-soft); line-height: 1.15; }
.level-grid .stars-mini { font-size: 15px; letter-spacing: 1px; }
.stars-mini .on, .stars .on { color: var(--red); }
.stars-mini .off, .stars .off { color: rgba(212, 47, 47, 0.2); }
.settings { display: flex; justify-content: center; gap: 24px; margin-top: 24px; font-size: 19px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--ink); }

/* ---------- окно результата ---------- */
.modal {
  position: absolute; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(253, 252, 246, 0.4);
  animation: fade 0.25s ease;
}
.modal[hidden] { display: none; }
.card {
  background: var(--paper); border: 2.5px solid var(--ink);
  border-radius: 20px 6px 24px 8px / 8px 22px 6px 20px;
  padding: 20px 20px 18px; width: min(360px, 100%); text-align: center;
  box-shadow: 4px 5px 0 rgba(31, 58, 156, 0.2);
  transform: rotate(-1deg);
}
.card h2 { margin: 0 0 6px; font-size: 32px; }
.card p { font-size: 18px; margin: 6px 0 16px; line-height: 1.3; white-space: pre-line; }
/* звёзды результата — красной ручкой */
.stars { font-size: 42px; letter-spacing: 6px; line-height: 1.1; margin: 2px 0; }
.stars[hidden] { display: none; }

/* иврит: интерфейс справа налево (игровой мир не зеркалится — он рисуется на canvas) */
[dir="rtl"] .level-name { text-align: right; }
[dir="rtl"] .card { transform: rotate(1deg); }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.row .pen-btn[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 480px) {
  .level-name b { font-size: 16px; }
  .tools canvas { width: 34px; height: 22px; }
  .tools { gap: 2px; }
}

@media (max-width: 360px) {
  .level-name b { font-size: 17px; }
  .tools canvas { width: 38px; height: 25px; }
  .pen-btn.big { font-size: 21px; padding: 8px 20px; }
}
