:root {
  --ink: #2B2350;
  --cream: #FFF7E6;
  --coral: #FF7A66;
  --coral-dk: #E85B47;
  --gold: #FFC24B;
  --teal: #51C2B8;
  --sky: #87D4F5;
  --pink: #FF8FA3;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Nunito', system-ui, sans-serif;
  background: var(--sky);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas {
  display: block;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.chip {
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 4px 0 rgba(43, 35, 80, .35);
  color: var(--ink);
}

#hearts {
  position: absolute;
  top: 14px;
  left: 14px;
  padding: 6px 12px;
  font-size: 20px;
  letter-spacing: 2px;
}

#levelChip {
  position: absolute;
  top: 64px;
  left: 14px;
  padding: 4px 12px;
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 14px;
}

#scoreBox {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 6px 14px;
  text-align: right;
  min-width: 110px;
}

#scoreVal {
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 24px;
  line-height: 1;
}

#bestVal {
  font-size: 11px;
  font-weight: 800;
  opacity: .65;
}

#combo {
  position: absolute;
  top: 84px;
  right: 14px;
  padding: 4px 12px;
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 16px;
  background: var(--gold);
  transform: scale(0);
  transition: transform .18s cubic-bezier(.34, 1.56, .64, 1);
}

#combo.on {
  transform: scale(1);
}

#combo.pop {
  animation: pop .25s;
}

#tray {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
}

#trayEmoji {
  font-size: 30px;
  line-height: 1;
}

#slots {
  display: flex;
  gap: 6px;
}

.slot {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 24px;
  color: var(--ink);
  border: 3px dashed rgba(43, 35, 80, .3);
  background: rgba(255, 255, 255, .55);
}

.slot.ghost {
  color: rgba(43, 35, 80, .28);
}

.slot.current {
  border: 3px solid var(--coral);
  background: #fff;
  animation: pulse 1s infinite;
}

.slot.filled {
  border: 3px solid var(--ink);
  background: var(--gold);
  animation: pop .3s;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(255, 122, 102, .55);
  }
  50% {
    box-shadow: 0 0 0 7px rgba(255, 122, 102, 0);
  }
}

@keyframes pop {
  0% {
    transform: scale(.4);
  }
  70% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}

.iconBtn {
  position: absolute;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
  border: 3px solid var(--ink);
  background: var(--cream);
  box-shadow: 0 3px 0 rgba(43, 35, 80, .35);
}

.iconBtn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(43, 35, 80, .35);
}

#muteBtn {
  top: 120px;
  right: 14px;
}

#pauseBtn {
  top: 170px;
  right: 14px;
}

#toast {
  position: absolute;
  top: 26%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  font-family: 'Fredoka';
  font-weight: 700;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  font-size: 42px;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 4px 0 rgba(43, 35, 80, .4);
  white-space: nowrap;
}

#toast.show {
  animation: toastIn .3s forwards;
}

#toast.hide {
  animation: toastOut .25s forwards;
}

#toast.intro {
  font-size: 52px;
}

#toast .sub {
  display: block;
  font-size: .45em;
  -webkit-text-stroke: 1px var(--ink);
}

@keyframes toastIn {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(.4);
  }
  70% {
    transform: translateX(-50%) scale(1.12);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateX(-50%) scale(.8) translateY(-18px);
  }
}

#flash {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 35%, rgba(232, 77, 71, .55));
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  transition: opacity .12s;
}

#flash.on {
  opacity: 1;
}

#hint {
  position: absolute;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 16px;
  font-weight: 800;
  font-size: 13px;
  opacity: 0;
  transition: opacity .4s;
}

#hint.show {
  opacity: 1;
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(43, 35, 80, .35);
  backdrop-filter: blur(3px);
}

.overlay.hidden {
  display: none;
}

.card {
  background: var(--cream);
  border: 4px solid var(--ink);
  border-radius: 26px;
  padding: 30px 34px;
  width: min(420px, 92vw);
  max-height: 92vh;
  overflow: auto;
  text-align: center;
  color: var(--ink);
  box-shadow: 0 8px 0 rgba(43, 35, 80, .45);
}

.title {
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 44px;
  line-height: 1.05;
  margin: 4px 0 2px;
}

.title .accent {
  color: var(--coral);
}

.tagline {
  font-weight: 800;
  font-size: 14px;
  opacity: .75;
  margin-bottom: 18px;
}

.howto {
  text-align: left;
  margin: 0 auto 20px;
  max-width: 300px;
  display: grid;
  gap: 10px;
}

.howto div {
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 700;
  font-size: 14px;
}

.howto .ico {
  font-size: 22px;
  width: 30px;
  text-align: center;
  flex: none;
}

