:root {
  --cream: #fff3e0;
  --pink: #ff8fb2;
  --pink-dark: #e0527f;
  --choc: #5b3a29;
  --choc-dark: #3d2417;
  --gold: #ffc93c;
  --teal: #2ec4b6;
  --red: #e63946;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #2a1a12;
  font-family: 'Fredoka', 'Segoe UI', sans-serif;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #4a2e1e 0%, #241510 70%);
}

/* The fixed-aspect stage: 1024x768, scaled to fit */
#frame {
  position: relative;
  width: 1024px; height: 768px;
  transform-origin: center center;
  box-shadow: 0 0 0 6px #1a0e08, 0 0 80px rgba(0,0,0,.7);
  border-radius: 6px;
  overflow: hidden;
}

#game {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  background: #ffe8d0;
  image-rendering: pixelated;
  touch-action: none;
}

/* ---------------- screens ---------------- */
.screen {
  position: absolute; inset: 0;
  z-index: 20;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px;
  background: linear-gradient(160deg, rgba(255,243,224,.97), rgba(255,214,233,.97));
  text-align: center;
  padding: 30px;
}
.screen.hidden { display: none; }

.hidden { display: none !important; }

kbd {
  background: #5b3a29; color: #ffe8d0;
  padding: 1px 7px; border-radius: 4px;
  font-family: inherit; font-size: .82em;
  box-shadow: 0 2px 0 #3d2417;
}

