:root {
  --ink: #1b2140;
  --stroke: rgba(255, 255, 255, 0.18);
  --panel: rgba(12, 18, 32, 0.66);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #87ceeb;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
#hub { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---- Teleport flash (§3) ---- */
#flash {
  position: fixed; inset: 0; background: #fff; opacity: 0;
  pointer-events: none; transition: opacity .22s ease; z-index: 60;
}
#flash.on { opacity: 1; }

/* ---- HUD ---- */
#hud {
  position: fixed; top: max(10px, env(safe-area-inset-top)); left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 0 12px; gap: 12px; pointer-events: none; z-index: 20;
}
.hud-left { display: flex; align-items: center; gap: 10px; }
.chevron {
  display: flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, #ffd34d, #ff9f1c);
  color: #3a2a00; font-weight: 800; font-size: 20px;
  padding: 7px 14px 7px 10px; border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.chev-icon { font-size: 18px; }
.xp-bar {
  width: 140px; height: 12px; border-radius: 999px;
  background: rgba(10, 14, 24, 0.5); border: 1px solid var(--stroke); overflow: hidden;
}
#xp-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #7bff9b, #37b34a); transition: width .4s ease; }
.hud-right { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  background: var(--panel); color: #fff; font-weight: 700; font-size: 15px;
  padding: 8px 13px; border-radius: 999px; border: 1px solid var(--stroke);
  backdrop-filter: blur(4px);
}

/* ---- Toast (spoken hints duplicate here) ---- */
#toast {
  position: fixed; left: 50%; top: 24%; transform: translate(-50%, -6px);
  background: rgba(12, 18, 32, 0.9); color: #fff; font-weight: 700; font-size: 17px;
  padding: 13px 20px; border-radius: 16px; border: 1px solid var(--stroke);
  max-width: min(86vw, 520px); text-align: center; line-height: 1.35;
  opacity: 0; pointer-events: none; transition: opacity .25s ease, transform .25s ease;
  z-index: 40;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Emotions + phrases (§2) ----
   Desktop: the wheel sits open at the bottom-left, there is room.
   Touch: the bottom-left belongs to the joystick thumb, so the controls collapse
   into two buttons on the RIGHT, above the jump button. */
#social {
  position: fixed; left: max(10px, env(safe-area-inset-left));
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex; align-items: flex-end; gap: 8px; z-index: 30;
}
#wheel { display: grid; grid-template-columns: repeat(4, 44px); gap: 6px; }
.wheel-btn, .social-toggle {
  width: 44px; height: 44px; border-radius: 50%; font-size: 22px; line-height: 1;
  background: var(--panel); color: #fff; border: 1px solid var(--stroke);
  cursor: pointer; backdrop-filter: blur(4px); padding: 0;
}
.wheel-btn:active, .social-toggle:active { transform: scale(0.92); }
#btn-emotes { display: none; }          /* desktop: the wheel is already open */
#phrases {
  position: fixed; left: max(10px, env(safe-area-inset-left));
  bottom: calc(74px + env(safe-area-inset-bottom));
  display: none; flex-direction: column; gap: 6px; max-height: 42vh; overflow: auto;
  background: var(--panel); padding: 10px; border-radius: 16px; border: 1px solid var(--stroke);
  backdrop-filter: blur(6px); z-index: 31;
}
#phrases.open { display: flex; }
.phrase-btn {
  background: rgba(255, 255, 255, 0.1); color: #fff; border: 1px solid var(--stroke);
  border-radius: 12px; padding: 10px 14px; font-size: 15px; font-weight: 600;
  text-align: left; cursor: pointer; white-space: nowrap;
}
.phrase-btn:active { background: rgba(255, 255, 255, 0.2); }

