:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --line: #2f3148;
  --accent: #6842ff;
  --accent-2: #8f74ff;
  --text: #fff;
  --muted: #aaadbe;
  --secondary: #2a2b3d;
  --green-1: #6ee89a;
  --green-2: #22b45a;
  --green-lip: #178543;
  --yellow-1: #ffdc62;
  --yellow-2: #f3a712;
  --yellow-lip: #b9760a;
  --gray-1: #555872;
  --gray-2: #3a3c55;
  --gray-lip: #25263a;
  --tile: clamp(44px, calc((100vw - 64px) / 5.4), 52px);
  --gap: 6px;
  --key-h: 50px;
  font-family:
    "Nunito",
    ui-rounded,
    "SF Pro Rounded",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(
      ellipse 70% 45% at 50% 0%,
      rgba(104, 66, 255, 0.22),
      transparent 70%
    ),
    radial-gradient(
      ellipse 60% 40% at 50% 100%,
      rgba(34, 180, 90, 0.08),
      transparent 70%
    ),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid #b9a8ff;
  outline-offset: 2px;
}

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

.wg-shell {
  position: relative;
  width: min(560px, 100%);
  margin: 0 auto;
  padding: 10px 12px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 560px;
}

/* ---------- HUD ---------- */
.wg-hud {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 18px;
  background: linear-gradient(180deg, #212233, #1a1b28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 6px 18px rgba(0, 0, 0, 0.35);
}

.wg-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 4px 0 2px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.wg-brand-mark {
  display: inline-flex;
  gap: 2px;
}

.wg-brand-mark i {
  display: grid;
  place-items: center;
  width: 20px;
  height: 22px;
  border-radius: 6px;
  font-style: normal;
  font-size: 12px;
  font-weight: 900;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 2px 0 var(--lip);
}

.wg-brand-mark .c {
  --lip: var(--green-lip);
  background: linear-gradient(180deg, var(--green-1), var(--green-2));
}

.wg-brand-mark .p {
  --lip: var(--yellow-lip);
  background: linear-gradient(180deg, var(--yellow-1), var(--yellow-2));
}

.wg-modes {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: #11121f;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

.wg-mode {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition:
    background 0.2s,
    color 0.2s;
}

.wg-mode[aria-pressed="true"] {
  background: linear-gradient(180deg, #7d5cff, var(--accent));
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 2px 8px rgba(104, 66, 255, 0.5);
}

.wg-chips {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.wg-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--secondary);
  font-size: 14px;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  white-space: nowrap;
}

.wg-chip-label {
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
}

.wg-chip svg {
  width: 16px;
  height: 16px;
  fill: #ff9a3d;
}

.wg-chip-hard {
  background: linear-gradient(180deg, #ff6b8a, #e23d62);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.wg-chip-hard[hidden] {
  display: none;
}

.wg-tools {
  display: flex;
  gap: 4px;
}

.wg-icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--secondary);
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 3px 0 #17182a;
  transition: transform 0.12s;
}

.wg-icon-btn svg {
  width: 20px;
  height: 20px;
  fill: #d9dbf0;
}

.wg-icon-btn:active {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* ---------- Board ---------- */
.wg-stage {
  position: relative;
  display: flex;
  justify-content: center;
  width: 100%;
  padding: 2px 0;
}

.wg-board {
  outline: none;
  display: grid;
  grid-template-rows: repeat(6, var(--tile));
  gap: var(--gap);
}

.wg-row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: var(--gap);
}

.wg-row.shake {
  animation: wg-shake 0.5s;
}

.wg-tile {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--tile);
  height: var(--tile);
  border-radius: 12px;
  border: 2px solid var(--line);
  background: linear-gradient(180deg, #1d1e2d, #181927);
  font-size: calc(var(--tile) * 0.56);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
}

.wg-tile[data-filled="true"] {
  border-color: var(--accent-2);
  background: linear-gradient(180deg, #2a2946, #211f38);
  box-shadow:
    0 0 0 2px rgba(104, 66, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.wg-tile[data-filled="true"].pop {
  animation: wg-pop 0.12s ease-out;
}

.wg-tile[data-state],
.wg-mini[data-state] {
  border-color: transparent;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
}

.wg-tile[data-state="correct"],
.wg-mini[data-state="correct"] {
  background: linear-gradient(180deg, var(--green-1), var(--green-2) 70%);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.35),
    inset 0 -3px 0 rgba(0, 0, 0, 0.08),
    0 4px 0 var(--green-lip),
    0 8px 14px rgba(34, 180, 90, 0.35);
}

.wg-tile[data-state="present"],
.wg-mini[data-state="present"] {
  background: linear-gradient(180deg, var(--yellow-1), var(--yellow-2) 70%);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.4),
    inset 0 -3px 0 rgba(0, 0, 0, 0.08),
    0 4px 0 var(--yellow-lip),
    0 8px 14px rgba(243, 167, 18, 0.3);
}

.wg-tile[data-state="absent"],
.wg-mini[data-state="absent"] {
  background: linear-gradient(180deg, var(--gray-1), var(--gray-2) 70%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.14),
    0 4px 0 var(--gray-lip);
  color: #e3e4f2;
}

.wg-tile.flip {
  animation: wg-flip 0.5s ease-in-out;
}

.wg-tile.bounce {
  animation: wg-bounce 0.6s cubic-bezier(0.3, 1.6, 0.5, 1);
}

@keyframes wg-pop {
  0% {
    transform: scale(0.82);
  }
  60% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes wg-flip {
  0% {
    transform: rotateX(0);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0);
  }
}

@keyframes wg-bounce {
  0%,
  100% {
    transform: translateY(0);
  }
  35% {
    transform: translateY(-26px) scale(1.06);
  }
  60% {
    transform: translateY(4px) scale(0.98);
  }
}

@keyframes wg-shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(4px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-7px);
  }
  40%,
  60% {
    transform: translateX(7px);
  }
}

