:root {
  --ink: #23313a;
  --paper: #fbf5e8;
  --accent: #e8763a;
  --teal: #2f8f83;
  --sky: #f2e3c6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  color: var(--ink);
  font-family: 'Tajawal', system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app canvas { display: block; }

[hidden] { display: none !important; }

/* ---------- full screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 16px;
  text-align: center;
  z-index: 20;
}

#loading { background: var(--sky); font-size: 22px; font-weight: 700; }
#loading .spin { font-size: 54px; animation: bob 1s ease-in-out infinite; }

#title { background: radial-gradient(ellipse at center, rgba(246,230,200,0) 35%, rgba(246,230,200,.5) 100%); }

.logo {
  font-family: 'Reem Kufi', 'Tajawal', sans-serif;
  font-weight: 700;
  font-size: clamp(72px, 16vw, 150px);
  line-height: 1.1;
  color: #fff;
  text-shadow:
    4px 0 var(--ink), -4px 0 var(--ink), 0 4px var(--ink), 0 -4px var(--ink),
    3px 3px var(--ink), -3px 3px var(--ink), 3px -3px var(--ink), -3px -3px var(--ink),
    0 10px 0 var(--ink);
}
.logo.small { font-size: 72px; text-shadow: none; }

.tag {
  font-size: clamp(18px, 4vw, 26px);
  font-weight: 800;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 22px;
  box-shadow: 0 4px 0 var(--ink);
}

.howto {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 640px;
  margin-top: 6px;
}
.howto span {
  background: rgba(251,245,232,.92);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 15px;
  font-weight: 700;
}

.btn {
  font: 800 24px 'Tajawal', sans-serif;
  padding: 10px 44px;
  color: #fff;
  background: var(--accent);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition: transform .08s, box-shadow .08s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn.alt { background: var(--teal); }
.btn.small { font-size: 19px; padding: 8px 22px; }

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

#end { background: rgba(143,216,207,.6); }
.endTitle {
  font-family: 'Reem Kufi', sans-serif;
  font-size: clamp(36px, 8vw, 64px);
  font-weight: 700;
  color: #fff;
  text-shadow: 3px 0 var(--ink), -3px 0 var(--ink), 0 3px var(--ink), 0 -3px var(--ink), 0 7px 0 var(--ink);
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button { pointer-events: auto; }

.panel {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
}

#quest {
  position: fixed;
  top: 16px;
  right: 16px;
  padding: 10px 14px;
  max-width: min(340px, calc(100vw - 32px));
  font-size: 16px;
  line-height: 1.55;
}
#quest .step { font-size: 13px; font-weight: 800; color: var(--teal); }
#quest .main { font-size: 18px; font-weight: 800; }
#quest .where { font-size: 14px; opacity: .85; }
#quest .dist { font-size: 13px; color: var(--accent); font-weight: 800; }

#place {
  position: fixed;
  top: 58px;
  left: 50%;
  transform: translate(-50%, -10px);
  text-align: center;
  opacity: 0;
  transition: opacity .6s, transform .6s;
  pointer-events: none;
  white-space: nowrap;
}
#place.show { opacity: 1; transform: translate(-50%, 0); }
#place .pn {
  font-family: 'Reem Kufi', sans-serif;
  font-size: clamp(26px, 5vw, 42px);
  font-weight: 700;
  color: #fff;
  text-shadow: 3px 0 var(--ink), -3px 0 var(--ink), 0 3px var(--ink), 0 -3px var(--ink), 0 6px 0 var(--ink);
}
#place .pp {
  display: inline-block;
  margin-top: 4px;
  font-size: 17px;
  font-weight: 800;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 2px 14px;
}

#toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translate(-50%, -80px);
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  padding: 8px 18px;
  border-radius: 999px;
  transition: transform .35s;
  white-space: nowrap;
}
#toast.show { transform: translate(-50%, 0); }

#emojis {
  position: fixed;
  bottom: 16px;
  left: 16px;
  display: flex;
  gap: 6px;
}
#emojis button {
  width: 44px;
  height: 44px;
  font-size: 22px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
  padding: 0;
}
#emojis button:active { transform: translateY(3px); box-shadow: none; }

#talkBtn {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}
#talkBtn:active { transform: translate(-50%, 4px); }
#talkBtn.quest { background: var(--teal); animation: pulse 1.2s ease-in-out infinite; }

/* Speech bubble: floats above the speaker; docked at the bottom on narrow screens. */
#dialog {
  position: fixed;
  left: 50%;
  top: 60%;
  transform: translate(-50%, -100%);
  width: min(420px, calc(100vw - 32px));
  min-height: 84px;
  padding: 22px 18px 18px 18px;
  padding-right: 64px;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 20px;
  animation: pop .18s ease-out;
}
#dialog::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -14px;
  width: 22px;
  height: 22px;
  background: var(--paper);
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  transform: translateX(-50%) rotate(45deg);
}
#dialog.docked {
  top: auto;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  width: min(680px, calc(100vw - 24px));
}
#dialog.docked::after { display: none; }
#dlgFace {
  position: absolute;
  top: 14px;
  right: 12px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  border: 3px solid var(--ink);
  display: grid;
  place-items: center;
  font: 800 20px 'Tajawal', sans-serif;
}
#dlgWho {
  position: absolute;
  top: -16px;
  right: 58px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 15px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 1px 10px;
  white-space: nowrap;
}
#dlgText { font-size: clamp(17px, 3.4vw, 20px); font-weight: 700; line-height: 1.6; min-height: 1.6em; }
#dlgNext { position: absolute; bottom: 4px; left: 14px; font-size: 13px; animation: bob .8s ease-in-out infinite; }
@keyframes pop { from { opacity: 0; scale: .9; } to { opacity: 1; scale: 1; } }

