/* ============================================================
   FAKEMON FRIENDS — a storybook world for a new reader
   Crayon-bright colours, thick ink lines, sticker shadows.
   ============================================================ */

:root {
  --paper:      #FFF6E0;
  --paper-deep: #FBE9C4;
  --ink:        #3B3354;
  --ink-soft:   #6B628C;
  --white:      #FFFFFF;
  --red:        #FF6B6B;
  --orange:     #FFA94D;
  --yellow:     #FFD43B;
  --green:      #69DB7C;
  --teal:       #3BC9DB;
  --blue:       #4DABF7;
  --purple:     #B197FC;
  --pink:       #FAA2C1;
  --shadow:     #E4CFA3;

  --display: "Fredoka", sans-serif;
  /* Andika is designed by SIL specifically for beginner readers:
     single-storey a, clear b/d distinction, generous letterforms. */
  --reader:  "Andika", sans-serif;

  --line: 3px solid var(--ink);
  --pop: cubic-bezier(.34, 1.56, .64, 1);
}

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

html, body { height: 100%; }

body {
  font-family: var(--reader);
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 212, 59, .18) 0 140px, transparent 141px),
    radial-gradient(circle at 85% 80%, rgba(77, 171, 247, .12) 0 180px, transparent 181px),
    radial-gradient(rgba(59, 51, 84, .05) 1.2px, transparent 1.3px),
    var(--paper);
  background-size: auto, auto, 26px 26px, auto;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

button { font-family: var(--display); cursor: pointer; color: var(--ink); }
input  { font-family: var(--reader); color: var(--ink); }

/* ============ TOP BAR ============ */

#topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--white);
  border-bottom: var(--line);
  box-shadow: 0 4px 0 rgba(59, 51, 84, .08);
  position: sticky;
  top: 0;
  z-index: 40;
}

.logo { display: flex; align-items: center; gap: 9px; }

.logo-ball {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: var(--line);
  background: linear-gradient(to bottom, var(--red) 0 46%, var(--ink) 46% 54%, var(--white) 54%);
  position: relative;
  animation: ball-wobble 4s ease-in-out infinite;
}
.logo-ball::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  background: var(--white);
}
@keyframes ball-wobble {
  0%, 80%, 100% { transform: rotate(0); }
  85% { transform: rotate(-14deg); }
  92% { transform: rotate(12deg); }
}

.logo-text {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: .04em;
}
.logo-text em { font-style: normal; color: var(--red); }

.clockbox {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--paper);
  border: var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  font-family: var(--display);
  font-weight: 600;
}
#clock-time { font-size: 1.05rem; min-width: 52px; text-align: center; }
#clock-day  { font-size: .78rem; color: var(--ink-soft); letter-spacing: .06em; }

.starbox {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--yellow);
  border: var(--line);
  border-radius: 999px;
  padding: 4px 13px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 3px 0 var(--ink);
}
.starbox.bump { animation: bump .45s var(--pop); }
@keyframes bump { 40% { transform: scale(1.25) rotate(-4deg); } }

/* ============ BUTTONS ============ */

.btn {
  border: var(--line);
  border-radius: 16px;
  background: var(--white);
  font-weight: 600;
  font-size: 1.05rem;
  padding: 10px 20px;
  box-shadow: 0 5px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }

.btn-go {
  background: var(--green);
  font-size: 1.2rem;
  padding: 13px 26px;
  border-radius: 20px;
}
.btn-small { font-size: .95rem; padding: 8px 14px; box-shadow: 0 4px 0 var(--ink); }
.btn-quiet { background: var(--paper); color: var(--ink-soft); }

.mini-btn {
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  background: var(--white);
  font-size: .85rem;
  padding: 3px 9px;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.mini-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.mini-btn.big { font-size: 1.25rem; padding: 6px 12px; border-radius: 14px; }

/* ============ SCREENS / NAV ============ */

main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 18px 16px 110px; }

.screen { display: none; animation: screen-in .35s var(--pop); }
.screen.active { display: block; }
@keyframes screen-in { from { opacity: 0; transform: translateY(14px); } }

.screen-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.7rem, 4vw, 2.4rem);
  transform: rotate(-1.2deg);
  margin-bottom: 4px;
}
.screen-sub { color: var(--ink-soft); margin-bottom: 18px; font-size: 1.05rem; }

#bottom-nav {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  background: var(--white);
  border: var(--line);
  border-radius: 26px;
  padding: 8px;
  box-shadow: 0 6px 0 var(--ink), 0 14px 30px rgba(59, 51, 84, .18);
  z-index: 65;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border: 3px solid transparent;
  border-radius: 18px;
  background: transparent;
  padding: 7px 22px;
  transition: background .15s, transform .15s;
}
.nav-btn .nav-ico  { font-size: 1.5rem; }
.nav-btn .nav-word { font-weight: 700; font-size: .72rem; letter-spacing: .08em; }
.nav-btn.active {
  background: var(--yellow);
  border-color: var(--ink);
  transform: rotate(-2deg) scale(1.05);
}

