:root {
  --game-w: 960px;
  --game-h: 540px;
  --pink: #ffd1dc;
  --pink-deep: #ff9eb5;
  --mint: #b8f0d4;
  --sky: #cfeafd;
  --sun: #ffe9a8;
  --cream: #fff6e0;
  --ink: #3b2f4a;
  --shadow: rgba(60, 47, 74, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #1c1730;
  font-family: 'Comic Sans MS', 'Marker Felt', 'Trebuchet MS', sans-serif;
  color: var(--ink);
  overflow: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #87ceeb;
  user-select: none;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-size: 18px;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
}

#hud.hidden { display: none; }

#hud-left, #hud-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#hearts {
  display: flex;
  gap: 4px;
}

.heart {
  width: 32px;
  height: 32px;
  display: inline-block;
  filter: drop-shadow(0 2px 0 var(--shadow));
}

.heart svg {
  width: 100%;
  height: 100%;
}

.coin {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.18em;
  margin: 0 1px;
}

#level-label {
  background: rgba(255, 255, 255, 0.7);
  padding: 4px 10px;
  border-radius: 10px;
  font-weight: bold;
}

#score, #timer {
  background: rgba(255, 255, 255, 0.7);
  padding: 4px 12px;
  border-radius: 10px;
  font-weight: bold;
  text-align: right;
  min-width: 80px;
}

#timer.hidden { display: none; }

#control-column {
  position: absolute;
  right: 14px;
  top: 90px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
  z-index: 11;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid var(--ink);
  color: var(--ink);
  cursor: pointer;
  padding: 6px;
  box-shadow: 0 3px 0 var(--shadow);
  transition: transform 80ms ease, opacity 80ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--cream);
}

.icon-btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--shadow);
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.icon-btn svg {
  width: 100%;
  height: 100%;
}

.icon-btn.muted {
  background: #ffd1dc;
}

#mission {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.88);
  padding: 8px 22px;
  border-radius: 18px;
  font-weight: bold;
  font-size: 20px;
  box-shadow: 0 4px 0 var(--shadow);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 400ms ease;
}

#mission.visible {
  opacity: 1;
}

#overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(255, 246, 224, 0.86);
  backdrop-filter: blur(2px);
  pointer-events: auto;
  text-align: center;
  padding: 60px 24px 40px;        /* top room for the floating back chip */
  overflow-y: auto;                /* lets every screen scroll on small viewports */
  -webkit-overflow-scrolling: touch;
}

.screen.hidden { display: none; }

h1 {
  font-size: 80px;
  margin: 0;
  color: var(--pink-deep);
  text-shadow: 4px 4px 0 var(--ink), 8px 8px 0 var(--sun);
  letter-spacing: 2px;
}

h2 {
  font-size: 48px;
  margin: 0;
  color: var(--ink);
}

.subtitle {
  font-size: 22px;
  margin: 0;
  color: var(--ink);
  opacity: 0.7;
}

.hint {
  font-size: 14px;
  color: var(--ink);
  opacity: 0.7;
  margin-top: 16px;
}

.intro-eyebrow {
  font-size: 18px;
  font-weight: bold;
  color: var(--pink-deep);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin: 0;
}

#intro-animal {
  font-size: 56px;
  margin: 0;
  color: var(--ink);
}

.intro-scenario {
  font-size: 24px;
  margin: 0;
  color: var(--ink);
  max-width: 600px;
}

.intro-scenario b {
  color: var(--pink-deep);
}

#intro-screen {
  background: rgba(255, 246, 224, 0.4);
  backdrop-filter: blur(6px);
}

#intro-screen > * {
  background: rgba(255, 246, 224, 0.92);
  padding: 6px 22px;
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--shadow);
}

#intro-screen #intro-btn {
  background: var(--pink-deep);
  color: white;
  box-shadow: 0 6px 0 #c46c85;
  padding: 14px 40px;
}

.big-btn {
  font-family: inherit;
  font-size: 26px;
  font-weight: bold;
  padding: 14px 40px;
  background: var(--pink-deep);
  color: white;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  box-shadow: 0 6px 0 #c46c85;
  transition: transform 80ms ease;
}

.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #c46c85; }

