/* duel.css -- duel-specific chrome only. Word list, caret, travel-bar fill,
   focus overlay and hidden input reuse test.css's classes unchanged (both
   files are loaded together on /duel/{id}) so the race surface looks and
   behaves identically to the solo test screen the student already knows. */

.duel-page {
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  max-width: 860px;
  margin: 4vh auto 0;
}

.duel-lobby {
  background: var(--plate);
  border: 1px solid transparent;
  border-radius: var(--r-lg);
  padding: var(--s-12) var(--s-8);
  box-shadow: var(--e-1);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-4);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

/* Opponent is ready and it's your move -- the whole card gets an attention
   ring rather than relying on the status line alone (frontend-ux ask). */
.duel-lobby--opponent-ready:not(.duel-lobby--me-ready) {
  border-color: rgb(242 179 61 / 0.5);
  box-shadow: var(--e-1), 0 0 0 3px rgb(242 179 61 / 0.12);
}

.duel-lobby.is-pinging { animation: lobby-ping 700ms var(--ease); }

@keyframes lobby-ping {
  0% { box-shadow: var(--e-1), 0 0 0 0 rgb(242 179 61 / 0.5); }
  60% { box-shadow: var(--e-1), 0 0 0 10px rgb(242 179 61 / 0); }
  100% { box-shadow: var(--e-1), 0 0 0 0 rgb(242 179 61 / 0); }
}

.duel-lobby__room {
  background: var(--housing);
  border: 1px dashed var(--plate-hi);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  width: 100%;
}

.duel-lobby__room-label {
  color: var(--muted);
  font-size: var(--t-xs);
  margin-bottom: var(--s-2);
}

.duel-lobby__room-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
}

.duel-lobby__room-value {
  font-family: var(--f-mono);
  font-size: var(--t-xl);
  letter-spacing: 0.25em;
  color: var(--hit);
}

.duel-lobby__vs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-6);
  width: 100%;
}

.duel-lobby__side {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-4);
  border-radius: var(--r-md);
  background: var(--housing);
  border: 1px solid var(--plate-hi);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.duel-lobby__side--is-ready {
  border-color: rgb(94 224 192 / 0.5);
  background: rgb(94 224 192 / 0.06);
}

.duel-lobby__vs-label {
  font-family: var(--f-display);
  color: var(--muted);
  font-size: var(--t-sm);
  flex-shrink: 0;
}

.duel-lobby__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

.duel-lobby__dot--ready {
  background: var(--pace);
  box-shadow: 0 0 0 4px rgb(94 224 192 / 0.18);
}

