:root {
  --bg: #3a2416;
  --panel: rgba(255, 248, 234, 0.95);
  --text: #4a2c18;
  --wood: #d9a868;
  --wood-light: #ecc48d;
  --wood-dark: #8a5a32;
  --cream: #fffaf0;
  --gold: #c0392b;
  --orange: #b4560f;
  --green: #1e8449;
  --mustard: #e8c21c;
  --mustard-dark: #b8930a;
  --font: 'Press Start 2P', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  /* The bar continues on both sides on wide screens (tablets, desktop): the
     bands match the scene drawn on the canvas, so the game fills the screen. */
  background: linear-gradient(
    to bottom,
    #6e4426 0 5.6%,
    #fbf8f2 5.6% 17.2%,
    #b3ada4 17.2% 26.25%,
    #d9a868 26.25% 27.5%,
    #7d5a45 27.5% 31.9%,
    #a8743e 31.9% 32.5%,
    #cb8f5f 32.5% 62.5%,
    #a8743e 62.5% 63.1%,
    #ecc48d 63.1% 100%
  );
}

/* Taller screens than the game (most phones): plain wood above and below. */
@media (max-aspect-ratio: 9/16) {
  body {
    background: #6e4426;
  }
}

:fullscreen body,
:-webkit-full-screen body {
  height: 100vh;
}

#stage {
  position: relative;
  width: min(100vw, calc(100vh * 9 / 16));
  width: min(100vw, calc(100dvh * 9 / 16));
  aspect-ratio: 9 / 16;
  overflow: hidden;
  box-shadow: 0 0 24px rgba(40, 20, 8, 0.35);
}

/* Scale the menus up on big screens (tablets) so they match the game. */
@media (min-height: 860px) and (min-width: 520px) {
  .screen > * {
    zoom: 1.3;
  }
}

@media (min-height: 1080px) and (min-width: 680px) {
  .screen > * {
    zoom: 1.6;
  }
}


#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding: 1rem;
  background: var(--panel);
  text-align: center;
  overflow-y: auto;
}

.hidden {
  display: none !important;
}

h1,
h2 {
  margin: 0;
  color: var(--gold);
  line-height: 1.4;
  text-shadow: 2px 2px 0 var(--mustard);
}

h1 {
  font-size: clamp(16px, 5.5vw, 22px);
}

h2 {
  font-size: clamp(14px, 4.5vw, 18px);
}

p {
  margin: 0;
}

.subtitle,
.scores,
.hint,
.team-title,
.team-desc {
  font-size: 10px;
  line-height: 1.7;
}

.scores strong {
  color: var(--gold);
}

.buttons {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(100%, 300px);
}

.row {
  display: flex;
  gap: 0.6rem;
}

.row .btn {
  flex: 1;
}

.btn,
.chip {
  font-family: var(--font);
  color: var(--text);
  background: var(--wood-light);
  border: 0;
  box-shadow: inset 0 -4px 0 var(--wood-dark), 0 0 0 2px var(--wood-dark);
  cursor: pointer;
}

.btn {
  padding: 0.85rem 0.6rem;
  font-size: 11px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.btn small {
  font-size: 8px;
  color: var(--orange);
}

.btn:active,
.chip:active {
  transform: translateY(2px);
  box-shadow: inset 0 -2px 0 var(--wood-dark), 0 0 0 2px var(--wood-dark);
}

.btn.primary {
  background: var(--mustard);
  color: #3a2416;
  font-size: 14px;
  box-shadow: inset 0 -4px 0 var(--mustard-dark), 0 0 0 2px var(--wood-dark);
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
}

.chip {
  padding: 0.5rem 0.7rem;
  font-size: 8px;
}

.team {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
}

.team-list {
  display: flex;
  gap: 0.4rem;
}

.member {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  width: 58px;
  padding: 0.3rem 0.1rem;
  font-family: var(--font);
  color: var(--text);
  background: #fff3dc;
  border: 2px solid var(--wood);
  cursor: pointer;
}

.member canvas {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}

.member-name {
  font-size: 6px;
  white-space: nowrap;
}

.member.selected {
  border-color: var(--mustard);
  background: #fde9a8;
  box-shadow: 0 0 0 2px var(--mustard-dark);
}

.member.locked {
  opacity: 0.6;
}

.team-desc {
  max-width: 300px;
  min-height: 2.6em;
  color: var(--orange);
}

.howto {
  margin: 0;
  padding-left: 1.4rem;
  max-width: 320px;
  text-align: left;
  font-size: 10px;
  line-height: 1.8;
}

.howto li + li {
  margin-top: 0.5rem;
}

.album {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
  width: min(100%, 320px);
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.5rem;
  background: #fff3dc;
  border: 2px solid var(--wood);
  font-size: 7px;
  line-height: 1.6;
}

.card canvas {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
}

.card strong {
  color: var(--gold);
  font-size: 8px;
}

.card.locked {
  opacity: 0.6;
}

.big-score {
  font-size: clamp(24px, 9vw, 36px);
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--mustard);
}

