:root {
  --bg: #0a0a1a;
  --berry: #4a2f8f;
  --berry-dark: #2a1a5e;
  --ink: #e8e4ff;
  --accent: #8f7bff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
/* prevent iOS focus-zoom & double-tap zoom jank */
input, select, textarea { font-size: 16px !important; }
button { touch-action: manipulation; }
body {
  background: radial-gradient(ellipse at 50% 30%, #1a1440 0%, var(--bg) 70%);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

/* ---------- Berry ---------- */
#berry {
  position: relative;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255,255,255,0.28) 0%, rgba(255,255,255,0) 42%),
    radial-gradient(circle at 50% 55%, #5d3fb5 0%, var(--berry) 55%, var(--berry-dark) 100%);
  box-shadow:
    inset -14px -18px 40px rgba(0,0,0,0.45),
    0 18px 50px rgba(60,40,160,0.35);
  cursor: pointer;
  touch-action: none;
  transition: transform 0.15s ease;
}
#berry.listening { animation: pulse 1s ease-in-out infinite; }
#berry.thinking { animation: wobble 0.9s ease-in-out infinite; }
#berry.squish:active { transform: scale(0.94); }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}
@keyframes wobble {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-4deg) scale(1.02); }
  75% { transform: rotate(4deg) scale(1.02); }
}

/* tiny blueberry drupelet dots */
#berry::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background-image:
    radial-gradient(circle at 30% 38%, rgba(255,255,255,0.10) 0 6px, transparent 7px),
    radial-gradient(circle at 62% 30%, rgba(255,255,255,0.08) 0 5px, transparent 6px),
    radial-gradient(circle at 70% 58%, rgba(255,255,255,0.09) 0 6px, transparent 7px),
    radial-gradient(circle at 40% 70%, rgba(255,255,255,0.07) 0 5px, transparent 6px),
    radial-gradient(circle at 55% 80%, rgba(255,255,255,0.08) 0 5px, transparent 6px);
  pointer-events: none;
}

/* crown / calyx */
.crown {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 16px solid transparent;
  border-right: 16px solid transparent;
  border-bottom: 22px solid #2f8f4f;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.4));
}
.crown::after {
  content: "";
  position: absolute;
  top: 20px; left: -22px;
  width: 44px; height: 12px;
  background: #2f8f4f;
  border-radius: 50%;
  transform: rotate(-4deg);
}

/* eyes */
.eye {
  position: absolute;
  top: 62px;
  width: 44px; height: 52px;
  background: #fff;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.3);
}
.eye.left  { left: 34px; }
.eye.right { right: 34px; }
.pupil {
  position: absolute;
  top: 50%; left: 50%;
  width: 20px; height: 20px;
  margin: -10px 0 0 -10px;
  background: #1a1030;
  border-radius: 50%;
  transition: transform 0.08s linear;
}
.pupil::after {
  content: "";
  position: absolute;
  top: 3px; left: 4px;
  width: 7px; height: 7px;
  background: #fff;
  border-radius: 50%;
}
#berry.thinking .pupil { animation: dart 0.5s ease-in-out infinite alternate; }
@keyframes dart {
  from { transform: translate(-4px, -3px); }
  to   { transform: translate(4px, 3px); }
}

/* blush + mouth */
.blush {
  position: absolute;
  top: 122px;
  width: 18px; height: 9px;
  background: rgba(255,120,160,0.35);
  border-radius: 50%;
}
.blush.left  { left: 44px; }
.blush.right { right: 44px; }
.mouth {
  position: absolute;
  top: 108px; left: 50%;
  width: 26px; height: 14px;
  transform: translateX(-50%);
  border-bottom: 4px solid #1a1030;
  border-radius: 0 0 20px 20px;
}
#berry.listening .mouth {
  height: 18px;
  border-radius: 50%;
  border-bottom-width: 0;
  background: #1a1030;
  animation: chew 0.4s ease-in-out infinite alternate;
}
@keyframes chew {
  from { transform: translateX(-50%) scaleY(0.7); }
  to   { transform: translateX(-50%) scaleY(1.15); }
}