/* ============ TOWN ============ */

#town-wrap {
  position: relative;
  border: var(--line);
  border-radius: 26px;
  overflow: hidden;
  box-shadow: 0 8px 0 var(--shadow);
  background: #BCE3FF;
  aspect-ratio: 1000 / 620;
}
#town-map, #town-map svg { position: absolute; inset: 0; width: 100%; height: 100%; }

#npc-layer, #wild-layer, #pet-layer { position: absolute; inset: 0; pointer-events: none; }

.npc {
  position: absolute;
  width: 9.5%;
  transform: translate(-50%, -92%);
  transition: left 3.2s linear, top 3.2s linear;
  pointer-events: auto;
  cursor: pointer;
  filter: drop-shadow(0 4px 2px rgba(59, 51, 84, .25));
}
.npc svg { width: 100%; height: auto; animation: npc-bob 2.6s ease-in-out infinite; }
.npc:hover svg { animation: npc-hop .5s var(--pop); }
@keyframes npc-bob { 50% { transform: translateY(-3.5%); } }
@keyframes npc-hop { 40% { transform: translateY(-12%) rotate(-3deg); } }

.npc-tag {
  position: absolute;
  left: 50%;
  top: -16px;
  transform: translateX(-50%);
  background: var(--white);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(.55rem, 1.3vw, .8rem);
  padding: 1px 9px;
  white-space: nowrap;
}
.npc.asleep .npc-tag::after { content: " 💤"; }

.wild {
  position: absolute;
  width: 8%;
  transform: translate(-50%, -85%);
  pointer-events: auto;
  cursor: pointer;
  animation: wild-pop .5s var(--pop);
  filter: drop-shadow(0 4px 2px rgba(59, 51, 84, .25));
}
.wild svg { width: 100%; height: auto; animation: npc-bob 1.8s ease-in-out infinite; }
.wild .wild-spark {
  position: absolute;
  top: -14px; right: -8px;
  font-size: 1.1rem;
  animation: twinkle 1.2s ease-in-out infinite;
}
@keyframes wild-pop { from { transform: translate(-50%, -85%) scale(0); } }
@keyframes twinkle { 50% { transform: scale(1.5) rotate(20deg); opacity: .5; } }

.pet {
  position: absolute;
  width: 6%;
  transform: translate(-50%, -85%);
  pointer-events: auto;
  cursor: pointer;
  filter: drop-shadow(0 3px 2px rgba(59, 51, 84, .2));
}
.pet svg { width: 100%; height: auto; animation: npc-bob 2.2s ease-in-out infinite; }
.pet.cheer svg { animation: npc-hop .5s var(--pop) 3; }

.town-hint {
  text-align: center;
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 1rem;
}

/* ============ WORDS (the heart of it all) ============ */

.word {
  cursor: pointer;
  border-radius: 7px;
  padding: 0 2px;
  transition: background .12s;
}
.word:hover { background: var(--yellow); box-shadow: 0 2px 0 var(--orange); }
.word.lit   { background: var(--yellow); box-shadow: 0 2px 0 var(--orange); }

.syl-line {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: .03em;
  color: var(--ink-soft);
  min-height: 1.6em;
}
.syl-line .syl { color: var(--ink); }
.syl-line .syl-dot { color: var(--red); margin: 0 4px; }

.word-toast {
  position: fixed;
  transform: translate(-50%, -120%);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.15rem;
  padding: 7px 16px;
  border-radius: 14px;
  box-shadow: 0 5px 14px rgba(59, 51, 84, .35);
  cursor: pointer;
  z-index: 90;
  animation: toast-in .3s var(--pop);
  white-space: nowrap;
}
.word-toast .syl-dot { color: var(--yellow); margin: 0 5px; }
.word-toast::after {
  content: "🐢 tap me";
  display: block;
  font-size: .62rem;
  text-align: center;
  opacity: .7;
  letter-spacing: .05em;
}
@keyframes toast-in { from { transform: translate(-50%, -60%) scale(.6); opacity: 0; } }
.word-toast.gone { transition: opacity .3s; opacity: 0; }

/* ============ TALK SHEET ============ */

#talk-sheet {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translate(-50%, calc(100% + 130px));
  width: min(720px, calc(100% - 20px));
  background: var(--white);
  border: var(--line);
  border-radius: 28px;
  box-shadow: 0 8px 0 rgba(59, 51, 84, .25), 0 18px 40px rgba(59, 51, 84, .25);
  display: flex;
  gap: 16px;
  padding: 20px 22px 22px;
  z-index: 60;
  transition: transform .4s var(--pop);
}
#talk-sheet.open { transform: translate(-50%, 0); }