@media (pointer: coarse) {
  /* Keep the whole bottom-left clear for the floating joystick. */
  #social {
    left: auto; right: max(14px, env(safe-area-inset-right));
    bottom: calc(184px + env(safe-area-inset-bottom));
    flex-direction: column; align-items: flex-end; gap: 10px;
  }
  #btn-emotes { display: block; }
  #wheel {
    display: none;
    position: fixed; right: max(70px, env(safe-area-inset-right));
    bottom: calc(184px + env(safe-area-inset-bottom));
    grid-template-columns: repeat(4, 52px); gap: 8px;
    background: var(--panel); padding: 10px; border-radius: 18px;
    border: 1px solid var(--stroke); backdrop-filter: blur(6px);
  }
  #wheel.open { display: grid; }
  .wheel-btn, .social-toggle { width: 52px; height: 52px; font-size: 26px; }
  #phrases {
    left: auto; right: max(70px, env(safe-area-inset-right));
    bottom: calc(184px + env(safe-area-inset-bottom));
    max-width: 62vw;
  }
  .phrase-btn { white-space: normal; }
}

/* ---- Look picker ---- */
#skin-block {
  position: fixed; right: max(10px, env(safe-area-inset-right)); top: 78px;
  display: flex; align-items: center; gap: 6px; z-index: 20;
  background: var(--panel); padding: 7px 10px; border-radius: 999px; border: 1px solid var(--stroke);
}
.skin-label { font-size: 15px; background: none; border: 0; color: #fff; padding: 0; cursor: default; }
.skin-row { display: flex; gap: 5px; }
.skin-swatch {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.5);
  cursor: pointer; padding: 0;
}
.skin-swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px #ffd34d; }

@media (pointer: coarse) {
  /* A narrow screen can't spare a row of eight swatches over the scene. */
  .skin-label { font-size: 20px; cursor: pointer; }
  #skin-block .skin-row { display: none; }
  #skin-block.open .skin-row { display: flex; flex-wrap: wrap; max-width: 54vw; }
  #skin-block { top: calc(124px + env(safe-area-inset-top)); }
  .skin-swatch { width: 28px; height: 28px; }
}

/* ---- Touch controls ---- */
#touch-controls { position: fixed; inset: 0; pointer-events: none; z-index: 25; }
/* Floating joystick (Roblox-style): drawn wherever the finger lands on the left
   half of the screen. Touches are handled window-wide, so the ring itself must
   never intercept them. */
.joystick {
  position: fixed;
  left: 0; top: 0;
  width: 132px; height: 132px;
  margin: -66px 0 0 -66px;   /* centre on the touch point */
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12); border: 2px solid rgba(255, 255, 255, 0.32);
  pointer-events: none; touch-action: none;
  opacity: 0; transition: opacity .12s ease;
}
.joystick.active { opacity: 1; }
.joystick-knob {
  position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%; background: rgba(255, 255, 255, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.6); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.touch-buttons {
  position: absolute; right: max(18px, env(safe-area-inset-right));
  bottom: calc(96px + env(safe-area-inset-bottom)); display: flex; gap: 12px;
}
.touch-btn {
  width: 76px; height: 76px; border-radius: 50%; font-size: 30px; pointer-events: auto;
  background: rgba(255, 255, 255, 0.24); color: #fff; border: 2px solid rgba(255, 255, 255, 0.45);
}
@media (pointer: fine) { #touch-controls { display: none; } }

/* ---- World frame (§7: our bar stays above the world) ---- */
#world { position: fixed; inset: 0; background: #0b1020; z-index: 50; }
#world.hidden { display: none; }
#world-bar {
  position: absolute; top: 0; left: 0; right: 0; height: 64px;
  display: flex; align-items: center; gap: 18px; padding: 0 16px;
  background: #151b33; color: #fff; font-weight: 700; font-size: 16px; z-index: 2;
  padding-top: env(safe-area-inset-top);
  height: calc(64px + env(safe-area-inset-top));
}
#world-clock.low { color: #ff8a9b; }
/* Nothing in this bar may wrap: it is a fixed 64 px tall, so a second line
   simply falls out of it. On a phone "⚡ 3" was breaking between the icon and
   the number, and the world's name between its two words. */
#world-bar > * { white-space: nowrap; }
#world-title {
  opacity: .65; font-weight: 600; margin-left: auto;
  min-width: 0; overflow: hidden; text-overflow: ellipsis;
}
#world-exit {
  background: rgba(255, 255, 255, 0.12); color: #fff; border: 1px solid var(--stroke);
  width: 36px; height: 36px; border-radius: 10px; font-size: 17px; cursor: pointer;
}
#world-frame { position: absolute; inset: 0; }
#world-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
#world-loading {
  position: absolute; inset: 0; display: none; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; color: #fff; background: #0b1020; z-index: 3;
}
#world.loading #world-loading { display: flex; }

