/* =========================================================================
   Elodie's Worlds — style.css
   Bold, bright, chibi-flavoured UI chrome around the SVG paper doll.
   ========================================================================= */

:root {
  --pink: #ff5fb0;
  --pink-dark: #e0398f;
  --purple: #8a6ae0;
  --purple-dark: #6a48c2;
  --cyan: #4fd1e0;
  --yellow: #ffd166;
  --mint: #6fe3c0;
  --ink: #2b2233;
  --paper: #ffffff;
  --cloud: #f6f3fb;
  --lilac: #eae2fb;
  --shadow: 0 6px 0 rgba(43, 34, 51, 0.15);
  --shadow-sm: 0 3px 0 rgba(43, 34, 51, 0.15);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: linear-gradient(160deg, #fff2f9 0%, #f1ecfe 45%, #e8f9f6 100%);
  color: var(--ink);
  font-family: 'Nunito', 'Baloo 2', system-ui, sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------------------------------------------------------------------- */
/* Top bar                                                                */
/* ---------------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: var(--paper);
  border-bottom: 4px solid var(--ink);
  flex-wrap: wrap;
  /* Above Loki (3000), so when he hangs from under the bar he slides out
     from behind it. Floating menus and modals (4000+) still sit above. */
  position: relative;
  z-index: 3100;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-star { font-size: 28px; }
.brand h1 {
  font-family: 'Baloo 2', 'Nunito', sans-serif;
  font-size: 26px;
  font-weight: 800;
  margin: 0;
  background: linear-gradient(90deg, var(--pink), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tabs { display: flex; gap: 10px; }

.sound-toggle-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--cloud);
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, background 0.15s ease;
}
.sound-toggle-btn:hover { transform: translateY(-2px); }
.sound-toggle-btn.on { background: var(--mint); }

.tab {
  font-family: 'Baloo 2', 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 15px;
  padding: 10px 20px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--cloud);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, background 0.15s ease;
}
.tab:hover { transform: translateY(-2px); }
.tab.active {
  background: var(--pink);
  color: #fff;
}

/* ---------------------------------------------------------------------- */
/* Buttons                                                                */
/* ---------------------------------------------------------------------- */

.btn {
  font-family: 'Baloo 2', 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 3px solid var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
input:disabled { opacity: 0.4; }

.btn-primary { background: var(--purple); color: #fff; }
.btn-fun { background: var(--yellow); color: var(--ink); }
.btn-ghost { background: #fff; color: var(--ink); }
.btn-chip { background: var(--mint); color: var(--ink); font-size: 13px; padding: 9px 14px; }
.btn-chip.active { background: var(--purple); color: #fff; }

/* ---------------------------------------------------------------------- */
/* Layout                                                                 */
/* ---------------------------------------------------------------------- */

main { flex: 1; padding: 24px; }

.view { display: none; }
.view.active { display: block; }

.hint { text-align: center; font-size: 13px; color: #6b5f7a; margin: 6px 0 0; }

/* ---- Creator ---- */

.creator-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  align-items: start;
}

.stage-panel {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  position: sticky;
  top: 18px;
}

.doll-stage {
  position: relative;
  border-radius: var(--radius-md);
  /* visible, not hidden: #doll-svg fills this box exactly, so clipping
     here would undo the overflow:visible fix on the svg itself and still
     cut off a hand/foot that swings past the viewBox in an extreme pose */
  overflow: visible;
  background: radial-gradient(circle at 50% 30%, #fff 0%, var(--lilac) 70%, #e2d6fb 100%);
  aspect-ratio: 400 / 620;
}

.stage-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 88%, rgba(138,106,224,0.25) 0%, transparent 55%);
}

/* SVG's UA stylesheet defaults to overflow:hidden, which otherwise clips a
   limb the moment an extreme pose (a raised waving hand, say) swings it
   past the doll's own 400x620 viewBox — override it so those poses read
   properly instead of getting their hands/feet cut off. */
#doll-svg, .scene-doll, .cast-thumb svg { overflow: visible; }

#doll-svg { position: relative; width: 100%; height: 100%; display: block; }

.name-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.name-field label {
  font-family: 'Baloo 2', 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: var(--ink);
}
.name-field input {
  flex: 1;
  font-family: 'Nunito', 'Baloo 2', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  background: #fff;
}
.name-field input:focus {
  outline: none;
  border-color: var(--pink);
  box-shadow: 0 0 0 3px rgba(255, 95, 176, 0.25);
}

.stage-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.options-panel {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  min-height: 560px;
}

.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 3px dashed var(--lilac);
}

.cat-tab {
  font-family: 'Baloo 2', 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: #fff;
  cursor: pointer;
}
.cat-tab.active { background: var(--cyan); }

.option-grid {
  display: grid;
  gap: 12px;
}
.preview-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
.swatch-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }

.opt-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--cloud);
  border: 3px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 6px 10px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease, background 0.1s ease;
}
.opt-btn:hover { transform: translateY(-2px); background: var(--lilac); }
.opt-btn.selected {
  border-color: var(--pink);
  background: #fff0f8;
  box-shadow: 0 0 0 3px rgba(255, 95, 176, 0.25);
}

