/* Phone layout (mobile-first) */
body.play { min-height: 100dvh; }
#app {
  min-height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
}
.small { font-size: 0.9rem; }
.conn {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 95;
  background: var(--red); padding: 0.45rem 1rem; border-radius: 99px; font-weight: 800; font-size: 0.9rem;
}

/* ---------- join ---------- */
.p-join { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 26px; padding: 28px 0; }
.p-hero { display: grid; justify-items: center; gap: 10px; text-align: center; }
.p-hero .title { font-size: clamp(3rem, 16vw, 4.6rem); }
.p-hero p { margin: 0; }
.p-fin {
  display: grid; place-items: center; width: 86px; height: 86px; border-radius: 50%; font-size: 2.8rem;
  background: var(--red); box-shadow: 0 0 0 5px #fff, 0 16px 40px rgba(227, 18, 27, 0.6); animation: bob 3s ease-in-out infinite;
}
.p-card {
  display: grid; gap: 16px; padding: 22px; border-radius: 24px;
  background: rgba(22, 22, 27, 0.9); border: 1px solid var(--line); backdrop-filter: blur(8px);
}
.p-code-pill { justify-self: center; padding: 0.4rem 1.1rem; border-radius: 999px; background: #fff; color: var(--ink); font-weight: 700; }
.p-code-pill b { font-family: var(--display); font-weight: 400; color: var(--red); letter-spacing: 0.15em; font-size: 1.3em; }
.p-err { margin: 0; min-height: 1.2em; text-align: center; color: var(--red-hi); font-weight: 700; }

/* ---------- in-game chrome ---------- */
.p-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 0; }
.p-me { display: flex; align-items: center; gap: 0.55rem; min-width: 0; font-weight: 800; }
.p-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-av {
  flex: none; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--red); box-shadow: 0 0 0 2px #fff; font-family: var(--display); font-size: 0.9rem;
}
.p-score { flex: none; padding: 0.35rem 0.85rem; border-radius: 999px; background: #fff; color: var(--ink); font-weight: 800; }
.p-score span { font-family: var(--display); font-weight: 400; font-size: 1.1em; }
.p-main { flex: 1; display: flex; flex-direction: column; }

.p-center { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 16px 0 28px; }
.p-center p { margin: 0; }
.p-h1 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 2.2rem; line-height: 1.05; }
.p-h1.big { font-size: 3.2rem; text-transform: uppercase; }
.p-emoji { font-size: 6rem; line-height: 1.1; filter: drop-shadow(0 10px 26px rgba(227, 18, 27, 0.6)); }
.p-big-av {
  display: grid; place-items: center; width: 120px; height: 120px; border-radius: 50%; font-family: var(--display); font-size: 3rem;
  background: var(--red); box-shadow: 0 0 0 6px #fff, 0 18px 46px rgba(227, 18, 27, 0.6);
}
.p-dots { display: flex; gap: 8px; }
.p-dots span { width: 12px; height: 12px; border-radius: 50%; background: #fff; animation: dot 1.2s ease-in-out infinite; }
.p-dots span:nth-child(2) { animation-delay: 0.15s; }
.p-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot { 0%, 100% { transform: translateY(0); opacity: 0.35; } 40% { transform: translateY(-10px); opacity: 1; background: var(--red-hi); } }

/* ---------- question ---------- */
.p-q { flex: 1; display: flex; flex-direction: column; gap: 14px; padding-bottom: 8px; }
.p-q-center { justify-content: center; gap: 26px; padding-bottom: 40px; }
.p-qnum { text-align: center; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.82rem; }
.p-prompt { margin: 0; text-align: center; font-weight: 900; font-size: 1.75rem; line-height: 1.15; }
.p-prompt.small { font-size: 1.15rem; font-weight: 800; line-height: 1.25; }
.p-qimg { align-self: center; max-height: 22vh; max-width: 100%; border-radius: 12px; background: rgba(255, 255, 255, 0.92); }
.p-meter .meter-pts { font-size: 2.3rem; }
.p-meter .meter-secs { width: 46px; height: 46px; font-size: 1.35rem; }
.p-meter .meter-track { height: 18px; }
.p-tiles { flex: 1; display: grid; gap: 12px; grid-auto-rows: minmax(64px, 1fr); }
.p-tiles .tile { width: 100%; font-size: 1.25rem; cursor: pointer; touch-action: manipulation; }
.p-tiles .tile:active { transform: scale(0.96); }
.p-locked .tile { min-width: min(320px, 85vw); font-size: 1.35rem; padding: 1.1em 1.2em; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5); }

