/* Medve Futo — Duolingo-flavoured look (green accent, chunky buttons).
   Overlays are laid out HORIZONTALLY so they fit a landscape phone
   (~640x360 CSS px) without any scrolling; the only scrollable area is the
   leaderboard list (3 rows visible, up to 30 by scrolling). */

:root {
  --green: #58cc02;
  --green-dark: #46a302;
  --green-light: #d7ffb8;
  --green-border: #a5ed6e;
  --green-text: #58a700;
  --red: #ff4b4b;
  --red-light: #ffdfe0;
  --red-border: #ffb2b2;
  --red-text: #ea2b2b;
  --blue: #1cb0f6;
  --text: #4b4b4b;
  --muted: #777;
  --border: #e5e5e5;
  --card-bg: #ffffff;
  --page-bg: #14532d;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Nunito", -apple-system, "Segoe UI", Inter, sans-serif;
  background: var(--page-bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wrap {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #cdeffd;
}

canvas { display: block; width: 100%; height: 100%; }

/* ---------- HUD ---------- */

#hud { position: absolute; top: 0.6rem; left: 0.6rem; pointer-events: none; z-index: 2; }

.chip {
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-radius: 0.75rem;
  padding: 0.25rem 0.75rem;
  font-weight: 900;
  font-size: 1rem;
  color: var(--text);
}

/* ---------- Quiz ---------- */

#quiz {
  position: absolute;
  /* Kept clear of the top edge: taps near it hit the browser chrome (tab
     switcher) in mobile Safari. */
  top: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(80%, 34rem);
  background: rgba(255, 255, 255, 0.95);
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-radius: 1rem;
  padding: 0.5rem 0.75rem 0.6rem;
  text-align: center;
  z-index: 3;
}

.q-label {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.answers { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }

.btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-radius: 0.75rem;
  padding: 0.5rem 1rem;
  min-height: 2.75rem;
  min-width: 5.5rem;
  cursor: pointer;
  transition: background 0.1s, transform 0.05s, border-color 0.1s;
  touch-action: manipulation;
}
.btn:hover { background: #f7f7f7; }
.btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn:disabled { cursor: default; }

.btn.correct { background: var(--green-light); border-color: var(--green-border); color: var(--green-text); }
.btn.wrong {
  background: var(--red-light);
  border-color: var(--red-border);
  color: var(--red-text);
  animation: shake 0.3s;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.timerbar { height: 0.4rem; background: var(--border); border-radius: 0.2rem; margin-top: 0.5rem; overflow: hidden; }
.timerbar i {
  display: block; height: 100%; width: 100%;
  background: var(--green); border-radius: 0.2rem;
  transition: width 0.1s linear, background 0.2s;
}
.timerbar i.low { background: var(--red); }

/* ---------- Overlays: horizontal cards, no scroll ---------- */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 40, 20, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(0.4rem, 2vmin, 1rem);
  z-index: 4;
}

.card {
  background: var(--card-bg);
  border-radius: 1.25rem;
  padding: clamp(0.6rem, 2.5vmin, 1.25rem) clamp(0.8rem, 3vmin, 1.5rem);
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.25);
  display: flex;
  align-items: center;
  gap: clamp(0.6rem, 2.5vmin, 1.25rem);
  max-width: min(96%, 38rem);
  max-height: 100%;
  overflow: hidden; /* the card itself never scrolls */
}

.card-main { flex: 1 1 auto; text-align: center; min-width: 0; }
.card-side { flex: 0 0 clamp(11rem, 34vw, 14rem); min-width: 0; }

.mascot {
  height: clamp(4.5rem, 22vmin, 9rem);
  width: auto;
  flex: 0 0 auto;
}

.card h1, .card h2 {
  font-size: clamp(1.1rem, 4.5vmin, 1.6rem);
  font-weight: 900;
  color: var(--text);
  margin-bottom: clamp(0.25rem, 1.5vmin, 0.5rem);
}

.rules {
  font-size: clamp(0.72rem, 2.8vmin, 0.9rem);
  line-height: 1.4;
  color: var(--muted);
  margin-bottom: clamp(0.4rem, 2vmin, 0.9rem);
}

.name-input {
  font-family: inherit;
  font-weight: 800;
  font-size: clamp(0.9rem, 3vmin, 1rem);
  color: var(--text);
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-radius: 0.75rem;
  padding: clamp(0.35rem, 1.5vmin, 0.5rem) 0.9rem;
  width: 100%;
  text-align: center;
  margin-bottom: clamp(0.4rem, 2vmin, 0.75rem);
}
.name-input:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.name-input::placeholder { color: var(--muted); font-weight: 700; }

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  border-bottom: 4px solid var(--green-dark);
  color: #fff;
  font-size: clamp(0.95rem, 3vmin, 1.05rem);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: clamp(0.45rem, 2vmin, 0.65rem) 1.5rem;
}
.btn-primary:hover { background: #61e002; }
.btn-primary:disabled { background: #b7e29a; border-color: #b7e29a; border-bottom-color: #9ecf7f; }

/* Game-over left column */
.score-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: clamp(0.2rem, 1vmin, 0.4rem);
}
.score-big { font-size: clamp(2rem, 9vmin, 3rem); font-weight: 900; color: var(--green); line-height: 1; }
.score-label { font-size: clamp(0.7rem, 2.5vmin, 0.85rem); color: var(--muted); text-align: left; line-height: 1.2; }
.best { font-size: clamp(0.8rem, 2.8vmin, 0.9rem); font-weight: 800; color: var(--blue); margin-bottom: 0.2rem; }
.last-word { font-size: clamp(0.75rem, 2.8vmin, 0.9rem); color: var(--muted); margin-bottom: clamp(0.4rem, 2vmin, 0.9rem); }
.last-word b { color: var(--text); }

/* Leaderboard: the ONLY scrollable area — 3 rows visible, scroll to 30 */
.lb-title {
  font-size: clamp(0.7rem, 2.5vmin, 0.8rem);
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
  text-align: center;
}
.lb-place {
  font-size: clamp(0.8rem, 2.8vmin, 0.95rem);
  font-weight: 800;
  color: var(--blue);
  margin-bottom: 0.35rem;
  text-align: center;
}
.lb-top {
  list-style: none;
  counter-reset: lb;
  max-height: calc(3 * 2.35rem); /* exactly 3 rows */
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-right: 0.15rem;
}
.lb-top li {
  counter-increment: lb;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.25rem 0.55rem;
  margin-bottom: 0.3rem;
  font-weight: 800;
  font-size: clamp(0.75rem, 2.8vmin, 0.9rem);
  height: 2.05rem;
}
.lb-top li::before {
  content: counter(lb);
  color: var(--muted);
  min-width: 1.2rem;
  text-align: center;
  flex: 0 0 auto;
}
.lb-top li.me { border-color: var(--green); background: #f0ffe4; }
.lb-name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: var(--green-dark); flex: 0 0 auto; }

/* ---------- Rotate gate (portrait phones) ---------- */

#rotateOverlay { background: var(--page-bg); z-index: 20; }
.rotate-box { text-align: center; color: #eaffdd; padding: 1rem; }
.rotate-icon {
  width: 9rem;
  height: auto;
  margin-bottom: 1rem;
  animation: tilt 2s ease-in-out infinite;
}
@keyframes tilt {
  0%, 15% { transform: rotate(0deg); }
  50%, 80% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}
.rotate-box p { font-size: 1.05rem; font-weight: 800; line-height: 1.5; }

/* ---------- Fullscreen button ---------- */

.fs-btn {
  position: absolute;
  top: 0.6rem;
  right: 0.6rem;
  z-index: 5;
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-radius: 0.75rem;
  cursor: pointer;
  touch-action: manipulation;
}
.fs-btn:hover { background: #f7f7f7; }
.fs-btn:active { transform: translateY(2px); border-bottom-width: 2px; }
.fs-btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.fs-btn svg { width: 1.25rem; height: 1.25rem; }

/* Pseudo-fullscreen fallback (old iPhones without the Fullscreen API):
   pin the page to the visible viewport. */
body.pseudo-fs .wrap { height: 100dvh; }

.hidden { display: none !important; }

/* Landscape phones: tighten paddings further, keep everything scroll-free */
@media (max-height: 30rem) {
  #quiz { top: 2.2rem; padding: 0.35rem 0.6rem 0.45rem; }
  .q-label { display: none; }
  .btn { font-size: 0.9rem; min-height: 2.5rem; padding: 0.35rem 0.8rem; }
  .mascot { display: none; } /* the start card goes text-only, height is scarce */
  .fs-btn, .chip { width: 2.5rem; height: 2.5rem; }
  .chip { width: auto; height: auto; font-size: 0.85rem; }
}
