:root {
  --bg-start: #ffd6ea;
  --bg-end: #c9e2ff;
  --text: #3d2f52;
  --shadow: rgba(120, 90, 170, 0.18);

  --panel: rgba(255, 255, 255, 0.35);
  --glass-border: rgba(255, 255, 255, 0.7);
  --glass-shine: rgba(255, 255, 255, 0.55);

  --n: #ffd6e0;
  --g: #d9c8ff;
  --h: #ffe9a8;
  --a: #ffc9b3;
  --e: #ffdfa0;
  --m: #c9f0d8;
  --l: #c4e6ff;
  --c: #bfe3ee;
  --p: #d6e8b5;
  --t: #f9cfe8;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg-start: #2a1745;
  --bg-end: #10203a;
  --text: #f1e9ff;
  --shadow: rgba(0, 0, 0, 0.35);

  --panel: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.2);
  --glass-shine: rgba(255, 255, 255, 0.15);

  --n: #7a4562;
  --g: #5d4a8f;
  --h: #8a7230;
  --a: #8a5440;
  --e: #8a6a30;
  --m: #3f7a58;
  --l: #3a6f99;
  --c: #3a7584;
  --p: #617d3a;
  --t: #85467a;

  color-scheme: dark;
}

html,
body {
  height: auto;
  margin: 0;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  font-family: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 120, 190, 0.55), transparent 40%),
    radial-gradient(circle at 88% 12%, rgba(110, 180, 255, 0.55), transparent 42%),
    radial-gradient(circle at 75% 88%, rgba(180, 140, 255, 0.5), transparent 45%),
    radial-gradient(circle at 15% 85%, rgba(130, 230, 200, 0.45), transparent 40%),
    linear-gradient(135deg, var(--bg-start), var(--bg-end));
  background-attachment: fixed;
}

header {
  position: relative;
  z-index: 1;
  padding: 26px 14px 6px;
  text-align: center;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.4rem);
  font-weight: 600;
}

.grad {
  background: linear-gradient(90deg, #ff5fa8, #a77bff, #4fa8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

header p {
  margin: 6px 0 14px;
  opacity: 0.75;
}

#search {
  width: min(320px, 80vw);
  padding: 10px 18px;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  box-shadow: 0 8px 24px var(--shadow), inset 0 1px 0 var(--glass-shine);
  outline: none;
  transition: 0.25s;
}

#search::placeholder {
  color: var(--text);
  opacity: 0.55;
}

#search:focus {
  border-color: #ff9ac4;
  transform: scale(1.04);
}

.play {
  margin-left: 8px;
  padding: 10px 20px;
  font: inherit;
  color: #fff;
  background: linear-gradient(135deg, #ff6fb1, #a77bff);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  box-shadow: 0 8px 20px rgba(255, 90, 170, 0.35), inset 0 1px 0 var(--glass-shine);
  cursor: pointer;
  transition: transform 0.2s;
}

.play:hover {
  transform: scale(1.08);
}

.play.ghost {
  color: var(--text);
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 20px var(--shadow), inset 0 1px 0 var(--glass-shine);
}

#theme {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: 12px;
  z-index: 15;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  font-size: 1.2rem;
  border-radius: 50%;
}

#legend {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 14px 12px;
}

.chip {
  padding: 6px 14px;
  font: inherit;
  font-size: 0.82rem;
  color: var(--text);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  box-shadow: 0 4px 12px var(--shadow), inset 0 1px 0 var(--glass-shine);
  cursor: pointer;
  transition: transform 0.2s;
}

.chip:hover {
  transform: translateY(-3px) scale(1.06);
}

.chip.on {
  outline: 3px solid #ff7eb6;
}

#modes {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding-top: 8px;
}

#modes .chip {
  --bg: #ffffff;
  font-weight: 500;
}

.wrap {
  position: relative;
  z-index: 1;
  padding: 10px 8px 40px;
  container-type: inline-size;
}

#grid {
  display: grid;
  grid-template-columns: repeat(18, 1fr);
  grid-template-rows: repeat(7, auto) clamp(6px, 2cqw, 18px) repeat(2, auto);
  gap: clamp(1px, 0.5cqw, 6px);
  max-width: 1500px;
  margin: 0 auto;
}

.el {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  aspect-ratio: 1 / 1.05;
  padding: 0;
  text-align: center;
  box-sizing: border-box;
  color: var(--text);
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--bg) 85%, transparent),
    color-mix(in srgb, var(--bg) 40%, transparent)
  );
  backdrop-filter: blur(6px);
  border: 1px solid var(--glass-border);
  border-radius: clamp(3px, 1cqw, 14px);
  box-shadow: 0 4px 12px var(--shadow), inset 0 1px 0 var(--glass-shine);
  cursor: pointer;
  animation: pop-in 0.6s cubic-bezier(0.3, 1.6, 0.5, 1) backwards;
  transition: transform 0.2s, filter 0.3s, opacity 0.3s;
}

.el:hover {
  z-index: 5;
  transform: scale(1.18) rotate(-2deg);
  box-shadow: 0 10px 24px var(--shadow), 0 0 20px color-mix(in srgb, var(--bg) 90%, white);
}

.el.dim {
  filter: grayscale(0.9) opacity(0.28);
  transform: scale(0.92);
}

.el .z {
  position: absolute;
  top: 4px;
  left: 7px;
  font-size: 0.62rem;
  opacity: 0.7;
}

.el .s {
  font-size: clamp(0.45rem, 3cqw, 1.35rem);
  font-weight: 600;
  line-height: 1;
}

.el .nm {
  margin-top: 3px;
  font-size: 0.56rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.8;
}

