html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* The field stays inside the iPhone's safe area (notch / home bar);
   the black page fills the rest, so nothing important hides under them. */
/* A <canvas> is a replaced element: insets alone do not stretch it, so the
   safe-area box is a plain div and the canvas simply fills it. */
#stage {   /* the whole screen, edge to edge (under the notch too) */
  position: fixed;
  inset: 0;
  background: #000;
}
canvas#world {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background: #000;
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: #000;
  color: #fff;
  font-family: 'Arial Black', Arial, sans-serif;
  text-align: center;
  z-index: 50;
}

#loading { display: flex; font-size: 22px; letter-spacing: 2px; }
#loading.done { display: none; }

/* Phones in portrait: ask to rotate. */
@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: flex; }
}

/* rotate screen: the designer's art; the circling arrows spin (as a picture, so their outlines stay clean) */
#rotate { z-index: 2147483000; }   /* above everything, the REAL LIFE title and world included */
#rotate .rot-art { position: relative; width: min(78vw, 520px); animation: rot-bob 2.4s ease-in-out infinite; }
#rotate .rot-art img { display: block; width: 100%; height: auto; }
#rotate .rot-art img.rot-spin { position: absolute; left: 18.925%; top: -1.43%; width: 19.14%; animation: rot-spin 2.2s cubic-bezier(.6,0,.3,1) infinite; }
@keyframes rot-spin { 0%, 25% { transform: rotate(0deg); } 75%, 100% { transform: rotate(-360deg); } }
@keyframes rot-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
#loading { background: #F3F3F1; }
/* the opening titles (white, black logos dissolving into each other) */
#intro { position: fixed; inset: 0; z-index: 2147482000; background: #fff; transition: opacity 1.6s ease; }
#intro img { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); opacity: 0; transition: opacity 1.4s ease; }
#intro #introA { width: min(20vw, 210px); }
#intro #introB { width: min(9vw, 96px); }
#intro img.on { opacity: 1; }
#intro.out { opacity: 0; pointer-events: none; }

/* Developer panel (5 x F2). */
#dev {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 340px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  background: #090909;
  color: #fff;
  border: 1px solid #2e2e2e;
  border-radius: 12px;
  font: 12px Arial, sans-serif;
  padding: 12px;
  z-index: 60;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
#dev.hidden { display: none; }
#dev h3 { margin: 0 0 8px; font-size: 14px; }
#dev .egg-head { color: #ff02bd; font: 900 11px 'Arial Black', Arial; margin: 10px 0 5px; }
#dev .row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#dev button {
  background: #1d0d1e; color: #fff; border: 1px solid #9e4285; border-radius: 11px;
  padding: 6px 4px; font: 11px Arial; cursor: pointer;
}
#dev button:hover { background: #ff02bd; color: #000; }
#dev input, #dev select {
  width: 100%; box-sizing: border-box; background: #171717; color: #fff;
  border: 1px solid #343434; border-radius: 7px; padding: 6px 8px; margin: 6px 0;
}
#dev .list { max-height: 260px; overflow: auto; border: 1px solid #252525; border-radius: 7px; }
#dev .item { display: flex; align-items: center; gap: 8px; padding: 4px 6px; cursor: pointer; }
#dev .item:hover { background: #2d2d2d; }
#dev .item img { width: 28px; height: 28px; object-fit: contain; background: #111; border-radius: 4px; }
#dev .hint { color: #888; margin-top: 8px; }
#dev .dev-close { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; padding: 0; font-size: 14px; }
/* Phones: narrower panel inside the safe area, scrolls by finger. */
@media (pointer: coarse) {
  #dev {
    top: calc(env(safe-area-inset-top, 0px) + 6px); right: calc(env(safe-area-inset-right, 0px) + 6px);
    width: min(340px, 55vw); max-height: calc(100% - 12px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch; touch-action: pan-y;
  }
  #dev .hint { display: none; }
}

/* ---- LUCKY CHANCE plaque, Erika advert, messenger (over the canvas) ---- */
.ui-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.ui-layer.end-hidden { display: none; }
.ui-layer > * { pointer-events: auto; position: absolute; touch-action: none; user-select: none; -webkit-user-select: none; }
.lucky-ad { cursor: pointer; }
.lucky-ad .plaque { width: 100%; height: 100%; display: block; pointer-events: none; }
.lucky-ad .x { position: absolute; right: 6px; top: 6px; width: clamp(18px, 9%, 30px); cursor: pointer; }
.chat-ad { cursor: pointer; }
.chat-ad .card { width: 100%; height: 100%; display: block; border-radius: 6px; pointer-events: none; }
.chat-ad .x { position: absolute; right: -11px; top: -11px; width: clamp(18px, 9%, 27px); cursor: pointer; }
.messenger {
  display: flex; flex-direction: column; background: #0a080f; border: 2.4px solid #ad6cff; border-radius: 22px;
  overflow: hidden; font-family: Arial, sans-serif; box-sizing: border-box;
}
.messenger.pop { animation: chat-pop .19s cubic-bezier(.34,1.56,.64,1); }
@keyframes chat-pop { from { transform: scale(.72); } to { transform: scale(1); } }
.messenger .head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 8px 12px; height: 66px; box-sizing: border-box; cursor: move; flex: none; }
.messenger .ava { width: 46px; height: 46px; border-radius: 12px; object-fit: cover; flex: none; pointer-events: none; }
.messenger .names { flex: 1; min-width: 0; }
.messenger .name { color: #ffe144; font: bold 17px Arial; }
.messenger .status { color: #74f88f; font: 11px Arial; margin-top: 1px; }
.messenger .status.off { color: #9a8aa5; }
.messenger .close {
  height: 30px; min-width: 118px; border: 1px solid #ad6cff; border-radius: 15px; background: transparent;
  color: #fff; font: bold 10px Arial; cursor: pointer;
}
.messenger .close:hover { background: #c58cff; }
.messenger .feed { flex: 1; overflow-y: auto; padding: 12px 12px 10px; display: flex; flex-direction: column; gap: 9px; touch-action: pan-y; }
.messenger .feed::-webkit-scrollbar { width: 7px; background: #190f24; }
.messenger .feed::-webkit-scrollbar-thumb { background: #ad6cff; border-radius: 3px; }
.messenger .row { display: flex; }
.messenger .row.me { justify-content: flex-end; }
.messenger .bubble { max-width: 78%; background: #312142; color: #f1e9ff; border-radius: 12px; padding: 8px 12px; font: 12px Arial; line-height: 1.3; user-select: text; }
.messenger .row.me .bubble { background: #73407b; color: #fff; }
.messenger .opts { min-height: 28px; padding: 4px 10px 12px; display: flex; flex-direction: column; gap: 6px; flex: none; }
.messenger .reply {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; padding: 4px 8px 4px 16px;
  background: #ffe144; color: #211607; border: none; border-radius: 16px; font: bold 11px Arial; text-align: left; cursor: pointer;
}
.messenger .reply:hover { background: #fff58b; }
.messenger .reply img { width: 24px; height: 24px; flex: none; }
