:root {
  --bg: #fefefe;
  --bg-2: #fff4d9;
  --card: #fff4d9;
  --card-2: #ffecc4;
  --line: #ff9800;
  --text: #333333;
  --muted: #806b52;
  --gold: #ff9800;
  --gold-2: #ff5722;
  --red: #e53935;
  --green: #4caf50;
  --lcd: #f0f8e9;
  --lcd-text: #287b38;
  --radius: 16px;
  --display: 'Bebas Neue', Impact, 'Arial Narrow', sans-serif;
  --body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'DM Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--body);
  color: var(--text);
  background: var(--bg);
  background-image:
	radial-gradient(ellipse 120% 60% at 50% -10%, #fff3d0 0%, transparent 60%),
	radial-gradient(ellipse 80% 40% at 50% 110%, #ffecc4 0%, transparent 70%);
  background-attachment: fixed;
}

.app {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}

[hidden] {
  display: none !important;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 400;
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

/* ---------- Tarjetas, formularios, botones ---------- */

.card {
  background: linear-gradient(180deg, #fff3e0, #fff4d9);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 5px 14px rgba(255, 152, 0, .12);
}

.card h2 {
  font-family: var(--display);
  font-size: 1.7rem;
  letter-spacing: .05em;
  margin-bottom: 12px;
  color: #ff5722;
}

.card h3 {
  font-family: var(--display);
  font-size: 1.4rem;
  letter-spacing: .05em;
  margin: 18px 0 10px;
  color: #333;
}

.card hr {
  border: 0;
  border-top: 2px dashed #ff9800;
  margin: 22px 0;
}

form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

input, select {
  width: 100%;
  padding: 14px 16px;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: #fff;
  border: 2px solid #ffcc80;
  border-radius: 12px;
  outline: none;
}

input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 152, 0, .18);
}

input[readonly], .input-gris {
  color: var(--muted);
  letter-spacing: .3em;
  text-align: center;
  font-family: var(--mono);
}

#pin {
  text-transform: uppercase;
  letter-spacing: .25em;
  text-align: center;
  font-family: var(--mono);
}

.btn {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  padding: 14px 22px;
  font-size: 1.2rem !important;
  font-weight: 700;
  border: 2px solid #e68a00;
  border-radius: 12px;
  background: #fff3e0;
  color: #333;
  border-bottom: 4px solid #d47700;
  transition: transform .08s, filter .15s;
}

.btn:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:disabled {
  opacity: .5;
}

.btn-gold {
  background: linear-gradient(180deg, #ffb52e, #ff9800);
  color: #fff;
  border-color: #e68a00;
  border-bottom-color: #bd6500;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .2);
}

.msg {
  min-height: 1.3em;
  margin: 12px 0 0;
  color: #e53935;
  text-align: center;
  font-size: .95rem;
}

.hint {
  color: var(--muted);
  text-align: center;
  margin: 4px 0;
}

.rules {
  margin-top: 8px;
  color: var(--muted);
}

.rules summary {
  cursor: pointer;
  text-align: center;
  padding: 8px;
  color: #ff5722;
}

.rules ul {
  padding-left: 20px;
  line-height: 1.55;
}

.rules li {
  margin-bottom: 6px;
}

/* ---------- Lobby ---------- */

#players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.player-box {
  color: #ff9800;
  padding: 10px 12px;
  border: 2px solid #ffcc80;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-box.me {
  border-color: #ff9800;
  background: #fff3e0;
}

.player-box.away {
  opacity: .45;
}

.pill {
  font-family: var(--body);
  font-size: .8rem;
  background: #ff9800;
  color: #fff;
  padding: 1px 8px;
  border-radius: 99px;
  vertical-align: middle;
}

#start {
  width: 100%;
  margin-bottom: 4px;
}

.share {
  text-align: center;
}

.share .label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .2em;
  color: var(--muted);
  margin: 10px 0 6px;
}

.copy-btn {
  width: 100%;
  padding: 12px;
  border: 2px dashed #ff9800;
  border-radius: 12px;
  background: #fff4d9;
  color: #333;
  font-family: var(--mono);
  font-size: .9rem;
  word-break: break-all;
}

.copy-btn:hover {
  background-color: #ff9800;
  color: #fff;
  border-color: #ff9800;
  cursor: pointer;
  transition: background-color .2s ease;
}

.pin-big {
  font-size: 2rem;
  letter-spacing: .3em;
  color: #ff5722;
}

#qrcode {
  display: inline-block;
  margin-top: 18px;
  padding: 12px;
  background: #fff;
  border: 2px solid #ff9800;
  border-radius: 12px;
  line-height: 0;
}

/* ===============================================================
   Juego
   =============================================================== */

.hud {
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0 -16px;
  padding: 10px 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: rgba(255, 248, 230, .96);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid #ff9800;
}

.hud-round {
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: .08em;
  color: var(--muted);
}

.hud-round b {
  color: var(--text);
  font-size: 1.6rem;
  font-weight: 400;
}

