:root {
  color-scheme: dark;
  --ink: #fdf8ff;
  --muted: rgba(253, 248, 255, 0.62);
  --bg1: #180b3c;
  --bg2: #341277;
  --card: rgba(255, 255, 255, 0.07);
  --card-line: rgba(255, 255, 255, 0.14);
  --pink: #ff4d8d;
  --violet: #8b5cf6;
  --cyan: #22d3ee;
  --amber: #fbbf24;
  --green: #34d399;
  --red: #fb7185;
  --shadow: 0 18px 44px rgba(8, 2, 28, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--ink);
  font-family: "Fredoka", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  background:
    radial-gradient(900px 480px at 12% -8%, rgba(255, 77, 141, 0.32), transparent 60%),
    radial-gradient(820px 520px at 95% 4%, rgba(34, 211, 238, 0.22), transparent 55%),
    radial-gradient(700px 600px at 50% 110%, rgba(251, 191, 36, 0.16), transparent 60%),
    linear-gradient(160deg, var(--bg1), var(--bg2) 70%, #1c0c45);
  background-attachment: fixed;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
}

#confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.app {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1.05fr) minmax(340px, 0.95fr);
  grid-template-areas:
    "topbar topbar"
    "match match"
    "target result"
    "bank bank";
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.topbar { grid-area: topbar; }
.match-banner { grid-area: match; }
.target-panel { grid-area: target; }
.result-panel { grid-area: result; }
.word-bank { grid-area: bank; }

.topbar,
.match-banner,
.target-panel,
.result-panel,
.word-bank {
  border: 1px solid var(--card-line);
  border-radius: 24px;
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.logo {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  font-size: 28px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--pink), var(--violet));
  box-shadow: 0 10px 24px rgba(255, 77, 141, 0.4);
  animation: bob 3.2s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50% { transform: translateY(-5px) rotate(4deg); }
}

h1 {
  margin: 0;
  font-size: clamp(24px, 4vw, 40px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.2px;
  background: linear-gradient(92deg, #ffd1e3, var(--pink) 38%, var(--amber) 85%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.language-control {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--card-line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.language-control:hover {
  background: rgba(255, 255, 255, 0.14);
}

.language-control:focus-within {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.25);
}

.language-globe {
  font-size: 17px;
  line-height: 1;
}

.language-control select {
  appearance: none;
  -webkit-appearance: none;
  max-width: 96px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  text-overflow: ellipsis;
}

.language-caret {
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.language-control option {
  color: #180b3c;
  background: white;
  font-weight: 600;
}

.ghost-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--card-line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.round-card {
  display: grid;
  place-items: center;
  min-width: 74px;
  padding: 6px 12px;
  border: 1px solid var(--card-line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
  text-align: center;
}

.round-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.round-card strong {
  font-size: 24px;
  line-height: 1.05;
}

/* ---------- match banner ---------- */

.match-banner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 10px;
  padding: 12px;
}

.player-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "avatar name"
    "avatar meta";
  align-items: center;
  column-gap: 12px;
  padding: 12px 14px;
  border: 2px solid transparent;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: border-color 200ms ease, background 200ms ease, transform 200ms ease;
}

.player-card.active {
  border-color: var(--cyan);
  background: rgba(34, 211, 238, 0.12);
  box-shadow: 0 0 26px rgba(34, 211, 238, 0.25);
}

.player-card.winner {
  border-color: var(--amber);
  background: rgba(251, 191, 36, 0.14);
}

.player-card .avatar {
  grid-area: avatar;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  font-size: 30px;
  border: 0;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: transform 150ms ease;
}

.player-card .avatar:active {
  transform: scale(1.15) rotate(8deg);
}

.player-card .name {
  grid-area: name;
  min-width: 0;
  font-size: 17px;
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  outline: none;
  border-radius: 6px;
}

.player-card .name:focus {
  box-shadow: 0 0 0 2px var(--cyan);
}

.player-card .meta {
  grid-area: meta;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.pips {
  display: inline-flex;
  gap: 4px;
}

.pip {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.pip.full {
  background: var(--amber);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.7);
}

.streak {
  color: var(--amber);
}

.turn-tag {
  position: absolute;
  top: -9px;
  right: 10px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--cyan);
  color: #06283a;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 200ms ease, transform 200ms ease;
}

.player-card.active .turn-tag {
  opacity: 1;
  transform: translateY(0);
}

.vs {
  display: grid;
  place-items: center;
  align-self: center;
  width: 46px;
  height: 46px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--pink), var(--violet));
  font-size: 15px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(139, 92, 246, 0.45);
}

