html, body {
  margin: 0; height: 100%; background: #000; overflow: hidden;
  touch-action: none; overscroll-behavior: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: ui-rounded, "Trebuchet MS", system-ui, sans-serif;
}
#game {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  image-rendering: pixelated; image-rendering: crisp-edges;
}
#controls button {
  position: fixed; bottom: calc(14px + env(safe-area-inset-bottom));
  width: 72px; height: 72px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.75); background: rgba(255,255,255,.22);
  color: #fff; font-size: 30px; line-height: 1; padding: 0;
  touch-action: none; -webkit-user-select: none; user-select: none;
}
#controls button.pressed { background: rgba(255,182,193,.65); }
#btn-left  { left: calc(14px + env(safe-area-inset-left)); }
#btn-right { left: calc(100px + env(safe-area-inset-left)); }
#btn-jump  { right: calc(18px + env(safe-area-inset-right)); width: 84px !important; height: 84px !important; }
#btn-down  { right: calc(116px + env(safe-area-inset-right)); width: 64px !important; height: 64px !important; font-size: 24px !important; }
@media (hover: hover) and (pointer: fine) { #controls { display: none; } }
#rotate {
  display: none; position: fixed; top: calc(60px + env(safe-area-inset-top)); left: 0; right: 0;   /* below the corner buttons */
  text-align: center; color: #fff; font-size: 15px; opacity: .85; pointer-events: none;
}
@media (orientation: portrait) and (pointer: coarse) { #rotate { display: block; } }

/* ---- screens: which parts show in which app state (body[data-state]) ---- */
#game, #controls, #corner { visibility: hidden; }
body[data-state="PLAYING"] #game, body[data-state="PAUSED"] #game,
body[data-state="GAME_OVER"] #game, body[data-state="VICTORY"] #game { visibility: visible; }
body[data-state="PLAYING"] #controls, body[data-state="PLAYING"] #corner,
body[data-state="PAUSED"] #corner { visibility: visible; }
#menu { display: none; }
body[data-state="MAIN_MENU"] #menu, body[data-state="LOADING"][data-from="MAIN_MENU"] #menu { display: block; }
body[data-state="LOADING"]:not([data-from="MAIN_MENU"]) #game { visibility: visible; }   /* "Jogar de novo" */
body.starting button { pointer-events: none; }   /* one click starts it: no double start */

/* the veil of the start sequence */
#veil {
  position: fixed; inset: 0; z-index: 40; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 45%, #f6c6dc 0%, #c7a6e8 55%, #4a2d5e 100%);
  display: flex; align-items: center; justify-content: center;
}
#veil[hidden] { display: none; }
#veil span { opacity: 0; color: #fff; font: 800 22px ui-rounded, "Trebuchet MS", system-ui, sans-serif; text-shadow: 0 2px 0 #a32a63; transition: opacity .3s; }
#veil.waiting span { opacity: 1; }

/* round corner buttons (pause, sound, full screen) */
#corner { position: fixed; z-index: 5; top: calc(8px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); display: flex; gap: 8px; }
.round {
  width: 40px; height: 40px; border-radius: 50%; padding: 0; font-size: 19px; line-height: 1;
  border: 2px solid rgba(255,255,255,.65); background: rgba(42,26,46,.45); color: #fff; cursor: pointer;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}

/* ---- the title screen ---- */
#menu { position: fixed; inset: 0; background: #2a1a2e; overflow: hidden; }
#menu-art { position: absolute; inset: 0; width: 100%; height: 100%; }
/* the largest 16:9 box that fits: everything in it scales with --u (1% of its height) */
.stage {
  --u: calc(var(--sh, 1080px) / 100);
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: var(--sw, 1920px); height: var(--sh, 1080px);
}
.logo {
  position: absolute; left: 50%; top: calc(var(--u) * 2.5); transform: translateX(-50%);
  width: calc(var(--u) * 76); height: auto; pointer-events: none;
  filter: drop-shadow(0 calc(var(--u) * .6) calc(var(--u) * 1.2) rgba(60,20,70,.45));
  animation: float 4.5s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateX(-50%) translateY(calc(var(--u) * -.9)); } }