.hud-timer {
  text-align: center;
  width: 84px;
}

.hud-timer span {
  font-family: var(--display);
  font-size: 2.1rem;
  line-height: 1;
  display: block;
  transition: color .2s;
}

.hud-timer .bar {
  height: 5px;
  border-radius: 3px;
  background: #ffe0a3;
  overflow: hidden;
  margin-top: 2px;
}

.hud-timer .bar i {
  display: block;
  height: 100%;
  background: #ff9800;
  transform-origin: left;
  transform: scaleX(1);
}

.hud-timer.low span {
  color: var(--red);
  animation: pulse .5s ease-in-out infinite alternate;
}

.hud-timer.low .bar i {
  background: var(--red);
}

@keyframes pulse {
  to { transform: scale(1.18); }
}

.hud-me {
  justify-self: end;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.15;
  max-width: 100%;
  padding: 6px 12px;
  background: linear-gradient(180deg, #fff3e0, #ffecc4);
  border: 2px solid #ff9800;
  border-radius: 12px;
}

.me-name {
  font-size: .78rem;
  color: var(--muted);
  max-width: 11ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.me-score {
  font-size: .8rem;
  color: var(--muted);
}

.me-score b {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.7rem;
  color: #ff9800;
  letter-spacing: .03em;
}

.me-score.neg b {
  color: #e53935;
}

.hud-me.bump {
  animation: bump .6s ease;
}

@keyframes bump {
  30% {
	transform: scale(1.14);
	box-shadow: 0 0 22px rgba(255, 152, 0, .4);
  }
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 8px;
}

.question-card {
  position: relative;
  text-align: center;
  padding: 0px 8px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff3e0, #ffecc4);
  border: 3px dashed #ff5722;
  box-shadow: 0 6px 18px rgba(255, 152, 0, .15);
}

.question-card h2 {
  font-family: var(--display);
  font-size: clamp(1.7rem, 7vw, 2.3rem);
  line-height: 1.1;
  letter-spacing: .03em;
  color: #333;
  margin: 0;
  padding: 0;
}

.banner {
  text-align: center;
  padding: 6px 4px;
  font-size: 1.05rem;
  color: var(--muted);
}

.banner b {
  color: var(--text);
}

.banner small {
  display: block;
  color: var(--muted);
  font-size: .85rem;
  margin: 2px 0;
}

.banner .big {
  display: block;
  font-family: var(--display);
  font-size: 4.6rem;
  line-height: 1;
  color: #ff9800;
  text-shadow: 2px 2px 0 #ffe0a3;
}

.banner .big.ok {
  color: var(--green);
  text-shadow: 0 0 10px rgba(76, 175, 80, .3);
  animation: land .5s cubic-bezier(.2, 1.6, .4, 1);
}

@keyframes land {
  from {
	transform: scale(.4);
	opacity: 0;
  }
}

.banner.spinning {
  font-family: var(--display);
  font-size: 1.7rem;
  letter-spacing: .08em;
  color: #ff5722;
}

.res-line {
  font-size: 1.15rem;
  margin-top: 4px;
}

.res-win {
  margin-top: 6px;
  color: var(--text);
}

.up { color: var(--green); }
.down { color: #e53935; }
.zero { color: var(--muted); }

/* ---------- Zona de votación: calculadora ---------- */

.vote-zone {
  background: linear-gradient(180deg, #fff3e0, #ffecc4);
  border: 2px solid #ff9800;
  border-radius: 22px;
  padding: 14px;
  box-shadow: 0 8px 20px rgba(255, 152, 0, .15);
}

.display {
  background: var(--lcd);
  border: 2px solid #9ccc65;
  border-radius: 12px;
  padding: 8px 18px;
  margin-bottom: 12px;
  text-align: right;
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, .08);
}

.display span {
  font-family: var(--mono);
  font-size: 2.8rem;
  line-height: 1.25;
  color: var(--lcd-text);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.keypad button {
  height: 66px;
  font-family: var(--mono);
  font-size: 1.7rem;
  font-weight: 500;
  border: 2px solid #ffb74d;
  border-radius: 14px;
  background: linear-gradient(180deg, #fff3e0, #ffe0a3);
  color: #333;
  border-bottom: 5px solid #e68a00;
  transition: transform .07s, background .15s;
}

.keypad button:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

.keypad button.sel {
  background: linear-gradient(180deg, #ffb52e, #ff9800);
  color: #fff;
  border-color: #e68a00;
  border-bottom-color: #bd6500;
}

.keypad button.send {
  font-family: var(--body);
  font-size: 1.05rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  background: linear-gradient(180deg, #ff7043, #ff5722);
  color: #fff;
  border-color: #e64a19;
  border-bottom-color: #bf360c;
}

.keypad button.send:disabled {
  background: #eeeeee;
  color: #999;
  border-color: #ddd;
  border-bottom-color: #bbb;
}

.keypad.locked button {
  opacity: .45;
  pointer-events: none;
}

.keypad.locked button.send {
  opacity: .45;
}

/* ---------- Escalera ---------- */

.stairs-zone {
  padding: 4px 0 8px;
}

.stairs {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.step {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 40px;
  margin-left: calc(var(--v) * 4%);
  background: linear-gradient(90deg, #fff3e0, #ffecc4);
  border-top: 3px solid #ff9800;
  border-left: 3px solid #ffb74d;
  border-radius: 6px 0 0 0;
  transition: background .12s, box-shadow .12s;
}

.step-num {
  flex: none;
  width: 34px;
  text-align: center;
  font-family: var(--mono);
  font-size: 1rem;
  color: #e65100;
  align-self: stretch;
  display: grid;
  place-items: center;
  border-right: 1px dashed #ffb74d;
}

.riders {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 6px;
  min-width: 0;
}

.step.pointer {
  background: linear-gradient(90deg, #ffb52e, #ff9800);
  border-top-color: #ff5722;
  box-shadow: 0 0 18px rgba(255, 152, 0, .35);
  z-index: 1;
}

.step.pointer .step-num {
  color: #fff;
  border-color: rgba(255, 255, 255, .5);
  font-weight: 700;
}

.step.pointer::after {
  content: "◀";
  flex: none;
  padding-right: 10px;
  color: #fff;
  font-size: 1.1rem;
}

.step.correct {
  background: linear-gradient(90deg, #81c784, #4caf50);
  border-top-color: #2e7d32;
  box-shadow: 0 0 18px rgba(76, 175, 80, .3);
  z-index: 1;
}

.step.correct .step-num {
  color: #fff;
  font-weight: 700;
  border-color: rgba(255, 255, 255, .5);
}

.step.correct::after {
  content: "✔";
  flex: none;
  padding-right: 10px;
  color: #fff;
  font-weight: 700;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px 2px 2px;
  font-size: .8rem;
  max-width: 100%;
  background: hsl(var(--h) 45% 88%);
  border: 1px solid hsl(var(--h) 55% 55%);
  border-radius: 99px;
  color: #333;
}

.chip i {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-style: normal;
  font-weight: 700;
  font-size: .75rem;
  color: #fff;
  background: hsl(var(--h) 65% 45%);
}

.chip b {
  font-weight: 600;
  max-width: 9ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip em {
  font-style: normal;
  font-weight: 700;
  font-family: var(--mono);
  font-size: .78rem;
}

.chip em:empty {
  display: none;
}

.chip em.up { color: #2e7d32; }
.chip em.down { color: #d32f2f; }
.chip em.zero { color: #806b52; }

.chip.me {
  outline: 2px solid #ff9800;
  outline-offset: 1px;
}

.chip.win {
  box-shadow: 0 0 10px rgba(255, 152, 0, .5);
  border-color: #ff9800;
}

.chip.win b::after {
  content: " ★";
  color: #ff9800;
}

.chip.pop {
  animation: pop .45s cubic-bezier(.2, 1.7, .4, 1);
}

@keyframes pop {
  from {
	transform: scale(0) translateY(10px);
	opacity: 0;
  }
}

/* ---------- Final / ranking ---------- */

.final {
  text-align: center;
}

.final .btn {
  margin-top: 16px;
  display: block;
}

.rank {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rank li {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 2px solid #ffcc80;
  border-radius: 12px;
  background: #fff;
}

.rank li.me {
  border-color: #ff9800;
  background: #fff3e0;
}

.rank li.away {
  opacity: .55;
}

.rank .pos {
  font-size: 1.15rem;
  text-align: center;
  font-family: var(--mono);
  color: var(--muted);
}

.rank .nm {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank em {
  font-style: normal;
  font-family: var(--mono);
  font-size: .85rem;
}

.rank .sc {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.6rem;
  color: #ff9800;
  min-width: 2ch;
  text-align: right;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(51, 35, 15, .55);
  backdrop-filter: blur(5px);
}

.modal {
  width: 100%;
  max-width: 440px;
  max-height: 85dvh;
  overflow: auto;
  background: linear-gradient(180deg, #fff3e0, #ffecc4);
  border: 3px solid #ff9800;
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, .2);
  animation: land .25s ease-out;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-head h3 {
  font-family: var(--display);
  font-size: 1.9rem;
  letter-spacing: .05em;
  color: #ff5722;
}

.x {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #ff9800;
  background: #fff;
  font-size: 1rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  background: #fff3e0;
  border: 2px solid #ff5722;
  color: #333;
  padding: 12px 18px;
  border-radius: 12px;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 5px 15px rgba(0, 0, 0, .15);
}

#nextBtn {
  align-self: center;
  min-width: 220px;
}

/* ---------- Escritorio ---------- */

@media (min-width: 640px) {
  .app {
	max-width: 600px;
  }

  .keypad button {
	height: 72px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
	animation: none !important;
	transition: none !important;
  }
}