/* ---------- target panel ---------- */

.target-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 20px;
}

.word-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.word-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.word-actions .chip-button[hidden] {
  display: none;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.chip-button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--card-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.target-word {
  display: grid;
  min-height: 110px;
  align-items: center;
  padding-bottom: 10px;
  border-bottom: 3px dashed rgba(255, 255, 255, 0.16);
  font-size: clamp(44px, 7vw, 84px);
  font-weight: 700;
  line-height: 0.96;
  letter-spacing: 1px;
  overflow-wrap: anywhere;
  text-shadow: 0 6px 30px rgba(255, 77, 141, 0.35);
}

.target-word.long {
  font-size: clamp(30px, 4.6vw, 54px);
  letter-spacing: 0.4px;
}

.target-word.xlong {
  font-size: clamp(22px, 3.2vw, 36px);
  letter-spacing: 0;
}

.target-word.is-hidden {
  color: rgba(253, 248, 255, 0.38);
  letter-spacing: 0.35em;
  text-shadow: none;
  user-select: none;
}

.target-word.pop {
  animation: pop 450ms cubic-bezier(.2, 1.6, .4, 1);
}

@keyframes pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

#targetHint {
  min-height: 26px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
}

.difficulty {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.diff-pill {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--card-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
}

.diff-pill.active {
  border-color: var(--pink);
  background: rgba(255, 77, 141, 0.22);
  box-shadow: 0 0 18px rgba(255, 77, 141, 0.25);
}

.controls {
  display: grid;
  grid-template-columns: 1fr 64px 1fr;
  gap: 10px;
}

.record-button,
.secondary-button {
  min-height: 62px;
  border: 0;
  border-radius: 18px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, filter 150ms ease;
}

.record-button:active,
.secondary-button:active,
.chip-button:active,
.ghost-button:active,
.diff-pill:active,
.word-chip:active {
  transform: translateY(1px) scale(0.98);
}

.record-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, var(--pink), var(--violet) 75%);
  box-shadow: 0 14px 30px rgba(255, 77, 141, 0.4);
}

.record-button.listening {
  background: linear-gradient(135deg, #e11d48, var(--red));
  animation: throb 1.1s ease-in-out infinite;
}

@keyframes throb {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 113, 133, 0.55); }
  50% { box-shadow: 0 0 0 16px rgba(251, 113, 133, 0); }
}

.record-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.16);
}

.secondary-button {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--card-line);
}

.secondary-button.wide {
  font-size: 15px;
}

/* ---------- result panel ---------- */

.result-panel {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 20px;
}

.ring-wrap {
  display: grid;
  place-items: center;
  padding: 8px 0;
}

.ring {
  --p: 0;
  --ring-color: var(--cyan);
  position: relative;
  display: grid;
  place-items: center;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background:
    conic-gradient(var(--ring-color) calc(var(--p) * 1%), rgba(255, 255, 255, 0.09) 0);
  transition: --p 300ms ease;
  box-shadow: 0 0 40px rgba(34, 211, 238, 0.18);
}

.ring::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: linear-gradient(160deg, #241055, #170a38);
  box-shadow: inset 0 4px 18px rgba(0, 0, 0, 0.45);
}

.ring-core {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  gap: 2px;
  text-align: center;
}

.ring-face {
  font-size: 38px;
  line-height: 1;
}

.ring-core strong {
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
}

.ring.listening {
  --ring-color: var(--red);
  animation: ringpulse 1s ease-in-out infinite;
}

@keyframes ringpulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.result-readout {
  display: grid;
  gap: 10px;
}