.big-btn.secondary {
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 6px 0 #c8b89d;
  border: 2px solid var(--ink);
}

.big-btn.secondary:active {
  box-shadow: 0 2px 0 #c8b89d;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.screen.home {
  padding: 24px 40px;
  gap: 24px;
  background: linear-gradient(180deg, rgba(207, 234, 253, 0.92) 0%, rgba(255, 209, 220, 0.88) 100%);
  backdrop-filter: blur(2px);
  overflow: hidden;
  justify-content: center;
}

/* Home theme variants — applied via class on .screen.home */
.screen.home.theme-sunset {
  background: linear-gradient(180deg, rgba(207, 234, 253, 0.92) 0%, rgba(255, 209, 220, 0.88) 100%);
}
.screen.home.theme-forest {
  background: linear-gradient(180deg, rgba(232, 244, 207, 0.92) 0%, rgba(176, 220, 178, 0.92) 100%);
}
.screen.home.theme-night {
  background: linear-gradient(180deg, rgba(45, 35, 72, 0.94) 0%, rgba(85, 65, 130, 0.92) 100%);
  color: #fff;
}
.screen.home.theme-night .home-title {
  color: #fff7c4;
  text-shadow: 3px 3px 0 #1a1224, 6px 6px 0 #ff9eb5;
}
.screen.home.theme-night .home-subtitle,
.screen.home.theme-night #user-greeting,
.screen.home.theme-night .hint {
  background: rgba(255, 255, 255, 0.16);
  color: #fff7c4;
}
.screen.home.theme-candy {
  background: linear-gradient(180deg, rgba(255, 213, 248, 0.95) 0%, rgba(204, 178, 247, 0.92) 100%);
}
.screen.home.theme-beach {
  background: linear-gradient(180deg, rgba(255, 244, 198, 0.94) 0%, rgba(178, 224, 247, 0.92) 100%);
}
.screen.home.theme-galaxy {
  background: linear-gradient(180deg, rgba(20, 18, 60, 0.95) 0%, rgba(80, 38, 130, 0.94) 60%, rgba(180, 78, 168, 0.92) 100%);
  color: #fff;
}
.screen.home.theme-galaxy .home-title {
  color: #c6acff;
  text-shadow: 3px 3px 0 #1a1224, 6px 6px 0 #ff9eb5;
}
.screen.home.theme-galaxy .home-subtitle,
.screen.home.theme-galaxy #user-greeting,
.screen.home.theme-galaxy .hint {
  background: rgba(255, 255, 255, 0.16);
  color: #ffeaff;
}
.screen.home.theme-mint {
  background: linear-gradient(180deg, rgba(204, 245, 226, 0.94) 0%, rgba(174, 230, 220, 0.92) 100%);
}
.screen.home.theme-sunrise {
  background: linear-gradient(180deg, rgba(255, 209, 153, 0.94) 0%, rgba(255, 166, 158, 0.93) 55%, rgba(212, 119, 184, 0.92) 100%);
}
.screen.home.theme-pastel {
  background: linear-gradient(45deg, rgba(255, 209, 220, 0.92), rgba(207, 234, 253, 0.92), rgba(204, 245, 226, 0.92), rgba(255, 244, 198, 0.92));
}

.home-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 1;
}

.home-title {
  font-size: 120px;
  line-height: 1;
  margin: 0;
  color: var(--pink-deep);
  text-shadow:
    4px 4px 0 var(--ink),
    8px 8px 0 var(--sun),
    12px 12px 0 rgba(60, 47, 74, 0.18);
  letter-spacing: 3px;
  transform: rotate(-2deg);
}

.home-subtitle {
  font-size: 22px;
  margin: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  padding: 6px 18px;
  border-radius: 14px;
}

.home-cards {
  position: absolute;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  z-index: 2;
  max-width: 380px;
}

.home-cards .home-card {
  width: 170px;
  min-height: 140px;
  padding: 12px 8px 10px;
  gap: 4px;
}

.home-cards .home-card .card-icon {
  font-size: 38px;
}

.home-cards .home-card .card-title {
  font-size: 16px;
}

.home-cards .home-card .card-sub {
  font-size: 12px;
  padding: 2px 8px;
}

