/* ===========================================================
   Glass · Modern Skeuomorphism + Glassmorphism
   =========================================================== */

:root {
  --bg-deep: #1a1030;
  --bg-mid: #2c1a52;
  --bg-violet: #3d2170;
  --bg-indigo: #201446;

  --glass-fill: rgba(255, 255, 255, 0.08);
  --glass-fill-strong: rgba(255, 255, 255, 0.12);
  --glass-fill-user: rgba(255, 255, 255, 0.14);
  --glass-border: rgba(255, 255, 255, 0.16);
  --glass-border-soft: rgba(255, 255, 255, 0.09);
  --glass-shine: rgba(255, 255, 255, 0.35);

  --text-primary: #f3f0ff;
  --text-secondary: rgba(243, 240, 255, 0.62);
  --text-tertiary: rgba(243, 240, 255, 0.4);

  --accent: #ff8a5c;
  --accent-bright: #ffab7a;
  --accent-deep: #e2653a;
  --accent-glow: rgba(255, 138, 92, 0.55);

  --error: #ff8a8a;
  --error-glow: rgba(255, 120, 120, 0.35);

  --radius-xl: 28px;
  --radius-l: 22px;
  --radius-m: 16px;
  --radius-s: 12px;

  --shadow-ambient: 0 20px 60px -20px rgba(10, 5, 30, 0.7);
  --shadow-soft: 0 10px 30px -12px rgba(10, 5, 30, 0.55);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-soft: cubic-bezier(0.22, 1, 0.36, 1);

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Sohne", "Inter", "Söhne", -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button,
textarea {
  font-family: inherit;
}

/* -----------------------------------------------------------
   Stage — the deep gradient "backdrop" behind the glass
   ----------------------------------------------------------- */

.stage {
  position: relative;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background: radial-gradient(
      130% 90% at 15% -10%,
      var(--bg-violet) 0%,
      transparent 55%
    ),
    radial-gradient(120% 100% at 100% 110%, #170c33 0%, transparent 60%),
    linear-gradient(160deg, var(--bg-indigo) 0%, var(--bg-deep) 45%, var(--bg-mid) 100%);
}

/* subtle grain texture so the backdrop isn't flat */
.stage__grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  background-size: 180px 180px;
}

.stage__glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.45;
  pointer-events: none;
}

.stage__glow--a {
  width: 42vw;
  height: 42vw;
  top: -12vw;
  right: -8vw;
  background: radial-gradient(circle, #6a4bd6 0%, transparent 70%);
  animation: driftA 26s ease-in-out infinite alternate;
}

.stage__glow--b {
  width: 36vw;
  height: 36vw;
  bottom: -10vw;
  left: -6vw;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  opacity: 0.18;
  animation: driftB 32s ease-in-out infinite alternate;
}

@keyframes driftA {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(-4%, 6%) scale(1.08);
  }
}

@keyframes driftB {
  from {
    transform: translate(0, 0) scale(1);
  }
  to {
    transform: translate(5%, -5%) scale(1.05);
  }
}

/* -----------------------------------------------------------
   App layout
   ----------------------------------------------------------- */

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
  padding: clamp(10px, 3vw, 22px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* -----------------------------------------------------------
   Glass panel — the reusable frosted-glass surface
   ----------------------------------------------------------- */

.glass-panel {
  position: relative;
  background: linear-gradient(
    165deg,
    var(--glass-fill-strong) 0%,
    var(--glass-fill) 60%
  );
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  box-shadow: var(--shadow-ambient),
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    inset 0 -1px 0 rgba(0, 0, 0, 0.18);
}

.glass-panel::before {
  /* soft top sheen — light "caught" by the glass */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.16) 0%,
    rgba(255, 255, 255, 0) 32%
  );
}

/* -----------------------------------------------------------
   Header
   ----------------------------------------------------------- */