.record {
  font-size: 11px;
  color: var(--green);
  animation: blink 0.8s steps(2) infinite;
}

.unlock {
  font-size: 9px;
  line-height: 1.7;
  color: var(--orange);
}

.stats {
  display: grid;
  grid-template-columns: auto auto;
  gap: 0.5rem 1rem;
  margin: 0;
  font-size: 9px;
  text-align: left;
}

.stats dd {
  margin: 0;
  color: var(--gold);
  text-align: right;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 1.2rem;
  transform: translate(-50%, 1rem);
  padding: 0.6rem 0.8rem;
  max-width: 90%;
  background: var(--cream);
  border: 2px solid var(--mustard-dark);
  font-size: 8px;
  line-height: 1.6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes blink {
  50% {
    opacity: 0.3;
  }
}

.btn small.light {
  color: #6b4a14;
}

.week {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  width: min(100%, 320px);
}

.day {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.5rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  font-family: var(--font);
  color: var(--text);
  text-align: left;
  background: var(--wood-light);
  border: 0;
  box-shadow: inset 0 -4px 0 var(--wood-dark), 0 0 0 2px var(--wood-dark);
  cursor: pointer;
}

.day:active {
  transform: translateY(2px);
}

.day.locked {
  opacity: 0.5;
}

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

.day-stars {
  font-size: 14px;
  color: var(--mustard-dark);
  letter-spacing: 2px;
}

.day-info {
  grid-column: 1 / -1;
  font-size: 7px;
  line-height: 1.6;
  color: #7a4e28;
}

.big-stars {
  font-size: clamp(32px, 12vw, 48px);
  color: var(--mustard);
  letter-spacing: 6px;
  text-shadow: 3px 3px 0 var(--wood-dark);
  animation: pop 0.5s ease-out;
}

@keyframes pop {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }
  70% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.row-contents {
  display: contents;
}

.row-contents.hidden {
  display: none !important;
}

.logo {
  width: min(78%, 300px);
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 0 rgba(90, 54, 29, 0.35));
}

#screen-title h1 {
  font-size: clamp(11px, 3.6vw, 15px);
  text-shadow: none;
  color: #8a5a32;
}

/* ---- Title screen: game-style menu ---------------------------------------- */

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

.screen.title-screen {
  justify-content: safe center;
  gap: 0.75rem;
  padding: 0.8rem 0.9rem 1rem;
  /* Let the living bar show through at the top, then a warm, sunny backdrop */
  background:
    linear-gradient(
      to bottom,
      rgba(255, 243, 220, 0.05) 0%,
      rgba(255, 243, 220, 0.6) 24%,
      rgba(255, 238, 205, 0.93) 42%,
      rgba(255, 228, 182, 0.97) 100%
    ),
    repeating-linear-gradient(
      45deg,
      rgba(233, 184, 32, 0.08) 0 14px,
      rgba(255, 255, 255, 0) 14px 28px
    );
}

.title-screen .logo {
  width: min(86%, 320px);
  margin-top: 0.2rem;
  animation: swing 3.2s ease-in-out infinite;
  transform-origin: 50% 0;
}

@keyframes swing {
  0%, 100% { transform: rotate(-1.2deg); }
  50% { transform: rotate(1.2deg); }
}