/* ---------- Toasts ---------- */
.wg-toasts {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transform: translateX(-50%);
  pointer-events: none;
}

.wg-toast {
  padding: 10px 16px;
  border-radius: 999px;
  background: #fff;
  color: #151628;
  font-weight: 900;
  font-size: 15px;
  white-space: nowrap;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
  animation: wg-toast-in 0.18s ease-out;
  transition:
    opacity 0.3s,
    transform 0.3s;
}

.wg-toast.big {
  background: linear-gradient(180deg, #8f74ff, var(--accent));
  color: #fff;
  font-size: 18px;
  padding: 12px 22px;
}

.wg-toast.out {
  opacity: 0;
  transform: translateY(-6px);
}

@keyframes wg-toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.9);
  }
}

/* ---------- Keyboard ---------- */
.wg-keyboard {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  user-select: none;
}

.wg-krow {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.wg-key {
  flex: 1 1 0;
  min-width: 0;
  height: var(--key-h);
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #3c3e58, #2e3046);
  color: #fff;
  font-size: 17px;
  font-weight: 900;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 3px 0 #1a1b2b;
  transition:
    transform 0.08s,
    box-shadow 0.08s,
    background 0.25s;
}

.wg-key.wide {
  flex: 1.55 1 0;
  font-size: 12px;
  letter-spacing: 0.04em;
}

.wg-key.enter {
  background: linear-gradient(180deg, #8568ff, var(--accent));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 3px 0 #3f22b8;
}

.wg-key svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  vertical-align: middle;
}

.wg-key:active,
.wg-key.pressed {
  transform: translateY(3px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.wg-krow-spacer {
  flex: 0.5 1 0;
}

.wg-key[data-state="correct"] {
  background: linear-gradient(180deg, var(--green-1), var(--green-2) 75%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    0 3px 0 var(--green-lip);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.wg-key[data-state="present"] {
  background: linear-gradient(180deg, var(--yellow-1), var(--yellow-2) 75%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 3px 0 var(--yellow-lip);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.wg-key[data-state="absent"] {
  background: #20212f;
  color: #676a84;
  box-shadow: 0 3px 0 #15161f;
}

/* ---------- Overlays ---------- */
.wg-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(8, 8, 20, 0.72);
  backdrop-filter: blur(4px);
  overflow-y: auto;
}

.wg-overlay[data-open="false"] {
  display: none;
}

.wg-card {
  position: relative;
  width: min(420px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 22px 22px 20px;
  border-radius: 24px;
  background: linear-gradient(180deg, #25263a, #1a1b28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 24px 60px rgba(0, 0, 0, 0.55);
  animation: wg-card-in 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.wg-card h2 {
  margin: 0 0 10px;
  font-size: 22px;
  font-weight: 900;
  text-align: center;
}

.wg-card p {
  margin: 6px 0;
  font-weight: 700;
  line-height: 1.4;
}

.wg-muted {
  color: var(--muted);
  font-size: 14px;
}

@keyframes wg-card-in {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(12px);
  }
}

.wg-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: var(--secondary);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.wg-start-card {
  text-align: center;
  padding: 28px 24px 22px;
}

.wg-logo {
  display: inline-flex;
  gap: 6px;
  margin-bottom: 8px;
}

.wg-logo span {
  display: grid;
  place-items: center;
  width: 52px;
  height: 56px;
  border-radius: 14px;
  font-size: 30px;
  font-weight: 900;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  animation: wg-float 2.6s ease-in-out infinite;
}

.wg-logo span:nth-child(2) {
  animation-delay: 0.15s;
}

.wg-logo span:nth-child(3) {
  animation-delay: 0.3s;
}

.wg-logo span:nth-child(4) {
  animation-delay: 0.45s;
}

.wg-logo .c {
  background: linear-gradient(180deg, var(--green-1), var(--green-2) 70%);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.35),
    0 5px 0 var(--green-lip);
}

.wg-logo .p {
  background: linear-gradient(180deg, var(--yellow-1), var(--yellow-2) 70%);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.4),
    0 5px 0 var(--yellow-lip);
}

.wg-logo .a {
  background: linear-gradient(180deg, var(--gray-1), var(--gray-2) 70%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.14),
    0 5px 0 var(--gray-lip);
}

@keyframes wg-float {
  0%,
  100% {
    transform: translateY(0) rotate(-2deg);
  }
  50% {
    transform: translateY(-6px) rotate(2deg);
  }
}

.wg-start-title {
  margin-top: 8px !important;
  font-size: 34px !important;
  letter-spacing: -0.02em;
  background: linear-gradient(180deg, #fff, #cfc4ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.wg-start-copy {
  color: var(--muted);
}

.wg-start-actions {
  display: grid;
  gap: 10px;
  margin: 18px 0 8px;
}

.wg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.1s;
}

.wg-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.wg-btn-big {
  min-height: 58px;
  font-size: 21px;
}

.wg-btn-primary {
  background: linear-gradient(180deg, #8a6dff, var(--accent));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    0 4px 0 #3f22b8,
    0 10px 24px rgba(104, 66, 255, 0.45);
}

.wg-btn-secondary {
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 0 #17182a;
}

.wg-btn:active {
  transform: translateY(3px);
}

.wg-link {
  min-height: 40px;
  border: 0;
  background: none;
  color: #b9a8ff;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.wg-example {
  display: flex;
  gap: 5px;
  margin-top: 12px;
}

.wg-mini {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 9px;
  border: 2px solid var(--line);
  font-weight: 900;
  font-size: 20px;
}

.wg-example-copy {
  font-size: 14px;
  color: #d7d8e8;
}

.wg-setting {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  padding: 12px 0;
}

.wg-switch {
  flex: none;
  position: relative;
  width: 58px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: #3a3c55;
  cursor: pointer;
  transition: background 0.2s;
}

.wg-switch[aria-checked="true"] {
  background: var(--accent);
}

.wg-switch-knob {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s;
}

.wg-switch[aria-checked="true"] .wg-switch-knob {
  transform: translateX(24px);
}

.wg-switch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Result ---------- */
.wg-answer {
  text-align: center;
  margin-bottom: 14px;
}

.wg-answer[hidden] {
  display: none;
}

.wg-answer-label {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.wg-answer-tiles {
  display: inline-flex;
  gap: 5px;
  margin-top: 6px;
}

.wg-answer-tiles .wg-mini {
  width: 42px;
  height: 44px;
  font-size: 23px;
  text-transform: uppercase;
}

.wg-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.wg-stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 2px 8px;
  border-radius: 14px;
  background: #151624;
}

.wg-stats strong {
  font-size: 26px;
  font-weight: 900;
  line-height: 1.1;
}

.wg-stats span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.wg-dist-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-align: center;
}

.wg-dist {
  display: grid;
  gap: 5px;
}

.wg-dist-row {
  display: grid;
  grid-template-columns: 14px 1fr;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  font-size: 14px;
}

.wg-dist-bar {
  min-width: 26px;
  width: var(--w, 0%);
  height: 22px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--gray-2);
  text-align: right;
  line-height: 22px;
  font-size: 13px;
  transition: width 0.6s cubic-bezier(0.2, 1, 0.3, 1);
}

.wg-dist-row.current .wg-dist-bar {
  background: linear-gradient(180deg, var(--green-1), var(--green-2));
  box-shadow: 0 2px 0 var(--green-lip);
}

.wg-next {
  text-align: center;
  color: var(--muted);
  margin-top: 14px !important;
}

.wg-next[hidden] {
  display: none;
}

.wg-next strong {
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.wg-result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

/* ---------- Confetti ---------- */
.wg-confetti {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  overflow: hidden;
}

.wg-confetti i {
  position: absolute;
  top: -16px;
  width: 9px;
  height: 14px;
  border-radius: 3px;
  animation: wg-fall var(--dur, 1.8s) cubic-bezier(0.25, 0.6, 0.5, 1) forwards;
}

@keyframes wg-fall {
  to {
    transform: translate3d(var(--dx, 0), 110vh, 0) rotate(var(--rot, 540deg));
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 520px) {
  .wg-shell {
    padding: 8px 8px 12px;
    gap: 10px;
  }
  .wg-brand,
  .wg-chip:first-child {
    display: none;
  }
  .wg-chips {
    margin-left: auto;
  }
  .wg-chip {
    padding: 0 9px;
  }
  .wg-mode {
    padding: 0 11px;
  }
  .wg-key {
    font-size: 15px;
    border-radius: 8px;
  }
  .wg-krow {
    gap: 4px;
  }
}

@media (max-width: 370px) {
  .wg-hud {
    gap: 5px;
  }
  .wg-mode {
    padding: 0 8px;
    font-size: 13px;
  }
  .wg-chip {
    padding: 0 7px;
  }
  .wg-icon-btn {
    width: 34px;
  }
  .wg-logo span {
    width: 44px;
    height: 48px;
    font-size: 25px;
  }
}

@media (min-width: 521px) {
  .wg-shell {
    width: min(680px, 100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .wg-confetti {
    display: none;
  }
}
