/* Cozy Medieval Marketplace at Dusk — UI & Storybook Overlay */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #17162e;
  font-family: "Georgia", "Palatino Linotype", "Book Antiqua", serif;
  color: #2b1d12;
  user-select: none;
  -webkit-user-select: none;
}

#canvas-container {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#canvas-container canvas {
  display: block;
  width: 100%;
  height: 100%;
}

body.hovering-interactive #canvas-container {
  cursor: pointer;
}

/* Top-left title badge */
#hud-header {
  position: fixed;
  top: 16px;
  left: 18px;
  z-index: 20;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.title-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(26, 20, 42, 0.76);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid rgba(255, 198, 122, 0.38);
  border-radius: 14px;
  padding: 8px 14px;
  box-shadow: 0 6px 20px rgba(8, 5, 18, 0.45);
}

.title-emblem {
  font-size: 20px;
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(255, 140, 50, 0.65));
}

.title-text h1 {
  font-size: 16px;
  font-weight: 700;
  color: #ffe8c2;
  letter-spacing: 0.3px;
  line-height: 1.15;
}

.title-text p {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 11px;
  color: #cbb8e8;
  letter-spacing: 0.2px;
}

.controls-hint {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 11.5px;
  color: rgba(255, 236, 209, 0.82);
  background: rgba(22, 17, 37, 0.55);
  border: 1px solid rgba(255, 210, 150, 0.2);
  border-radius: 999px;
  padding: 4px 11px;
  width: fit-content;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

/* Top-right camera drift toggle */
#hud-tools {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 20;
  display: flex;
  gap: 8px;
}

.tool-pill {
  pointer-events: auto;
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: #ffe7c4;
  background: rgba(28, 21, 45, 0.76);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1.5px solid rgba(255, 196, 118, 0.35);
  border-radius: 999px;
  padding: 6px 13px;
  transition: transform 0.14s ease, background 0.18s ease, border-color 0.18s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.tool-pill:hover {
  background: rgba(52, 37, 78, 0.88);
  border-color: rgba(255, 210, 140, 0.7);
  transform: translateY(-1px);
}

.tool-pill.active {
  border-color: #ffb35c;
  color: #fff5e4;
}

/* 3D-Projected Speech Bubbles Layer */
#bubbles-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  overflow: hidden;
}

.speech-bubble {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 255px;
  min-width: 130px;
  background: linear-gradient(180deg, #fffdf6 0%, #f8ebd2 100%);
  color: #2c1c10;
  border: 2.5px solid #3c2616;
  border-radius: 16px;
  padding: 9px 13px 10px;
  box-shadow:
    0 8px 20px rgba(15, 9, 28, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transform: translate(-50%, -100%) scale(0.92);
  opacity: 0;
  transition: opacity 0.24s ease, transform 0.24s cubic-bezier(0.22, 1.25, 0.36, 1);
  will-change: left, top, transform, opacity;
}

.speech-bubble.visible {
  opacity: 1;
  transform: translate(-50%, -100%) scale(1);
}

.speech-bubble.reaction-bubble {
  max-width: 225px;
  background: linear-gradient(180deg, #fff9e6 0%, #ffe9b8 100%);
  border-color: #5a3414;
  z-index: 17;
}

.speech-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -11px;
  transform: translateX(-50%);
  border-width: 11px 9px 0 9px;
  border-style: solid;
  border-color: #3c2616 transparent transparent transparent;
}

.speech-bubble::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7.5px;
  transform: translateX(-50%);
  z-index: 1;
  border-width: 9px 7px 0 7px;
  border-style: solid;
  border-color: #f8ebd2 transparent transparent transparent;
}

.speech-bubble.reaction-bubble::before {
  border-color: #ffe9b8 transparent transparent transparent;
}

.bubble-speaker {
  display: inline-block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.65px;
  color: #ffffff;
  background: #1d63b8;
  padding: 2px 7px;
  border-radius: 999px;
  margin-bottom: 4px;
}

.bubble-text {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  color: #2a1a0e;
}

/* Hover Tooltip Pill for Interactive Characters & Stalls */
#hover-label {
  position: fixed;
  z-index: 18;
  pointer-events: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 11.5px;
  font-weight: 700;
  color: #fff4df;
  background: rgba(24, 17, 38, 0.86);
  border: 1px solid rgba(255, 198, 115, 0.55);
  border-radius: 999px;
  padding: 3px 10px;
  transform: translate(-50%, -140%);
  opacity: 0;
  transition: opacity 0.14s ease;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

#hover-label.visible {
  opacity: 1;
}

/* Bottom Storybook Narrator Card */
#story-dock {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 20;
  width: min(650px, calc(100vw - 24px));
  background: linear-gradient(180deg, rgba(35, 25, 52, 0.9) 0%, rgba(23, 17, 36, 0.94) 100%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1.5px solid rgba(255, 192, 112, 0.42);
  border-radius: 18px;
  padding: 12px 16px 11px;
  box-shadow:
    0 12px 32px rgba(5, 3, 14, 0.65),
    inset 0 1px 0 rgba(255, 228, 185, 0.16);
  overflow: hidden;
}

.story-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.story-chapter {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: #ffb869;
}

.beat-dots {
  display: flex;
  align-items: center;
  gap: 6px;
}

.beat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 214, 165, 0.25);
  cursor: pointer;
  padding: 0;
  transition: transform 0.16s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.beat-dot:hover {
  background: rgba(255, 214, 165, 0.6);
  transform: scale(1.2);
}

.beat-dot.active {
  background: #ff9d42;
  transform: scale(1.28);
  box-shadow: 0 0 8px rgba(255, 150, 55, 0.85);
}

.story-body-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

#narrator-text {
  flex: 1;
  font-size: 14.5px;
  line-height: 1.42;
  color: #fff3de;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  min-height: 40px;
  display: flex;
  align-items: center;
}

.story-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.story-btn {
  cursor: pointer;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: #ffe9c8;
  background: rgba(255, 188, 108, 0.14);
  border: 1px solid rgba(255, 195, 120, 0.36);
  border-radius: 10px;
  padding: 6px 10px;
  transition: background 0.15s ease, transform 0.12s ease, border-color 0.15s ease;
}

.story-btn:hover {
  background: rgba(255, 188, 108, 0.28);
  border-color: rgba(255, 210, 145, 0.75);
  transform: translateY(-1px);
}

.story-btn:active {
  transform: translateY(0);
}

.story-btn.primary {
  background: linear-gradient(180deg, #e57a2e 0%, #c45719 100%);
  border-color: #ffad66;
  color: #fffaf0;
  box-shadow: 0 3px 10px rgba(215, 92, 24, 0.4);
}

.story-btn.primary:hover {
  background: linear-gradient(180deg, #f2883b 0%, #d46220 100%);
}

#story-progress-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, #ff7b29, #ffd06b);
  transition: width 0.1s linear;
}

/* Loading / Fallback Screen */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: radial-gradient(circle at 50% 60%, #34214d 0%, #16142b 80%);
  color: #ffe9c7;
  transition: opacity 0.45s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#loading-overlay .spinner {
  font-size: 32px;
  animation: sizzleBounce 0.9s infinite alternate ease-in-out;
}

@keyframes sizzleBounce {
  from { transform: translateY(0) rotate(-6deg); }
  to { transform: translateY(-8px) rotate(6deg); }
}

@media (max-width: 600px) {
  .controls-hint {
    display: none;
  }
  .story-body-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .story-controls {
    justify-content: flex-end;
  }
  #narrator-text {
    font-size: 13.5px;
    min-height: 34px;
  }
}
