/* ---------- Font ---------- */

@font-face {
  font-family: "Fredoka";
  src: url("../assets/fonts/fredoka-latin-wght.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- Variabili ---------- */

:root {
  --font: "Fredoka", "Comic Neue", "Nunito", system-ui, sans-serif;

  --sky: #bfe6ff;
  --sky-deep: #8fd0fb;
  --paper: #fffaf0;
  --ink: #2b2118;
  --ink-soft: #6b5a4a;
  --line: #3b2a1a;

  --primary: #2f80ed;
  --primary-ink: #ffffff;
  --accent: #ffcf3f;

  --right: #2fb36b;
  --right-soft: #dcf7e7;
  --wrong: #f39c34;
  --wrong-soft: #ffeedb;

  --rock: #a07b5b;
  --rock-dark: #7a5a40;
  --hold: #ff7a59;

  --highlight-fill: #ffe14d;
  --highlight-stroke: #e0307a;

  --radius-s: 10px;
  --radius-m: 18px;
  --radius-l: 28px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --shadow: 0 4px 0 rgba(59, 42, 26, 0.25);
  --tap: 56px;
}

/* ---------- Base ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.35;
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0%, var(--paper) 100%) fixed;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
}

:focus-visible {
  outline: 4px solid var(--primary);
  outline-offset: 3px;
}

.btn {
  min-height: var(--tap);
  padding: var(--space-2) var(--space-5);
  border: 3px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--primary);
  color: var(--primary-ink);
  font-size: 1.15rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(59, 42, 26, 0.25);
}

.btn--ghost {
  background: var(--paper);
  color: var(--ink);
}

.btn--small {
  min-height: 44px;
  padding: var(--space-1) var(--space-3);
  font-size: 1rem;
}

.loading,
.fatal {
  padding: var(--space-6) var(--space-4);
  text-align: center;
  font-size: 1.3rem;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Scelta dell'argomento ---------- */

.screen {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-4);
}

.hero {
  padding: var(--space-6) 0 var(--space-5);
  text-align: center;
}

.hero__title {
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  font-weight: 700;
  color: var(--primary);
  text-shadow: 0 3px 0 var(--line);
  -webkit-text-stroke: 1.5px var(--line);
}

.hero__subtitle {
  margin-top: var(--space-2);
  font-size: 1.25rem;
  color: var(--ink-soft);
}

.topics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.topic-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  width: 100%;
  min-height: 120px;
  justify-content: center;
  padding: var(--space-4) var(--space-5);
  border: 3px solid var(--line);
  border-radius: var(--radius-l);
  background: var(--accent);
  box-shadow: var(--shadow);
  text-align: left;
}

button.topic-card:hover {
  filter: brightness(1.05);
}

.topic-card__name {
  font-size: 1.7rem;
  font-weight: 700;
}

.topic-card__meta {
  color: var(--ink-soft);
}

.credits {
  margin-top: var(--space-6);
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-align: center;
}

.credits a {
  color: inherit;
}

.topic-card--broken {
  background: #eee6dc;
  border-style: dashed;
  box-shadow: none;
}

/* ---------- Partita ---------- */