.opt-preview {
  width: 100%;
  aspect-ratio: 400 / 620;
  background: #fff;
  border-radius: 10px;
}

.swatch-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--ink);
}

.opt-label {
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  color: var(--ink);
}

/* ---- Simulator ---- */

.sim-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  align-items: start;
}

.sim-room-wrap { display: flex; flex-direction: column; gap: 10px; }

.sim-room {
  position: relative;
  aspect-ratio: 16 / 10;
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #ffffff;
  box-shadow: var(--shadow);
  cursor: default;
}

.room-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.room-bg svg { width: 100%; height: 100%; display: block; }

/* A scene's own fixed scenery lights (streetlamps, lit windows, neon
   billboards — see wireSceneLights in roomcontroller.js), made directly
   tappable instead of needing a separate movable light prop. */
.scene-lights { cursor: pointer; transition: opacity 0.25s ease, filter 0.25s ease; }
.scene-lights-off { opacity: 0.3; filter: grayscale(85%) brightness(0.55); }

/* No z-index here on purpose: dolls and props live in separate layer divs
   but must interleave by depth (their own inline z-index), so neither
   wrapper may create its own stacking context. */
.scene-dolls, .scene-props {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.scene-doll {
  position: absolute;
  width: 230px;
  height: 356.5px;
  touch-action: none;
  cursor: grab;
  pointer-events: auto;
  filter: drop-shadow(0 6px 4px rgba(43,34,51,0.25));
  transition: filter 0.15s ease;
}
.scene-doll.dragging { cursor: grabbing; }
.scene-doll:active { cursor: grabbing; }
/* Selection reads as a soft golden glow traced around the character
   herself, rather than a flat ring drawn at her feet — same stacked-
   drop-shadow trick used for a switched-on prop's glow (.prop-active). */
.scene-doll.selected {
  filter: drop-shadow(0 6px 4px rgba(43,34,51,0.25)) drop-shadow(0 0 10px rgba(255,205,70,0.95)) drop-shadow(0 0 22px rgba(255,186,40,0.7));
}

.scene-prop {
  position: absolute;
  touch-action: none;
  cursor: grab;
  pointer-events: auto;
  filter: drop-shadow(0 4px 3px rgba(43,34,51,0.22));
  border-radius: 10px;
  outline: 0 dashed transparent;
  outline-offset: 4px;
  transition: outline-color 0.1s ease;
}
.scene-prop.dragging { cursor: grabbing; }
.scene-prop.selected { outline: 4px dashed #ff2d84; }
.scene-prop.prop-active {
  filter: drop-shadow(0 4px 3px rgba(43,34,51,0.22)) drop-shadow(0 0 22px rgba(255,226,122,0.85)) drop-shadow(0 0 40px rgba(255,226,122,0.5));
}

/* Small emoji badge popped above a doll's head while an interaction rule
   (see js/interactions.js) is reacting to it — dancing, warming by a
   fire, and so on. */
.reaction-badge, .consume-badge { animation: badge-pop 0.18s ease-out; transform-box: fill-box; transform-origin: center; }
@keyframes badge-pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---- Cast / roster panel ---- */

.cast-panel {
  border: 3px dashed var(--lilac);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cast-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cast-header h2 { margin: 0; font-size: 16px; }
.btn-sm { padding: 7px 12px; font-size: 12px; }

.cast-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.cast-thumb {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  height: 80px;
  border-radius: 10px;
  border: 3px solid transparent;
  background: var(--cloud);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
}
.cast-thumb svg { width: 100%; height: 100%; display: block; }
.cast-thumb.selected { border-color: var(--pink); box-shadow: 0 0 0 2px rgba(255,95,176,0.3); }
.cast-thumb-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  font-size: 8px;
  font-weight: 700;
  line-height: 1.3;
  padding: 1px 3px;
  background: rgba(43,34,51,0.75);
  color: #fff;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.cast-empty { font-size: 12px; color: #8a7f99; padding: 6px 2px; }
.cast-hint { margin: -4px 0 0; font-size: 11.5px; color: #8a7f99; }

/* ---- Scene cast roster (toggle hub dolls on/off instead of "Add") ---- */

.cast-roster-thumb.inactive { opacity: 0.4; filter: grayscale(55%); }
.cast-roster-thumb.inactive:hover { opacity: 0.65; }
.cast-roster-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--ink);
  font-size: 10px;
  font-weight: 800;
  line-height: 12px;
  text-align: center;
  color: var(--ink);
}
.cast-roster-thumb.active .cast-roster-badge { background: var(--mint); }
.cast-warning {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--pink-dark);
  background: #fff0f8;
  border: 2px solid var(--pink);
  border-radius: 8px;
  padding: 6px 10px;
}

/* ---- Worn-items panel & prop-inspector panel ---- */

.worn-panel:empty, .prop-panel:empty { display: none; }
.worn-panel, .prop-panel {
  border: 3px dashed var(--lilac);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.panel-title {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 2px;
}
.worn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  padding: 3px 0;
}
.worn-row.worn-empty { color: #b0a6bd; font-weight: 600; }
.btn-xs { padding: 4px 8px; font-size: 11px; }

.prop-hint { font-size: 12px; color: #8a7f99; margin: 2px 0; }
.prop-hint-inline { font-size: 11px; color: #8a7f99; font-style: italic; }
.prop-contents { display: flex; flex-direction: column; gap: 6px; }
.prop-content-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  background: var(--cloud);
  border-radius: 8px;
  padding: 5px 8px;
}
.prop-content-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

/* ---- Floating press-and-hold interact menu ---- */

.floating-menu {
  position: fixed;
  /* Higher than any doll/prop's inline depth z-index (capped ~1001 — see
     layoutDoll/layoutProp in roomcontroller.js) so a press-and-hold menu
     never opens underneath a near-camera character or piece of furniture. */
  z-index: 4000;
  width: 280px;
  max-width: calc(100vw - 16px);
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fm-pop 0.12s ease-out;
}
@keyframes fm-pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---- Container window — a bottom tray of drag-able item cards, opened by
   a single tap on a container/shelf prop. Anchored to the bottom of the
   screen (not centered) so the stage — and every doll on it — stays fully
   visible and reachable behind it for the actual drag-onto-a-character
   gesture. ---- */
.container-window {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4000;
  max-height: 44vh;
  background: var(--paper);
  border-top: 4px solid var(--ink);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -8px 24px rgba(43, 34, 51, 0.25);
  padding: 14px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: cw-pop 0.15s ease-out;
}
.container-window[hidden] { display: none; }
@keyframes cw-pop {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.container-window-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'Baloo 2', 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 17px;
}
.container-window-items {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  overflow-y: auto;
  padding-top: 4px;
}
.container-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 84px;
  padding: 10px 6px;
  border-radius: 16px;
  background: var(--cloud);
  border: 3px solid var(--ink);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.container-card.drag-source-active { cursor: grabbing; opacity: 0.4; }
.container-card-icon { font-size: 28px; }
.container-card-label { font-size: 11px; font-weight: 700; text-align: center; line-height: 1.2; }

.drag-ghost {
  position: fixed;
  width: 84px;
  pointer-events: none;
  z-index: 6000;
  opacity: 0.95;
  transform: scale(1.08) rotate(-3deg);
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.3));
}
.floating-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--lilac);
  border-bottom: 3px solid var(--ink);
}
.floating-menu-close {
  border: none;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  line-height: 1;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}