/* Top-left: sound and stamps. */
#topbar { position: fixed; top: 16px; left: 16px; display: flex; gap: 8px; }
#topbar .round {
  height: 44px;
  min-width: 44px;
  padding: 0 12px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: 0 3px 0 var(--ink);
  font: 800 18px 'Tajawal', sans-serif;
  pointer-events: auto;
}
#muteBtn { cursor: pointer; font-size: 20px; }

/* Arrow on the screen edge towards the next person. */
#pointer {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
#pointer .arrow {
  position: absolute;
  left: -22px;
  top: -22px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 30px;
  text-shadow: 0 0 0 var(--ink), 2px 2px 0 var(--ink);
}
#pointer .icon {
  position: absolute;
  left: -19px;
  top: -19px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 50%;
  font-size: 18px;
  animation: bob 1s ease-in-out infinite;
}
#pointer .dist {
  position: absolute;
  left: -30px;
  top: 22px;
  width: 60px;
  text-align: center;
  font: 800 13px 'Tajawal', sans-serif;
  color: var(--ink);
  text-shadow: 0 0 4px var(--paper), 0 0 4px var(--paper);
}

/* Floating joystick (touch). */
#stick {
  position: fixed;
  left: -70px;
  top: -70px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(251, 245, 232, .25);
  border: 3px solid rgba(35, 49, 58, .45);
  pointer-events: none;
}
#knob {
  position: absolute;
  left: 42px;
  top: 42px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(251, 245, 232, .9);
  border: 3px solid var(--ink);
}

.howto.touch { display: none; }
@media (pointer: coarse) {
  .howto.desktop { display: none; }
  .howto.touch { display: flex; }
}

@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes pulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.15); } }

@media (max-width: 640px) {
  #place { top: 150px; }
  #topbar { top: auto; bottom: 90px; left: auto; right: 16px; flex-direction: column; }
  #emojis { flex-direction: column; bottom: 90px; }
  #emojis button { width: 40px; height: 40px; font-size: 20px; }
  #quest { font-size: 14px; padding: 8px 12px; }
  #quest .main { font-size: 16px; }
  .howto span { font-size: 13px; }
}