/* ---------- reveal ---------- */
.p-result {
  flex: 1; margin-bottom: 8px; border-radius: 28px; padding: 28px 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center;
}
.p-result.good { background: radial-gradient(circle at 50% 20%, #33e384, #0b7a3e 75%); box-shadow: 0 20px 60px rgba(31, 203, 107, 0.35); }
.p-result.bad { background: linear-gradient(160deg, #26262d, #111115); border: 3px solid var(--red); animation: shake 0.45s both 0.15s; }
.p-result.none { background: linear-gradient(160deg, #26262d, #111115); border: 3px solid rgba(255, 255, 255, 0.25); }
.res-icon {
  display: grid; place-items: center; width: 110px; height: 110px; border-radius: 50%;
  background: #fff; color: var(--good-lo); font-size: 4rem; font-weight: 900; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
}
.bad .res-icon { color: var(--red); }
.none .res-icon { color: var(--ink); font-size: 3.4rem; }
.res-h { margin: 0; font-family: var(--display); font-weight: 400; font-size: 2.7rem; line-height: 1; }
.res-pts { font-family: var(--display); font-size: 4.6rem; line-height: 1; text-shadow: 0 6px 0 rgba(0, 0, 0, 0.2); }
.res-sub { opacity: 0.85; font-weight: 700; }
.streak { padding: 0.4rem 1rem; border-radius: 999px; background: #fff; color: var(--red); font-weight: 900; }
.res-answer { display: grid; gap: 8px; width: 100%; }
.res-answer > span { color: var(--muted); font-weight: 700; text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.08em; }
.res-answer .tile { font-size: 1.15rem; }
.res-standing { margin-top: 6px; font-size: 1.1rem; }
.res-standing b { font-family: var(--display); font-weight: 400; font-size: 1.2em; }

/* ---------- standings ---------- */
.p-rank { font-family: var(--display); font-size: 5.2rem; line-height: 1; text-shadow: 0 6px 0 var(--red-lo); }
.p-stats { display: flex; gap: 12px; }
.p-stats div { display: grid; padding: 12px 20px; border-radius: 18px; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); }
.p-stats b { font-family: var(--display); font-weight: 400; font-size: 1.9rem; }
.p-stats span { font-size: 0.8rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.p-top3 { display: grid; gap: 6px; width: 100%; }
.p-top-row { display: flex; gap: 10px; align-items: center; padding: 0.55rem 0.9rem; border-radius: 14px; background: rgba(22, 22, 27, 0.9); border: 1px solid var(--line); font-weight: 800; }
.p-top-row .nm { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-top-row b { font-family: var(--display); font-weight: 400; }

/* ---------- swim race ---------- */
.race-keys { font-size: 2rem; }
.p-race-pts { font-weight: 800; padding: 0.6rem 1rem; border-radius: 99px; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); }
.p-race { flex: 1; display: flex; flex-direction: column; gap: 10px; padding: 6px 0 18px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.p-race-top { display: flex; justify-content: space-between; gap: 8px; }
.p-lane {
  position: relative; padding: 12px 0; border-radius: 16px; border: 3px solid #fff; box-shadow: 0 0 0 3px var(--red);
  background: repeating-linear-gradient(100deg, rgba(255, 255, 255, 0.04) 0 26px, transparent 26px 60px), linear-gradient(180deg, #0f4c75, #0a3352);
}
.p-lane::before, .p-lane::after {
  content: ''; position: absolute; left: 0; right: 0; height: 4px; background: repeating-linear-gradient(90deg, var(--red) 0 12px, #fff 12px 24px);
}
.p-lane::before { top: 2px; }
.p-lane::after { bottom: 2px; }
.p-lane-water { position: relative; height: 46px; margin: 0 10px; border-right: 5px solid rgba(255, 255, 255, 0.85); font-size: 2rem; }
.p-race-dist { text-align: center; color: var(--muted); font-weight: 800; }
.p-race-dist span { font-family: var(--display); font-weight: 400; color: #fff; font-size: 1.6em; }
.p-race-call { min-height: 2.4em; display: grid; place-items: center; text-align: center; font-family: var(--display); text-transform: uppercase; font-size: 1.5rem; line-height: 1.1; }
.p-race-call.go { color: var(--gold); animation: popIn 0.35s both; }
.p-race-call.bad { color: var(--red-hi); }
.dpad {
  margin-top: auto; align-self: center; width: min(100%, 340px, 44vh, 44dvh); aspect-ratio: 1; touch-action: none;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 10px;
}
.dk {
  border: 0; border-radius: 22px; background: var(--panel-2); color: #fff; font-size: 2.8rem; font-weight: 900; line-height: 1;
  box-shadow: 0 6px 0 #000; touch-action: none; cursor: pointer; transition: background 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.dk:active { transform: translateY(4px); box-shadow: 0 2px 0 #000; }
.dk.up { grid-area: 1 / 2; }
.dk.left { grid-area: 2 / 1; }
.dk.right { grid-area: 2 / 3; }
.dk.down { grid-area: 3 / 2; }
.dk.next { background: var(--red); box-shadow: 0 6px 0 var(--red-lo), 0 0 26px rgba(227, 18, 27, 0.55); }
.dk-mid { grid-area: 2 / 2; display: grid; place-items: center; font-size: 2rem; opacity: 0.45; }
.dpad.off { opacity: 0.35; pointer-events: none; }
.dpad.splash { animation: shake 0.35s; }
.dpad.splash .dk.next { background: #3a3a44; box-shadow: 0 6px 0 #000; }

/* ---------- picture answers: 2 × 2 grid so four pictures fit on a phone ---------- */
.p-tiles:has(.tile-img) { grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(0, 1fr); }
.p-tiles .tile:has(.tile-img) { position: relative; padding: 8px; min-height: 0; }
.p-tiles .tile:has(.tile-img) .tile-letter { position: absolute; top: 8px; left: 8px; z-index: 1; width: 1.7em; height: 1.7em; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); }
.p-tiles .tile:has(.tile-img) .tile-body { align-self: stretch; display: flex; flex-direction: column; justify-content: center; min-height: 0; }
.p-tiles .tile-img { width: 100%; height: 100%; max-height: none; min-height: 0; object-fit: contain; }
.res-answer .tile-img { max-height: 20vh; max-width: 70%; }

/* sound on/off */
.p-top-r { flex: none; display: flex; align-items: center; gap: 8px; }
.p-snd {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07); font-size: 1rem; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
