:root {
  --sky: #9ADCF7;
  --ink: #1F1A3D;
  --stage: #2F3E9E;
  --yolk: #FFC21A;
  --shell: #FFF6E3;
  --alert: #FF5A5F;
  --paper: #FFFDF6;

  --font-display: "Lilita One", "Arial Black", Impact, system-ui, sans-serif;
  --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 800;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  display: flex;
  justify-content: center;
  overflow: hidden;
}

#stage {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  background: var(--sky);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 2;
}
#hud[hidden] { display: none; }

#hud-lives {
  display: flex;
  gap: 6px;
  padding-top: 8px;
}
.life {
  width: 20px;
  height: 26px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--shell);
  border: 3px solid var(--ink);
  transition: transform .2s, opacity .2s;
}
.life.lost {
  opacity: .25;
  transform: scale(.8);
}

.score-box {
  min-width: 64px;
  height: 64px;
  padding: 0 10px;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 10px;
  box-shadow: 4px 4px 0 var(--ink);
  font-family: var(--font-display);
  font-size: 34px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.score-box.pop { animation: pop .25s ease-out; }
@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.22) rotate(-4deg); background: var(--yolk); }
  100% { transform: scale(1); }
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) 18px calc(var(--safe-bottom) + 16px);
  overflow-y: auto;
}
.overlay[hidden] { display: none; }

.panel {
  width: 100%;
  max-width: 360px;
  padding: 22px 22px 18px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 18px;
  box-shadow: 6px 6px 0 var(--ink);
  text-align: center;
  animation: panel-in .28s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes panel-in {
  from { transform: translateY(18px) scale(.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.logo {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(54px, 16vw, 80px);
  line-height: .95;
  color: var(--yolk);
  -webkit-text-stroke: 5px var(--ink);
  paint-order: stroke fill;
  text-shadow: 5px 5px 0 var(--ink);
  transform: rotate(-4deg);
  letter-spacing: .01em;
}

.lead {
  margin: 10px auto 18px;
  max-width: 28ch;
  font-size: 16px;
  line-height: 1.4;
  font-weight: 700;
}

.btn {
  display: block;
  width: 100%;
  padding: 14px 18px 12px;
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1;
  color: var(--ink);
  background: var(--yolk);
  border: 4px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 6px 0 var(--ink);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.btn:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 var(--ink);
}
.btn:focus-visible,
.btn-link:focus-visible,
.mute:focus-visible,
#name-input:focus-visible {
  outline: 3px solid var(--alert);
  outline-offset: 3px;
}
.btn:disabled { opacity: .6; cursor: default; }

.btn-small {
  width: auto;
  flex: 0 0 auto;
  padding: 10px 14px 8px;
  font-size: 20px;
  box-shadow: 0 4px 0 var(--ink);
}

.plays {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--stage);
}

.board-title {
  margin: 16px 0 6px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 24px;
}

.board {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: pos;
  text-align: left;
}
.board li {
  counter-increment: pos;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 4px;
  border-bottom: 2px dashed rgba(31, 26, 61, .18);
  font-size: 16px;
}
.board li:last-child { border-bottom: 0; }
.board li::before {
  content: counter(pos);
  flex: 0 0 22px;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--stage);
}
.board li:first-child::before { color: var(--alert); }
.board .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board .pts {
  font-family: var(--font-display);
  font-size: 19px;
  font-variant-numeric: tabular-nums;
}
.board li.me {
  background: var(--yolk);
  border-radius: 8px;
}
.board li.empty {
  justify-content: center;
  font-weight: 700;
  color: var(--stage);
}
.board li.empty::before { content: none; }

.btn-link {
  display: block;
  margin: 12px auto 0;
  padding: 6px 10px;
  font: 800 15px var(--font-body);
  color: var(--stage);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.btn-link[hidden] { display: none; }

.credits {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 3px solid var(--ink);
  font-size: 14px;
  font-weight: 800;
}
.credits img {
  display: block;
  width: 42px;
  height: auto;
  border-radius: 6px;
}

.btn-secondary {
  margin-top: 12px;
  padding: 11px 16px 9px;
  font-size: 22px;
  background: var(--paper);
  box-shadow: 0 5px 0 var(--ink);
}
.btn-secondary:active { box-shadow: 0 1px 0 var(--ink); }

.studio-link {
  display: block;
  border-radius: 8px;
  transition: transform .15s;
}
.studio-link:hover, .studio-link:focus-visible { transform: scale(1.08) rotate(-3deg); }
.studio-link:focus-visible { outline: 3px solid var(--alert); outline-offset: 3px; }

.toast {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 76px);
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 12px;
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  animation: toast-in .2s ease-out;
}
.toast[hidden] { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Game over ---------- */
.over-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
}
.final {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-size: 76px;
  line-height: 1;
  color: var(--yolk);
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  text-shadow: 4px 4px 0 var(--ink);
}
.final small {
  display: block;
  margin-top: 4px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink);
  -webkit-text-stroke: 0;
  text-shadow: none;
}
.best {
  margin: 8px 0 14px;
  font-size: 14px;
  color: var(--stage);
}

#name-form { margin: 0 0 8px; text-align: left; }
#name-form[hidden] { display: none; }
#name-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 15px;
}
.name-row { display: flex; gap: 8px; }
#name-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font: 800 18px var(--font-body);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 10px;
}

.status {
  min-height: 1.3em;
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
}
.status.error { color: #C8262B; }

/* ---------- Pausa / som ---------- */
.pause {
  background: rgba(31, 26, 61, .55);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 26px;
  text-align: center;
  cursor: pointer;
}

.mute {
  position: absolute;
  z-index: 4;
  left: calc(env(safe-area-inset-left, 0px) + 14px);
  bottom: calc(var(--safe-bottom) + 14px);
  width: 44px;
  height: 44px;
  font-size: 20px;
  line-height: 1;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
}
.playing .mute { opacity: .7; }

@media (prefers-reduced-motion: reduce) {
  .panel, .score-box.pop { animation: none; }
}