.home-card {
  width: 220px;
  min-height: 200px;
  background: #ffffff;
  border: 3px solid var(--ink);
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 16px;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 8px 0 var(--shadow);
  transition: transform 100ms ease, box-shadow 100ms ease, background 100ms ease;
  color: var(--ink);
}

.home-card:hover {
  transform: translateY(-4px) rotate(-1deg);
  box-shadow: 0 12px 0 var(--shadow);
  background: var(--cream);
}

.home-card:active {
  transform: translateY(2px);
  box-shadow: 0 4px 0 var(--shadow);
}

.home-card.primary {
  background: var(--pink-deep);
  color: white;
  box-shadow: 0 10px 0 #c46c85;
  width: 320px;
  min-height: 220px;
  border-width: 4px;
  align-self: center;
}

.home-card.primary:hover {
  background: #ff7da3;
  transform: translateY(-4px) rotate(-1deg);
  box-shadow: 0 14px 0 #c46c85;
}

.home-card.primary:active {
  transform: translateY(2px);
  box-shadow: 0 6px 0 #c46c85;
}

.home-card.primary .card-icon {
  font-size: 76px;
}

.home-card.primary .card-title {
  font-size: 36px;
}

.home-card.primary .card-sub {
  font-size: 16px;
}

.home-card .card-icon {
  font-size: 56px;
  line-height: 1;
  filter: drop-shadow(0 3px 0 rgba(60, 47, 74, 0.22));
}

.home-card.primary .card-icon {
  color: white;
}

.home-card .card-title {
  font-size: 24px;
  font-weight: bold;
  letter-spacing: 0.5px;
}

.home-card .card-sub {
  font-size: 14px;
  opacity: 0.85;
  background: rgba(60, 47, 74, 0.08);
  padding: 3px 10px;
  border-radius: 10px;
}

.home-card.primary .card-sub {
  background: rgba(255, 255, 255, 0.22);
}

.home-hint {
  margin-top: 6px;
  z-index: 1;
}

.home-deco {
  position: absolute;
  font-size: 56px;
  pointer-events: none;
  opacity: 0.4;
  filter: drop-shadow(0 3px 0 rgba(60, 47, 74, 0.18));
  animation: float 6s ease-in-out infinite;
}

.home-deco-1 {
  top: 24px;
  left: 40px;
  transform: rotate(-18deg);
  font-size: 48px;
  animation-delay: 0s;
}

.home-deco-2 {
  top: 30px;
  right: 60px;
  animation-delay: 1.2s;
}

.home-deco-3 {
  bottom: 36px;
  right: 36px;
  transform: rotate(14deg);
  animation-delay: 2.4s;
}

.home-deco-4 {
  bottom: 80px;
  left: 24px;
  font-size: 64px;
  animation-delay: 3.6s;
}

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-18deg); }
  50% { transform: translateY(-10px) rotate(-12deg); }
}

.home-deco-2, .home-deco-4 {
  animation-name: float-cloud;
}

@keyframes float-cloud {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(12px); }
}

#quests-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 540px;
}

.quest {
  background: white;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 3px 0 var(--shadow);
}

.quest.done {
  background: #d6f0d8;
}

.quest-label {
  display: flex;
  justify-content: space-between;
  font-weight: bold;
  font-size: 16px;
}

.quest-progress {
  height: 10px;
  background: rgba(60, 47, 74, 0.12);
  border-radius: 5px;
  overflow: hidden;
}

.quest-progress > .fill {
  height: 100%;
  background: var(--pink-deep);
  transition: width 200ms ease;
}

.quest.done .fill { background: #5cb85c; }

#quest-tabs {
  display: flex;
  gap: 8px;
}

.quest-tab {
  font-family: inherit;
  font-weight: bold;
  font-size: 15px;
  padding: 6px 18px;
  background: white;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--shadow);
}

.quest-tab.active {
  background: var(--pink-deep);
  color: white;
  box-shadow: 0 3px 0 #c46c85;
}

.quest-tab.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.quest-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.quest-info { flex: 1; }

.chest-btn {
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 4px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--shadow);
  transition: transform 100ms ease;
  animation: chest-bounce 1s ease-in-out infinite;
}

