/* ---- Phone page (index.html) ----
   Loaded after styles.css, whose older "Player / join page" and "Player clue
   picker" rules this supersedes (same selectors, later in the cascade). Shared
   tokens (--jeopardy-*) and .hidden / .error-text / .buzz-countdown still come
   from styles.css. */

html,
body {
  /* No pull-to-refresh / rubber-banding mid-game: it reloads the page and
     costs a student the clue. */
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh; /* 100vh is taller than the visible area under a mobile URL bar */
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.player-wrap {
  width: 100%;
  max-width: 30rem;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0.75rem 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.player-wrap h1 {
  max-width: 100%;
  margin: 0;
  font-size: clamp(1.05rem, 5vw, 1.4rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* :where() keeps this at zero specificity so the buzz button, picker chips and
   the like (which size themselves) still win. */
:where(.player-wrap) button {
  min-height: 44px;
  font-size: 1.05rem;
}

.player-wrap :focus-visible {
  outline: 3px solid var(--jeopardy-white);
  outline-offset: 2px;
}

/* >= 16px keeps iOS from zooming the page on focus (zooming is otherwise left
   enabled -- see the viewport meta). */
.player-wrap input[type="text"],
.player-wrap input[type="number"] {
  font-size: max(16px, 1.1rem);
  min-height: 48px;
  min-width: 0;
}

button.secondary {
  background: transparent;
  color: var(--jeopardy-white);
  border: 2px solid rgba(255, 255, 255, 0.55);
}

.connection-banner {
  width: 100%;
  margin: 0;
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  background: #a31515;
  color: #fff;
  font-weight: bold;
  text-align: center;
}

.screen {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.play-screen {
  gap: 0.75rem;
}

.view {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}

.player-wrap .status-line {
  margin: 0;
  min-height: 1.4em;
  font-size: 1.15rem;
}

/* ---- Join ---- */

.join-form {
  width: 100%;
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
}

.join-status {
  min-height: 1.6em;
}

.join-status.error-text {
  color: #ff9b9b;
}

.location-choice {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.location-choice legend {
  padding: 0;
  font-size: 0.95rem;
  opacity: 0.85;
  text-align: center;
}

.location-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

.location-option {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.4rem 0.95rem;
  border: 2px solid var(--jeopardy-gold);
  border-radius: 999px;
  cursor: pointer;
}

.location-option input {
  width: 1.2rem;
  height: 1.2rem;
  margin: 0;
  accent-color: var(--jeopardy-gold);
}

.location-option:has(input:checked) {
  background: var(--jeopardy-gold);
  color: var(--jeopardy-blue-dark);
  font-weight: bold;
}

.how-to-play {
  margin: 0.5rem 0 0;
}

.how-to-play a {
  display: inline-block;
  padding: 0.6rem 0.4rem;
  color: var(--jeopardy-gold);
}

/* ---- Score row ---- */

.score-row {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

.score-line {
  font-size: 1.35rem;
  font-weight: bold;
  color: var(--jeopardy-gold);
}

.rank-line {
  font-size: 1.05rem;
  opacity: 0.9;
}

.score-toast {
  position: absolute;
  left: 0;
  top: calc(100% + 0.1rem);
  z-index: 3;
  padding: 0.05rem 0.75rem;
  border: 2px solid currentColor;
  border-radius: 999px;
  background: var(--jeopardy-blue-dark);
  font-size: 1.4rem;
  font-weight: bold;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
}

.score-toast.gain {
  color: #6dff6d;
}

.score-toast.loss {
  color: #ff8a8a;
}

.score-toast.show {
  animation: toast-rise 2.4s ease-out forwards;
}

@keyframes toast-rise {
  0% { opacity: 0; transform: translateY(0.6rem) scale(0.8); }
  12% { opacity: 1; transform: translateY(0) scale(1.12); }
  24% { transform: translateY(0) scale(1); }
  78% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-0.4rem) scale(1); }
}

.location-prompt {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem;
  border: 2px dashed var(--jeopardy-gold);
  border-radius: 12px;
}

/* ---- Buzz view ---- */

.buzz-view {
  gap: 0.6rem;
}

/* Nothing on the buzz screen is meant to be selected. A long press or a quick
   double tap used to highlight text (the BUZZ label, the status line, the
   clue); on iOS the next taps then went to the selection handles instead of
   the button. The clue box still scrolls -- this only stops selection. */
.buzz-view,
.buzz-view * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* The clue lives in a fixed-height, scrolling box so a long clue (or one with a
   picture) can never push BUZZ around: its position is the same on every clue. */
.clue-area {
  width: 100%;
  height: clamp(6.5rem, 22dvh, 13rem);
  padding: 0.6rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow: hidden;
  border-radius: 12px;
  background: var(--jeopardy-blue);
}

.clue-area.empty {
  background: rgba(6, 12, 233, 0.18);
}

.clue-meta {
  margin: 0;
  min-height: 1.1em;
  font-size: 0.8rem;
  font-weight: bold;
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  color: var(--jeopardy-gold);
}

.clue-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  text-align: center;
}

/* A hint of fade where a long clue runs off the bottom of its box (player.js
   sets .more-below only while there's actually more to scroll to). */
.buzz-view .clue-scroll.more-below {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 1.1rem), transparent);
  mask-image: linear-gradient(to bottom, #000 calc(100% - 1.1rem), transparent);
}

.clue-scroll .player-clue-text,
.final-clue-area .player-clue-text {
  padding: 0;
  border-radius: 0;
  background: none;
  font-size: clamp(1rem, 4.4vw, 1.3rem);
  line-height: 1.3;
}

.final-clue-area {
  height: auto;
  max-height: 45dvh;
  min-height: 6.5rem;
}

.clue-image-btn {
  display: block;
  margin: 0 auto 0.5rem;
  padding: 0;
  background: none;
  color: inherit;
  font-weight: normal;
}

.clue-image-btn img {
  display: block;
  max-width: 100%;
  max-height: min(9rem, 22dvh);
  margin: 0 auto;
  object-fit: contain;
  border-radius: 8px;
}

/* With a picture, the box is too short to stack it above the words: put them
   side by side so the clue text stays on screen. */
.clue-scroll.with-image {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  text-align: left;
}

.clue-scroll.with-image .clue-image-btn {
  flex: 0 0 38%;
  margin: 0;
}

.clue-scroll.with-image .clue-image-btn img {
  width: 100%;
  max-height: min(7.5rem, 18dvh);
}

.clue-scroll.with-image .player-clue-text {
  flex: 1 1 0;
  min-width: 0;
}

.clue-image-hint {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  opacity: 0.75;
}

/* Two lines tall always, so a 1-line "Buzz in!" and a 2-line "You already
   answered — wait for the next clue." don't shift BUZZ. */
#status-line {
  min-height: 2.8em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.buzz-stack {
  --size: min(70vw, 55dvh, 300px);
  width: 100%;
  /* The area around BUZZ takes the near-misses: no double-tap zoom or tap flash. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.buzz-stack .buzz-countdown {
  width: var(--size);
  margin: 0;
}

.buzz-btn {
  width: var(--size, min(70vw, 55dvh, 300px));
  height: var(--size, min(70vw, 55dvh, 300px));
  aspect-ratio: 1;
  margin-bottom: 8px; /* room for the 3D shadow below */
  padding: 0;
  border-radius: 50%;
  font-size: clamp(1.6rem, 9vw, 2.4rem);
  line-height: 1.05;
  letter-spacing: 0.04em;
  background: radial-gradient(circle at 35% 30%, #ff3333, #b30000);
  color: #fff;
  box-shadow: 0 8px 0 #7a0000;
  /* A button you hammer with a thumb mustn't zoom, select text, pop a callout
     or flash a tap highlight. */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.buzz-btn[data-look="ready"] {
  animation: ready-pulse 1.4s ease-in-out infinite;
}

/* Sink the instant the thumb lands, before the server has said anything. */
.buzz-btn[data-look="ready"]:active {
  animation: none;
  transform: translateY(6px);
  box-shadow: 0 2px 0 #7a0000;
}

@keyframes ready-pulse {
  0%, 100% { box-shadow: 0 8px 0 #7a0000, 0 0 0 0 rgba(255, 90, 90, 0.6); }
  50% { box-shadow: 0 8px 0 #7a0000, 0 0 0 14px rgba(255, 90, 90, 0); }
}

/* Not pressable. Three distinct reasons, three distinct looks (and labels, so
   colour alone doesn't carry it): not open yet, waiting out another location's
   head-start, locked out of this clue. */
.buzz-btn:disabled {
  opacity: 1;
  background: #3b3b4f;
  color: #c9c9d6;
  box-shadow: 0 8px 0 #1e1e2a;
}

/* The clue is still being read: grey like a dead button, but it takes presses
   (an early press counts if the buzzers open within a beat -- see
   player-buzz.js), so it sinks under the thumb like the live one. */
.buzz-btn[data-look="waiting"],
.buzz-btn[data-look="armed"],
.buzz-btn[data-look="early"] {
  background: #3b3b4f;
  color: #c9c9d6;
  box-shadow: 0 8px 0 #1e1e2a;
}

.buzz-btn[data-look="waiting"]:active,
.buzz-btn[data-look="armed"] {
  transform: translateY(6px);
  box-shadow: 0 2px 0 #1e1e2a;
}

/* Mashed during the read: locked for a beat. */
.buzz-btn[data-look="early"] {
  color: #ffcf7a;
}

.buzz-btn[data-look="held"]:disabled {
  background: radial-gradient(circle at 35% 30%, #c79a1a, #6b4f00);
  color: #fff3c4;
  box-shadow: 0 8px 0 #3d2d00;
}

.buzz-btn[data-look="out"]:disabled {
  background: #2a1f2a;
  color: #ff9b9b;
  font-size: clamp(1.3rem, 7vw, 1.9rem);
  box-shadow: 0 8px 0 #130d13, inset 0 0 0 5px #b30000;
}

.buzz-btn.buzzed-in,
.buzz-btn.buzzed-in:disabled {
  background: radial-gradient(circle at 35% 30%, #33dd33, #1a8f1a);
  color: #fff;
  transform: translateY(6px);
  box-shadow: 0 2px 0 #0d5c0d;
}

/* ---- Picker ---- */

.picker-view {
  gap: 0.6rem;
}

.picker-board {
  width: 100%;
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 21rem), 1fr));
}

.picker-cat {
  padding: 0.55rem 0.6rem 0.65rem;
  border-radius: 12px;
  background: rgba(6, 12, 233, 0.28);
}

.picker-cat-name {
  margin: 0 0 0.45rem;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.2;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.picker-cat-clues {
  display: grid;
  grid-template-columns: repeat(var(--n, 5), minmax(0, 1fr));
  gap: 0.4rem;
  /* Lets the chips size their text off the card they sit in (cqi below). */
  container-type: inline-size;
}

.picker-cat-clues .picker-chip {
  min-height: 48px;
}

.picker-chip {
  min-width: 0;
  width: 100%;
  padding: 0.3rem 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--jeopardy-blue);
  color: var(--jeopardy-gold);
  font-size: 0.85rem;
  /* A fifth of the card, less its gaps, divided by the widest label's width in
     em (~0.66 per character) -- see --chars in player-picker.js. */
  font-size: min(1.05rem, calc((20cqi - 0.6rem) / (var(--chars, 6) * 0.66)));
  font-weight: bold;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

.picker-chip:disabled {
  background: var(--jeopardy-blue);
  color: var(--jeopardy-gold);
  opacity: 0.55;
}

.picker-chip.selected,
.picker-chip.selected:disabled {
  background: var(--jeopardy-gold);
  color: var(--jeopardy-blue-dark);
  border-color: var(--jeopardy-white);
  opacity: 1;
}

.picker-chip.answered {
  background: var(--answered-gray);
  color: #555;
  opacity: 0.5;
}

.picker-confirm {
  position: sticky;
  bottom: 0;
  z-index: 5;
  width: calc(100% + 2rem);
  margin: 0 -1rem;
  padding: 0.6rem 1rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: var(--jeopardy-blue-dark);
  border-top: 2px solid var(--jeopardy-gold);
}

.picker-confirm-text {
  flex: 1 1 9rem;
  font-size: 1.05rem;
  font-weight: bold;
  text-align: center;
}

/* ---- Daily Double / Final Jeopardy ---- */

.wager-form {
  width: 100%;
  max-width: 26rem;
  display: flex;
  gap: 0.6rem;
}

.wager-form input {
  flex: 1;
}

.wager-form button {
  flex: none;
}

.form-message {
  margin: 0;
  min-height: 1.3em;
  font-weight: bold;
  text-align: center;
}

.form-message.error {
  color: #ff9b9b;
}

.nudge {
  color: var(--jeopardy-gold);
  font-weight: bold;
}

.view .player-clue-text {
  font-family: Georgia, 'Times New Roman', serif;
}

.final-results-detail {
  opacity: 0.85;
  font-size: 1rem;
}

.game-over-view {
  gap: 0.4rem;
}

.medal {
  margin: 0;
  font-size: 4.5rem;
  line-height: 1;
}

.game-over-line {
  margin: 0;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.7rem;
  font-weight: bold;
  text-align: center;
  color: var(--jeopardy-gold);
}

/* ---- Image overlay ---- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3.75rem 1rem 1rem;
  background: rgba(0, 0, 0, 0.92);
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: calc(0.75rem + env(safe-area-inset-top, 0px));
  right: 0.75rem;
  min-width: 44px;
}

/* ---- Landscape phone: everything on one screen, no scrolling ---- */

@media (orientation: landscape) and (max-height: 520px) {
  .player-wrap {
    max-width: 60rem;
    padding: 0.4rem 1rem 0.6rem;
    gap: 0.4rem;
  }

  .player-wrap h1 {
    font-size: 1rem;
  }

  .score-line {
    font-size: 1.15rem;
  }

  .buzz-view {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "clue buzz"
      "status buzz";
    grid-template-rows: auto 1fr;
    align-items: start;
    column-gap: 1.25rem;
    row-gap: 0.4rem;
  }

  .clue-area {
    grid-area: clue;
    height: auto;
    min-height: 5rem;
    max-height: calc(100dvh - 11rem);
  }

  #status-line {
    grid-area: status;
    align-self: start;
  }

  .buzz-stack {
    grid-area: buzz;
    width: auto;
    align-self: center;
  }

  .clue-image-btn img {
    max-height: 6rem;
  }

  .medal {
    font-size: 3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .buzz-btn[data-look="ready"] {
    animation: none;
  }

  .score-toast.show {
    animation: toast-fade 2.4s linear forwards;
  }
}

@keyframes toast-fade {
  0%, 85% { opacity: 1; }
  100% { opacity: 0; }
}