.screen--game {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.topbar__title {
  font-size: 1.2rem;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game {
  flex: 1;
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: var(--space-5);
  align-items: stretch;
}

/* Parete */

.wall {
  --climber: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  min-height: 0;
}

.wall__field {
  padding: var(--space-1) var(--space-3);
  border: 3px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  font-weight: 700;
  white-space: nowrap;
}

.wall[data-field="c1"] .wall__field {
  background: #ffe2a8;
}

.wall[data-field="c2"] .wall__field {
  background: #ffc2c2;
}

.wall__track {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 260px;
  border: 3px solid var(--line);
  border-radius: var(--radius-l) var(--radius-l) var(--radius-m) var(--radius-m);
  background: linear-gradient(180deg, #b48d6b 0%, var(--rock) 60%, var(--rock-dark) 100%);
  overflow: hidden;
}

.wall__holds {
  position: absolute;
  inset: 0;
}

.wall__hold {
  position: absolute;
  left: 50%;
  bottom: calc(var(--at) * (100% - var(--climber)) + var(--climber) / 2 - 7px);
  width: 18px;
  height: 14px;
  margin-left: -9px;
  border: 2.5px solid var(--line);
  border-radius: 50% 50% 40% 40%;
  background: var(--hold);
  transform: translateX(-16px);
}

.wall__hold:nth-child(even) {
  transform: translateX(16px);
}

.wall__flag {
  position: absolute;
  top: 2px;
  left: 50%;
  width: 34px;
  height: 34px;
  transform: translateX(-30%);
}

.wall__climber {
  position: absolute;
  left: 50%;
  bottom: calc(var(--progress, 0) * (100% - var(--climber)));
  width: var(--climber);
  height: var(--climber);
  margin-left: calc(var(--climber) / -2);
}

.wall__flag svg,
.wall__climber svg,
.icon svg,
.summit__art svg {
  display: block;
  width: 100%;
  height: 100%;
}

.wall__left {
  font-size: 0.95rem;
  text-align: center;
  color: var(--ink-soft);
}

/* Domanda */

.quiz {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.quiz__prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.quiz__label {
  color: var(--ink-soft);
}

.quiz__word {
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 700;
  line-height: 1.1;
}

.quiz__figure {
  width: 100%;
  max-width: 560px;
  /* tutto lo spazio che avanza sopra parola, opzioni e messaggio */
  height: clamp(260px, calc(100dvh - 440px), 620px);
  padding: var(--space-2);
  border: 3px solid var(--line);
  border-radius: var(--radius-l);
  background: #ffffff;
  /* la freccia del marcatore può partire da fuori del disegno: si taglia sul bordo */
  overflow: hidden;
}

.quiz__image {
  display: block;
  width: 100%;
  height: 100%;
  padding: 12%;
  object-fit: contain;
  user-select: none;
}

.quiz__figure svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.options {
  display: grid;
  gap: var(--space-3);
  width: 100%;
  max-width: 520px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.option {
  display: flex;
  gap: var(--space-2);
}

.option__choose {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  min-height: var(--tap);
  padding: var(--space-2) var(--space-4);
  border: 3px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: 1.5rem;
  font-weight: 600;
  text-align: left;
}

.option__choose:not(:disabled):hover {
  background: #ffffff;
}

.option__choose:not(:disabled):active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(59, 42, 26, 0.25);
}

.option__key {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--sky);
  font-size: 1rem;
}

.option__text {
  overflow-wrap: anywhere;
}

.option__listen {
  display: none;
  flex: none;
  width: var(--tap);
  min-height: var(--tap);
  place-items: center;
  border: 3px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--sky);
  box-shadow: var(--shadow);
}

.has-speech .option__listen {
  display: grid;
}

.option__listen .icon {
  width: 26px;
  height: 26px;
}

.option.is-correct .option__choose {
  border-color: var(--right);
  background: var(--right-soft);
  box-shadow: 0 0 0 4px var(--right);
}

.option.is-correct .option__choose::after {
  content: "✓";
  margin-left: auto;
  color: var(--right);
  font-size: 1.6rem;
}

.option.is-wrong .option__choose {
  border-color: var(--wrong);
  background: var(--wrong-soft);
}

.option.is-wrong .option__choose::after {
  content: "✗";
  margin-left: auto;
  color: var(--wrong);
  font-size: 1.4rem;
}

.option__choose:disabled {
  color: var(--ink);
}

.quiz__feedback {
  min-height: 1.6em;
  font-size: 1.3rem;
  font-weight: 600;
  text-align: center;
}

.quiz__status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  max-width: 520px;
}

/* Visibile solo quando si sa che non ci sono voci inglesi */
.quiz__audio-note {
  display: none;
  padding: var(--space-2) var(--space-3);
  border: 2px dashed var(--ink-soft);
  border-radius: var(--radius-s);
  color: var(--ink-soft);
  font-size: 0.95rem;
  text-align: center;
}

.no-speech .quiz__audio-note {
  display: block;
}

.quiz__feedback.is-correct {
  color: #1d8a50;
}

.quiz__feedback.is-wrong {
  color: #b5600c;
}

.quiz__oops {
  display: inline-block;
  font-size: 1.25em;
}

/* Omino: parte chiesta */

.body-figure [data-part].is-target,
.body-figure [data-part].is-target * {
  stroke: var(--highlight-stroke);
  stroke-width: 5px;
}

.body-figure [data-part].is-target :not([fill="none"]):not(.keep),
.body-figure [data-part].is-target > :not([fill="none"]):not(.keep) {
  fill: var(--highlight-fill);
}

.body-figure .is-target .keep {
  stroke: none;
}

.figure-marker {
  pointer-events: none;
}

.figure-marker__ring {
  fill: none;
  stroke: var(--highlight-stroke);
  stroke-width: 4px;
  stroke-dasharray: 10 7;
}

.figure-marker__line {
  stroke: var(--highlight-stroke);
  stroke-width: 6px;
  stroke-linecap: round;
}

.figure-marker__head {
  fill: var(--highlight-stroke);
}

/* Banner di cambio campo */

.banner {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: rgba(191, 230, 255, 0.85);
  font-size: clamp(2.6rem, 12vw, 5rem);
  font-weight: 700;
  color: var(--primary);
  -webkit-text-stroke: 2px var(--line);
  text-shadow: 0 4px 0 var(--line);
  overflow: hidden;
}

.banner__text {
  position: relative;
  z-index: 1;
}

/* Conferma Riavvia */

.confirm {
  width: min(420px, calc(100vw - 2 * var(--space-4)));
  padding: var(--space-5);
  border: 3px solid var(--line);
  border-radius: var(--radius-l);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 8px 0 rgba(59, 42, 26, 0.3);
}

.confirm::backdrop {
  background: rgba(43, 33, 24, 0.45);
}

.confirm__text {
  font-size: 1.35rem;
  font-weight: 600;
  text-align: center;
}

.confirm__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

/* ---------- Vetta ---------- */

.screen--summit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: 100dvh;
  text-align: center;
  overflow: hidden;
}