.title-logo { font-size: 92px; font-weight: 700; line-height: .95; letter-spacing: 2px; }
.logo-fry { color: var(--choc-dark); text-shadow: 4px 4px 0 rgba(255,201,60,.6); }
.logo-hard { color: var(--pink-dark); text-shadow: 4px 4px 0 rgba(91,58,41,.25); }
.title-sub { font-size: 20px; color: var(--choc); font-weight: 600; letter-spacing: 4px; text-transform: uppercase; }
.title-story { font-size: 16px; color: #6b4a36; line-height: 1.6; max-width: 560px; }
.title-buttons { display: flex; gap: 14px; margin-top: 8px; }
.title-controls { margin-top: 10px; font-size: 13px; color: #8a6a52; line-height: 1.8; }

.btn {
  font-family: inherit;
  font-size: 18px; font-weight: 700;
  padding: 12px 26px;
  border: 3px solid var(--choc-dark);
  border-radius: 10px;
  background: var(--cream);
  color: var(--choc-dark);
  cursor: pointer;
  box-shadow: 0 5px 0 var(--choc-dark);
  transition: transform .05s, box-shadow .05s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--choc-dark); }
.btn-primary { background: var(--pink); color: #fff; }
.btn-primary:hover { background: var(--pink-dark); }

/* howto */
#screen-howto h2 { font-size: 40px; color: var(--choc-dark); }
.howto-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 12px; max-width: 860px;
}
.howto-card {
  background: #fff; border: 3px solid var(--choc);
  border-radius: 10px; padding: 12px 14px;
  font-size: 13.5px; color: #5b3a29; line-height: 1.45;
  text-align: left; position: relative;
}
.howto-num {
  position: absolute; top: -12px; left: 10px;
  background: var(--gold); color: var(--choc-dark);
  border: 2px solid var(--choc-dark); border-radius: 50%;
  width: 26px; height: 26px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.gold { color: #c8860a; font-weight: 700; }

/* day card */
#day-card-inner {
  background: #fff; border: 4px solid var(--choc);
  border-radius: 14px; padding: 34px 48px;
  display: flex; flex-direction: column; gap: 12px; align-items: center;
  box-shadow: 0 10px 0 rgba(61,36,23,.25);
}
#day-card-title { font-size: 48px; font-weight: 700; color: var(--pink-dark); }
#day-card-quota { font-size: 17px; color: var(--choc); }
.day-tip { font-size: 14px; color: #8a6a52; font-style: italic; max-width: 420px; }

/* shop */
.shop-head { display: flex; align-items: baseline; gap: 40px; }
.shop-title { font-size: 42px; font-weight: 700; color: var(--choc-dark); }
.shop-cash { font-size: 30px; font-weight: 700; color: #c8860a; }
.shop-sub { font-size: 15px; color: #8a6a52; }
.shop-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; max-width: 720px; max-height: 400px; overflow: auto;
  padding: 6px;
}
.upgrade-card {
  display: flex; gap: 12px; align-items: center;
  background: #fff; border: 3px solid var(--choc);
  border-radius: 10px; padding: 10px 14px;
  text-align: left;
}
.upgrade-icon { width: 56px; height: 56px; flex: 0 0 56px; object-fit: contain; image-rendering: pixelated; }
.upgrade-info { flex: 1; }
.upgrade-name { font-weight: 700; color: var(--choc-dark); font-size: 16px; }
.upgrade-desc { font-size: 12.5px; color: #7a5a42; line-height: 1.35; }
.upgrade-level { font-size: 12px; color: #c8860a; font-weight: 600; }
.upgrade-card .btn { font-size: 14px; padding: 8px 14px; }
.upgrade-card.maxed { opacity: .55; }
.shop-foot { display: flex; align-items: center; gap: 24px; }
.shop-note { font-size: 14px; color: var(--choc); font-style: italic; }

/* over / win */
.over-title { font-size: 72px; font-weight: 700; color: var(--red); text-shadow: 4px 4px 0 rgba(61,36,23,.2); }
.over-sub { font-size: 24px; font-weight: 600; color: var(--choc); letter-spacing: 3px; }
.over-stats { display: flex; gap: 34px; font-size: 16px; color: #6b4a36; }
.over-stats b { color: var(--choc-dark); font-size: 20px; }
.over-quote { font-size: 15px; color: #8a6a52; font-style: italic; }
.win-stamp { font-size: 60px; font-weight: 700; color: var(--gold); text-shadow: 3px 3px 0 rgba(61,36,23,.35); }
.win-title { font-size: 30px; font-weight: 700; color: var(--choc-dark); max-width: 620px; }
.win-sub { font-size: 17px; color: #7a5a42; font-style: italic; }
.win-stars { font-size: 42px; letter-spacing: 8px; color: var(--gold); }

.pause-title { font-size: 60px; font-weight: 700; color: var(--choc-dark); }

/* coach (tutorial bubble) */
#coach {
  position: absolute; top: 86px; left: 50%; transform: translateX(-50%);
  z-index: 30;
  background: #fff; border: 3px solid var(--choc);
  border-radius: 12px; padding: 10px 18px;
  font-size: 16px; font-weight: 600; color: var(--choc-dark);
  box-shadow: 0 6px 0 rgba(61,36,23,.25);
  max-width: 640px; text-align: center;
  animation: coach-pop .2s ease-out;
}
@keyframes coach-pop { from { transform: translateX(-50%) scale(.9); opacity: 0; } }

/* mobile controls */
#mobile-controls { position: absolute; inset: 0; z-index: 15; pointer-events: none; }
#mobile-controls .ctrl { pointer-events: auto; }
#joy-zone {
  position: absolute; left: 14px; bottom: 14px;
  width: 132px; height: 132px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  border: 3px solid rgba(255,255,255,.5);
}
#joy-knob {
  position: absolute; left: 50%; top: 50%;
  width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255,143,178,.9);
  border: 3px solid #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,.3);
}
#btn-action {
  position: absolute; right: 20px; bottom: 26px;
  width: 108px; height: 108px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: var(--pink);
  color: #fff; font-weight: 700; font-size: 17px;
  font-family: inherit;
  box-shadow: 0 6px 0 rgba(61,36,23,.4), 0 0 0 4px rgba(255,255,255,.25);
  touch-action: none;
}
#btn-action:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(61,36,23,.4); }
#btn-pause-mobile {
  position: absolute; top: 12px; right: 12px;
  width: 46px; height: 46px;
  border-radius: 10px;
  border: 3px solid #fff;
  background: rgba(61,36,23,.65);
  color: #fff; font-size: 16px;
}
#rotate-hint {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  z-index: 40;
  background: rgba(61,36,23,.8); color: #ffe8d0;
  border-radius: 20px; padding: 6px 16px; font-size: 13px;
}

@media (pointer: coarse) {
  #mobile-controls { display: block; }
}
