@import url("https://fonts.googleapis.com/css2?family=Fredoka:wght@500;600&family=Nunito:wght@400;700;800&display=swap");

:root {
  --ink: #2B2350;
  --ink-deep: #17123A;
  --muted: #4A4270;
  --lav: #EFE9FF;
  --lav-mid: #AFA4F5;
  --violet: #5B4FC9;
  --butter: #FFD27A;
  --pink: #F7A8C4;
  --pink-bg: #FFE6EF;
  --mint: #CDEFE1;
  --mint-bg: #E4F5EC;
  --sky-bg: #E3F1FA;
  --cream-bg: #FFF4DE;
  --red-soft: #FFD6D6;
  --white: #FFFFFF;
  --page: var(--lav);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--page);
  color: var(--ink);
  font-family: Nunito, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: 96px;
  transition: filter .6s ease;
}

body[data-theme="pink"] { --page: var(--pink-bg); }
body[data-theme="mint"] { --page: var(--mint-bg); }
body[data-theme="sky"] { --page: var(--sky-bg); }
body[data-theme="cream"] { --page: var(--cream-bg); }

h1, h2, h3, .display { font-family: Fredoka, system-ui, sans-serif; font-weight: 600; margin: 0; }
h1 { font-size: clamp(30px, 6vw, 48px); line-height: 1.1; }
h2 { font-size: 20px; }
p { margin: 0; }
a { color: var(--violet); }

