/* Каляки-маляки — оригинальная браузерная игра MargoStory.com. © 2026 MargoStory.com */
:root {
  --paper: #1c1433;
  --grid: rgba(160, 140, 255, 0.08);
  --ink: #f1e9ff;
  --ink-soft: rgba(225, 212, 255, 0.68);
  --red: #ff8a2a;
  --font: "Marker Felt", "Segoe Print", "Comic Sans MS", "Chalkboard SE", "Arial Hebrew", "Noto Sans Hebrew", cursive;
  --hud-top: 60px;
  --hud-bottom: 84px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #120c22; 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(rgba(14, 9, 28, 0.92) 70%, rgba(14, 9, 28, 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(14, 9, 28, 0), rgba(14, 9, 28, 0.9) 30%);
}

.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(0, 0, 0, 0.45);
  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(255, 140, 40, 0.35); }
.pen-btn:active { transform: translate(1px, 2px); box-shadow: 0 0 0 rgba(255, 140, 40, 0.35); }
.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; }
/* ссылка «Все игры MargoStory» (видна только на сайте MargoStory) */
.site-back:not([hidden]) { display: inline-flex; align-items: center; margin-top: 18px; font-size: 18px; text-decoration: none; }
/* подпись MargoStory внизу меню: мелко и не мешает игре */
.credits { margin-top: 28px; font-size: 15px; line-height: 1.4; color: var(--ink-soft); }
.credits p { margin: 4px 0; }
.credits summary { cursor: pointer; display: inline-block; }
.credits details p { max-width: 34em; margin: 6px auto; }
.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(255, 138, 42, 0.3); }

/* ---------- меню ---------- */
.screen {
  position: absolute; inset: 0; z-index: 5; overflow-y: auto;
  /* Spooky: ночное небо с луной и холмами вместо тетрадного листа */
  background-color: #120c22;
  background-image:
    radial-gradient(circle at 90% 7%, rgba(255, 236, 190, 0.9) 0 26px, rgba(255, 236, 190, 0.18) 28px, rgba(255, 236, 190, 0) 120px),
    radial-gradient(ellipse 70% 22% at 25% 104%, #18112c 0 98%, transparent 100%),
    radial-gradient(ellipse 80% 26% at 85% 108%, #1d1535 0 98%, transparent 100%),
    linear-gradient(#0b0820, #1f1642 60%, #2e1c3c);
}
.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));
}
.game-title { 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(255, 138, 42, 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(255, 138, 42, 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(8, 5, 18, 0.55);
  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(0, 0, 0, 0.4);
  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; }
}

/* ---------- кнопка «Уровни» в меню ---------- */
.menu-levels { display: flex; justify-content: center; align-items: center; gap: 10px; flex-wrap: wrap; margin: 16px 0 0; }
#btn-levels-menu { display: inline-flex; align-items: center; gap: 8px; font-size: 19px; padding: 6px 16px; }
.menu-progress { font-size: 16px; color: var(--ink-soft); }
#btn-levels svg { display: block; margin: auto; }

/* ---------- окно выбора уровня ---------- */
.levels-modal { background: rgba(8, 5, 18, 0.75); }
.levels-card {
  width: min(520px, 100%); max-height: calc(100% - 24px);
  display: flex; flex-direction: column; padding: 14px 14px 12px; text-align: start;
}
.levels-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.levels-head h2 { margin: 0; font-size: 26px; }
.levels-progress { margin: 6px 0 10px; font-size: 15px; color: var(--ink-soft); }
/* список прокручивается внутри окна; ячейки маленькие, чтобы и 300 уровней помещались удобно */
.level-grid.levels-list {
  position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 7px;
  padding: 4px 4px 6px;
}
.level-grid.levels-list .pen-btn.lvl {
  min-height: 54px; padding: 4px 2px; font-size: 16px; gap: 0; box-shadow: 1px 2px 0 rgba(0, 0, 0, 0.4);
}
.level-grid.levels-list .num { font-size: 21px; }
.level-grid.levels-list .stars-mini { font-size: 11px; letter-spacing: 0; }
.level-grid.levels-list .lvl.locked { opacity: 0.45; }
.level-grid.levels-list .lvl.locked small { font-size: 12px; }
.level-grid.levels-list .lvl.current { border-color: var(--red); color: var(--red); }

/* ---------- обучение (уровни 1–5) ---------- */
.tut {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 4;
  width: max-content; max-width: min(92%, 420px); padding: 8px 16px 9px; text-align: center;
  background: var(--paper); border: 2.5px solid var(--ink);
  border-radius: 18px 6px 20px 8px / 8px 18px 6px 20px; box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.4);
  pointer-events: none;                 /* окно не мешает распилам и касаниям */
  animation: tutIn 0.25s ease;
}
.tut[hidden] { display: none; }
.tut.top { top: calc(var(--hud-top) + env(safe-area-inset-top) + 8px); }
.tut.bottom { bottom: calc(var(--hud-bottom) + env(safe-area-inset-bottom) + 6px); }
.tut p { margin: 0; }
.tut-title { font-size: 15px; color: var(--red); margin-bottom: 2px !important; }
.tut-text { font-size: 19px; line-height: 1.25; color: var(--ink); }
.tut-skip {
  pointer-events: auto; margin-top: 4px; padding: 2px 6px; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--ink-soft); text-decoration: underline;
}
.tut-skip[hidden] { display: none; }
@keyframes tutIn { from { opacity: 0; } to { opacity: 1; } }

/* подсветка нужной кнопки (значки пил, «Вперёд!») */
.tut-glow { border-radius: 12px; animation: tutGlow 1.2s ease-in-out infinite; }
@keyframes tutGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 138, 42, 0.55); }
  50% { box-shadow: 0 0 0 9px rgba(255, 138, 42, 0); }
}
/* «пила в руке»: значки пил коротко подпрыгивают после нажатия */
.tools.tut-picked canvas { animation: tutPick 0.45s ease; }
@keyframes tutPick { 40% { transform: translateY(-6px) rotate(-8deg); } }

/* кнопка «Подсказка» слева от «Вперёд!» (в иврите — справа) */
.hint-btn { position: absolute; inset-inline-start: max(12px, env(safe-area-inset-left)); bottom: calc(18px + env(safe-area-inset-bottom)); font-size: 22px; }
.hint-btn[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .tut { animation: none; }
  .tut-glow { animation: none; box-shadow: 0 0 0 4px rgba(255, 138, 42, 0.45); }
  .tools.tut-picked canvas { animation: none; }
}
/* значки пил: увеличенная невидимая область нажатия (для пальца), раскладка не меняется */
#hud-top .tools { padding: 11px 6px; margin: -11px -6px; border-radius: 12px; cursor: pointer; }

/* ---------- Spooky Escape: тёмная тема ---------- */
.pen-btn { border-color: rgba(255, 166, 61, 0.85); }
.pen-btn:hover { background: #271c45; }
.pen-btn.primary, .pen-btn.big { color: #ffa63d; border-color: #ffa63d; text-shadow: 0 0 10px rgba(255, 138, 42, 0.45); }
.game-title { color: #ffa63d; text-shadow: 0 0 18px rgba(255, 138, 42, 0.55), 0 2px 0 #3b1606; letter-spacing: 1px; }
.card { background: #1f1638; border-color: rgba(255, 166, 61, 0.8); }
.level-name b { color: #ffa63d; }
.tools canvas { filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.35)); }
.tut { background: #1f1638; border-color: #ffa63d; }
.credits a { color: #ffa63d; }