/* ---------- Speech bubble ---------- */
#bubble {
  position: absolute;
  top: 6%;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(560px, 86vw);
  background: #fff;
  color: #241a4d;
  padding: 14px 20px;
  border-radius: 18px;
  font-size: 17px;
  line-height: 1.45;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  text-align: center;
  animation: pop 0.18s ease-out;
}
#bubble::after {
  content: "";
  position: absolute;
  bottom: -10px; left: 50%;
  transform: translateX(-50%);
  border: 10px solid transparent;
  border-top-color: #fff;
  border-bottom: 0;
}
#bubble.hidden { display: none; }
@keyframes pop {
  from { transform: translateX(-50%) scale(0.85); opacity: 0; }
  to   { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ---------- Status / controls ---------- */
#status { font-size: 13px; letter-spacing: 0.12em; color: var(--accent); text-transform: uppercase; }
#hint { font-size: 12px; color: rgba(232,228,255,0.45); }

#controls {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
}
#controls button {
  width: 48px; height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(143,123,255,0.35);
  background: rgba(26,20,60,0.85);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: all 0.15s;
}
#controls button:hover { border-color: var(--accent); transform: scale(1.08); }
#mic-btn.active { background: var(--accent); color: #14102e; border-color: var(--accent); }

/* ---------- Chat panel ---------- */
#chat {
  position: fixed;
  left: 50%; bottom: 84px;
  transform: translateX(-50%);
  width: min(620px, 92vw);
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  background: rgba(16,12,40,0.92);
  border: 1px solid rgba(143,123,255,0.3);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  overflow: hidden;
}
#chat.hidden { display: none; }
#chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}
.msg { max-width: 82%; padding: 8px 12px; border-radius: 12px; line-height: 1.4; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: #3d2f8f; border-bottom-right-radius: 4px; }
.msg.bluey { align-self: flex-start; background: #241c50; border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: rgba(232,228,255,0.5); font-size: 12px; }
.msg.error { align-self: center; background: transparent; color: #ff9d9d; font-size: 12px; }
.chat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid rgba(143,123,255,0.2); }
.chat-input-row input {
  flex: 1;
  background: #0d0a24;
  border: 1px solid rgba(143,123,255,0.3);
  border-radius: 10px;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
.chat-input-row button {
  background: var(--accent); color: #14102e; border: 0;
  border-radius: 10px; padding: 0 16px;
  font-weight: 700; cursor: pointer;
}

/* ---------- Confirm bar ---------- */
#confirm {
  position: fixed;
  bottom: 84px; left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: min(520px, 92vw);
}
#confirm.hidden { display: none; }
.confirm-box {
  background: #2a1440;
  border: 1px solid #ff9d5c;
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  animation: pop 0.15s ease-out;
}
#confirm-text { font-size: 14px; line-height: 1.4; margin-bottom: 10px; }
.confirm-buttons { display: flex; gap: 10px; }
.confirm-buttons button {
  flex: 1; padding: 9px;
  border-radius: 9px; border: 0;
  font-weight: 700; cursor: pointer; font-size: 13px;
}
#confirm-yes { background: #ff9d5c; color: #2a1440; }
#confirm-no { background: rgba(255,255,255,0.12); color: var(--ink); }

/* ---------- Settings ---------- */
#settings-panel {
  position: fixed; inset: 0;
  background: rgba(5,4,15,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
#settings-panel.hidden { display: none; }
.panel {
  width: min(460px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  background: #161230;
  border: 1px solid rgba(143,123,255,0.35);
  border-radius: 18px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.panel h2 { font-size: 16px; letter-spacing: 0.15em; margin-bottom: 8px; }
.panel label { font-size: 12px; color: rgba(232,228,255,0.65); margin-top: 6px; }
.panel .dim { color: rgba(232,228,255,0.35); }
.panel input, .panel select {
  width: 100%;
  background: #0d0a24;
  border: 1px solid rgba(143,123,255,0.3);
  border-radius: 10px;
  color: var(--ink);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  margin-top: 4px;
}
.panel input:focus, .panel select:focus { border-color: var(--accent); }
.panel-buttons { display: flex; gap: 10px; margin-top: 14px; }
.panel-buttons button {
  flex: 1; padding: 11px;
  border-radius: 10px; border: 0;
  font-weight: 700; cursor: pointer;
}
#save-settings { background: var(--accent); color: #14102e; }
#close-settings { background: rgba(143,123,255,0.15); color: var(--ink); }
.hint { font-size: 11px; color: rgba(232,228,255,0.4); line-height: 1.5; margin-top: 10px; }
.hint a, .hint code { color: var(--accent); }

@media (max-width: 560px) {
  #berry { width: 150px; height: 150px; }
  .eye { top: 50px; width: 36px; height: 42px; }
  .eye.left { left: 26px; } .eye.right { right: 26px; }
  .pupil { width: 16px; height: 16px; margin: -8px 0 0 -8px; }
  #bubble { font-size: 15px; }
}
