:root {
  --bg-1: #f8ffd2;
  --bg-2: #d8f8ff;
  --bg-3: #ffe4c8;
  --bg-glow: #ffffff;
  --panel: rgba(255, 255, 255, 0.84);
  --panel-border: rgba(20, 44, 53, 0.12);
  --ink: #122930;
  --ink-muted: #3e616b;
  --brand: #ff7f50;
  --brand-2: #41c58b;
  --tile: #fff9ef;
  --tile-border: #e4d7b8;
  --slot: #f4faff;
  --shadow: 0 8px 20px rgba(18, 41, 48, 0.1);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Baloo 2", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% 18%, var(--bg-glow) 0, transparent 36%),
    linear-gradient(130deg, var(--bg-1), var(--bg-2) 45%, var(--bg-3));
  overflow-x: hidden;
}

body.dark-mode {
  --bg-1: #0e1624;
  --bg-2: #101e31;
  --bg-3: #1a2334;
  --bg-glow: #233040;
  --panel: rgba(22, 34, 50, 0.88);
  --panel-border: rgba(158, 193, 212, 0.22);
  --ink: #e8f2f8;
  --ink-muted: #aac1d0;
  --brand: #ffa064;
  --brand-2: #54d4a0;
  --tile: #223247;
  --tile-border: #5b6f83;
  --slot: #1b2b3f;
  --shadow: 0 10px 28px rgba(4, 8, 14, 0.45);
}

.bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.blob {
  position: absolute;
  border-radius: 55% 45% 52% 48% / 43% 54% 46% 57%;
  filter: blur(2px);
  opacity: 0.38;
  transform-origin: center;
  animation: blobDrift 14s ease-in-out infinite alternate, blobTint 9.3s ease-in-out infinite alternate;
}

.blob-a {
  width: 280px;
  height: 280px;
  top: 8%;
  left: -5%;
  background: #ffd0a8;
  animation-delay: 0s, 0.3s;
}

.blob-b {
  width: 220px;
  height: 220px;
  top: 62%;
  right: 8%;
  background: #9af4ff;
  animation-delay: 8s, 1.8s;
  animation-duration: 18s, 10s;
}

.blob-c {
  width: 180px;
  height: 180px;
  top: 14%;
  right: 16%;
  background: #bff7af;
  animation-delay: 15s, 4.2s;
  animation-duration: 16s, 11.3s;
}

.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff8cf;
  box-shadow: 0 0 16px #fff8cf;
  animation: twinkle 3.6s ease-in-out infinite, sparkDrift 18s ease-in-out infinite alternate;
}

.s1 {
  top: 22%;
  left: 22%;
}
.s2 {
  top: 18%;
  right: 26%;
  animation-delay: 0.4s;
}
.s3 {
  top: 70%;
  left: 14%;
  animation-delay: 1s;
}
.s4 {
  top: 78%;
  right: 20%;
  animation-delay: 1.5s;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 36px;
  position: relative;
  z-index: 2;
}

.title-wrap {
  text-align: center;
  margin-bottom: 14px;
}

.title-wrap h1 {
  margin: 0;
  font-family: "Bungee", "Verdana", sans-serif;
  letter-spacing: 0.04em;
  font-size: clamp(1.85rem, 4.8vw, 2.7rem);
  color: #173744;
  text-shadow: 0 2px 0 #ffffff;
}

.kicker {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
  font-size: 0.86rem;
}

.panel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px;
  margin-top: 12px;
  backdrop-filter: blur(4px);
}

.panel-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.panel-top h2 {
  margin: 0;
  font-size: 1.25rem;
}

.meta-text {
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.95rem;
}

