/* Owl Runner — Duolingo-flavoured look: chunky rounded buttons with a hard
   bottom border, Nunito-style rounded type, brand green #58cc02. */

: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: #235390;
}

* { 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;
}

/* Fullscreen on desktop/landscape: the stage fills the whole browser window.
   The canvas adapts its logical width to the real aspect ratio in JS. */
.wrap {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #bdefff;
  /* Answer buttons must stay tappable on tiny screens even though the stage
     scales down — the quiz block uses rem sizes, not canvas-relative ones. */
}

/* Portrait phones: a fullscreen portrait canvas would leave no room to react,
   so fall back to a letterboxed 16:9 card centered on the page. */
@media (orientation: portrait) {
  .wrap { height: auto; padding: 0.5rem; }
  .stage {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    border-radius: 1rem;
    box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.35);
  }
}

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

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

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

.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 bar ---------- */

#quiz {
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 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;
  transition: opacity 0.15s;
}

.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 ---------- */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 40, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.card {
  background: var(--card-bg);
  border-radius: 1.25rem;
  padding: 1.25rem 1.5rem;
  text-align: center;
  max-width: 24rem;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.25);
}

.mascot { height: 5.5rem; width: auto; margin-bottom: 0.25rem; }

.card h1 {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.rules { font-size: 0.9rem; line-height: 1.45; color: var(--muted); margin-bottom: 1rem; }

.btn-primary {
  background: var(--green);
  border-color: var(--green);
  border-bottom-color: var(--green-dark);
  color: #fff;
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 1.75rem;
}
.btn-primary:hover { background: #61e002; }
.btn-primary:disabled { background: #b7e29a; border-color: #b7e29a; border-bottom-color: #9ecf7f; }

.score-big { font-size: 3rem; font-weight: 900; color: var(--green); line-height: 1.1; }
.score-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.5rem; }
.best { font-size: 0.9rem; font-weight: 800; color: var(--blue); margin-bottom: 0.35rem; }
.last-word { font-size: 0.9rem; color: var(--muted); margin-bottom: 1rem; }
.last-word b { color: var(--text); }

/* ---------- Player name + leaderboard ---------- */

.name-input {
  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 0.9rem;
  width: 100%;
  text-align: center;
  margin-bottom: 0.75rem;
}
.name-input:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.name-input::placeholder { color: var(--muted); font-weight: 700; }

.lb { margin-bottom: 1rem; }
.lb-place { font-size: 0.95rem; font-weight: 800; color: var(--blue); margin-bottom: 0.4rem; }
.lb-top { list-style: none; counter-reset: lb; }
.lb-top li {
  counter-increment: lb;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.3rem 0.6rem;
  margin-bottom: 0.3rem;
  font-weight: 800;
  font-size: 0.9rem;
}
.lb-top li::before {
  content: counter(lb);
  color: var(--muted);
  min-width: 1.1rem;
  text-align: center;
}
.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); }

/* ---------- 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; }

.hidden { display: none !important; }

/* ---------- Small screens ---------- */

@media (max-width: 30rem) {
  /* The quiz bar spans almost the full width here — move the score chip to
     the bottom-left corner so the two never overlap. */
  #hud { top: auto; bottom: 0.6rem; }
  /* Keep the corner button clear of the full-width quiz card */
  .fs-btn { top: auto; bottom: 0.6rem; }
  .btn { font-size: 0.85rem; min-width: 4.5rem; padding: 0.45rem 0.6rem; }
  #quiz { padding: 0.4rem 0.5rem 0.5rem; }
  .q-label { display: none; }
  .card h1 { font-size: 1.3rem; }
  .mascot { height: 4rem; }
}