.chest-btn:hover { transform: translateY(-2px); }

@keyframes chest-bounce {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-3px) rotate(2deg); }
}

.chest-claimed {
  font-weight: bold;
  font-size: 13px;
  color: #2e7d32;
  background: #e9f9eb;
  padding: 4px 10px;
  border-radius: 10px;
  border: 1.5px solid #2e7d32;
}

.chest-reward {
  position: absolute;
  inset: 0;
  background: rgba(60, 47, 74, 0.5);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  animation: fade-in 240ms ease;
}

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

.chest-reward-card {
  background: linear-gradient(180deg, #fff6e0 0%, #ffd1dc 100%);
  border: 4px solid var(--ink);
  border-radius: 22px;
  padding: 28px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 10px 0 var(--shadow);
  animation: pop-in 360ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-in {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.chest-burst {
  font-size: 64px;
  animation: burst-spin 600ms ease-out;
}

@keyframes burst-spin {
  from { transform: rotate(-30deg) scale(0.4); }
  to { transform: rotate(0deg) scale(1); }
}

.reward-line {
  font-size: 22px;
  font-weight: bold;
}

#race-standings {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 20px;
  min-width: 320px;
}

.race-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 6px 14px;
  font-weight: bold;
}

.race-row.player { background: var(--cream); }
.race-row.gold { background: #fff3c4; }

.race-pos {
  background: var(--pink-deep);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.race-pos.gold { background: #f1c40f; }
.race-pos.silver { background: #95a5a6; }
.race-pos.bronze { background: #cd7f32; }

#race-hud {
  position: absolute;
  left: 14px;
  bottom: 12px;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 14px;
  z-index: 11;
  display: none;
}

#race-hud.visible { display: block; }

#race-hud .race-line {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 2px 0;
}

#race-hud .swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1.5px solid var(--ink);
}

#race-hud .progress {
  flex: 1;
  height: 6px;
  background: rgba(60, 47, 74, 0.18);
  border-radius: 3px;
  position: relative;
  min-width: 120px;
}

#race-hud .progress > .bar {
  height: 100%;
  border-radius: 3px;
  background: var(--pink-deep);
}

#race-hud .lives-mini {
  display: flex;
  gap: 2px;
}
#race-hud .lives-mini span {
  width: 10px;
  height: 10px;
  background: #ff5d8f;
  border: 1px solid var(--ink);
  border-radius: 3px;
  display: inline-block;
}
#race-hud .lives-mini span.lost {
  background: rgba(255, 255, 255, 0.6);
}

.treats-balance {
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 20px;
  padding: 10px 28px;
  font-size: 28px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 0 var(--shadow);
}

.treats-balance .balance-label {
  font-size: 18px;
  opacity: 0.7;
}

#preview-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#preview-canvas {
  width: 220px;
  height: 220px;
  border-radius: 18px;
  border: 3px solid var(--ink);
  background: var(--cream);
  box-shadow: 0 6px 0 var(--shadow);
  display: block;
}

#preview-name {
  font-weight: bold;
  font-size: 16px;
  background: rgba(255, 255, 255, 0.7);
  padding: 4px 14px;
  border-radius: 12px;
}

#animal-picker {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.animal-tab {
  font-family: inherit;
  font-weight: bold;
  padding: 8px 10px 6px;
  background: white;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--shadow);
  transition: transform 100ms ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 84px;
}

.animal-tab:hover { transform: translateY(-2px); }