.menu-buttons { position: absolute; left: 50%; top: calc(var(--u) * 37); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: calc(var(--u) * .4); }
.menu-buttons .row { display: flex; gap: calc(var(--u) * 1.5); justify-content: center; }
.mbtn {
  --w: 26;
  /* the label sits in the pink capsule, whose middle is at 58% of the art's height (the crown
     and wings take the top): pad the top by (2 * 0.58 - 1) of the height = 0.16 / 2.067 of the width */
  width: calc(var(--u) * var(--w)); aspect-ratio: 707 / 342; padding: calc(var(--u) * var(--w) * .077) 0 0;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1; box-sizing: border-box;
  border: 0; background: url(assets/menu/button-normal.png) center / 100% 100% no-repeat; cursor: pointer;
  font: 800 calc(var(--u) * var(--w) * .11) ui-rounded, "Trebuchet MS", system-ui, sans-serif;
  color: #fff; letter-spacing: .02em;
  text-shadow: 0 2px 0 #a32a63, 0 -1px 0 #a32a63, 2px 0 0 #a32a63, -2px 0 0 #a32a63, 0 3px 6px rgba(90,20,60,.5);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; -webkit-user-select: none;
  transition: transform .12s ease;
}
.mbtn.big { --w: 34; }
.mbtn:hover, .mbtn:focus-visible { background-image: url(assets/menu/button-hover.png); transform: scale(1.04); outline: none; }
.mbtn:active, .mbtn.pressed { background-image: url(assets/menu/button-pressed.png); transform: scale(.97); }
.mbtn[hidden] { display: none; }
.pulse { animation: pulse 1.8s ease-in-out infinite; }
.pulse:hover, .pulse:focus-visible, .pulse:active { animation: none; }
@keyframes pulse { 50% { transform: scale(1.05); filter: brightness(1.06); } }
#btn-fullscreen { position: absolute; z-index: 2; top: calc(8px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); }
#btn-fullscreen[hidden] { display: none; }
/* preload the other two button states */
#menu::after { content: ""; position: absolute; width: 0; height: 0; overflow: hidden;
  background: url(assets/menu/button-hover.png), url(assets/menu/button-pressed.png); }

/* ---- panels: how to play, settings, credits, loading, pause, game over, victory ---- */
.panel { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; background: rgba(30,10,40,.55); }
.panel[hidden] { display: none; }
.card {
  --u: min(1vh, .56vw);
  max-width: min(92vw, calc(var(--u) * 140)); max-height: 92vh; overflow: auto; box-sizing: border-box;
  padding: calc(var(--u) * 4) calc(var(--u) * 6); border-radius: calc(var(--u) * 4);
  background: linear-gradient(#fff2f7, #ffd9e8); color: #5a1d43; text-align: center;
  border: calc(var(--u) * .8) solid #f1b93f; box-shadow: 0 0 0 calc(var(--u) * .5) #a3446f, 0 calc(var(--u) * 2) calc(var(--u) * 5) rgba(40,10,40,.5);
  font: 600 calc(var(--u) * 3.4) ui-rounded, "Trebuchet MS", system-ui, sans-serif;
  display: flex; flex-direction: column; align-items: center; gap: calc(var(--u) * 1.6);
}
.card h2 { margin: 0; font-size: calc(var(--u) * 6); color: #d2457f; text-shadow: 0 2px 0 #fff; }
.card p, .card ul, .card ol { margin: 0; }
.card ul, .card ol { text-align: left; padding-left: 1.2em; line-height: 1.35; }
.card .mbtn { --w: 32; --u: min(1vh, .56vw); }
.card .mbtn.small { --w: 30; }
.slider { display: grid; grid-template-columns: 7em 1fr 3em; gap: .8em; align-items: center; width: min(80vw, calc(var(--u) * 90)); text-align: left; }
.slider input { accent-color: #d2457f; }
.keys-desktop { display: none; }
@media (hover: hover) and (pointer: fine) {
  .keys-desktop { display: block; }
  .keys-touch { display: none; }
}
.card .mbtn { font-size: calc(var(--u) * var(--w) * .092); }