.readout-card {
  padding: 14px 16px;
  border: 1px solid var(--card-line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
}

.heard {
  margin-top: 6px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.8px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.heard .ok { color: var(--green); }
.heard .bad {
  color: var(--red);
  text-decoration: underline wavy rgba(251, 113, 133, 0.7) 2px;
}

.badge {
  display: block;
  margin-top: 6px;
  font-size: 22px;
  font-weight: 700;
}

.feedback {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
}

/* ---------- word bank ---------- */

.word-bank {
  display: flex;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  padding: 12px 14px;
  scrollbar-width: thin;
}

.word-bank > span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.word-chip {
  min-height: 42px;
  flex: 0 0 auto;
  padding: 0 16px;
  border: 1px solid var(--card-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease;
}

.word-chip:hover {
  background: rgba(255, 77, 141, 0.22);
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(10, 4, 28, 0.66);
  backdrop-filter: blur(12px);
}

.overlay[hidden] {
  display: none;
}

.victory-sheet,
.rules-sheet {
  width: min(440px, 100%);
  padding: 24px;
  border: 1px solid var(--card-line);
  border-radius: 26px;
  background: linear-gradient(165deg, #2c1366, #190b3e);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}

.victory-sheet {
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
  animation: pop 500ms cubic-bezier(.2, 1.6, .4, 1);
}

.victory-crown {
  font-size: 52px;
  line-height: 1;
  animation: bob 2.4s ease-in-out infinite;
}

.victory-avatar {
  display: grid;
  place-items: center;
  width: 92px;
  height: 92px;
  font-size: 54px;
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.3), rgba(255, 77, 141, 0.25));
  border: 2px solid var(--amber);
  box-shadow: 0 0 40px rgba(251, 191, 36, 0.4);
}

.victory-sheet h2 {
  margin: 6px 0 0;
  font-size: 34px;
  background: linear-gradient(92deg, var(--amber), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

#victoryText {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  font-weight: 500;
}

.victory-actions {
  display: grid;
  width: 100%;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 10px;
  margin-top: 14px;
}

.rules-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.rules-head h2 {
  margin: 0;
  font-size: 28px;
}

.rules-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rules;
}

.rules-list li {
  position: relative;
  padding: 12px 12px 12px 54px;
  border: 1px solid var(--card-line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
}

.rules-list li::before {
  counter-increment: rules;
  content: counter(rules);
  position: absolute;
  left: 12px;
  top: 50%;
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--pink), var(--violet));
  font-size: 14px;
  font-weight: 700;
  transform: translateY(-50%);
}

.rules-tip {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.rules-credit {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--card-line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.3px;
}

/* ---------- mobile ---------- */

@media (max-width: 880px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "match"
      "target"
      "result"
      "bank";
    gap: 10px;
    padding: 10px;
  }

  .topbar {
    flex-wrap: wrap;
    padding: 12px 14px;
  }

  .top-actions {
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .language-control {
    height: 40px;
    padding: 0 10px;
  }

  .logo {
    width: 46px;
    height: 46px;
    font-size: 24px;
  }

  .tagline {
    display: none;
  }

  .round-card strong {
    font-size: 20px;
  }

  .match-banner {
    gap: 8px;
    padding: 10px;
  }

  .vs {
    width: 38px;
    height: 38px;
    font-size: 13px;
  }

  .player-card {
    grid-template-columns: auto 1fr;
    padding: 10px;
  }

  .player-card .avatar {
    width: 44px;
    height: 44px;
    font-size: 26px;
  }

  .player-card .name {
    font-size: 15px;
  }

  .target-panel,
  .result-panel {
    padding: 16px;
  }

  .target-word {
    min-height: 86px;
    font-size: clamp(40px, 15vw, 72px);
  }

  .target-word.long {
    font-size: clamp(26px, 9vw, 40px);
  }

  .target-word.xlong {
    font-size: clamp(18px, 5.4vw, 28px);
  }

  .controls {
    grid-template-columns: 1fr 58px 1fr;
  }

  .ring {
    width: 165px;
    height: 165px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 22px;
  }

  .vs {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }

  .match-banner {
    gap: 6px;
    padding: 8px;
  }

  .player-card {
    column-gap: 8px;
    padding: 8px 10px;
  }

  .player-card .avatar {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }

  .player-card .meta {
    font-size: 12px;
  }

  .controls {
    grid-template-columns: 1fr 52px 0.9fr;
    gap: 8px;
  }

  .language-control select {
    max-width: 78px;
    font-size: 13px;
  }

  .record-button,
  .secondary-button {
    min-height: 56px;
    font-size: 15px;
  }
}