.app__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-radius: var(--radius-l);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__orb {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  background: radial-gradient(
    circle at 32% 28%,
    var(--accent-bright) 0%,
    var(--accent) 40%,
    var(--accent-deep) 100%
  );
  box-shadow: 0 6px 14px -4px var(--accent-glow),
    inset 0 1px 1px rgba(255, 255, 255, 0.6),
    inset 0 -3px 6px rgba(0, 0, 0, 0.25);
}

.brand__text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand__text p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-secondary);
  background: linear-gradient(
    165deg,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.03)
  );
  border: 1px solid var(--glass-border-soft);
  box-shadow: 0 4px 10px -4px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
  cursor: pointer;
  transition: transform 0.15s var(--ease-soft), color 0.15s ease,
    box-shadow 0.15s ease;
}

.icon-btn:hover {
  color: var(--text-primary);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px) scale(0.94);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* -----------------------------------------------------------
   Chat panel
   ----------------------------------------------------------- */

.chat {
  flex: 1 1 auto;
  min-height: 0;
  padding: 6px;
  overflow: hidden;
}

.chat__scroll {
  height: 100%;
  overflow-y: auto;
  padding: 20px 16px;
  scroll-behavior: smooth;
}

.chat__scroll::-webkit-scrollbar {
  width: 8px;
}
.chat__scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 10px;
}
.chat__scroll::-webkit-scrollbar-track {
  background: transparent;
}

.empty-state {
  height: 100%;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-secondary);
  gap: 14px;
}

.empty-state.is-hidden {
  display: none;
}

.empty-state__orb {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(
    circle at 30% 25%,
    rgba(255, 255, 255, 0.5),
    var(--accent) 45%,
    transparent 80%
  );
  opacity: 0.85;
  box-shadow: 0 0 40px var(--accent-glow);
}

