/* Оформление интерфейса поверх канваса. Стиль тот же — «нарисовано ручкой в тетради». */

:root {
  --paper: #fbf7ec;
  --ink: #3b3227;
  --green: #7dc94f;
  --green-dark: #47862a;
  --shadow: rgba(59, 50, 39, 0.85);
  --font: 'Chalkboard SE', 'Comic Sans MS', 'Marker Felt', 'Segoe Print', cursive;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  /* игра занимает весь экран: ни прокрутки, ни «потянуть чтобы обновить», ни зума по двойному тапу */
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#safe-probe {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: env(safe-area-inset-top, 0px);
  pointer-events: none;
  opacity: 0;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ─── кнопка паузы ────────────────────────────────────────────────────────── */
.corner-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  right: calc(env(safe-area-inset-right, 0px) + 12px);
  width: 44px;
  height: 44px;
  display: none;
  align-items: center;
  justify-content: center;
  font: 700 18px/1 var(--font);
  letter-spacing: 1px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  border: 2.5px solid var(--ink);
  border-radius: 60% 40% 55% 45% / 45% 55% 45% 55%;
  cursor: pointer;
}
body[data-phase='play'] .corner-btn {
  display: flex;
}

/* ─── экраны ──────────────────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 20px calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: rgba(251, 247, 236, 0.82);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  overflow-y: auto;
}
.screen.is-open {
  opacity: 1;
  pointer-events: auto;
}

.panel {
  width: min(360px, 100%);
  padding: 26px 22px;
  text-align: center;
  background: #fffdf6;
  border: 3px solid var(--ink);
  /* классический приём «неровная рамка от руки» на разных радиусах углов */
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  box-shadow: 5px 6px 0 var(--shadow);
}

.title {
  font-size: 44px;
  line-height: 1.05;
  letter-spacing: -1px;
  transform: rotate(-2deg);
}
.title.small {
  font-size: 32px;
}

.subtitle {
  margin-top: 6px;
  font-size: 15px;
  opacity: 0.6;
}

.best {
  margin: 16px 0 18px;
  font-size: 16px;
  opacity: 0.75;
}

.score-big {
  margin: 10px 0 4px;
  font-size: 62px;
  font-weight: 700;
  line-height: 1;
}

.record {
  margin-top: 10px;
  font-size: 18px;
  color: var(--green-dark);
  animation: pop 0.45s ease;
}
@keyframes pop {
  0% {
    transform: scale(0.5) rotate(-8deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.15) rotate(3deg);
  }
  100% {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

/* ─── кнопки ──────────────────────────────────────────────────────────────── */
.btn {
  display: block;
  width: 100%;
  margin: 10px 0 0;
  padding: 14px 18px;
  font: 700 20px/1.2 var(--font);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 200px 12px 180px 14px / 14px 180px 12px 200px;
  box-shadow: 3px 4px 0 var(--shadow);
  cursor: pointer;
  transition:
    transform 0.06s ease,
    box-shadow 0.06s ease;
}
.btn:active {
  transform: translate(3px, 4px);
  box-shadow: 0 0 0 var(--shadow);
}

.btn-primary {
  margin-top: 4px;
  font-size: 24px;
  color: #1f3d10;
  background: var(--green);
}

.btn-small {
  font-size: 15px;
  padding: 10px 12px;
}

.btn-ghost {
  background: transparent;
  box-shadow: 2px 3px 0 rgba(59, 50, 39, 0.5);
}

.row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}
.row .btn {
  margin-top: 0;
}

.note {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.4;
  opacity: 0.7;
}

/* ─── «как играть» ────────────────────────────────────────────────────────── */
.how {
  margin-top: 18px;
  text-align: left;
  font-size: 14px;
}
.how summary {
  cursor: pointer;
  text-align: center;
  opacity: 0.65;
  padding: 6px;
}
.how ul {
  margin: 8px 0 0 18px;
  line-height: 1.55;
  opacity: 0.85;
}
.how li {
  margin-bottom: 4px;
}

/* На низких экранах в горизонтальной ориентации панель не должна распирать вьюпорт */
@media (max-height: 520px) {
  .title {
    font-size: 32px;
  }
  .panel {
    padding: 16px;
  }
  .how {
    display: none;
  }
}