/* Big play button */
.hero {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 0.2rem 0.7rem;
  width: min(100%, 340px);
  padding: 0.7rem 0.8rem 0.9rem;
  font-family: var(--font);
  text-align: left;
  color: #3a2416;
  background: linear-gradient(180deg, #ffe066 0%, #e9b820 60%, #d4a017 100%);
  border: 0;
  border-radius: 6px;
  box-shadow: 0 0 0 3px #5a361d, inset 0 -6px 0 #b8930a, inset 0 3px 0 #fff3b0, 0 8px 0 rgba(90, 54, 29, 0.35);
  cursor: pointer;
  animation: pop-in 0.45s ease-out both, breathe 1.8s ease-in-out 0.6s infinite;
}

.hero:active {
  transform: translateY(3px) scale(0.99);
  box-shadow: 0 0 0 3px #5a361d, inset 0 -3px 0 #b8930a, 0 4px 0 rgba(90, 54, 29, 0.35);
}

.hero-icon {
  grid-row: 1 / span 2;
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  background: #fff8e1;
  border-radius: 6px;
  box-shadow: 0 0 0 2px #5a361d, inset 0 -3px 0 #f0d9a0;
}

.hero-text strong {
  display: block;
  font-size: 16px;
  line-height: 1.3;
  text-shadow: 1px 1px 0 #fff3b0;
}

.hero-text small {
  display: block;
  margin-top: 0.3rem;
  font-size: 8px;
  line-height: 1.5;
  color: #6b4a14;
}

.hero-play {
  justify-self: start;
  padding: 0.35rem 0.6rem;
  font-size: 11px;
  color: #fff;
  background: #c0392b;
  border-radius: 4px;
  box-shadow: 0 0 0 2px #5a361d, inset 0 -3px 0 #8e2a1f;
  animation: nudge 1.2s ease-in-out infinite;
}

.badge {
  position: absolute;
  top: -10px;
  right: 10px;
  padding: 0.25rem 0.45rem;
  font-size: 7px;
  color: #fff;
  background: #27ae60;
  border-radius: 3px;
  box-shadow: 0 0 0 2px #5a361d;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.025); }
}

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(4px); }
}

@keyframes pop-in {
  0% { opacity: 0; transform: translateY(14px) scale(0.92); }
  100% { opacity: 1; transform: none; }
}

/* Mode cards */
.modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  width: min(100%, 340px);
}

.mode {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.55rem 0.4rem 0.6rem;
  font-family: var(--font);
  color: #fff;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  animation: pop-in 0.45s ease-out both;
  box-shadow: 0 0 0 2px #3a2416, inset 0 -5px 0 rgba(0, 0, 0, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 5px 0 rgba(90, 54, 29, 0.3);
}

.mode:nth-child(1) { animation-delay: 0.08s; }
.mode:nth-child(2) { animation-delay: 0.14s; }
.mode:nth-child(3) { animation-delay: 0.2s; }
.mode:nth-child(4) { animation-delay: 0.26s; }

.mode:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 2px #3a2416, inset 0 -2px 0 rgba(0, 0, 0, 0.25), 0 2px 0 rgba(90, 54, 29, 0.3);
}

.mode-icon {
  width: 40px;
  height: 40px;
  image-rendering: pixelated;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 5px;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
}

.mode strong {
  font-size: 10px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
}

.mode small {
  font-size: 6.5px;
  line-height: 1.4;
  opacity: 0.95;
}