.empty-state h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-state p {
  margin: 0;
  font-size: 13.5px;
  max-width: 30ch;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* -----------------------------------------------------------
   Message bubbles — differentiated glass tint by role
   ----------------------------------------------------------- */

.msg {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 100%;
  animation: bubble-in 0.5s var(--ease-spring) both;
}

@keyframes bubble-in {
  0% {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg--user {
  justify-content: flex-end;
}

.msg--assistant {
  justify-content: flex-start;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-bottom: 4px;
  background: radial-gradient(
    circle at 32% 28%,
    var(--accent-bright),
    var(--accent-deep)
  );
  box-shadow: 0 3px 8px -2px var(--accent-glow),
    inset 0 1px 1px rgba(255, 255, 255, 0.55),
    inset 0 -2px 4px rgba(0, 0, 0, 0.25);
}

.bubble {
  position: relative;
  max-width: min(78%, 560px);
  padding: 12px 16px;
  border-radius: var(--radius-m);
  font-size: 14.5px;
  line-height: 1.55;
  border: 1px solid var(--glass-border-soft);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.bubble__text a {
  color: var(--accent-bright);
}

.bubble--user {
  background: linear-gradient(
    165deg,
    var(--glass-fill-user),
    rgba(255, 255, 255, 0.05)
  );
  border-bottom-right-radius: 6px;
  color: var(--text-primary);
}

.bubble--assistant {
  background: linear-gradient(
    165deg,
    rgba(120, 90, 220, 0.22),
    rgba(120, 90, 220, 0.08)
  );
  border-bottom-left-radius: 6px;
}

.bubble--assistant.is-empty::before {
  content: "";
}

/* streaming cursor — pulsing amber light living inside the glass */
.stream-cursor {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 4px;
  border-radius: 50%;
  vertical-align: middle;
  background: var(--accent-bright);
  box-shadow: 0 0 8px 2px var(--accent-glow);
  animation: pulse-cursor 1.1s ease-in-out infinite;
}

@keyframes pulse-cursor {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

/* -----------------------------------------------------------
   Error chip — same material, not a red alert box
   ----------------------------------------------------------- */

.error-chip[hidden] {
  display: none;
}

.error-chip {
  margin: 0 2px 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  border-radius: var(--radius-s);
  background: linear-gradient(
    165deg,
    rgba(255, 140, 140, 0.16),
    rgba(255, 140, 140, 0.06)
  );
  border: 1px solid rgba(255, 140, 140, 0.28);
  backdrop-filter: blur(16px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 6px 20px -8px var(--error-glow);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: bubble-in 0.4s var(--ease-spring) both;
}

.error-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--error);
  box-shadow: 0 0 8px 2px var(--error-glow);
}

/* -----------------------------------------------------------
   Composer
   ----------------------------------------------------------- */

.composer {
  flex: 0 0 auto;
  padding: 12px 14px 10px;
  border-radius: var(--radius-l);
}

.composer__form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.composer__field {
  flex: 1 1 auto;
  min-width: 0;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--radius-m);
  padding: 4px 6px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.composer__field:focus-within {
  border-color: rgba(255, 138, 92, 0.45);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.28),
    0 0 0 3px rgba(255, 138, 92, 0.15);
}

.composer__textarea {
  width: 100%;
  max-height: 180px;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  padding: 8px 10px;
}

.composer__textarea::placeholder {
  color: var(--text-tertiary);
}

.composer__hint {
  margin-top: 6px;
  padding-left: 4px;
  font-size: 11px;
  color: var(--text-tertiary);
}

/* -----------------------------------------------------------
   Send button — physical circular pushbutton with 3D glint
   ----------------------------------------------------------- */

.send-btn {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: #2a1206;
  background: radial-gradient(
    circle at 32% 26%,
    var(--accent-bright) 0%,
    var(--accent) 45%,
    var(--accent-deep) 100%
  );
  box-shadow: 0 10px 20px -6px var(--accent-glow),
    0 2px 4px rgba(0, 0, 0, 0.35),
    inset 0 2px 2px rgba(255, 255, 255, 0.65),
    inset 0 -4px 8px rgba(90, 30, 10, 0.4);
  transition: transform 0.15s var(--ease-spring), box-shadow 0.15s ease;
}

.send-btn__ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.14);
  pointer-events: none;
}

.send-btn__icon {
  transform: translateX(1px);
  filter: drop-shadow(0 1px 1px rgba(255, 255, 255, 0.35));
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.send-btn:hover {
  transform: translateY(-1px);
}

.send-btn:active {
  transform: translateY(1px) scale(0.93);
  box-shadow: 0 4px 10px -6px var(--accent-glow),
    inset 0 3px 8px rgba(0, 0, 0, 0.4),
    inset 0 -1px 2px rgba(255, 255, 255, 0.2);
}

.send-btn:disabled {
  cursor: not-allowed;
  filter: grayscale(0.15) brightness(0.8);
  transform: none !important;
}

.send-btn__stop {
  display: none;
}

/* streaming state: icon morphs into a small square "stop" glyph */
.send-btn.is-streaming .send-btn__icon {
  opacity: 0;
  transform: scale(0.6);
}

.send-btn.is-streaming .send-btn__stop {
  display: block;
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 4px;
  background: #2a1206;
}

/* -----------------------------------------------------------
   Responsive
   ----------------------------------------------------------- */

@media (max-width: 640px) {
  .app {
    padding: 8px;
    gap: 10px;
  }

  .app__header {
    padding: 12px 14px;
    border-radius: var(--radius-m);
  }

  .brand__text h1 {
    font-size: 15.5px;
  }

  .chat,
  .composer {
    border-radius: var(--radius-m);
  }

  .bubble {
    max-width: 86%;
    font-size: 14px;
  }

  .send-btn {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 380px) {
  .brand__text p {
    display: none;
  }
}

/* -----------------------------------------------------------
   Reduced motion
   ----------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .msg,
  .error-chip,
  .stream-cursor,
  .stage__glow--a,
  .stage__glow--b {
    animation: none !important;
  }
}