.summit__art {
  width: min(360px, 90vw);
  aspect-ratio: 320 / 200;
}

.summit__title {
  font-size: clamp(2.4rem, 10vw, 4rem);
  font-weight: 700;
  color: var(--primary);
  -webkit-text-stroke: 1.5px var(--line);
  text-shadow: 0 3px 0 var(--line);
}

.summit__topic {
  color: var(--ink-soft);
  font-size: 1.2rem;
}

.summit__score {
  font-size: 1.6rem;
}

.summit__score strong {
  font-size: 2.2rem;
  color: var(--right);
}

.summit__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.confetti span {
  position: absolute;
  top: -20px;
  left: var(--x);
  width: 10px;
  height: 16px;
  border-radius: 3px;
  background: var(--color);
  opacity: 0;
}

.streamers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.streamer {
  position: absolute;
  top: -100px;
  left: var(--x);
  width: 22px;
  height: 96px;
  color: var(--color);
  opacity: 0;
}

.streamer svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- PC largo: figura a sinistra, domanda a destra ---------- */

@media (min-width: 960px) {
  .quiz {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(300px, 1fr);
    grid-template-rows: 1fr auto auto 1fr;
    grid-template-areas:
      "figure ."
      "figure prompt"
      "figure options"
      "figure feedback";
    column-gap: var(--space-6);
    row-gap: var(--space-4);
    align-items: center;
  }

  .quiz__figure {
    grid-area: figure;
    max-width: none;
    height: clamp(360px, calc(100dvh - 120px), 720px);
  }

  .quiz__prompt {
    grid-area: prompt;
  }

  .options {
    grid-area: options;
  }

  .quiz__status {
    grid-area: feedback;
    align-self: start;
  }
}