.bigBtn {
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 24px;
  color: #fff;
  background: var(--coral);
  border: 4px solid var(--ink);
  border-radius: 18px;
  padding: 12px 44px;
  cursor: pointer;
  box-shadow: 0 6px 0 var(--coral-dk), 0 9px 0 rgba(43, 35, 80, .4);
  transition: transform .12s;
}

.bigBtn:hover {
  transform: scale(1.05);
}

.bigBtn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--coral-dk), 0 4px 0 rgba(43, 35, 80, .4);
}

.keysNote {
  margin-top: 16px;
  font-size: 12px;
  font-weight: 800;
  opacity: .6;
}

kbd {
  background: #fff;
  border: 2px solid var(--ink);
  border-bottom-width: 4px;
  border-radius: 7px;
  padding: 1px 7px;
  font-family: 'Nunito';
}

/* category picker */
.pickHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 2px 8px;
}

.pickHead .lbl {
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 15px;
}

.pickHead button {
  font-family: 'Nunito';
  font-weight: 800;
  font-size: 11px;
  background: #fff;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 9px;
  padding: 3px 9px;
  cursor: pointer;
}

.pickHead button:active {
  transform: translateY(1px);
}

#catGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 168px;
  overflow: auto;
  padding: 4px;
  border: 3px dashed rgba(43, 35, 80, .25);
  border-radius: 14px;
  margin-bottom: 6px;
}

.catTag {
  font-weight: 800;
  font-size: 12px;
  border: 2px solid var(--ink);
  border-radius: 11px;
  padding: 5px 9px;
  cursor: pointer;
  background: #fff;
  color: var(--ink);
  opacity: .42;
  transition: .12s;
  white-space: nowrap;
}

.catTag.on {
  opacity: 1;
  background: var(--teal);
  color: #fff;
  box-shadow: 0 2px 0 rgba(43, 35, 80, .3);
}

.catTag:active {
  transform: translateY(1px);
}

#poolInfo {
  font-size: 11px;
  font-weight: 800;
  opacity: .6;
  margin-bottom: 14px;
}

/* character roster */
#roster, #roster2 {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 4px 0 16px;
}

.charTile {
  position: relative;
  width: 74px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 8px 4px 6px;
  background: #fff;
  cursor: pointer;
  text-align: center;
  transition: .12s;
  box-shadow: 0 3px 0 rgba(43, 35, 80, .25);
}

.charTile .emoji {
  font-size: 32px;
  line-height: 1.1;
  filter: none;
}

.charTile .nm {
  font-size: 9px;
  font-weight: 800;
  margin-top: 3px;
  line-height: 1.05;
  color: var(--ink);
}

.charTile.locked {
  background: #EDE7DA;
  cursor: not-allowed;
}

.charTile.locked .emoji {
  filter: grayscale(1) opacity(.45);
}

.charTile.locked .nm {
  opacity: 0;
}

.charTile .lockreq {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 5px;
  font-size: 9px;
  font-weight: 800;
  color: var(--ink);
  opacity: .7;
}

.charTile .lockicon {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 12px;
}

.charTile.selected {
  background: var(--gold);
  box-shadow: 0 3px 0 rgba(43, 35, 80, .4);
  transform: translateY(-2px);
}

.charTile:not(.locked):active {
  transform: translateY(1px);
}

/* progress / stats screen */
#statsKid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0 6px;
}

.bigstat {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 10px;
}

.bigstat .v {
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
}

.bigstat .l {
  font-size: 11px;
  font-weight: 800;
  opacity: .7;
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-top: 2px;
}

.catProg {
  text-align: left;
  margin: 10px 0;
}

.catRow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
  font-weight: 800;
  font-size: 12px;
}

.catRow .nm {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar {
  flex: 2;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.bar>i {
  display: block;
  height: 100%;
  background: var(--teal);
}

.wordChips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 6px 0 12px;
  justify-content: center;
}

.wchip {
  font-weight: 800;
  font-size: 12px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 3px 8px;
  background: #fff;
}

.wchip.weak {
  background: #FFD9D2;
}

.wchip.master {
  background: #CDEFD6;
}

.sectionH {
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 14px;
  text-align: left;
  margin: 12px 0 4px;
}

#goTitle {
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 36px;
}

#newBest {
  display: inline-block;
  background: var(--gold);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 3px 14px;
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 15px;
  margin: 6px 0;
  animation: pop .4s;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 18px 0 22px;
}

.stat {
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 8px;
}

.stat .v {
  font-family: 'Fredoka';
  font-weight: 700;
  font-size: 24px;
}

.stat .l {
  font-size: 11px;
  font-weight: 800;
  opacity: .65;
  text-transform: uppercase;
  letter-spacing: .5px;
}

@media (max-width: 520px) {
  #tray {
    top: 64px;
  }

  .slot {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  #trayEmoji {
    font-size: 24px;
  }

  .title {
    font-size: 36px;
  }
}

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