html, body {
  margin: 0;
  height: 100%;
  background: #2a1a14;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Ramka z marginesem na wycięcia ekranu (notch) w telefonach */
#frame {
  position: fixed;
  inset: 0;
  box-sizing: border-box;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

#game {
  width: 100%;
  height: 100%;
}

#game canvas {
  display: block;
}

#rotate {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: #2a1a14;
  color: #ffe6ee;
  font: 800 22px/1.3 "Baloo 2", "Trebuchet MS", sans-serif;
  text-align: center;
}

#rotate p {
  margin: 0;
}

#rotate .phone {
  width: 54px;
  height: 92px;
  border: 4px solid #ff7aa5;
  border-radius: 12px;
  animation: tilt 1.8s ease-in-out infinite;
}

@keyframes tilt {
  0%, 25% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}

@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  #rotate .phone { animation: none; transform: rotate(-90deg); }
}

/* ---------- okna dialogowe nad grą (imię gracza, udostępnianie) ---------- */
:root {
  --ink: #3a2418;
  --muted: #7d5f50;
  --cream: #fff6f1;
  --accent: #d93d72;
  --accent-hover: #e85288;
  --accent-shadow: #a82555;
  --line: #ffd0de;
  --error: #c0263f;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(42, 26, 20, 0.62);
  font-family: Nunito, "Trebuchet MS", sans-serif;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}

.modal-card {
  box-sizing: border-box;
  width: min(440px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 24px 24px 20px;
  border-radius: 28px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 12px 0 rgba(42, 26, 20, 0.25), inset 0 0 0 6px var(--line);
}

.modal h2 {
  margin: 0 0 6px;
  font: 800 28px/1.15 "Baloo 2", "Trebuchet MS", sans-serif;
  text-align: center;
}

.modal p {
  margin: 0 0 14px;
  text-align: center;
  font-weight: 700;
}

.modal .muted { color: var(--muted); }

.modal .error {
  min-height: 1.3em;
  margin: 8px 0 4px;
  color: var(--error);
  font-size: 15px;
}

.modal input {
  box-sizing: border-box;
  width: 100%;
  padding: 12px 16px;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  font: 800 22px/1.2 "Baloo 2", "Trebuchet MS", sans-serif;
  text-align: center;
  outline: none;
}

.modal input:focus { border-color: var(--accent); }

.modal .actions,
.modal .share-grid {
  display: grid;
  gap: 10px;
  margin-top: 6px;
}

.modal .share-grid {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 10px;
}

.modal .btn {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 48px;
  padding: 10px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 5px 0 var(--accent-shadow);
  color: #fff;
  font: 800 20px/1.4 "Baloo 2", "Trebuchet MS", sans-serif;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.modal .btn:hover { background: var(--accent-hover); }
.modal .btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--accent-shadow); }
.modal .btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.modal .btn.ghost {
  background: #fff;
  box-shadow: 0 5px 0 #e0c2cc;
  color: var(--ink);
}

.modal .btn.ghost:hover { background: #fff0f5; }

.modal .btn:disabled,
.modal .btn:disabled:hover {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.modal .btn.ghost:disabled:hover { background: #fff; }

/* kod z e-maila: duże, czytelne cyfry */
.modal input[autocomplete="one-time-code"] {
  font-size: 28px;
  letter-spacing: 0.35em;
  text-align: center;
}

@media (max-height: 420px) {
  .modal { align-items: flex-start; }
  .modal-card { padding: 16px 18px 14px; }
  .modal h2 { font-size: 24px; }
}

.modal .field {
  display: block;
  margin-bottom: 10px;
}

.modal .field span {
  display: block;
  margin: 0 0 4px 6px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
}

.modal .consent {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  cursor: pointer;
}

.modal .consent input {
  flex: none;
  width: 22px;
  height: 22px;
  margin: 1px 0 0;
  padding: 0;
  border: 0;
  accent-color: var(--accent);
}

.modal .consent a { color: var(--accent); }

/* porównanie poprzedniego i nowego wyniku przy pytaniu o nadpisanie */
.modal .compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.modal .compare-item {
  display: grid;
  gap: 2px;
  padding: 10px 8px;
  border: 3px solid var(--line);
  border-radius: 18px;
  background: #fff;
  text-align: center;
}

.modal .compare-item span { color: var(--muted); font-weight: 700; font-size: 15px; }
.modal .compare-item strong { font: 800 26px/1.1 "Baloo 2", "Trebuchet MS", sans-serif; }
.modal .compare-item small { color: var(--muted); font-weight: 700; }

/* polityka prywatności w okienku nad formularzem */
.modal.policy { z-index: 30; }
.modal.policy .modal-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(860px, 100%);
  height: min(90vh, 900px);
  max-height: 100%;
}
.modal.policy iframe {
  flex: 1;
  width: 100%;
  border: 0;
  border-radius: 18px;
  background: #fff;
}

/* formularz rankingu: szeroki, żeby mieścił się bez przewijania także na telefonie trzymanym poziomo —
   imię i e-mail obok siebie, zgoda pod nimi, przyciski w jednym rzędzie */
.modal-card.wide { width: min(780px, 100%); }

@media (min-width: 600px) {
  .modal .join {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 16px;
  }
  .modal .join > h2,
  .modal .join > p,
  .modal .join > .consent { grid-column: 1 / -1; }
  .modal .join > .actions {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    grid-auto-flow: column;
  }
}

/* niski ekran (telefon poziomo): mniejsze odstępy i pola */
@media (max-height: 460px) {
  .modal { padding: 8px 16px; align-items: center; }
  .modal-card.wide { padding: 12px 18px 12px; border-radius: 22px; }
  .modal .join h2 { font-size: 22px; margin-bottom: 2px; }
  .modal .join > p.muted { font-size: 13px; line-height: 1.35; margin-bottom: 8px; }
  .modal .join .field { margin-bottom: 6px; }
  .modal .join .field span { font-size: 13px; margin-bottom: 2px; }
  .modal .join input:not([type="checkbox"]) { padding: 7px 14px; font-size: 18px; }
  .modal .join .consent { font-size: 12px; line-height: 1.3; }
  .modal .join .error { min-height: 1em; margin: 4px 0 2px; font-size: 13px; }
  .modal .join .btn { min-height: 40px; padding: 6px 14px; font-size: 17px; }
}