/* ---------- Telefono ---------- */

@media (max-width: 700px) {
  body {
    font-size: 17px;
  }

  .screen {
    padding: var(--space-3) var(--space-3) var(--space-4);
  }

  .game {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: var(--space-3);
  }

  .wall {
    --climber: 40px;
  }

  .wall__field {
    padding: 2px 6px;
    font-size: 0.8rem;
    border-width: 2px;
  }

  .wall__track {
    min-height: 200px;
    border-width: 2px;
  }

  .wall__hold {
    width: 14px;
    height: 11px;
    margin-left: -7px;
    transform: translateX(-10px);
  }

  .wall__hold:nth-child(even) {
    transform: translateX(10px);
  }

  .wall__flag {
    width: 26px;
    height: 26px;
  }

  .wall__left {
    font-size: 0.8rem;
  }

  .quiz__figure {
    height: clamp(220px, calc(100dvh - 405px), 520px);
    padding: var(--space-1);
  }

  .option__choose {
    font-size: 1.3rem;
    padding: var(--space-2) var(--space-3);
  }

  .option__key {
    display: none;
  }

  .quiz__audio-note {
    padding: 2px var(--space-2);
    font-size: 0.8rem;
    line-height: 1.25;
  }

  /* la nota occupa un po' di altezza: la si toglie all'omino per evitare lo scroll */
  .no-speech .quiz__figure {
    height: clamp(200px, calc(100dvh - 460px), 520px);
  }
}

@media (hover: none) and (pointer: coarse) {
  .option__key {
    display: none;
  }
}

/* ---------- Movimento: solo se non si chiede di ridurlo ---------- */

@media (prefers-reduced-motion: no-preference) {
  .wall__climber {
    transition: bottom 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  }

  .wall__climber.no-anim {
    transition: none;
  }

  .body-figure [data-part].is-target {
    animation: pulse 1.2s ease-in-out infinite;
  }

  .figure-marker__ring {
    animation: march 1s linear infinite;
  }

  .option.is-correct .option__choose {
    animation: pop 0.35s ease-out;
  }

  .option.is-wrong .option__choose {
    animation: wobble 0.4s ease-in-out;
  }

  .quiz__oops {
    animation: pop 0.35s ease-out;
  }

  .banner:not([hidden]) {
    animation: pop 0.4s ease-out;
  }

  .confetti span {
    animation: fall var(--duration) linear var(--delay) infinite;
  }

  .streamer {
    animation: streamer-fall var(--duration) ease-in var(--delay) both;
  }

  .streamers--loop .streamer {
    animation-iteration-count: infinite;
  }
}

@media (prefers-reduced-motion: reduce) {
  /* Coriandoli fermi, sparsi nella parte alta */
  .confetti span {
    top: var(--y);
    opacity: 1;
    transform: rotate(calc(var(--spin) * 30deg));
  }

  /* Stelle filanti ferme, appese nella parte alta */
  .streamer {
    top: var(--y);
    opacity: 1;
    transform: rotate(var(--tilt));
  }
}

@keyframes pulse {
  50% {
    opacity: 0.65;
  }
}

@keyframes march {
  to {
    stroke-dashoffset: -34;
  }
}

@keyframes pop {
  0% {
    transform: scale(0.9);
  }
  60% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes wobble {
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

@keyframes streamer-fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(var(--tilt));
  }
  50% {
    transform: translateY(55vh) rotate(calc(var(--tilt) + var(--spin) * 25deg));
  }
  100% {
    opacity: 1;
    transform: translateY(calc(100vh + 120px)) rotate(calc(var(--tilt) - var(--spin) * 20deg));
  }
}

@keyframes fall {
  0% {
    opacity: 1;
    transform: translateY(0) rotate(0);
  }
  100% {
    opacity: 1;
    transform: translateY(110vh) rotate(calc(var(--spin) * 720deg));
  }
}
