/* Word Rain – only what's specific to this game.
   Header, difficulty toggle and buttons come from /css/style.css. */

.wr-layout {
  gap: 18px;
}

/* ---------- HUD ---------- */

.wr-hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 28px;
}

.wr-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 56px;
}

.wr-stat-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.wr-lives {
  display: flex;
  gap: 4px;
  height: 33px;
  align-items: center;
}

.wr-heart {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.wr-heart.is-lost {
  color: var(--border-strong);
}

/* ---------- Playing field ---------- */

/* A rainy evening sky, in the game's colour */
.wr-field {
  --sky-top: color-mix(in srgb, var(--game, #6cb6ff) 14%, #10141f);
  --sky-bottom: color-mix(in srgb, var(--game, #6cb6ff) 26%, #151b29);
  --rain: rgba(190, 215, 255, 0.10);
  --puddle: color-mix(in srgb, var(--game, #6cb6ff) 45%, #1b2436);
  position: relative;
  width: min(100%, 760px);
  height: min(56vh, 460px);
  min-height: 300px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
}

:root[data-theme="light"] .wr-field {
  --sky-top: color-mix(in srgb, var(--game, #6cb6ff) 16%, #f4f8fc);
  --sky-bottom: color-mix(in srgb, var(--game, #6cb6ff) 32%, #eaf2fa);
  --rain: rgba(40, 90, 150, 0.10);
  --puddle: color-mix(in srgb, var(--game, #6cb6ff) 55%, #ffffff);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .wr-field {
    --sky-top: color-mix(in srgb, var(--game, #6cb6ff) 16%, #f4f8fc);
    --sky-bottom: color-mix(in srgb, var(--game, #6cb6ff) 32%, #eaf2fa);
    --rain: rgba(40, 90, 150, 0.10);
    --puddle: color-mix(in srgb, var(--game, #6cb6ff) 55%, #ffffff);
  }
}

/* Thin streaks of rain drifting down behind the words */
.wr-field::before {
  content: "";
  position: absolute;
  inset: -40px 0 0;
  background: repeating-linear-gradient(105deg, transparent 0 22px, var(--rain) 22px 23px, transparent 23px 47px);
  background-size: 140px 140px;
  animation: wr-rain 1.4s linear infinite;
  pointer-events: none;
}

@keyframes wr-rain {
  to { background-position: -38px 140px; }
}

.wr-words {
  position: absolute;
  inset: 0;
}

.wr-word {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  color: var(--text);
  transition: border-color 150ms, box-shadow 150ms, transform 150ms;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  will-change: translate;
}

.wr-word .typed {
  color: var(--accent);
}

/* The word you're typing: lit up, a touch bigger, in front */
.wr-word.is-target {
  z-index: 2;
  border-color: var(--accent-fill);
  box-shadow: 0 0 0 3px var(--accent-soft), 0 6px 16px rgba(0, 0, 0, 0.22);
  transform: scale(1.08);
}

/* Nearly on the ground */
.wr-word.is-low:not(.is-target) {
  border-color: color-mix(in srgb, var(--danger) 60%, transparent);
}

.wr-word.is-miss {
  border-color: var(--danger);
  animation: shake 160ms;
}

.wr-word.is-cleared {
  border-color: var(--accent);
  background: var(--accent-soft);
  animation: pop 220ms ease-out forwards;
}

.wr-word.is-dropped {
  border-color: var(--danger);
  color: var(--danger);
  animation: fade 300ms ease-out forwards;
}

.wr-points {
  position: absolute;
  top: 0;
  left: 0;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  pointer-events: none;
  animation: float-up 600ms ease-out forwards;
}

/* The puddle at the bottom */
.wr-ground {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 10px;
  background: linear-gradient(transparent, var(--puddle));
  border-top: 2px solid color-mix(in srgb, var(--puddle) 70%, var(--text));
  transition: background-color 200ms, border-color 200ms;
}

.wr-ground.is-hit {
  border-top-color: var(--danger);
  background: linear-gradient(transparent, color-mix(in srgb, var(--danger) 55%, transparent));
}

/* Droplets when you clear a word */
.wr-drop {
  position: absolute;
  z-index: 3;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50% 50% 50% 0;
  background: var(--accent-fill);
  pointer-events: none;
  animation: wr-drop 560ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes wr-drop {
  to {
    transform: translate(var(--dx), var(--dy)) scale(0.4);
    opacity: 0;
  }
}

/* A ripple where a word hit the puddle */
.wr-ripple {
  position: absolute;
  bottom: 2px;
  z-index: 1;
  width: 16px;
  height: 6px;
  margin-left: -8px;
  border-radius: 50%;
  border: 2px solid var(--danger);
  pointer-events: none;
  animation: wr-ripple 650ms ease-out forwards;
}

@keyframes wr-ripple {
  to {
    transform: scale(5);
    opacity: 0;
  }
}

/* ---------- Overlays (start / pause / end) ---------- */

.wr-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  background: var(--overlay);
  text-align: center;
}

.wr-overlay-light {
  background: var(--overlay-light);
  pointer-events: none;
}

.wr-count {
  margin: 0;
  font-family: var(--font-display);
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  animation: count-pop 600ms ease-out;
}

.wr-count.is-go {
  color: var(--accent);
}

@keyframes count-pop {
  from { transform: scale(1.4); opacity: 0; }
  30%  { transform: scale(1); opacity: 1; }
  to   { transform: scale(1); opacity: 1; }
}

.wr-overlay-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
}

.wr-themes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 520px;
}

.wr-start {
  min-width: 160px;
}

.wr-end-score {
  margin: 0;
  font-family: var(--font-display);
  font-size: 56px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.wr-new-best {
  margin: -6px 0 0;
  color: var(--accent);
  font-weight: 700;
}

.wr-end-stats {
  display: flex;
  gap: 28px;
  margin: 0;
}

.wr-end-stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.wr-end-stats dt {
  color: var(--text-muted);
  font-size: 13px;
}

.wr-end-stats dd {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}

kbd {
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  font-family: var(--font-body);
  font-size: 12px;
}

/* ---------- Typing input ---------- */

/* Invisible but focusable, so phones show their keyboard.
   16px font stops iPhones zooming in when it's focused. */
.wr-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px;
  pointer-events: none;
}

.wr-hint {
  margin: 0;
}

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

/* ---------- 1v1 race (inside a room) ---------- */

.wrr-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: min(100%, 560px);
  padding: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
}

.wrr-setup[hidden],
.wrr-race[hidden] {
  display: none;
}

.wrr-setup .chip:disabled,
.wrr-setup .segmented button:disabled {
  cursor: default;
}

.wrr-setup .chip:disabled:not([aria-pressed="true"]) {
  opacity: 0.55;
}

/* Your field on the left, friend's mini field on the right */
.wrr-race {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 20px;
  width: min(100%, 1040px);
  align-items: start;
}

.wrr-me {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.wrr-me .wr-field {
  width: 100%;
}

.wrr-friend {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wrr-friend-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  min-height: 56px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}

.wrr-friend-name {
  font-weight: 600;
}

.wrr-friend-score {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.wrr-friend-bar .wr-lives {
  height: auto;
}

.wrr-friend-bar .wr-heart {
  width: 12px;
  height: 12px;
}

.wrr-lead {
  margin-left: auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.wrr-lead[data-tone="good"] {
  color: var(--accent);
}

.wrr-lead[data-tone="bad"] {
  color: var(--danger);
}

/* The mini field: same rain, smaller */
.wrr-mini.wr-field {
  width: 100%;
  height: 300px;
  min-height: 0;
}

.wrr-mini .wr-word {
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 11px;
}

.wrr-mini .wr-ground {
  height: 2px;
}

.wrr-result-score {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0;
  font-family: var(--font-display);
  font-size: 48px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.wrr-dash {
  color: var(--text-faint);
}

.wrr-result-names {
  display: flex;
  gap: 64px;
  margin: -6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

[data-result-title][data-tone="good"] {
  color: var(--accent);
}

/* Phones and narrow windows: friend becomes a bar above your field */
@media (max-width: 860px) {
  .wrr-race {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  .wrr-friend {
    order: -1;
  }
  .wrr-mini.wr-field {
    display: none;
  }
}

/* ---------- Animations ---------- */

/* Words are positioned with the `translate` property, so these
   animations can use `transform` without moving them. */
@keyframes pop {
  to { transform: scale(1.25); opacity: 0; }
}

@keyframes fade {
  to { opacity: 0; }
}

@keyframes shake {
  25% { margin-left: -4px; }
  75% { margin-left: 4px; }
}

@keyframes float-up {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-28px); }
}

@media (prefers-reduced-motion: reduce) {
  .wr-word.is-miss,
  .wr-word.is-cleared,
  .wr-word.is-dropped,
  .wr-points,
  .wr-count,
  .wr-drop,
  .wr-ripple {
    animation-duration: 1ms;
  }
  .wr-field::before {
    animation: none;
  }
}

@media (max-width: 560px) {
  .wr-hud {
    flex-wrap: nowrap;
    gap: 10px;
  }
  .wr-stat {
    min-width: 0;
  }
  .wr-stat-value {
    font-size: 18px;
  }
  .wr-lives {
    gap: 2px;
    height: 27px;
  }
  .wr-heart {
    width: 12px;
    height: 12px;
  }
  .wr-word {
    font-size: 16px;
  }
  .wr-hint {
    display: none;
  }
}

/* Phone held sideways: fit the screen height (see css/style.css) */
@media (orientation: landscape) and (max-height: 540px) {
  .wr-field { width: var(--play-w); height: var(--play-h); min-height: 0; }
}
@media (orientation: landscape) and (max-height: 540px) {
  :root { --land-side: 236px; }
}
@media (orientation: landscape) and (max-height: 540px) {
  .wr-overlay { overflow-y: auto; justify-content: safe center; padding-top: 14px; padding-bottom: 14px; }
  .wr-overlay > * { flex-shrink: 0; }
}
/* With friends, phone held sideways */
@media (orientation: landscape) and (max-height: 540px) {
  .wrr-race { --play-h: calc(100dvh - 196px); }
  .wrr-me .wr-field { height: var(--play-h); min-height: 0; }
}
