:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --line: #2f3148;
  --accent: #6842ff;
  --accent-2: #8f6bff;
  --secondary: #2a2b3d;
  --text: #fff;
  --muted: #aaadbe;
  --ink: #23204a;
  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);
}

body {
  padding: 12px;
  overflow-x: hidden;
}

.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;
}

.ws {
  width: min(840px, 100%);
  margin: 0 auto;
}

/* HUD ------------------------------------------------------------------ */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

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

.logo {
  display: grid;
  flex: none;
  filter: drop-shadow(0 4px 10px rgba(104, 66, 255, 0.45));
}

.brand-text {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.theme-chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd84d, #ffab1f);
  color: #3a2300;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.02em;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    0 3px 10px rgba(255, 171, 31, 0.3);
}

.chips {
  display: flex;
  gap: 6px;
  flex: none;
}

.chip {
  min-width: 64px;
  padding: 5px 12px 6px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  text-align: center;
  line-height: 1.05;
}

.chip span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chip strong {
  display: block;
  font-size: 17px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.chip-best strong {
  color: #ffd84d;
}

.chip.bump strong {
  animation: bump 0.35s ease;
}

/* Stage ---------------------------------------------------------------- */
.stage {
  display: grid;
  grid-template-columns: minmax(0, 520px) minmax(240px, 280px);
  justify-content: center;
  align-items: start;
  gap: 14px;
}

.board-wrap {
  position: relative;
  width: 100%;
  min-width: 0;
}

.board {
  --n: 10;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: 3.2%;
  border-radius: 24px;
  background: radial-gradient(
    120% 80% at 50% 0%,
    #ffffff 0%,
    #f4f0ff 55%,
    #e7e0ff 100%
  );
  box-shadow:
    0 0 0 4px #6842ff,
    0 0 0 8px #3a2a99,
    0 18px 40px rgba(0, 0, 0, 0.5),
    inset 0 -6px 0 rgba(104, 66, 255, 0.12);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  outline: none;
  container-type: inline-size;
}

.board:focus-visible {
  box-shadow:
    0 0 0 4px #6842ff,
    0 0 0 8px #ffd84d,
    0 18px 40px rgba(0, 0, 0, 0.5);
}

.board.shake {
  animation: shake 0.36s ease;
}

.marks,
.cells,
.fx {
  position: absolute;
  inset: 3.2%;
  width: 93.6%;
  height: 93.6%;
}

.marks {
  overflow: visible;
}

.marks line {
  stroke-linecap: round;
}

.marks .cap {
  stroke-width: 0.78;
  opacity: 0.92;
}

.marks .cap-shine {
  stroke-width: 0.3;
  stroke: #fff;
  opacity: 0.3;
  transform: translateY(-0.14px);
}

.marks .cap-new {
  animation: capIn 0.38s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.marks .sel {
  stroke: var(--accent);
  stroke-width: 0.82;
  opacity: 0.88;
}

.cells {
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  color: var(--ink);
  font-size: calc(93.6cqi / var(--n) * 0.56);
  font-weight: 900;
  line-height: 1;
  transition:
    color 0.15s,
    transform 0.15s;
}

.cell.on,
.cell.sel {
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.cell.sel {
  transform: scale(1.12);
}

.cell.cursor::after {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 30%;
  border: 3px solid #ff5d8f;
  box-shadow: 0 0 0 2px #fff;
}

.cell.hint::before {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  background: radial-gradient(circle, #ffd84d 0%, #ffab1f 70%);
  box-shadow: 0 0 18px 4px rgba(255, 196, 40, 0.8);
  z-index: -1;
  animation: hintPulse 0.6s ease-in-out 3;
}

.cell.hint {
  z-index: 1;
  color: #3a2300;
}

.fx {
  pointer-events: none;
}

.spark {
  position: absolute;
  width: 10px;
  height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--c, #ffd84d);
  box-shadow: 0 0 8px var(--c, #ffd84d);
  animation: spark 0.7s ease-out forwards;
}

.spark.star {
  border-radius: 2px;
  transform: rotate(45deg);
}

/* Side panel -------------------------------------------------------------- */
.side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.seg-btn {
  min-height: 42px;
  padding: 4px 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
}

.seg-btn small {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 800;
  opacity: 0.75;
}

.seg-btn[aria-pressed="true"] {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 4px 12px rgba(104, 66, 255, 0.45);
}

.words-panel {
  padding: 12px;
  border-radius: 20px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.words-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.word {
  position: relative;
  padding: 6px 11px;
  border-radius: 999px;
  background: #2c2d44;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.06em;
  transition:
    background 0.25s,
    color 0.25s;
}

.word.found {
  background: var(--c);
  color: rgba(255, 255, 255, 0.92);
  text-decoration: line-through;
  text-decoration-thickness: 2.5px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 3px 8px rgba(0, 0, 0, 0.25);
  animation: pop 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.word.hinted {
  box-shadow: 0 0 0 2px #ffd84d;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Buttons ------------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  white-space: nowrap;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  font: inherit;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  transition:
    transform 0.12s,
    filter 0.12s;
}

.btn:active {
  transform: translateY(2px) scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.3),
    0 5px 0 #3e22b3,
    0 10px 22px rgba(104, 66, 255, 0.45);
}

.btn-secondary {
  background: var(--secondary);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 0 #1a1b2a;
}

.btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

.btn-big {
  min-height: 56px;
  min-width: 190px;
  font-size: 20px;
}

button:focus-visible {
  outline: 3px solid #ffd84d;
  outline-offset: 3px;
}

/* Overlays ----------------------------------------------------------------- */
.overlay {
  position: absolute;
  inset: -8px;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  border-radius: 30px;
  background: rgba(15, 16, 32, 0.72);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.25s ease;
}

.overlay[hidden] {
  display: none;
}

.card {
  width: min(340px, 100%);
  padding: 24px 20px 26px;
  border-radius: 26px;
  background: linear-gradient(180deg, #2a2b44, var(--panel));
  border: 1px solid #3a3c5c;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: cardIn 0.4s cubic-bezier(0.2, 1.4, 0.4, 1);
}

.card h2 {
  margin: 10px 0 6px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.card p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.4;
}

.card-badge {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.card-badge span {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, #e7e0ff);
  color: var(--ink);
  font-size: 24px;
  font-weight: 900;
  box-shadow: 0 4px 0 #b8a8ff;
  animation: bob 1.8s ease-in-out infinite;
}

.card-badge span:nth-child(2) {
  animation-delay: 0.15s;
}
.card-badge span:nth-child(3) {
  animation-delay: 0.3s;
}
.card-badge span:nth-child(4) {
  animation-delay: 0.45s;
}

.card-badge span:nth-child(-n + 3) {
  background: linear-gradient(180deg, #ff86ad, #ff4f86);
  color: #fff;
  box-shadow: 0 4px 0 #c22a5e;
}

.trophy {
  display: grid;
  place-items: center;
  filter: drop-shadow(0 6px 16px rgba(255, 190, 40, 0.5));
  animation: bob 1.8s ease-in-out infinite;
}

.win-badge {
  display: inline-block;
  margin: 0 0 12px !important;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffd84d, #ffab1f);
  color: #3a2300 !important;
  font-weight: 900 !important;
}

.win-badge[hidden] {
  display: none;
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 4px 0 20px;
}

.win-stats div {
  padding: 8px 4px;
  border-radius: 16px;
  background: var(--bg);
}

.win-stats dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.win-stats dd {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.confetti {
  position: absolute;
  top: 30%;
  left: 50%;
  width: 9px;
  height: 14px;
  border-radius: 3px;
  background: var(--c);
  pointer-events: none;
  animation: confetti 1.3s cubic-bezier(0.2, 0.7, 0.4, 1) forwards;
}

/* Animations ------------------------------------------------------------------ */
@keyframes bump {
  40% {
    transform: scale(1.3);
  }
}

@keyframes pop {
  0% {
    transform: scale(0.7);
  }
  60% {
    transform: scale(1.15);
  }
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-7px);
  }
  40%,
  80% {
    transform: translateX(7px);
  }
}

@keyframes capIn {
  from {
    stroke-width: 0.2;
    opacity: 0;
  }
}

@keyframes hintPulse {
  50% {
    transform: scale(1.25);
    opacity: 0.6;
  }
}

@keyframes spark {
  to {
    transform: translate(var(--dx), var(--dy)) scale(0.2);
    opacity: 0;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
}

@keyframes cardIn {
  from {
    transform: scale(0.8) translateY(12px);
    opacity: 0;
  }
}

@keyframes bob {
  50% {
    transform: translateY(-5px);
  }
}

@keyframes confetti {
  to {
    transform: translate(var(--dx), var(--dy)) rotate(var(--r));
    opacity: 0;
  }
}

/* Responsive -------------------------------------------------------------------- */
@media (max-width: 720px) {
  .stage {
    grid-template-columns: minmax(0, 1fr);
  }
  .board-wrap {
    max-width: 520px;
    margin: 0 auto;
  }
  .side {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
  }
  .hud {
    flex-wrap: wrap;
  }
}

@media (max-width: 440px) {
  body {
    padding: 10px 10px 16px;
  }
  .brand h1 {
    font-size: 19px;
  }
  .logo svg {
    width: 34px;
    height: 34px;
  }
  .chip {
    min-width: 0;
    padding: 4px 10px 5px;
  }
  .chip strong {
    font-size: 15px;
  }
  .board {
    border-radius: 18px;
    padding: 2.4%;
  }
  .marks,
  .cells,
  .fx {
    inset: 2.4%;
    width: 95.2%;
    height: 95.2%;
  }
  .cell {
    font-size: calc(95.2cqi / var(--n) * 0.58);
  }
  .word {
    font-size: 13px;
    padding: 5px 9px;
  }
  .btn {
    padding: 0 10px;
  }
}

@media (max-width: 360px) {
  .chips {
    width: 100%;
  }
  .chip {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
