*, *::before, *::after {
  box-sizing: border-box;
  margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'DM Sans', sans-serif;
  font-size: 15px;
  color: #f0ece0;
  background: #07060e;
}

/* ── Cosmic background ── */
.bg {
  position: fixed; inset: 0; z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(107,77,255,0.28) 0%, transparent 70%),
    radial-gradient(ellipse 55% 45% at 85% 90%,  rgba(201,168,76,0.14) 0%, transparent 65%),
    radial-gradient(ellipse 40% 40% at 10% 80%,  rgba(107,77,255,0.12) 0%, transparent 60%),
    #07060e;
  animation: bgShift 14s ease-in-out infinite alternate;
}

@keyframes bgShift {
  0%   { filter: brightness(1); }
  100% { filter: brightness(1.2); }
}

.bg::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    radial-gradient(1px   1px   at 12% 18%, rgba(255,255,255,0.55) 0%, transparent 100%),
    radial-gradient(1px   1px   at 33% 42%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 55% 11%, rgba(255,255,255,0.5)  0%, transparent 100%),
    radial-gradient(1px   1px   at 72% 66%, rgba(255,255,255,0.4)  0%, transparent 100%),
    radial-gradient(1px   1px   at 89% 28%, rgba(255,255,255,0.45) 0%, transparent 100%),
    radial-gradient(1px   1px   at  6% 79%, rgba(255,255,255,0.3)  0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 46% 88%, rgba(255,255,255,0.35) 0%, transparent 100%),
    radial-gradient(1px   1px   at 92% 82%, rgba(255,255,255,0.4)  0%, transparent 100%);
}

.bg::after {
  content: '';
  position: absolute;
  width: 900px; height: 900px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    rgba(201,168,76,0.05) 60deg,
    transparent 120deg,
    rgba(107,77,255,0.06) 180deg,
    transparent 240deg,
    rgba(201,168,76,0.05) 300deg,
    transparent 360deg
  );
  border-radius: 50%;
  animation: cosmosRotate 60s linear infinite;
  pointer-events: none;
}

@keyframes cosmosRotate {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ── App shell ── */
.app {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  height: 100vh;
  max-width: 780px;
  margin: 0 auto;
  padding: 0 16px 20px;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px 0 18px;
  flex-shrink: 0;
}

.header-emblem {
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, rgba(201,168,76,0.18), rgba(107,77,255,0.18));
  border: 1px solid rgba(201,168,76,0.35);
  border-radius: 50%;
  font-size: 22px;
  box-shadow: 0 0 20px rgba(201,168,76,0.2), inset 0 0 12px rgba(201,168,76,0.08);
  animation: emblemPulse 4s ease-in-out infinite;
}

@keyframes emblemPulse {
  0%, 100% { box-shadow: 0 0 20px rgba(201,168,76,0.2), inset 0 0 12px rgba(201,168,76,0.08); }
  50%       { box-shadow: 0 0 38px rgba(201,168,76,0.45), inset 0 0 20px rgba(201,168,76,0.18); }
}

.header-text {
  display: flex; flex-direction: column; align-items: flex-start;
}

.header-title {
  font-family: 'Cinzel', serif;
  font-size: 22px; font-weight: 700;
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, #e8cc80 0%, #c9a84c 50%, #a07830 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-sub {
  font-size: 11px; font-weight: 300;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #8a8097;
  margin-top: 2px;
}

.divider {
  height: 1px; flex-shrink: 0;
  background: linear-gradient(90deg, transparent, #7a5f28, transparent);
  margin-bottom: 14px;
}

/* ── Mode bar ── */
.mode-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.mode-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(201,168,76,0.25);
  background: rgba(18,15,35,0.6);
  color: #8a8097;
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.22s;
  white-space: nowrap;
  width: auto;
  height: auto;
  box-shadow: none;
  -webkit-appearance: none;
  touch-action: manipulation;
}

.mode-btn:hover {
  border-color: rgba(201,168,76,0.5);
  color: #e8cc80;
}

.mode-btn.active {
  background: linear-gradient(135deg, rgba(201,168,76,0.22), rgba(107,77,255,0.22));
  border-color: rgba(201,168,76,0.55);
  color: #e8cc80;
  box-shadow: 0 0 12px rgba(201,168,76,0.18);
}

/* ── Chat box ── */
#chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 6px 2px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

#chat-box::-webkit-scrollbar { width: 4px; }
#chat-box::-webkit-scrollbar-thumb {
  background: rgba(201,168,76,0.22);
  border-radius: 4px;
}