.level-buttons {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.level-btn {
  border: 1px solid rgba(18, 41, 48, 0.15);
  background: #f8ffff;
  color: #143541;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 46px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.level-btn:hover {
  transform: translateY(-1px);
}

.level-btn.active {
  background: linear-gradient(140deg, #ffedd2, #d8fdf2);
  box-shadow: 0 0 0 3px rgba(65, 197, 139, 0.26);
}

.level-btn.locked {
  opacity: 0.55;
  cursor: not-allowed;
  background: #ecf0f3;
}

.progress-track {
  width: 100%;
  height: 12px;
  margin-top: 10px;
  border-radius: 999px;
  background: #dfeef2;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  transition: width 0.35s ease;
}

.slots {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.slot {
  width: min(68px, 15vw);
  height: min(68px, 15vw);
  border: 2px dashed #9bb5c2;
  border-radius: 12px;
  background: var(--slot);
  display: grid;
  place-items: center;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 800;
  color: #1b3a46;
  transition: transform 0.16s ease, background-color 0.2s ease;
}

.slot.filled {
  border-style: solid;
  border-color: #7ec4d3;
  background: #f0fdff;
  animation: popIn 0.18s ease;
}

.controls {
  margin-top: 14px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  border: 0;
  border-radius: 999px;
  min-height: 40px;
  padding: 0 12px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.96rem;
  cursor: pointer;
  transition: transform 0.14s ease, filter 0.14s ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

.btn:active {
  transform: translateY(0);
}

.btn.soft {
  background: #e9f3f6;
  color: #21414d;
}

.btn.warn {
  background: #ffe3d8;
  color: #8e3a2f;
}

.btn.strong {
  background: linear-gradient(120deg, #ff9568, #ff7f50);
  color: #fff;
}

.letters {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(5, minmax(52px, 1fr));
  gap: 9px;
}

.tile {
  min-height: 58px;
  border: 2px solid var(--tile-border);
  border-radius: 14px;
  background: var(--tile);
  color: #16343e;
  font-family: inherit;
  font-weight: 800;
  font-size: 1.3rem;
  cursor: pointer;
  transition: transform 0.16s ease, background-color 0.16s ease, opacity 0.16s ease;
}

.tile:hover:not(:disabled) {
  transform: translateY(-2px) rotate(-1deg);
}

.tile:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.tile.used {
  background: #e6eff3;
}

.message {
  text-align: center;
  min-height: 28px;
  margin: 10px 0 0;
  font-weight: 700;
  color: #235568;
}

.found-words {
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.found-group {
  border: 1px solid rgba(140, 174, 188, 0.55);
  background: #f8fcff;
  border-radius: 12px;
  padding: 9px;
}

.found-group-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #1f4b5a;
}

.found-group-meta {
  margin-left: 6px;
  font-size: 0.88rem;
  font-weight: 700;
  color: #5f7d88;
}

.found-group-list {
  margin-top: 7px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.found-item {
  min-height: 40px;
  border-radius: 10px;
  border: 1px dashed #a2bbc5;
  background: #f9fdff;
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #55727d;
}

.found-item.done {
  color: #174155;
  border-style: solid;
  border-color: #85e2bc;
  background: #e9fff2;
  animation: pulseWord 0.34s ease;
}

.shake {
  animation: shake 0.26s linear;
}

.win-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(12, 35, 44, 0.3);
  z-index: 10;
}

.hidden {
  display: none;
}

.win-card {
  width: min(470px, calc(100vw - 24px));
  background: #fffef7;
  border: 2px solid rgba(18, 41, 48, 0.12);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 16px 30px rgba(18, 41, 48, 0.24);
  text-align: center;
  animation: dropIn 0.35s ease;
}

.win-card h3 {
  margin: 0;
  font-family: "Bungee", "Verdana", sans-serif;
  font-size: 1.45rem;
}

.win-card p {
  margin: 10px 0 14px;
  font-size: 1.02rem;
}

.win-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.confetti-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 18px;
  border-radius: 4px;
  top: -20px;
  animation: confettiFall 1.8s linear forwards;
}

.site-footer {
  margin-top: 16px;
  text-align: center;
  color: #2f5662;
  font-size: 0.92rem;
}

.site-footer p {
  margin: 4px 0;
}

.site-footer a {
  color: #1c6d89;
  font-weight: 700;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.floating-controls {
  position: fixed;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.floating-btn {
  border: 1px solid rgba(15, 42, 52, 0.18);
  border-radius: 999px;
  width: 46px;
  height: 46px;
  padding: 0;
  font-family: "Baloo 2", "Trebuchet MS", sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  display: grid;
  place-items: center;
  color: #1f4551;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 20px rgba(13, 30, 39, 0.2);
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.floating-btn:hover {
  filter: brightness(1.04);
}

.info-toggle {
  background: rgba(228, 245, 255, 0.94);
}

.theme-toggle {
  background: rgba(255, 255, 255, 0.92);
}

body.dark-mode .title-wrap h1 {
  color: #e7f3ff;
  text-shadow: none;
}

body.dark-mode .kicker,
body.dark-mode .meta-text,
body.dark-mode .site-footer {
  color: #abc2d2;
}

body.dark-mode .level-btn {
  background: #1a2a3e;
  color: #e4f1f8;
  border-color: rgba(158, 193, 212, 0.25);
}

body.dark-mode .level-btn.active {
  background: linear-gradient(140deg, #33465d, #254452);
}

body.dark-mode .level-btn.locked {
  background: #223243;
}

body.dark-mode .btn.soft {
  background: #24374d;
  color: #d8e8f2;
}

body.dark-mode .btn.warn {
  background: #4f3635;
  color: #ffd6d2;
}

body.dark-mode .tile {
  color: #e7f0f6;
}

body.dark-mode .message {
  color: #c2deeb;
}

body.dark-mode .found-group {
  background: #1a2c40;
  border-color: rgba(158, 193, 212, 0.3);
}

body.dark-mode .found-group-title {
  color: #d9ebf7;
}

body.dark-mode .found-group-meta {
  color: #acc2d1;
}

body.dark-mode .found-item {
  background: #22374e;
  border-color: #4e6780;
  color: #bbcfde;
}

body.dark-mode .found-item.done {
  background: #1f4a44;
  border-color: #66cfa8;
  color: #d6fff0;
}

body.dark-mode .site-footer a {
  color: #88ddff;
}

body.dark-mode .floating-btn {
  color: #d9edfb;
  background: rgba(24, 38, 54, 0.92);
  border-color: rgba(157, 194, 212, 0.3);
  box-shadow: 0 8px 20px rgba(3, 8, 16, 0.46);
}

body.dark-mode .info-toggle {
  background: rgba(28, 55, 80, 0.92);
}

body.dark-mode .theme-toggle {
  background: rgba(24, 38, 54, 0.92);
}

body.dark-mode .leaderboard-toggle {
  background: rgba(64, 50, 24, 0.92);
}

.info-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: rgba(7, 23, 31, 0.54);
  padding: 12px;
}

.info-modal.hidden {
  display: none;
}

.reveal-confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 32;
  display: grid;
  place-items: center;
  background: rgba(7, 23, 31, 0.54);
  padding: 12px;
}

.reveal-confirm-modal.hidden {
  display: none;
}

.leaderboard-modal {
  position: fixed;
  inset: 0;
  z-index: 31;
  display: grid;
  place-items: center;
  background: rgba(7, 23, 31, 0.54);
  padding: 12px;
}

.leaderboard-modal.hidden {
  display: none;
}

.leaderboard-card {
  position: relative;
  width: min(620px, calc(100vw - 24px));
  max-height: min(80vh, 760px);
  overflow-y: auto;
  border: 1px solid rgba(20, 44, 53, 0.18);
  border-radius: 14px;
  background: #fffef8;
  box-shadow: 0 16px 34px rgba(12, 30, 39, 0.28);
  padding: 14px;
}

.leaderboard-card h3 {
  margin: 0;
  font-family: "Bungee", "Verdana", sans-serif;
  font-size: 1.2rem;
}

.leaderboard-note {
  margin: 8px 0 12px;
  color: #456270;
  font-size: 0.92rem;
}

.leaderboard-content {
  display: grid;
  gap: 12px;
}

.leaderboard-block {
  border: 1px solid rgba(140, 174, 188, 0.55);
  background: #f8fcff;
  border-radius: 12px;
  padding: 12px;
}

.leaderboard-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.leaderboard-block h4 {
  margin: 0;
  font-size: 1rem;
}

.leaderboard-block-head p {
  margin: 0;
  color: #5d7b87;
  font-size: 0.86rem;
}

.leaderboard-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.leaderboard-kpi {
  border: 1px solid rgba(140, 174, 188, 0.5);
  border-radius: 10px;
  background: #ffffff;
  padding: 8px;
  display: grid;
  gap: 3px;
}

.leaderboard-kpi-label {
  color: #587683;
  font-size: 0.8rem;
  line-height: 1.15;
}

.leaderboard-kpi-value {
  font-size: 1.15rem;
  line-height: 1.1;
  color: #1a4050;
}

.leaderboard-rows {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: minmax(70px, auto) 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(140, 174, 188, 0.42);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.66);
  padding: 7px 9px;
}

.leaderboard-row-label {
  font-weight: 800;
  color: #244a59;
}

.leaderboard-row-value {
  font-weight: 800;
  color: #193e4d;
  text-align: right;
}

.leaderboard-row-meta {
  color: #5a7885;
  font-size: 0.82rem;
}

.leaderboard-level-rows .leaderboard-row {
  grid-template-columns: minmax(70px, auto) 1fr auto;
}

.leaderboard-meter {
  height: 8px;
  border-radius: 999px;
  background: #dbeaf0;
  overflow: hidden;
}

.leaderboard-meter-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6ec3ff, #57deaa);
  transition: width 0.25s ease;
}

.reveal-confirm-card {
  width: min(460px, calc(100vw - 24px));
  border: 1px solid rgba(20, 44, 53, 0.18);
  border-radius: 14px;
  background: #fffef8;
  box-shadow: 0 16px 34px rgba(12, 30, 39, 0.28);
  padding: 14px;
  text-align: center;
}

.reveal-confirm-card h3 {
  margin: 0;
  font-family: "Bungee", "Verdana", sans-serif;
  font-size: 1.15rem;
}

.reveal-confirm-card p {
  margin: 8px 0 14px;
  color: #34535f;
}

.info-card {
  position: relative;
  width: min(680px, calc(100vw - 24px));
  max-height: min(80vh, 760px);
  overflow-y: auto;
  border: 1px solid rgba(20, 44, 53, 0.18);
  border-radius: 14px;
  background: #fffef8;
  box-shadow: 0 16px 34px rgba(12, 30, 39, 0.28);
  padding: 14px 14px 12px;
}

.info-card h3 {
  margin: 0;
  font-family: "Bungee", "Verdana", sans-serif;
  font-size: 1.2rem;
}

.info-card h4 {
  margin: 12px 0 6px;
  font-size: 1rem;
}

.info-card p {
  margin: 8px 0;
  color: #34535f;
}

.info-card ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.info-card li {
  margin: 3px 0;
  color: #294450;
}

.info-card code {
  background: rgba(34, 70, 84, 0.08);
  border: 1px solid rgba(34, 70, 84, 0.16);
  border-radius: 6px;
  padding: 1px 5px;
  font-size: 0.88em;
}

.info-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: 1px solid rgba(20, 44, 53, 0.2);
  border-radius: 999px;
  width: 34px;
  height: 34px;
  background: #eef5fa;
  color: #234250;
  font-size: 1rem;
  cursor: pointer;
}

body.dark-mode .info-card {
  background: #17263a;
  border-color: rgba(157, 194, 212, 0.3);
}

body.dark-mode .info-card p,
body.dark-mode .info-card li {
  color: #bfd6e3;
}

body.dark-mode .info-card code {
  background: rgba(185, 213, 229, 0.12);
  border-color: rgba(185, 213, 229, 0.24);
}

body.dark-mode .info-card h3,
body.dark-mode .info-card h4 {
  color: #e4f2f8;
}

body.dark-mode .info-close {
  background: #213950;
  border-color: rgba(157, 194, 212, 0.3);
  color: #daedf8;
}

body.dark-mode .reveal-confirm-card {
  background: #17263a;
  border-color: rgba(157, 194, 212, 0.3);
}

body.dark-mode .reveal-confirm-card p,
body.dark-mode .reveal-confirm-card h3 {
  color: #d7e9f5;
}

body.dark-mode .leaderboard-card {
  background: #17263a;
  border-color: rgba(157, 194, 212, 0.3);
}

body.dark-mode .leaderboard-note,
body.dark-mode .leaderboard-card h3,
body.dark-mode .leaderboard-block h4,
body.dark-mode .leaderboard-row-label,
body.dark-mode .leaderboard-row-value {
  color: #d7e9f5;
}

body.dark-mode .leaderboard-block {
  background: #1a2c40;
  border-color: rgba(158, 193, 212, 0.3);
}

body.dark-mode .leaderboard-block-head p,
body.dark-mode .leaderboard-row-meta,
body.dark-mode .leaderboard-kpi-label {
  color: #a9c2d2;
}

body.dark-mode .leaderboard-kpi {
  background: #20354b;
  border-color: rgba(158, 193, 212, 0.26);
}

body.dark-mode .leaderboard-kpi-value {
  color: #e3f2fb;
}

body.dark-mode .leaderboard-row {
  background: rgba(30, 49, 69, 0.84);
  border-color: rgba(158, 193, 212, 0.24);
}

body.dark-mode .leaderboard-meter {
  background: #2b435a;
}

@media (max-width: 640px) {
  .floating-controls {
    left: 10px;
    gap: 6px;
  }

  .leaderboard-kpis {
    grid-template-columns: 1fr;
  }

  .leaderboard-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "label value"
      "meta meta";
    row-gap: 4px;
  }

  .leaderboard-row-label {
    grid-area: label;
  }

  .leaderboard-row-value {
    grid-area: value;
  }

  .leaderboard-row-meta {
    grid-area: meta;
  }

  .leaderboard-level-rows .leaderboard-row {
    grid-template-columns: auto 1fr auto;
    grid-template-areas: none;
  }

  .leaderboard-level-rows .leaderboard-row-meta {
    display: none;
  }
}

@keyframes floatBlob {
  0% {
    transform: translateY(0) translateX(0) rotate(0deg);
  }
  100% {
    transform: translateY(-18px) translateX(12px) rotate(8deg);
  }
}

@keyframes blobDrift {
  0% {
    transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
  }
  30% {
    transform: translate3d(48px, -30px, 0) scale(1.15) rotate(15deg);
  }
  60% {
    transform: translate3d(-30px, 42px, 0) scale(0.91) rotate(-12deg);
  }
  100% {
    transform: translate3d(24px, -18px, 0) scale(1.09) rotate(9deg);
  }
}

@keyframes blobTint {
  0% {
    filter: blur(2px) hue-rotate(0deg) saturate(1);
  }
  50% {
    filter: blur(2px) hue-rotate(12deg) saturate(1.08);
  }
  100% {
    filter: blur(2px) hue-rotate(-10deg) saturate(1.02);
  }
}

@keyframes twinkle {
  0%,
  100% {
    transform: scale(0.75);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.2);
    opacity: 1;
  }
}

@keyframes sparkDrift {
  0% {
    translate: 0 0;
  }
  100% {
    translate: 8px -10px;
  }
}

@keyframes popIn {
  0% {
    transform: scale(0.78);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes pulseWord {
  0% {
    transform: scale(0.94);
  }
  65% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

@keyframes dropIn {
  0% {
    transform: translateY(16px) scale(0.95);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(105vh) rotate(580deg);
    opacity: 0.1;
  }
}

@media (max-width: 560px) {
  .panel-top {
    flex-direction: column;
    align-items: flex-start;
  }

  .letters {
    grid-template-columns: repeat(5, minmax(48px, 1fr));
    gap: 7px;
  }

  .tile {
    min-height: 52px;
    font-size: 1.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .blob,
  .spark {
    animation: none;
  }
}