.animal-tab .animal-face {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  font-size: 44px;
  line-height: 1;
  background: radial-gradient(circle at 35% 30%, #fffaf0 0%, #ffd6dc 60%, #ffb8c4 100%);
  border: 3px solid var(--ink);
  border-radius: 50%;
  box-shadow: inset 0 -4px 0 rgba(60, 47, 74, 0.15), 0 2px 0 var(--shadow);
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.animal-tab:hover .animal-face {
  transform: scale(1.08) rotate(-4deg);
}

.animal-tab .animal-label {
  font-size: 14px;
}

.animal-tab.active {
  background: var(--pink-deep);
  color: white;
  box-shadow: 0 4px 0 #c46c85;
  transform: translateY(-4px);
}

.animal-tab.active .animal-face {
  background: radial-gradient(circle at 35% 30%, #fffce8 0%, #ffe066 60%, #f5c542 100%);
  animation: bounce-cute 1.4s ease-in-out infinite;
}

@keyframes bounce-cute {
  0%, 100% { transform: scale(1) rotate(0deg); }
  25% { transform: scale(1.08) rotate(-3deg); }
  50% { transform: scale(1.1) rotate(2deg); }
  75% { transform: scale(1.06) rotate(-2deg); }
}

#accessory-grid, #inventory-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 920px;
  max-height: 65vh;
  min-height: 240px;
  overflow-y: auto;
  padding: 6px;
}

#inventory-grid {
  max-height: 480px;
}

#badges-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  width: 100%;
  max-width: 920px;
  max-height: 460px;
  overflow-y: auto;
  padding: 6px;
}

.badge-card {
  background: white;
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 14px 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 0 var(--shadow);
  text-align: center;
}

.badge-card.earned {
  background: linear-gradient(180deg, #fff7c4 0%, #ffd76e 100%);
}

.badge-card.locked {
  opacity: 0.55;
  filter: saturate(0.5);
}

.badge-card .badge-icon {
  width: 72px;
  height: 72px;
  font-size: 44px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 35% 30%, #fffaf0 0%, #ffd6dc 60%, #ffb8c4 100%);
  border: 3px solid var(--ink);
  border-radius: 50%;
}

.badge-card.earned .badge-icon {
  animation: bounce-cute 1.4s ease-in-out infinite;
}

.badge-card .badge-name {
  font-size: 14px;
  font-weight: bold;
}

.badge-card .badge-desc {
  font-size: 11px;
  opacity: 0.78;
}

.badge-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  background: linear-gradient(180deg, #fff7c4 0%, #ffd76e 100%);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 12px 18px;
  box-shadow: 0 6px 0 var(--shadow);
  transform: translateX(120%);
  transition: transform 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.badge-toast.visible {
  transform: translateX(0);
}

.badge-toast-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge-toast .badge-icon-small {
  font-size: 32px;
}

.badge-toast-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.75;
}

.badge-toast-name {
  font-size: 18px;
  font-weight: bold;
}

#map-screen {
  justify-content: flex-start;
  overflow-y: auto;
  padding: 20px 30px 30px;
  gap: 14px;
}

#map-path {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 720px;
  position: relative;
}

#map-path::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 30px;
  bottom: 30px;
  width: 6px;
  background: repeating-linear-gradient(
    180deg,
    var(--cream) 0 14px,
    transparent 14px 22px
  );
  transform: translateX(-50%);
  z-index: 0;
}

.map-node {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  background: white;
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 12px 18px;
  box-shadow: 0 5px 0 var(--shadow);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: transform 100ms ease;
  width: 100%;
}

.map-node:hover:not(:disabled) {
  transform: translateY(-2px);
}