/* ── Messages ── */
.msg {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  animation: msgIn 0.35s cubic-bezier(.22,.68,0,1.2) both;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: none; }
}

.msg.user { flex-direction: row-reverse; }

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
}

.msg.bot .avatar {
  background: linear-gradient(145deg, rgba(201,168,76,0.22), rgba(107,77,255,0.22));
  border: 1px solid rgba(201,168,76,0.3);
  box-shadow: 0 0 10px rgba(201,168,76,0.15);
}

.msg.user .avatar {
  background: linear-gradient(145deg, rgba(107,77,255,0.3), rgba(80,50,200,0.3));
  border: 1px solid rgba(107,77,255,0.4);
}

.bubble {
  max-width: 74%;
  padding: 13px 17px;
  border-radius: 18px;
  line-height: 1.68;
  font-size: 14.5px;
}

.msg.bot .bubble {
  background: rgba(18,15,35,0.82);
  border: 1px solid rgba(201,168,76,0.16);
  border-bottom-left-radius: 5px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 4px 24px rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.04);
  color: #f0ece0;
}

.msg.user .bubble {
  background: linear-gradient(135deg, rgba(107,77,255,0.36), rgba(70,45,180,0.36));
  border: 1px solid rgba(107,77,255,0.35);
  border-bottom-right-radius: 5px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 20px rgba(107,77,255,0.18);
  color: #ddd8ff;
}

/* ── Typing dots ── */
.typing-dots {
  display: flex;
  gap: 5px;
  padding: 4px 2px;
}

.typing-dots span {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #7a5f28;
  animation: dot 1.3s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.18s; }
.typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes dot {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%            { transform: scale(1.15); opacity: 1; }
}

/* ── Input wrap ── */
.input-wrap {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  background: rgba(18,15,35,0.82);
  border: 1px solid rgba(201,168,76,0.2);
  border-radius: 56px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow:
    0 0 0 1px rgba(107,77,255,0.08),
    0 8px 32px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.04);
  transition: border-color 0.25s, box-shadow 0.25s;
}

.input-wrap:focus-within {
  border-color: rgba(201,168,76,0.45);
  box-shadow:
    0 0 0 3px rgba(201,168,76,0.08),
    0 8px 32px rgba(0,0,0,0.4),
    inset 0 1px 0 rgba(255,255,255,0.06);
}

/* ── Text input ── */
#msg {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #f0ece0;
  font-family: 'DM Sans', sans-serif;
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.5;
  padding: 4px 0;
}

#msg::placeholder { color: #8a8097; }

/* ── Send button ── */
.send-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  background: linear-gradient(135deg, #c9a84c 0%, #a07028 100%);
  color: #1a1000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(201,168,76,0.35);
  transition: transform 0.18s, box-shadow 0.18s, opacity 0.2s;
  -webkit-appearance: none;
  touch-action: manipulation;
}

.send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 22px rgba(201,168,76,0.55);
}

.send-btn:active { transform: scale(0.94); }

.send-btn.shake {
  animation: shake 0.35s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px) scale(1.05); }
  30%, 70% { transform: translateX(3px)  scale(1.05); }
  50%       { transform: translateX(-3px) scale(1.05); }
}

/* ── Clear button ── */
.clear-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid rgba(201,168,76,0.2);
  background: transparent;
  color: #8a8097;
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  -webkit-appearance: none;
  touch-action: manipulation;
  box-shadow: none;
}

.clear-btn:hover {
  color: #e8cc80;
  border-color: rgba(201,168,76,0.45);
}

/* ── Hint ── */
.hint {
  text-align: center;
  margin-top: 10px;
  font-size: 11px;
  color: rgba(138,128,151,0.45);
  letter-spacing: 0.05em;
}

/* ── Bubble markdown ── */
.bubble code {
  background: rgba(107,77,255,0.2);
  border: 1px solid rgba(107,77,255,0.3);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 13px;
  color: #c9b8ff;
}

.bubble strong { color: #e8cc80; font-weight: 600; }
.bubble em     { color: #b8b0d0; font-style: italic; }

/* ── Responsive ── */
@media (max-width: 520px) {
  .header-title { font-size: 18px; }
  .bubble { max-width: 86%; font-size: 14px; }
  .app { padding: 0 10px 16px; }
  .mode-btn { font-size: 11px; padding: 5px 10px; }
}