#talk-close { position: absolute; top: 12px; right: 14px; }

#talk-portrait {
  flex: 0 0 110px;
  align-self: flex-start;
  background: var(--paper);
  border: var(--line);
  border-radius: 20px;
  padding: 8px;
  transform: rotate(-2deg);
}
#talk-portrait svg { width: 100%; height: auto; }

#talk-body { flex: 1; min-width: 0; }

#talk-name-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
#talk-name { font-family: var(--display); font-weight: 700; font-size: 1.35rem; }
#talk-doing { color: var(--ink-soft); font-size: .92rem; font-style: italic; }

#talk-lines {
  margin: 10px 0 6px;
  font-size: 1.45rem;
  line-height: 2;
  word-spacing: .15em;
}

#talk-extra { margin: 8px 0; }

#talk-buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

/* word-of-the-day card + day plan, shown inside talk sheet */
.word-day-card {
  background: var(--paper);
  border: var(--line);
  border-radius: 18px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transform: rotate(-.6deg);
}
.word-day-big {
  font-family: var(--display);
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
}
.word-day-card .btn-small { margin-left: auto; }

.plan-list { list-style: none; font-size: 1.1rem; line-height: 1.9; }
.plan-list .plan-time {
  display: inline-block;
  min-width: 64px;
  font-family: var(--display);
  font-weight: 600;
  color: var(--ink-soft);
}
.plan-list li.now { background: var(--yellow); border-radius: 10px; padding: 0 8px; }

/* ============ DEX ============ */

#dex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 20px;
}

.dex-card {
  background: var(--white);
  border: var(--line);
  border-radius: 22px;
  padding: 16px 16px 18px;
  box-shadow: 0 6px 0 var(--shadow);
  position: relative;
  transition: transform .2s var(--pop);
}
.dex-card:nth-child(odd)  { transform: rotate(-1deg); }
.dex-card:nth-child(even) { transform: rotate(1deg); }
.dex-card:hover { transform: rotate(0) translateY(-5px); }

.dex-art {
  background: var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  padding: 6px;
  margin-bottom: 10px;
}
.dex-art svg { width: 100%; height: auto; display: block; }
.dex-card:hover .dex-art svg { animation: npc-hop .5s var(--pop); }

.dex-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.3rem;
  cursor: pointer;
}
.dex-syl { font-size: .95rem; min-height: 1.4em; }

.type-chip {
  display: inline-block;
  font-family: var(--display);
  font-weight: 600;
  font-size: .78rem;
  letter-spacing: .05em;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  padding: 2px 11px;
  margin: 6px 0 8px;
}

.dex-desc { font-size: 1.08rem; line-height: 1.75; }

.dex-badge {
  position: absolute;
  top: -12px;
  right: -8px;
  background: var(--yellow);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  font-family: var(--display);
  font-weight: 700;
  font-size: .72rem;
  padding: 3px 10px;
  transform: rotate(6deg);
  box-shadow: 0 3px 0 var(--ink);
}
.dex-badge.friend { background: var(--green); }

/* ============ MAKER ============ */

#maker { display: flex; gap: 26px; align-items: flex-start; flex-wrap: wrap; }

#maker-preview-col {
  flex: 0 0 320px;
  position: sticky;
  top: 80px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--white);
  border: var(--line);
  border-radius: 26px;
  padding: 18px;
  box-shadow: 0 7px 0 var(--shadow);
  transform: rotate(-.8deg);
}

#maker-preview {
  background:
    radial-gradient(circle at 50% 20%, rgba(255, 212, 59, .35), transparent 70%),
    var(--paper);
  border: 2.5px solid var(--ink);
  border-radius: 20px;
  padding: 10px;
}
#maker-preview svg { width: 100%; height: auto; display: block; animation: npc-bob 2.4s ease-in-out infinite; }

.name-row { display: flex; gap: 8px; }
#maker-name {
  flex: 1;
  min-width: 0;
  border: var(--line);
  border-radius: 14px;
  font-size: 1.3rem;
  font-weight: 700;
  padding: 8px 12px;
  background: var(--paper);
  text-transform: lowercase;
}
#maker-name:focus { outline: 3px solid var(--yellow); }

.likes-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.likes-label { font-size: 1.05rem; color: var(--ink-soft); }
#likes-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.like-chip {
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--white);
  font-family: var(--reader);
  font-size: .95rem;
  padding: 3px 11px;
}
.like-chip.on { background: var(--pink); font-weight: 700; }

#maker-parts-col { flex: 1; min-width: 300px; display: flex; flex-direction: column; gap: 18px; }

.part-group h3 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: .04em;
  margin-bottom: 8px;
  transform: rotate(-.5deg);
}
.part-row { display: flex; gap: 9px; flex-wrap: wrap; }