.mode-chinos { background: linear-gradient(180deg, #e2574c, #c0392b); }
.mode-week { background: linear-gradient(180deg, #3cc47a, #239a57); }
.mode-rush { background: linear-gradient(180deg, #ffad5a, #e67e22); }
.mode-daily { background: linear-gradient(180deg, #9b7bd1, #6c4bb0); }

/* Team strip */
.title-screen .team {
  width: min(100%, 340px);
  padding: 0.5rem 0.4rem 0.4rem;
  background: rgba(255, 243, 220, 0.85);
  border-radius: 6px;
  box-shadow: 0 0 0 2px #d9a868;
}

.title-screen .team-title {
  font-size: 8px;
  color: #8a5a32;
}

.title-screen .team-desc {
  min-height: 2.4em;
  font-size: 7.5px;
}

/* Bottom toolbar */
.toolbar {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  width: min(100%, 340px);
}

.tool {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.4rem 0.1rem;
  font-family: var(--font);
  font-size: 6px;
  color: #3a2416;
  background: #f0cc94;
  border: 0;
  border-radius: 5px;
  box-shadow: 0 0 0 2px #8a5a32, inset 0 -3px 0 #c4935a;
  cursor: pointer;
}

.tool:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 2px #8a5a32, inset 0 -1px 0 #c4935a;
}

.tool-icon {
  font-size: 14px;
  line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
  .hero,
  .hero-play,
  .mode,
  .title-screen .logo {
    animation: none;
  }
}

/* Simplified menu: two main choices, the rest under "More modes" */
.mode-wide {
  flex-direction: row;
  justify-content: flex-start;
  gap: 0.7rem;
  width: min(100%, 340px);
  padding: 0.6rem 0.8rem;
  text-align: left;
  animation-delay: 0.1s;
}

.mode-wide .mode-icon {
  width: 46px;
  height: 46px;
}

.mode-text {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.mode-wide strong {
  font-size: 12px;
}

.mode-wide small {
  font-size: 7px;
}

.mode-arrow {
  font-size: 12px;
  animation: nudge 1.4s ease-in-out infinite;
}

.more-toggle {
  padding: 0.45rem 0.9rem;
  font-family: var(--font);
  font-size: 8px;
  color: #8a5a32;
  background: transparent;
  border: 2px dashed #d9a868;
  border-radius: 5px;
  cursor: pointer;
  animation: pop-in 0.45s ease-out 0.18s both;
}

.more-caret {
  display: inline-block;
  transition: transform 0.2s;
}

.more-toggle.open .more-caret {
  transform: rotate(180deg);
}

.more-modes {
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.more-modes[hidden] {
  display: none;
}

.more-modes .mode {
  padding: 0.45rem 0.25rem 0.5rem;
}

.more-modes .mode-icon {
  width: 32px;
  height: 32px;
}

.more-modes .mode strong {
  font-size: 7.5px;
}

.more-modes .mode small {
  font-size: 6px;
}

/* Album: stickers */
.album-section {
  margin: 0.4rem 0 -0.4rem;
  font-size: 11px;
  color: var(--gold);
}

.stickers {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  width: min(100%, 330px);
}

.sticker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.3rem;
  background: #fff3dc;
  border-radius: 50% 50% 8px 8px / 30% 30% 8px 8px;
  box-shadow: 0 0 0 2px #d9a868, 0 3px 0 rgba(90, 54, 29, 0.25);
  font-size: 6.5px;
  line-height: 1.4;
  text-align: center;
}

.sticker-icon {
  font-size: 22px;
  line-height: 1.1;
}

.sticker strong {
  font-size: 7px;
  color: var(--gold);
}

.sticker.locked {
  opacity: 0.55;
  filter: grayscale(1);
}

/* End screen extras */
.over-line {
  max-width: 300px;
  padding: 0.5rem 0.7rem;
  font-size: 9px;
  line-height: 1.6;
  background: #fffaf0;
  border-radius: 6px;
  box-shadow: 0 0 0 2px #d9a868;
}

.over-stickers {
  font-size: 10px;
  color: var(--green);
}

.record.celebrate {
  font-size: 14px;
  animation: blink 0.8s steps(2) infinite, pop 0.5s ease-out;
}

/* Prize code: a ticket to show at the bar */
.prize {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  width: min(100%, 300px);
  padding: 0.55rem 0.8rem;
  background: #fff3c4;
  border: 2px dashed #b8930a;
  border-radius: 6px;
  animation: pop 0.5s ease-out;
}

.prize::before,
.prize::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  margin-top: -6px;
  background: var(--panel);
  border-radius: 50%;
}

.prize::before { left: -8px; }
.prize::after { right: -8px; }

.prize-label {
  font-size: 7px;
  color: var(--orange);
}

.prize-code {
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--gold);
  user-select: all;
  -webkit-user-select: all;
}

.prize-hint {
  font-size: 6px;
  line-height: 1.5;
}