/* ---- Boot ---- */
#boot {
  position: fixed; inset: 0; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; color: #fff;
  background: linear-gradient(160deg, #2a3560, #121935); z-index: 70;
}
#boot.hidden { display: none; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.25); border-top-color: #ffd34d;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- "Позови взрослого": the pairing panel (§9) ----
   The HUD ignores pointer events so the child can look around through it, so the
   one button in there has to opt back in. */
.pill-btn {
  pointer-events: auto; cursor: pointer; font-family: inherit;
  line-height: 1; padding: 7px 12px;
}
.pill-btn:active { transform: scale(0.95); }

#parent-panel {
  position: fixed; inset: 0; z-index: 60;
  display: none; align-items: center; justify-content: center;
  background: rgba(8, 12, 24, 0.66); backdrop-filter: blur(3px);
  padding: 16px;
}
#parent-panel.open { display: flex; }
.parent-card {
  position: relative; width: min(94vw, 520px); max-height: 92vh; overflow: auto;
  background: #ffffff; color: var(--ink); border-radius: 22px;
  padding: 22px 20px 18px; text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}
.parent-card h2 { margin: 0 0 6px; font-size: 24px; }
.parent-lead { margin: 0 0 16px; font-size: 15px; line-height: 1.4; color: #4a5372; }
.parent-close {
  position: absolute; top: 10px; right: 10px; width: 36px; height: 36px;
  border: 0; border-radius: 50%; background: #eef1f8; color: #4a5372;
  font-size: 17px; cursor: pointer;
}
#parent-body { display: flex; gap: 18px; align-items: center; justify-content: center; flex-wrap: wrap; }
#parent-qr {
  width: 216px; height: 216px; border-radius: 14px;
  border: 1px solid #e3e7f2; background: #fff; image-rendering: pixelated;
}
.parent-code-wrap { min-width: 180px; }
.parent-code-hint { font-size: 13px; color: #7a839e; }
#parent-code {
  font-size: 34px; font-weight: 800; letter-spacing: 3px; margin: 4px 0 2px;
  font-variant-numeric: tabular-nums;
}
#parent-url { font-size: 13px; color: #4a5372; word-break: break-all; }
#parent-left { font-size: 13px; color: #7a839e; margin-top: 8px; }
.parent-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 18px; padding-top: 14px; border-top: 1px solid #eef1f8;
  font-size: 14px; color: #7a839e; text-align: left;
}
#parent-status.ok { color: #1f9d55; font-weight: 700; }
.parent-btn {
  border: 0; border-radius: 12px; background: #4a63d8; color: #fff;
  font-weight: 700; font-size: 14px; padding: 10px 15px; cursor: pointer;
  font-family: inherit; white-space: nowrap;
}
.parent-btn:active { transform: scale(0.97); }

@media (max-width: 430px) {
  #parent-qr { width: 190px; height: 190px; }
  #parent-code { font-size: 29px; }
}

/* ---- The world bar on a phone ----
   Only the side padding shrinks: `padding` shorthand here would wipe out the
   safe-area padding-top and slide the bar under the notch. */
@media (max-width: 560px) {
  #world-bar {
    gap: 10px;
    padding-left: 10px;
    padding-right: 10px;
    font-size: 14px;
  }
  #world-title { font-size: 13px; }
  #world-exit { width: 32px; height: 32px; font-size: 15px; flex: 0 0 auto; }
}