.map-node.cleared {
  background: linear-gradient(180deg, #d6f0d8 0%, #b6e2b8 100%);
}

.map-node.current {
  background: linear-gradient(180deg, #fff7c4 0%, #ffd76e 100%);
  animation: bounce-cute 2.2s ease-in-out infinite;
}

.map-node.locked {
  opacity: 0.5;
  cursor: not-allowed;
  background: #ece8f0;
}

.map-node.special {
  border-color: #c46c85;
  border-width: 4px;
}

.map-num {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--cream);
  border: 3px solid var(--ink);
  font-size: 22px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: inset 0 -3px 0 rgba(60, 47, 74, 0.15);
}

.map-node.cleared .map-num { background: linear-gradient(180deg, #fffce8, #ffd76e); }
.map-node.current .map-num { background: var(--pink-deep); color: white; }
.map-node.special .map-num { background: var(--pink-deep); color: white; }

.map-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.map-title {
  font-size: 17px;
  font-weight: bold;
}

.map-detail {
  font-size: 13px;
  opacity: 0.8;
}

.map-prize {
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 6px 12px;
  font-weight: bold;
  font-size: 14px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
}

.map-prize.special { background: linear-gradient(180deg, #ffd1dc, #ff9eb5); color: #3b2f4a; }
.map-prize.breather { background: #cfeafd; }

.screen-back-btn {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  background: rgba(255, 255, 255, 0.95);
  border: 2.5px solid var(--ink);
  color: var(--ink);
  padding: 12px 22px;
  border-radius: 14px;
  font-family: inherit;
  font-weight: bold;
  font-size: 17px;
  min-width: 96px;
  min-height: 44px;     /* iOS recommended minimum tap target */
  cursor: pointer;
  box-shadow: 0 4px 0 var(--shadow);
  z-index: 30;
  pointer-events: auto;
  touch-action: manipulation;  /* kills 300ms tap delay + double-tap zoom on this button */
  transition: transform 80ms ease;
}

.screen-back-btn:hover {
  transform: translateY(-2px);
  background: var(--cream);
}

.screen-back-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--shadow);
}

/* Duolingo-style tiered chests for daily/bonus/weekend quests */
.chest-btn.tier-bronze .chest-base { fill: #a87148; }
.chest-btn.tier-bronze .chest-lid { fill: #c89060; }
.chest-btn.tier-silver .chest-base { fill: #6b7782; }
.chest-btn.tier-silver .chest-lid { fill: #99a4b0; }
.chest-btn.tier-gold .chest-base { fill: #c8a02a; }
.chest-btn.tier-gold .chest-lid { fill: #f5c542; }

.tier-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 8px;
  display: inline-block;
}
.tier-label.tier-bronze { background: #c89060; color: #fff; }
.tier-label.tier-silver { background: #99a4b0; color: #fff; }
.tier-label.tier-gold   { background: #f5c542; color: #3b2f4a; }

#inventory-grid .acc-card .acc-meta {
  font-size: 13px;
  text-align: center;
}

.acc-card {
  background: white;
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 18px 16px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  box-shadow: 0 5px 0 var(--shadow);
  transition: transform 100ms ease;
}

.acc-card:hover {
  transform: translateY(-2px);
}

.acc-card.equipped {
  background: linear-gradient(180deg, #e9f9eb 0%, #ccf0d3 100%);
  border-color: #2e7d32;
}

.acc-card.locked {
  opacity: 0.7;
}

.acc-icon {
  width: 96px;
  height: 96px;
  font-size: 58px;
  line-height: 1;
  background: radial-gradient(circle at 35% 30%, #fffaf0 0%, #ffd6dc 60%, #ffb8c4 100%);
  border: 3px solid var(--ink);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 -4px 0 rgba(60, 47, 74, 0.15), 0 2px 0 var(--shadow);
  filter: drop-shadow(0 2px 0 rgba(60, 47, 74, 0.18));
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.acc-card:hover .acc-icon {
  transform: scale(1.08) rotate(-3deg);
}

.acc-card.equipped .acc-icon {
  background: radial-gradient(circle at 35% 30%, #fffce8 0%, #ffe066 60%, #f5c542 100%);
  animation: bounce-cute 1.4s ease-in-out infinite;
}

/* Collapsible sections in the Customize screen */
#customize-screen {
  justify-content: flex-start;
  overflow-y: auto;
  padding: 20px 30px 30px;
  gap: 12px;
}

.customize-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.customize-section > summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 22px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 14px;
  font-weight: bold;
  font-size: 16px;
  box-shadow: 0 3px 0 var(--shadow);
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: center;
}

.customize-section > summary::-webkit-details-marker,
.customize-section > summary::marker {
  display: none;
  content: '';
}

.customize-section > summary::before {
  content: '▶';
  font-size: 12px;
  display: inline-block;
  transition: transform 200ms ease;
  color: var(--pink-deep);
}

.customize-section[open] > summary::before {
  transform: rotate(90deg);
}

.customize-section > summary:hover {
  background: var(--pink-deep);
  color: white;
}

.customize-section > summary:hover::before {
  color: white;
}

#home-theme-section {
  margin-top: 6px;
}

.theme-section-title {
  font-size: 18px;
  margin: 0;
}

#home-theme-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.theme-chip {
  background: white;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 6px 6px 4px;
  cursor: pointer;
  font-family: inherit;
  font-weight: bold;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: 0 3px 0 var(--shadow);
  transition: transform 100ms ease;
}

.theme-chip:hover { transform: translateY(-2px); }

.theme-chip.active {
  background: var(--pink-deep);
  color: white;
  box-shadow: 0 3px 0 #c46c85;
}

.theme-swatch {
  display: inline-block;
  width: 56px;
  height: 36px;
  border-radius: 8px;
  border: 1.5px solid var(--ink);
}

.theme-swatch.sunset  { background: linear-gradient(180deg, #cfeafd, #ffd1dc); }
.theme-swatch.forest  { background: linear-gradient(180deg, #e8f4cf, #b0dcb2); }
.theme-swatch.night   { background: linear-gradient(180deg, #2d2348, #554182); }
.theme-swatch.candy   { background: linear-gradient(180deg, #ffd5f8, #ccb2f7); }
.theme-swatch.beach   { background: linear-gradient(180deg, #fff4c6, #b2e0f7); }
.theme-swatch.galaxy  { background: linear-gradient(180deg, #14123c, #b44ea8); }
.theme-swatch.mint    { background: linear-gradient(180deg, #ccf5e2, #aee6dc); }
.theme-swatch.sunrise { background: linear-gradient(180deg, #ffd199, #d477b8); }
.theme-swatch.pastel  { background: linear-gradient(45deg, #ffd1dc, #cfeafd, #ccf5e2, #fff4c6); }

.theme-name { font-size: 12px; }

.acc-name {
  font-size: 17px;
  font-weight: bold;
}

.acc-price {
  font-size: 15px;
  color: var(--pink-deep);
  font-weight: bold;
  background: var(--cream);
  padding: 3px 12px;
  border-radius: 10px;
}

.acc-meta {
  font-size: 14px;
  color: var(--ink);
  opacity: 0.75;
}

.acc-meta b {
  color: var(--ink);
  opacity: 1;
}

.acc-btn {
  font-family: inherit;
  font-size: 16px;
  font-weight: bold;
  padding: 7px 20px;
  background: var(--pink-deep);
  color: white;
  border: 2px solid var(--ink);
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 3px 0 #c46c85;
}

.acc-btn.secondary {
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 2px 0 #c8b89d;
}

.acc-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#tutorial-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 580px;
  width: 100%;
}

.tut-row {
  display: flex;
  align-items: center;
  gap: 16px;
  background: white;
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 10px 16px;
  box-shadow: 0 3px 0 var(--shadow);
}

.key-icon {
  font-weight: bold;
  font-size: 18px;
  background: var(--cream);
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 4px 10px;
  min-width: 90px;
  text-align: center;
}

.tut-text {
  font-size: 17px;
  text-align: left;
  flex: 1;
}

.tut-text b {
  color: var(--pink-deep);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 360px;
  max-width: 90vw;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: bold;
  font-size: 14px;
  text-align: left;
}

.auth-form input {
  font-family: inherit;
  font-size: 17px;
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: white;
  outline: none;
}

.auth-form input:focus {
  border-color: var(--pink-deep);
  box-shadow: 0 0 0 3px rgba(255, 158, 181, 0.3);
}

.form-error {
  color: #c0392b;
  font-weight: bold;
  min-height: 1.2em;
  margin: 0;
  text-align: center;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.form-actions .big-btn {
  padding: 10px 24px;
  font-size: 20px;
}

.result-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.result-buttons .big-btn.hidden { display: none; }

#logout-link {
  position: absolute;
  top: 14px;
  right: 18px;
  font-size: 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--ink);
  cursor: pointer;
  text-decoration: none;
}

#logout-link:hover { background: white; }

#user-greeting {
  font-size: 16px;
  background: rgba(255, 255, 255, 0.75);
  padding: 4px 14px;
  border-radius: 14px;
  font-weight: bold;
  margin-top: -4px;
}

.text-btn {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  cursor: pointer;
  opacity: 0.7;
  text-decoration: underline;
}

#game.shake { animation: shake 240ms ease; }

@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-6px, 3px); }
  50% { transform: translate(5px, -2px); }
  75% { transform: translate(-3px, 4px); }
}