.part-btn {
  width: 64px; height: 64px;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  background: var(--white);
  padding: 4px;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .1s;
}
.part-btn svg { width: 100%; height: 100%; }
.part-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.part-btn.on { background: var(--yellow); transform: scale(1.07) rotate(-2deg); }

.swatch {
  width: 40px; height: 40px;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 3px 0 var(--ink);
}
.swatch.on { outline: 4px solid var(--yellow); transform: scale(1.12); }

.type-btn {
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  font-family: var(--display);
  font-weight: 600;
  font-size: .9rem;
  padding: 6px 14px;
  background: var(--white);
  box-shadow: 0 3px 0 var(--ink);
}
.type-btn.on { transform: scale(1.08) rotate(-2deg); }

/* ============ MODALS ============ */

.modal-veil {
  position: fixed;
  inset: 0;
  background: rgba(59, 51, 84, .45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 70;
  padding: 16px;
}
.modal-veil.open { display: flex; }

#catch-card, #welcome-card {
  background: var(--white);
  border: var(--line);
  border-radius: 28px;
  box-shadow: 0 10px 0 rgba(59, 51, 84, .3);
  padding: 24px 26px;
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  text-align: center;
  animation: card-in .4s var(--pop);
}
@keyframes card-in { from { transform: scale(.6) rotate(3deg); opacity: 0; } }

#catch-title { font-family: var(--display); font-weight: 700; font-size: 1.5rem; }

#catch-sprite { width: 150px; margin: 8px auto; }
#catch-sprite svg { width: 100%; height: auto; animation: npc-bob 1.6s ease-in-out infinite; }
#catch-sprite.sad svg { animation: shake .45s; }
#catch-sprite.happy svg { animation: npc-hop .5s var(--pop) 4; }
@keyframes shake { 25% { transform: translateX(-7px) rotate(-3deg); } 75% { transform: translateX(7px) rotate(3deg); } }

.catch-help { display: flex; gap: 10px; justify-content: center; margin: 10px 0 14px; }

#catch-slots { display: flex; gap: 7px; justify-content: center; flex-wrap: wrap; margin-bottom: 16px; }
.slot {
  width: 46px; height: 54px;
  border: 3px dashed var(--ink-soft);
  border-radius: 12px;
  background: var(--paper);
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  position: relative;
}
.slot .hint-letter { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ink); opacity: .22; }
.slot.filled { border-style: solid; border-color: var(--ink); background: var(--white); }
.slot.yes { background: var(--green); animation: bump .4s var(--pop); }
.slot.no  { background: var(--red); }
.slot.gap { width: 14px; border: none; background: transparent; }

#catch-tiles { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.tile {
  width: 52px; height: 56px;
  border: var(--line);
  border-radius: 14px;
  background: var(--yellow);
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.7rem;
  text-transform: uppercase;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .1s;
}
.tile:nth-child(3n)  { background: var(--pink); }
.tile:nth-child(3n+1){ background: var(--teal); }
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.tile.used { opacity: .25; pointer-events: none; transform: scale(.85); }

.catch-foot { display: flex; gap: 12px; justify-content: center; align-items: center; }

/* ============ WELCOME ============ */

#welcome-card h2 { font-family: var(--display); font-weight: 700; font-size: 1.6rem; margin: 12px 0 6px; }
#welcome-ask { font-size: 1.3rem; margin-bottom: 14px; }
#welcome-name {
  width: min(300px, 100%);
  border: var(--line);
  border-radius: 16px;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  padding: 10px;
  background: var(--paper);
  margin-bottom: 16px;
}
#welcome-name:focus { outline: 3px solid var(--yellow); }
.welcome-art { width: 130px; margin: 0 auto; }
.welcome-art svg { width: 100%; height: auto; animation: npc-bob 2s ease-in-out infinite; }
.welcome-tip { margin-top: 16px; font-size: .82rem; color: var(--ink-soft); }

/* ============ CONFETTI & TOASTS ============ */

#confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 95; overflow: hidden; }
.confetti-bit {
  position: absolute;
  top: -20px;
  width: 12px; height: 12px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); }
}

.note-toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.1rem;
  border-radius: 16px;
  padding: 10px 22px;
  z-index: 90;
  animation: toast-in .35s var(--pop);
  box-shadow: 0 6px 16px rgba(59, 51, 84, .35);
}
.note-toast.gone { transition: opacity .4s; opacity: 0; }

/* ============ SMALL SCREENS ============ */

@media (max-width: 720px) {
  .logo-text { display: none; }
  #talk-sheet { gap: 10px; padding: 16px 14px 20px; }
  #talk-portrait { flex-basis: 76px; }
  #talk-lines { font-size: 1.25rem; }
  #maker-preview-col { position: static; flex: 1 1 100%; }
  .npc-tag { display: none; }
}