.floating-menu-scroll {
  padding: 10px 12px 12px;
  max-height: min(60vh, 480px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fm-row-label {
  font-size: 11px;
  font-weight: 800;
  color: #8a7f99;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 4px;
}
.fm-btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* Subtle pulse while a character/prop is being pressed-and-held, before
   the floating menu opens — gives feedback that something is about to
   happen rather than a drag. */
.scene-doll.holding, .scene-prop.holding { outline: 4px solid rgba(255,45,132,0.55); outline-offset: 3px; animation: hold-pulse 0.48s ease-out; }
@keyframes hold-pulse {
  from { outline-color: rgba(255,45,132,0); }
  to { outline-color: rgba(255,45,132,0.55); }
}

/* ---- Fullscreen toggle ---- */

.room-fullscreen-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 60;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: var(--paper);
  font-size: 17px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.fullscreen-btn { margin-left: auto; }

/* ---- Floating ➕ Cast button — reachable in fullscreen too, where the
   side panel (and its old cast list) is hidden by default now. Fixed to
   the browser viewport (not the room) so it stays put even though the
   scene itself scrolls sideways. ---- */
.cast-fab {
  position: fixed;
  bottom: 18px;
  left: 18px;
  z-index: 70;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 4px solid var(--ink);
  background: var(--mint);
  color: var(--ink);
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.cast-fab:hover { transform: translateY(-2px) scale(1.05); }
.cast-fab:active { transform: scale(0.94); }

/* ---- Modals (Cast window + floating Character Creator) ---- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(43, 34, 51, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
/* The [hidden] attribute and this class have equal CSS specificity, and
   this rule comes later in the cascade — without this override a "hidden"
   modal would still render (and eat clicks) as a flex overlay. */
.modal-overlay[hidden] { display: none; }
.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'Baloo 2', 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 19px;
}
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: #fff;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}
.cast-modal-list { flex-wrap: wrap; overflow-x: visible; }
.cast-modal-list .cast-thumb { width: 72px; height: 110px; }
.cast-modal-create-btn { width: 100%; }

.creator-modal-card { max-width: 380px; align-items: stretch; }
.creator-modal-stage {
  position: relative;
  border-radius: var(--radius-md);
  overflow: visible;
  background: radial-gradient(circle at 50% 30%, #fff 0%, var(--lilac) 70%, #e2d6fb 100%);
  aspect-ratio: 400 / 480;
}
.creator-modal-stage svg { position: relative; width: 100%; height: 100%; display: block; overflow: visible; }
.creator-modal-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.creator-modal-footer .btn-primary { flex: 1; }

body.fullscreen-mode .sim-controls,
body.fullscreen-mode .footer {
  display: none !important;
}
body.fullscreen-mode .sim-layout {
  grid-template-columns: 1fr;
  max-width: 1500px;
}
body.fullscreen-mode .sim-room,
body.fullscreen-mode .scene-viewport {
  aspect-ratio: unset;
  height: min(80vh, 920px);
}

.sim-controls {
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sim-controls h2 {
  font-family: 'Baloo 2', sans-serif;
  font-size: 18px;
  margin: 0 0 4px;
}

.control-group { display: flex; flex-direction: column; gap: 6px; }
.control-group label {
  font-size: 13px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
}
.control-group input[type="range"] {
  width: 100%;
  accent-color: var(--pink);
}
.control-label { font-size: 13px; font-weight: 700; }

.preset-btns { display: flex; flex-wrap: wrap; gap: 6px; }

.back-link { margin-top: 4px; text-align: center; }

/* ---- Hub portals ---- */

.hub-portals {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.hub-portal {
  position: absolute;
  width: 12%;
  min-width: 74px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  pointer-events: auto;
}
.hub-portal-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 50% 50% 14% 14%;
  background: linear-gradient(160deg, var(--portal-a), var(--portal-b));
  border: 5px solid var(--ink);
  box-shadow: 0 6px 0 rgba(43, 34, 51, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform 0.15s ease;
}
.hub-portal:hover .hub-portal-frame { transform: translateY(-4px); }
.hub-portal-glow {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.65), transparent 70%);
  animation: portalPulse 3s ease-in-out infinite;
}
@keyframes portalPulse {
  0%, 100% { opacity: 0.5; transform: scale(0.9); }
  50% { opacity: 0.9; transform: scale(1.08); }
}
.hub-portal-emoji {
  position: relative;
  z-index: 1;
  font-size: clamp(18px, 3vw, 34px);
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35));
}
.hub-portal-label {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 11px;
  color: var(--ink);
  background: #fff;
  padding: 3px 9px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  white-space: nowrap;
}

/* ---- Overworld map ---- */

.overworld-layout {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.overworld-header {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 14px 20px;
  box-shadow: var(--shadow);
}
.overworld-header h2 { margin: 0; font-family: 'Baloo 2', sans-serif; font-size: 22px; }
.overworld-blurb { margin: 2px 0 0; font-size: 13px; color: #6b5f7a; }

.overworld-map {
  position: relative;
  aspect-ratio: 5 / 3;
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #fff;
}
.overworld-map-bg { position: absolute; inset: 0; }
.overworld-map-bg svg { width: 100%; height: 100%; display: block; }
.overworld-pins { position: absolute; inset: 0; }

.overworld-pin {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.overworld-pin-dot {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 0 rgba(43, 34, 51, 0.2);
  animation: pinBounce 2.4s ease-in-out infinite;
}
@keyframes pinBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.overworld-pin-label {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 12px;
  background: var(--ink);
  color: #fff;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ---- Wide scrollable world scenes ---- */

.scene-header {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}
.scene-header h2 { margin: 0; font-family: 'Baloo 2', sans-serif; font-size: 18px; }
.scene-world-name { margin: 0; font-size: 12px; color: #6b5f7a; }

.scene-viewport {
  position: relative;
  aspect-ratio: 16 / 10;
  border: 4px solid var(--ink);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  overflow-y: hidden;
  overflow-anchor: none;
  box-shadow: var(--shadow);
  background: #fff;
  scroll-behavior: smooth;
}
.scene-viewport::-webkit-scrollbar { height: 14px; }
.scene-viewport::-webkit-scrollbar-track { background: var(--cloud); }
.scene-viewport::-webkit-scrollbar-thumb { background: var(--pink); border-radius: 8px; border: 3px solid var(--cloud); }

.scene-track {
  position: relative;
  width: 300%;
  height: 100%;
}

/* ---------------------------------------------------------------------- */
/* Loki the meerkat (js/loki.js) — pops in from a screen edge now and then */
/* ---------------------------------------------------------------------- */

/* Above rooms, the Cast button and fullscreen buttons; below floating
   menus/container window (4000) and modals (5000+). */
.loki {
  position: fixed;
  z-index: 3000;
  width: 70px;
  height: 130px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.65s cubic-bezier(0.34, 1.4, 0.5, 1);
}
.loki[hidden] { display: none; }
.loki svg { display: block; width: 100%; height: 100%; overflow: visible; }
.loki-body { display: block; width: 100%; height: 100%; }
.loki-flip svg { transform: scaleX(-1); }

/* Up from the bottom edge: shows head and chest */
.loki-bottom { bottom: 0; transform: translateY(105%); }
.loki-bottom.loki-out { transform: translateY(30%); }

/* Leaning in from the bottom-right corner, pivoting on his feet */
.loki-corner { bottom: 0; right: -35px; transform-origin: 50% 100%; transform: rotate(95deg); }
.loki-corner.loki-out { transform: rotate(-28deg); }

/* Hanging upside-down from under the top bar (loki.js sets `top`) */
.loki-top { transform: translateY(-105%) rotate(180deg); }
.loki-top.loki-out { transform: translateY(-38%) rotate(180deg); }

/* Looking around and blinking while he's out */
.loki-head, .loki-eyes { transform-box: fill-box; transform-origin: 50% 70%; }
.loki-out .loki-head { animation: loki-look 3.2s ease-in-out infinite; }
.loki-eyes { transform-origin: 50% 50%; animation: loki-blink 3.7s infinite; }
@keyframes loki-look {
  0%, 18%   { transform: rotate(0deg); }
  28%, 45%  { transform: rotate(-14deg); }
  58%, 75%  { transform: rotate(12deg); }
  88%, 100% { transform: rotate(0deg); }
}
@keyframes loki-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95%           { transform: scaleY(0.1); }
}

.loki-hop .loki-body { animation: loki-hop 0.5s cubic-bezier(0.3, 0.7, 0.4, 1); }
@keyframes loki-hop {
  0%, 100% { transform: translateY(0); }
  40%      { transform: translateY(-22px) scale(1.04, 0.97); }
}

.loki-heart {
  position: absolute;
  left: 50%;
  top: 0;
  font-size: 22px;
  color: var(--pink);
  pointer-events: none;
  animation: loki-heart 1.2s ease-out forwards;
}
.loki-top .loki-heart { top: auto; bottom: 0; transform: rotate(180deg); }
@keyframes loki-heart {
  from { opacity: 1; translate: -50% 0; }
  to   { opacity: 0; translate: -50% -40px; }
}

@media (max-width: 860px) {
  .loki { width: 54px; height: 100px; }
  .loki-corner { right: -27px; }
}

@media (prefers-reduced-motion: reduce) {
  .loki { transition: opacity 0.4s; opacity: 0; }
  .loki.loki-out { opacity: 1; }
  .loki-out .loki-head, .loki-eyes, .loki-hop .loki-body, .loki-heart { animation: none; }
}

/* ---------------------------------------------------------------------- */
/* Footer                                                                 */
/* ---------------------------------------------------------------------- */

.footer {
  text-align: center;
  font-size: 12px;
  color: #8a7f99;
  padding: 14px;
}

/* ---------------------------------------------------------------------- */
/* Responsive                                                             */
/* ---------------------------------------------------------------------- */

@media (max-width: 860px) {
  .creator-layout, .sim-layout { grid-template-columns: 1fr; }
  .stage-panel { position: static; }
  .overworld-header, .scene-header { flex-direction: column; align-items: flex-start; }
}
