/* ==========================================================================
   AI Transformation City — style.css
   Warm, rounded, tactile UI floating on top of a full-screen canvas.
   ========================================================================== */

:root {
  --ink: #2d3550;
  --ink-soft: #6b7393;
  --cream: #fffaf0;
  --white: #ffffff;
  --grass: #8fd16a;
  --sun: #ffd23f;
  --coral: #ff7b54;
  --coral-dark: #e0623f;
  --mint: #3ccf91;
  --mint-dark: #26a874;
  --blue: #5b8cff;
  --blue-dark: #3f6be0;
  --lilac-line: #e6e0ff;
  --lilac-shadow: #d6cff5;

  --font: "Nunito", "Segoe UI Rounded", ui-rounded, "Segoe UI", system-ui, sans-serif;
  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --soft-shadow: 0 5px 0 rgba(45, 53, 80, 0.1), 0 12px 28px rgba(45, 53, 80, 0.2);
}

/* ---------- Reset & screen lock ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--grass);
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#cityCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
  touch-action: manipulation;
}

/* ---------- Floating pill badges ---------- */
.pill {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px 8px 8px;
  background: var(--white);
  border-radius: 999px;
  box-shadow: var(--soft-shadow);
  transition: transform 0.3s var(--bounce);
}
.pill:hover { transform: scale(1.05) rotate(-1deg); }

.pill--title { left: 16px; }
.pill--score { right: 16px; }

.pill__icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 22px;
  background: #d9ecff;
  box-shadow: inset 0 -3px 0 rgba(45, 53, 80, 0.08);
}
.pill__icon--star { background: #fff0b8; }

.pill__text { display: flex; flex-direction: column; line-height: 1.1; }
.pill__label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.pill__value { font-size: 17px; font-weight: 900; }

/* Score "bump" when a star is earned */
.pill--score.is-bumping { animation: bump 0.7s var(--bounce); }
.pill--score.is-bumping .pill__icon--star { animation: spin 0.7s var(--bounce); }

@keyframes bump {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.22) rotate(-3deg); }
  100% { transform: scale(1); }
}
@keyframes spin {
  from { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(200deg) scale(1.3); }
  to   { transform: rotate(360deg) scale(1); }
}

/* Small screens: tighter pills */
@media (max-width: 560px) {
  .pill { padding: 6px 14px 6px 6px; gap: 8px; }
  .pill__icon { width: 34px; height: 34px; font-size: 18px; }
  .pill__value { font-size: 14px; }
  .pill__label { font-size: 9px; }
  .pill--title { left: 10px; }
  .pill--score { right: 10px; }
}

/* ---------- Speech-bubble modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px max(24px, env(safe-area-inset-bottom));
  visibility: hidden;
  pointer-events: none;
  /* Delay hiding so the closing animation can play */
  transition: visibility 0s linear 0.35s;
}
.modal.is-open {
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 52, 90, 0.28);
  backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.modal.is-open .modal__backdrop { opacity: 1; }

.modal__card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(78vh, 640px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px 20px;
  margin-top: 56px; /* room for the avatar that pokes out above */
  background: var(--cream);
  border-radius: 32px;
  box-shadow: 0 8px 0 rgba(45, 53, 80, 0.12), 0 30px 60px rgba(30, 40, 80, 0.32);
  outline: none;
  opacity: 0;
  transform: translateY(60px) scale(0.85);
  transform-origin: 20% 100%;
  transition: transform 0.45s var(--bounce), opacity 0.25s ease;
}
.modal.is-open .modal__card { opacity: 1; transform: none; }

/* Character avatar pokes out of the top-left of the card */
.modal__avatar {
  position: absolute;
  top: -48px;
  left: 20px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 50px;
  line-height: 1;
  background: #ffe1b3;
  border: 6px solid var(--white);
  box-shadow: 0 6px 0 rgba(45, 53, 80, 0.1), 0 10px 20px rgba(45, 53, 80, 0.18);
  animation: bob 2.4s ease-in-out infinite;
}
.modal__avatar svg { width: 70%; height: 70%; }

@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-6px) rotate(2deg); }
}

.modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #efe9dc;
  color: var(--ink-soft);
  font: 900 16px var(--font);
  cursor: pointer;
  transition: transform 0.25s var(--bounce), background 0.2s;
}
.modal__close:hover { transform: scale(1.12) rotate(90deg); background: #e6dfcf; }
.modal__close:active { transform: scale(0.92); }

.modal__speaker {
  min-height: 40px;
  padding-left: 104px;
  padding-right: 44px;
}
.modal__name { font-size: 20px; font-weight: 900; line-height: 1.15; }
.modal__role { font-size: 13px; font-weight: 700; color: var(--ink-soft); }

.modal__chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 4px 2px 8px;
  scrollbar-width: thin;
}

/* Speech bubbles */
.bubble {
  align-self: flex-start;
  max-width: 94%;
  padding: 12px 16px;
  background: var(--white);
  border-radius: 22px 22px 22px 6px;
  box-shadow: 0 3px 0 rgba(45, 53, 80, 0.08);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
  transform-origin: 0% 100%;
  animation: pop 0.45s var(--bounce) backwards;
}
.bubble--good { background: #dcf8e9; box-shadow: 0 3px 0 #b5ecd2; }
.bubble--oops { background: #ffe4dc; box-shadow: 0 3px 0 #ffc9b8; }
.bubble--tip  { background: #fff4cc; box-shadow: 0 3px 0 #ffe598; font-size: 15px; }

@keyframes pop {
  from { opacity: 0; transform: scale(0.6) translateY(12px); }
  to   { opacity: 1; transform: none; }
}

/* Answer choices */
.choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
  animation: pop 0.45s var(--bounce) backwards;
}

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px 12px 12px;
  text-align: left;
  background: var(--white);
  color: var(--ink);
  border: 3px solid var(--lilac-line);
  border-radius: 20px;
  box-shadow: 0 5px 0 var(--lilac-shadow);
  font: 800 16px/1.3 var(--font);
  cursor: pointer;
  transition: transform 0.25s var(--bounce), box-shadow 0.15s, background 0.2s, border-color 0.2s;
}
.choice:hover:not(:disabled) { transform: translateY(-2px) scale(1.02); border-color: #c9bdff; }
.choice:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--lilac-shadow); }
.choice:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.choice:disabled { cursor: default; opacity: 0.55; }

.choice__key {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #efeaff;
  color: #6a5bd6;
  font-weight: 900;
}

.choice.is-correct,
.choice.is-wrong { opacity: 1; color: var(--white); }
.choice.is-correct {
  background: var(--mint);
  border-color: var(--mint);
  box-shadow: 0 5px 0 var(--mint-dark);
  animation: tada 0.6s var(--bounce);
}
.choice.is-wrong {
  background: var(--coral);
  border-color: var(--coral);
  box-shadow: 0 5px 0 var(--coral-dark);
  animation: shake 0.45s ease;
}
.choice.is-correct .choice__key,
.choice.is-wrong .choice__key { background: rgba(255, 255, 255, 0.3); color: var(--white); }

@keyframes tada {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.06) rotate(-1.5deg); }
  70%  { transform: scale(0.98) rotate(1deg); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}

/* Footer action buttons */
.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.modal__actions:empty { display: none; }

.btn {
  padding: 12px 22px;
  border: none;
  border-radius: 999px;
  font: 900 16px var(--font);
  cursor: pointer;
  color: var(--white);
  background: var(--blue);
  box-shadow: 0 5px 0 var(--blue-dark);
  animation: pop 0.45s var(--bounce) backwards;
  transition: transform 0.25s var(--bounce), box-shadow 0.15s;
}
.btn:hover { transform: translateY(-2px) scale(1.05); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--blue-dark); }
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.btn--soft { background: #efe9dc; color: var(--ink); box-shadow: 0 5px 0 #d9d0bd; }
.btn--soft:active { box-shadow: 0 1px 0 #d9d0bd; }

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  padding: 16px;
  background: var(--white);
  border-radius: 20px;
  font-weight: 800;
}

/* Respect users who prefer less motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