.duel-lobby__side-name {
  font-family: var(--f-display);
  font-size: var(--t-md);
  color: var(--legend);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.duel-lobby__pill {
  font-size: var(--t-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.duel-lobby__pill--ready { color: var(--pace); font-weight: 600; }

.duel-lobby__status {
  color: var(--muted);
  font-size: var(--t-sm);
  min-height: 1.4em;
}

.duel-lobby__rule {
  color: var(--muted);
  font-size: var(--t-xs);
  margin-top: var(--s-2);
}

/* Live accuracy readout dips below the ADR-011 win floor -- a quiet color
   cue rather than only a number, since the number itself is easy to glance
   past mid-race. */
#duelLiveAccuracy.is-below-floor { color: var(--miss); }

.duel-finished-banner {
  text-align: center;
  color: var(--hit);
  font-size: var(--t-sm);
  background: rgb(242 179 61 / 0.1);
  border: 1px solid rgb(242 179 61 / 0.3);
  border-radius: var(--r-md);
  padding: var(--s-3);
  margin-bottom: var(--s-4);
}

/* It's your move: opponent is ready and waiting, or the race just started. */
.duel-lobby__status.match-status--urgent {
  color: var(--hit);
  font-weight: 600;
}

.duel-countdown {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 220px;
}

.duel-countdown__number {
  font-family: var(--f-display);
  font-size: clamp(4rem, 14vw, 8rem);
  color: var(--hit);
  line-height: 1;
}

.duel-race__bars {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  margin-top: var(--s-6);
}

.duel-bar {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.duel-bar__label {
  width: 140px;
  flex-shrink: 0;
  font-size: var(--t-xs);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.duel-bar__track {
  flex: 1;
  height: 10px;
  background: var(--housing);
  border-radius: 5px;
  overflow: hidden;
}

.duel-bar__fill {
  height: 100%;
  width: 100%;
  border-radius: 5px;
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform var(--dur) var(--ease);
}

.duel-bar--me .duel-bar__fill { background: var(--hit); }
.duel-bar--opponent .duel-bar__fill { background: var(--pace); }

/* Graceful cutoff: shown over the still-visible race surface for a beat
   before the result panel replaces it, instead of an instant hide. */
/* Visibility is driven by the [hidden] attribute, same as every other panel
   on this page (not the .test-surface__overlay--visible class the focus
   overlay uses) -- :not([hidden]) has to out-specificity test.css's base
   .test-surface__overlay{display:none} for that to actually take effect.
   .is-visible below only owns the fade transition on top of that. */
.duel-cutoff-overlay:not([hidden]) {
  display: flex;
}

.duel-cutoff-overlay {
  background: rgb(16 20 26 / 0.82);
  opacity: 0;
  transition: opacity 300ms var(--ease);
}

.duel-cutoff-overlay.is-visible { opacity: 1; }

.duel-cutoff-overlay__text {
  font-family: var(--f-display);
  font-size: var(--t-lg);
  color: var(--legend);
  text-align: center;
  padding: 0 var(--s-8);
}

.duel-result {
  position: relative;
  background: var(--plate);
  border-radius: var(--r-lg);
  padding: var(--s-12) var(--s-8);
  box-shadow: var(--e-1);
  text-align: center;
  overflow: hidden;
  opacity: 0;
  transform: translateY(8px) scale(0.98);
}

.duel-result.is-visible {
  animation: duel-result-in 420ms var(--ease) forwards;
}

@keyframes duel-result-in {
  0% { opacity: 0; transform: translateY(8px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.duel-result__burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 30%, rgb(94 224 192 / 0.28), rgb(94 224 192 / 0) 60%);
  opacity: 0;
}

.duel-result--win .duel-result__burst { animation: duel-burst 900ms var(--ease); }

@keyframes duel-burst {
  0% { opacity: 0; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1.05); }
  100% { opacity: 0; transform: scale(1.15); }
}

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

.duel-result__confetti span {
  position: absolute;
  top: -10px;
  width: 7px;
  height: 12px;
  border-radius: 2px;
  opacity: 0;
}

.duel-result--win .duel-result__confetti span { animation: duel-confetti-fall 1100ms var(--ease) forwards; }

@keyframes duel-confetti-fall {
  0% { opacity: 1; transform: translateY(0) rotate(0deg); }
  100% { opacity: 0; transform: translateY(160px) rotate(200deg); }
}

.duel-result__headline {
  position: relative;
  font-family: var(--f-display);
  font-size: var(--t-2xl);
  margin-bottom: var(--s-6);
}

.duel-result--win .duel-result__headline { color: var(--pace); animation: duel-headline-pop 480ms var(--ease); }
.duel-result--loss .duel-result__headline { color: var(--muted); }

@keyframes duel-headline-pop {
  0% { transform: scale(0.9); }
  55% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* "Back to the bracket in Ns" -- sits between the headline and the actions,
   above them in the stacking order so the confetti falls behind it. */
.duel-result__sub {
  position: relative;
  color: var(--muted);
  font-size: var(--t-sm);
  margin: calc(-1 * var(--s-4)) 0 var(--s-4);
}

.duel-result__actions { position: relative; display: flex; justify-content: center; gap: var(--s-3); flex-wrap: wrap; }

/* ---------- lobby page (create / join) ---------- */

.duel-entry {
  display: flex;
  flex-direction: column;
  gap: var(--s-6);
  max-width: 480px;
  margin: 8vh auto 0;
}

.duel-entry__card {
  background: var(--plate);
  border-radius: var(--r-lg);
  padding: var(--s-8);
  box-shadow: var(--e-1);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.duel-entry__card h2 {
  font-family: var(--f-display);
  font-size: var(--t-lg);
  color: var(--legend);
}

.duel-entry__card input[type="text"] {
  background: var(--housing);
  border: 1px solid var(--plate-hi);
  border-radius: var(--r-md);
  padding: var(--s-3);
  color: var(--legend);
  font-family: var(--f-mono);
  font-size: var(--t-md);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.duel-entry__error { color: var(--miss); font-size: var(--t-sm); min-height: 1.2em; }

/* ---------- matchmaking radar ----------
   A sweep over concentric rings: it reads as "actively looking" rather than
   as a generic spinner, and it's pure CSS transform/opacity so it composites
   on the GPU and costs nothing while the page also polls. */

.duel-find { position: relative; }

.duel-radar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) 0 var(--s-2);
}

.duel-radar[hidden] { display: none; }

.duel-radar__scope {
  position: relative;
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
}

.duel-radar__ring,
.duel-radar__core,
.duel-radar__sweep {
  position: absolute;
  border-radius: 50%;
}

.duel-radar__ring {
  width: 100%;
  height: 100%;
  border: 1px solid rgb(94 224 192 / 0.30);
  animation: radar-pulse 2.4s var(--ease) infinite;
}

.duel-radar__ring--2 { animation-delay: 0.8s; }
.duel-radar__ring--3 { animation-delay: 1.6s; }

@keyframes radar-pulse {
  0% { transform: scale(0.32); opacity: 0; }
  25% { opacity: 0.9; }
  100% { transform: scale(1); opacity: 0; }
}

/* The sweep is a conic wedge rotating once per 2s -- the "scanning" cue. */
.duel-radar__sweep {
  width: 100%;
  height: 100%;
  background: conic-gradient(from 0deg, rgb(94 224 192 / 0.28), rgb(94 224 192 / 0) 70deg);
  animation: radar-sweep 2s linear infinite;
}

@keyframes radar-sweep {
  to { transform: rotate(360deg); }
}

.duel-radar__core {
  width: 14px;
  height: 14px;
  background: var(--pace);
  box-shadow: 0 0 0 6px rgb(94 224 192 / 0.16);
}

.duel-radar__status {
  margin: 0;
  font-family: var(--f-display);
  color: var(--legend);
  font-size: var(--t-md);
}

.duel-radar__meta {
  margin: 0;
  color: var(--muted);
  font-size: var(--t-xs);
  font-variant-numeric: tabular-nums;
  min-height: 1.2em;
}

/* Found: the sweep stops, everything snaps to amber for a beat before the
   redirect, so the match registers as an event rather than a page jump. */
.duel-radar.is-found .duel-radar__sweep { animation: none; opacity: 0; }
.duel-radar.is-found .duel-radar__ring { animation: radar-found 420ms var(--ease) forwards; border-color: var(--hit); }
.duel-radar.is-found .duel-radar__core { background: var(--hit); box-shadow: 0 0 0 10px rgb(242 179 61 / 0.22); }
.duel-radar.is-found .duel-radar__status { color: var(--hit); }

@keyframes radar-found {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(1); opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .duel-radar__ring,
  .duel-radar__sweep { animation: none; }
  .duel-radar__sweep { opacity: 0.25; }
  .duel-radar__ring { opacity: 0.5; }
}

/* ---------- win record + mini rankings on the lobby ---------- */

.duel-record__line {
  font-family: var(--f-display);
  font-size: var(--t-2xl);
  margin: 0;
  line-height: 1;
}

.duel-record__line strong { color: var(--pace); font-weight: 700; }
.duel-record__line .duel-record__loss { color: var(--muted); }

.duel-record__wl {
  font-size: var(--t-sm);
  color: var(--muted);
  margin-left: 2px;
}

.duel-record__sep { color: var(--muted); margin: 0 var(--s-2); }

.duel-record__meta {
  color: var(--muted);
  font-size: var(--t-sm);
  margin: var(--s-2) 0 0;
}

.duel-top {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.duel-top__row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-1) var(--s-2);
  border-radius: var(--r-sm);
  font-size: var(--t-sm);
}

.duel-top__row.is-me { background: rgb(94 224 192 / 0.10); color: var(--pace); }

.duel-top__rank {
  width: 14px;
  color: var(--muted);
  font-size: var(--t-xs);
  text-align: right;
}

.duel-top__name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.duel-top__wins { font-family: var(--f-display); }

.duel-record .btn { align-self: flex-start; margin-top: var(--s-3); }

@media (prefers-reduced-motion: reduce) {
  .duel-bar__fill,
  .duel-lobby,
  .duel-lobby__side,
  .duel-lobby__dot,
  .duel-cutoff-overlay { transition: none; }

  .duel-lobby.is-pinging,
  .duel-result.is-visible,
  .duel-result__burst,
  .duel-result__confetti span,
  .duel-result--win .duel-result__headline {
    animation: none;
  }

  .duel-result.is-visible { opacity: 1; transform: none; }
}

/* ---------- "your run is in, waiting on your opponent" ----------
   Deliberately OUTSIDE .test-surface (see duel.php): the focus veil covers
   that box, and this panel exists precisely because the veil used to frost
   the message explaining what was happening -- reported as "I don't know if
   I'm paused or waiting or whatever". */
.duel-wait {
  margin-top: var(--s-6);
  padding: var(--s-6);
  border: 1px solid var(--plate-hi);
  border-radius: var(--r-lg);
  background: var(--plate);
  text-align: center;
}
.duel-wait__spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--plate-hi);
  border-top-color: var(--pace);
  animation: duel-wait-spin 900ms linear infinite;
  margin-bottom: var(--s-3);
}
@keyframes duel-wait-spin { to { transform: rotate(360deg); } }

.duel-wait__title {
  margin: 0 0 var(--s-2);
  color: var(--pace);
  font-family: var(--f-display);
  font-size: var(--t-lg);
}
.duel-wait__body {
  margin: 0;
  color: var(--muted);
  font-size: var(--t-sm);
  max-width: 46ch;
  margin-inline: auto;
}
.duel-wait #duelWaitAd { margin-top: var(--s-6); }

@media (prefers-reduced-motion: reduce) {
  .duel-wait__spinner { animation: none; }
}