.mark {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.38rem, 1.5cqw, 0.7rem);
  text-align: center;
  opacity: 0.7;
}

@container (max-width: 760px) {
  .el .z,
  .el .nm {
    display: none;
  }
}

.el.right {
  outline: 3px solid #4fe3a0;
  box-shadow: 0 0 22px #4fe3a0;
}

.el.wrong {
  outline: 3px solid #ff6b8b;
}

.el.got::after {
  content: "⭐";
  position: absolute;
  top: -3px;
  right: -2px;
  font-size: clamp(0.4rem, 1.7cqw, 0.85rem);
}

.el.rel {
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.95), inset 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.el:focus-visible {
  outline: 3px solid #ff7eb6;
  outline-offset: 2px;
}

.el.picked {
  outline: 3px solid #ffb84f;
  box-shadow: 0 0 20px #ffb84f;
}

#modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(40, 20, 70, 0.25);
  backdrop-filter: blur(8px);
}

#modal.show {
  display: flex;
  animation: fade-in 0.25s;
}

.card {
  position: relative;
  width: min(420px, 100%);
  padding: 22px;
  text-align: center;
  color: var(--text);
  background: linear-gradient(
    145deg,
    color-mix(in srgb, var(--bg) 75%, transparent),
    color-mix(in srgb, var(--bg) 30%, transparent)
  );
  backdrop-filter: blur(24px) saturate(160%);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25), inset 0 1px 0 var(--glass-shine);
  animation: card-in 0.5s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.card h2 {
  margin: 4px 0 2px;
  font-size: 1.7rem;
}

.orbit {
  position: relative;
  width: 124px;
  height: 124px;
  margin: 0 auto 10px;
  color: #3d2f52;
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.35));
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  box-shadow: 0 10px 24px var(--shadow), inset 0 -8px 16px rgba(255, 255, 255, 0.4);
}

.big {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 20px;
  font-size: 2.5rem;
  font-weight: 600;
}

.face {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 20px;
  display: flex;
  justify-content: center;
  gap: 18px;
}

.face i {
  width: 7px;
  height: 10px;
  background: #3d2f52;
  border-radius: 50%;
  animation: blink 4s infinite;
}

.face::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  width: 10px;
  height: 6px;
  margin-left: -36px;
  background: #ff8fb8;
  border-radius: 50%;
  opacity: 0.7;
  box-shadow: 62px 0 #ff8fb8;
}

.face::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 50%;
  width: 12px;
  height: 6px;
  margin-left: -6px;
  border-bottom: 2px solid #3d2f52;
  border-radius: 0 0 12px 12px;
}

.say {
  position: relative;
  margin: 0 0 12px;
  padding: 9px 14px;
  font-size: 0.86rem;
  line-height: 1.35;
  background: var(--panel);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
}

.say::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background: var(--panel);
  border-top: 1px solid var(--glass-border);
  border-left: 1px solid var(--glass-border);
  transform: rotate(45deg);
}

.tag {
  display: inline-block;
  margin-bottom: 12px;
  padding: 3px 14px;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
}

.info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  text-align: left;
}

.info div {
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
}

.info b {
  display: block;
  font-size: 1.05rem;
}

.info .wide {
  grid-column: 1 / -1;
}

.nav {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
}

.nav button,
.x {
  padding: 8px 16px;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  cursor: pointer;
  transition: transform 0.2s;
}

.nav button:hover,
.x:hover {
  transform: scale(1.1);
}

.x {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 4px 11px;
}

#quiz,
#lab {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  width: fit-content;
  max-width: calc(100% - 24px);
  margin: 10px auto 0;
  padding: 10px 22px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--glass-border);
  border-radius: 99px;
  box-shadow: 0 8px 24px var(--shadow), inset 0 1px 0 var(--glass-shine);
}

#quiz[hidden],
#lab[hidden] {
  display: none;
}

.slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
}

.slot.empty {
  border-style: dashed;
  opacity: 0.6;
}

.spark {
  position: fixed;
  z-index: 30;
  font-size: 1.2rem;
  pointer-events: none;
  animation: spark 0.9s ease-out forwards;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.2) rotate(-25deg); }
  to   { opacity: 1; transform: none; }
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes card-in {
  from { opacity: 0; transform: scale(0.4) rotate(8deg); }
}

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

@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  96%           { transform: scaleY(0.1); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01s !important;
  }
}

.card {
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}

@media (min-width: 900px) {
  body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px 16px;
    padding: 10px 72px 0 20px;
  }

  h1 {
    font-size: clamp(1.4rem, 3.2vh, 2rem);
  }

  header p {
    display: none;
  }

  #search {
    width: 230px;
    padding: 7px 16px;
  }

  .play {
    margin-left: 0;
    padding: 7px 16px;
  }

  #quiz,
  #lab {
    margin-top: 6px;
    padding: 6px 18px;
  }

  .controls {
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 6px 14px;
    padding: 6px 20px 0;
  }

  #modes,
  #legend {
    padding: 0;
  }

  .chip {
    padding: 4px 11px;
    font-size: 0.74rem;
  }

  .wrap {
    flex: 1;
    min-height: 0;
    padding: 6px 16px 12px;
  }

  #grid {
    height: 100%;
    max-width: 100%;
    aspect-ratio: 18 / 9.6;
    margin: 0 auto;
    grid-template-rows: repeat(7, 1fr) clamp(4px, 1.2vh, 12px) repeat(2, 1fr);
  }

  .el {
    aspect-ratio: auto;
  }

  .el .s {
    font-size: clamp(0.6rem, min(1.7cqw, 3.2vh), 1.35rem);
  }
}

@media (min-width: 900px) and (max-height: 720px) {
  .el .nm {
    display: none;
  }
}