.wrap { max-width: 980px; margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: 20px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { font-family: Fredoka, sans-serif; font-size: 24px; font-weight: 600; color: var(--ink); text-decoration: none; }
.logo span { color: #7B6CF6; }
.lede { color: var(--muted); font-size: 15px; }
.kicker { font-weight: 800; font-size: 13px; color: var(--violet); }

/* Chunky 3D look */
.pop, .card3d {
  border: 2px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 6px 0 var(--ink);
}
.pop {
  font: 800 15px Nunito, sans-serif;
  color: var(--ink);
  background: var(--white);
  min-height: 52px;
  padding: 12px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: transform .1s ease, box-shadow .1s ease;
  -webkit-tap-highlight-color: transparent;
}
.pop:hover { transform: translateY(-2px); box-shadow: 0 8px 0 var(--ink); }
.pop:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.pop:focus-visible { outline: 3px solid #7B6CF6; outline-offset: 3px; }
.card3d { background: var(--white); padding: 16px; }

.tilt { perspective: 800px; }
.tilt > * { transform: rotateX(12deg) rotateZ(-2deg); transition: transform .4s ease; }
.tilt:hover > * { transform: rotateX(4deg) rotateZ(0deg); }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* Home */
.scene { background: var(--ink); border-radius: 28px; border: 2px solid var(--ink); box-shadow: 0 10px 0 var(--ink-deep), 0 22px 0 #C9BEF7; padding: 16px 12px 8px; }
.scene svg { width: 100%; display: block; }
.zzz { animation: float 3s ease-in-out infinite; }
.breathe { animation: breathe 3.5s ease-in-out infinite; transform-origin: 60% 80%; transform-box: fill-box; }
@keyframes float { 0%,100% { transform: translateY(0); opacity: .9; } 50% { transform: translateY(-8px); opacity: .5; } }
@keyframes breathe { 0%,100% { transform: scaleY(1); } 50% { transform: scaleY(1.04); } }
.room a { flex-direction: column; align-items: flex-start; gap: 2px; padding: 14px; }
.room a span:first-child { font-family: Fredoka, sans-serif; font-size: 18px; font-weight: 500; }
.room a span:last-child { font-size: 13px; font-weight: 700; color: var(--muted); }
.run-zone { position: relative; height: 110px; }
#runaway { position: absolute; left: 0; top: 0; transition: left .25s ease, top .25s ease; border-style: dashed; background: transparent; box-shadow: none; color: var(--violet); }

/* Battery */
.battery { display: flex; align-items: center; gap: 6px; }
.battery-body { flex: 1; height: 110px; border: 4px solid var(--ink); border-radius: 26px; padding: 8px; background: var(--white); box-shadow: 0 12px 0 var(--ink); display: flex; }
.battery-fill { border-radius: 16px; box-shadow: inset 0 -10px 0 rgba(0,0,0,.15); transition: width .5s ease, background .5s ease; }
.battery-tip { width: 16px; height: 44px; background: var(--ink); border-radius: 0 10px 10px 0; }
.big-num { font-family: Fredoka, sans-serif; font-size: 56px; line-height: 1; }
.drain { background: var(--red-soft); color: #6E1616; }
.charge { background: var(--mint); color: #0E4A31; }
#blanket { position: fixed; inset: 0; background: var(--lav-mid); transform: translateY(-110%); transition: transform .8s cubic-bezier(.6,.1,.3,1); z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
#blanket.on { transform: translateY(0); }
#blanket::before { content: ""; position: absolute; inset: 0; background: repeating-linear-gradient(135deg, transparent 0 40px, rgba(91,79,201,.18) 40px 44px); pointer-events: none; }

/* Simulator */
.bubble { flex: 1; background: var(--white); border: 2px solid var(--ink); border-radius: 22px 22px 22px 6px; box-shadow: 0 6px 0 var(--ink); padding: 14px; font-weight: 800; font-size: 17px; }
.choice { justify-content: flex-start; text-align: left; background: #FFF7D6; }
.outcome { background: var(--ink); color: var(--white); border-radius: 22px; box-shadow: 0 6px 0 var(--ink-deep); padding: 16px; }
.outcome .label { font-family: Fredoka, sans-serif; font-size: 18px; color: var(--butter); }
.pill { display: inline-block; padding: 6px 12px; border-radius: 999px; background: var(--ink); color: var(--white); font-weight: 800; font-size: 13px; }

/* Library */
.shelf { background: #8B5E3C; border: 2px solid var(--ink); border-radius: 18px; box-shadow: 10px 10px 0 #5E3E25; padding: 14px 14px 0; }
.shelf-books { display: flex; align-items: flex-end; gap: 5px; min-height: 150px; flex-wrap: nowrap; overflow: hidden; }
.spine { width: 26px; border: 2px solid var(--ink); border-radius: 5px; box-shadow: inset -6px 0 0 rgba(0,0,0,.18); flex-shrink: 0; transition: transform .2s ease; }
.spine:hover { transform: translateY(-10px); }
.shelf-board { height: 14px; background: #5E3E25; margin: 0 -14px; border-top: 2px solid var(--ink); border-radius: 0 0 16px 16px; }
.book { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.book .title { font-family: Fredoka, sans-serif; font-size: 17px; font-weight: 500; }
.book .note { font-size: 13px; color: var(--muted); }
.hugs { padding: 6px 10px; border-radius: 999px; background: var(--lav); color: #3A2F7A; font-weight: 800; font-size: 13px; white-space: nowrap; }
.book .remove { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; min-width: 44px; min-height: 44px; }
form.add { display: flex; flex-direction: column; gap: 10px; }
label { font-weight: 800; font-size: 14px; }
input, select { font: 16px Nunito, sans-serif; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--ink); background: var(--white); color: var(--ink); width: 100%; }
#pick { font-family: Fredoka, sans-serif; font-size: 20px; min-height: 30px; }

/* Excuses */
.pillow { background: var(--white); border: 3px solid var(--ink); border-radius: 40px; box-shadow: 0 14px 0 var(--ink), 0 26px 0 var(--pink); padding: 34px 24px; min-height: 220px; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.pillow .tag { align-self: flex-start; padding: 6px 12px; border-radius: 999px; background: #FFD3E2; color: #6B2344; font-weight: 800; font-size: 12px; }
#excuse { font-family: Fredoka, sans-serif; font-size: clamp(22px, 4vw, 30px); line-height: 1.3; font-weight: 500; }
.big-btn { min-height: 64px; font-family: Fredoka, sans-serif; font-size: 22px; font-weight: 500; background: var(--pink); width: 100%; }

/* Leaderboard */
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; align-items: end; }
.podium > div { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.podium .rank { font-family: Fredoka, sans-serif; font-size: 22px; }
.podium .what { font-size: 13px; font-weight: 800; }
.podium .block { width: 100%; border: 2px solid var(--ink); border-radius: 14px 14px 6px 6px; box-shadow: 0 8px 0 var(--ink); display: flex; align-items: center; justify-content: center; font-family: Fredoka, sans-serif; font-size: 26px; }
.counter { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.counter .pop { min-width: 52px; padding: 0; font-size: 22px; }
.badge .name { font-family: Fredoka, sans-serif; font-size: 16px; font-weight: 500; }
.badge .how { font-size: 12px; color: var(--muted); }
.badge.locked { background: #F1EFE8; border-style: dashed; box-shadow: none; color: #5F5E5A; }

/* Bottom tab bar */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--white); border-top: 2px solid var(--ink); padding: 8px 6px calc(10px + env(safe-area-inset-bottom)); }
.tabs ul { list-style: none; margin: 0 auto; padding: 0; max-width: 560px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
.tabs a { min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 800; text-decoration: none; color: #5A5280; border-radius: 14px; }
.tabs a[aria-current="page"] { color: var(--ink); background: var(--page); }
.tabs svg { width: 22px; height: 22px; }

/* Sleepy idle mode */
body.sleepy { filter: brightness(.55) saturate(.7); }
#snore { position: fixed; right: 20px; bottom: 110px; font-family: Fredoka, sans-serif; font-size: 34px; color: var(--butter); z-index: 60; opacity: 0; pointer-events: none; transition: opacity .6s; }
body.sleepy #snore { opacity: 1; animation: float 2.5s ease-in-out infinite; }

.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--white); padding: 12px 18px; border-radius: 14px; font-weight: 800; opacity: 0; transition: all .3s; z-index: 70; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (min-width: 760px) {
  .grid2.room { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

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