/* ---------------------------------------------------------------
   Tokyo Night tokens
--------------------------------------------------------------- */
:root {
  --bg-dark: #16161e;
  --bg: #1a1b26;
  --bg-highlight: #292e42;
  --border: #3b4261;
  --border-soft: #24283b;
  --fg: #c0caf5;
  --fg-dim: #a9b1d6;
  --fg-mute: #565f89;

  --font-display: "Spectral", Georgia, serif;
  --font-body: "Inter", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg-dark);
  color: var(--fg);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--fg-dim);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------------------
   Custom scrollbars (Firefox + WebKit/Chromium)
--------------------------------------------------------------- */
* {
  scrollbar-width: auto;
  scrollbar-color: var(--border) var(--bg);
}

*::-webkit-scrollbar {
  width: 14px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: var(--bg);
}

*::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 8px;
  border: 2px solid var(--bg);
}

*::-webkit-scrollbar-thumb:hover {
  background-color: var(--fg-mute);
}

*::-webkit-scrollbar-corner {
  background: var(--bg);
}

/* ---------------------------------------------------------------
   App shell
--------------------------------------------------------------- */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
  border-left: 1px solid var(--border-soft);
  border-right: 1px solid var(--border-soft);
  overflow: hidden;
  position: relative;
}

/* ---------------------------------------------------------------
   Edge glow: persona-colored bands wash in from alternating sides
   as replies land, behind the thread only (header/composer sit
   above it via z-index and stay opaque).
--------------------------------------------------------------- */
.edge-glow {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.edge-glow__side {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 120px;
  display: flex;
  flex-direction: column;
  filter: blur(34px);
}

.edge-glow__side--left {
  left: -55px;
}

.edge-glow__side--right {
  right: -55px;
}

.edge-band {
  flex: 1;
  opacity: 0;
  transform: scaleY(0.3);
  transform-origin: center;
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(.3, .7, .3, 1);
}

.edge-band.on {
  opacity: 0.55;
  transform: scaleY(1);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, var(--bg) 0%, rgba(22, 22, 30, 0.4) 100%);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.app-header__mark {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
}

.app-header__glyph {
  width: 24px;
  height: 24px;
  color: #e0af68;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header__clear {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-mute);
  font-family: var(--font-body);
  font-size: 12px;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.app-header__clear:hover {
  color: var(--fg);
  border-color: var(--fg-mute);
}

.app-header__clear.is-active {
  color: #e0af68;
  border-color: #e0af68;
}

.demo-banner {
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: #e0af68;
  background: rgba(224, 175, 104, 0.1);
  border-bottom: 1px solid var(--border-soft);
  padding: 6px 12px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

/* ---------------------------------------------------------------
   Thread
--------------------------------------------------------------- */
.thread {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: relative;
  z-index: 1;
  background: transparent;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 88%;
  animation: rise 0.25s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg--user {
  align-self: flex-end;
  max-width: 78%;
}

.msg--persona {
  align-self: flex-start;
}

.msg__label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--persona-color);
  padding-left: 2px;
}

.msg__icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.msg__name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  font-variant-caps: small-caps;
  letter-spacing: 0.03em;
}

.msg__name .cap {
  font-size: 1.05em;
  font-variant-caps: normal;
}

.msg__bubble {
  background: var(--bg-highlight);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 11px 15px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--fg);
}

.msg--user .msg__bubble {
  background: var(--border);
  border-color: var(--border);
  border-bottom-right-radius: 4px;
}

.msg--persona .msg__bubble {
  border-left: 2px solid var(--persona-color);
  border-bottom-left-radius: 4px;
}

.bubble-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-highlight);
  border: 1px solid var(--border-soft);
  border-left: 2px solid var(--persona-color);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  width: fit-content;
}

.bubble-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-mute);
  animation: bubble-dots-bounce 1.2s infinite ease-in-out;
}

.bubble-dots span:nth-child(2) { animation-delay: 0.15s; }
.bubble-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bubble-dots-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------------------------------------------------------------
   Clear Chat: swipe away
--------------------------------------------------------------- */
.msg.clearing {
  animation: swipe-out-left 0.45s cubic-bezier(.4, 0, .6, 1) forwards;
}

.msg--user.clearing {
  animation-name: swipe-out-right;
}

@keyframes swipe-out-left {
  0% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(-60px); }
}

@keyframes swipe-out-right {
  0% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(60px); }
}

/* ---------------------------------------------------------------
   Send message: button pulse + bubble pop-in
--------------------------------------------------------------- */
.composer__send {
  position: relative;
}

.composer__send.is-pulsing::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  border: 1.5px solid #e0af68;
  animation: send-ring 0.5s ease-out;
}

@keyframes send-ring {
  0% { transform: scale(1); opacity: 0.9; }
  100% { transform: scale(1.7); opacity: 0; }
}

.msg--sent {
  animation: msg-pop-in 0.32s cubic-bezier(.34, 1.56, .64, 1) both;
}

@keyframes msg-pop-in {
  0% { opacity: 0; transform: scale(0.7); }
  100% { opacity: 1; transform: scale(1); }
}

/* ---------------------------------------------------------------
   Composer
--------------------------------------------------------------- */
.composer {
  display: flex;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border-soft);
  background: var(--bg);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}

.composer__input {
  flex: 1;
  background: var(--bg-highlight);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14.5px;
}

.composer__input::placeholder {
  color: var(--fg-mute);
}

.composer__input:focus {
  border-color: var(--fg-mute);
}

.composer__send {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-highlight);
  color: var(--fg-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.composer__send:hover {
  color: var(--fg);
  border-color: var(--fg-mute);
}

.composer__send svg {
  width: 18px;
  height: 18px;
}

/* ---------------------------------------------------------------
   Mobile
--------------------------------------------------------------- */
@media (max-width: 640px) {
  .app { border-left: none; border-right: none; }
  .msg { max-width: 94%; }
}
