/* =========================================
   Nuwa Chat — Clean Glass Design
   ========================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Warm earth palette — "Loess & Sky" */
  --bg-warm: #f7f3eb;
  --bg-warm-mid: #f2ece2;
  --bg-warm-deep: #ece4d6;

  --surface-glass: rgba(255, 248, 240, 0.72);
  --surface-glass-hover: rgba(255, 248, 240, 0.92);
  --border-glass: rgba(0, 0, 0, 0.06);
  --border-glass-strong: rgba(0, 0, 0, 0.1);
  --text-primary: #1c1c1e;
  --text-secondary: rgba(60, 60, 67, 0.6);
  --text-tertiary: rgba(60, 60, 67, 0.3);
  --accent: #ff9f43;
  --accent-dim: rgba(255, 159, 67, 0.15);
  --user-msg-from: #ff9f43;
  --user-msg-to: #ff6b6b;
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.08);
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 22px;
  --radius-full: 9999px;
  --font-display: 'Outfit', 'Noto Sans SC', system-ui, sans-serif;
  --font-body: 'Noto Sans SC', 'Outfit', system-ui, sans-serif;
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.22, 1, 0.36, 1);
}

html,
body {
  height: 100%;
  font-family: var(--font-body);
  background:
    radial-gradient(ellipse 70% 55% at 15% 20%, rgba(255, 159, 67, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 85% 85%, rgba(255, 107, 107, 0.05) 0%, transparent 55%),
    radial-gradient(ellipse 40% 35% at 50% 0%, rgba(168, 85, 247, 0.03) 0%, transparent 50%),
    linear-gradient(168deg, var(--bg-warm) 0%, var(--bg-warm-mid) 45%, var(--bg-warm-deep) 100%);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 10px;
}

/* ========= Background Atmosphere ========= */
#bg-atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  will-change: transform;
  backface-visibility: hidden;
}

.bg-orb--amber {
  width: 55vmax;
  height: 55vmax;
  background: radial-gradient(circle, rgba(255, 159, 67, 0.10) 0%, transparent 65%);
  top: -18%;
  left: -12%;
  animation: orbDrift1 20s ease-in-out infinite;
}

.bg-orb--rose {
  width: 45vmax;
  height: 45vmax;
  background: radial-gradient(circle, rgba(255, 107, 107, 0.07) 0%, transparent 65%);
  bottom: -14%;
  right: -8%;
  animation: orbDrift2 24s ease-in-out infinite;
}

.bg-orb--violet {
  width: 38vmax;
  height: 38vmax;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.05) 0%, transparent 65%);
  top: 35%;
  left: 45%;
  animation: orbDrift3 28s ease-in-out infinite;
}

@keyframes orbDrift1 {
  0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.7; }
  33%      { transform: translate(35px, -25px) scale(1.06); opacity: 1; }
  66%      { transform: translate(-20px, 30px) scale(0.94); opacity: 0.8; }
}

@keyframes orbDrift2 {
  0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.7; }
  33%      { transform: translate(-30px, -20px) scale(1.04); opacity: 0.9; }
  66%      { transform: translate(25px, 25px) scale(0.96); opacity: 0.75; }
}

@keyframes orbDrift3 {
  0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.5; }
  50%      { transform: translate(20px, -35px) scale(1.1); opacity: 0.8; }
}

/* ========= Settings Button ========= */
#settings-btn {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 50;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--surface-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

#settings-btn:hover {
  background: var(--surface-glass-hover);
  color: var(--text-primary);
  transform: rotate(30deg);
}

/* ========= Settings Overlay ========= */
#settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#settings-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

/* ========= Settings Panel ========= */
#settings-panel {
  position: fixed;
  top: 0;
  right: -320px;
  z-index: 70;
  width: 300px;
  height: 100%;
  background: rgba(255, 252, 245, 0.95);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-left: 1px solid var(--border-glass);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.08);
  transition: right 0.35s var(--ease-smooth);
  display: flex;
  flex-direction: column;
}

#settings-panel.open {
  right: 0;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-glass);
}

#settings-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

#settings-close:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
  box-shadow: none;
  transform: none;
}

.settings-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.settings-label {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

.settings-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-glass-strong);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-primary);
  font-family: 'Outfit', monospace;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s ease;
}

.settings-input:focus {
  border-color: var(--accent);
}

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

#settings-save {
  width: 100%;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #ff6b6b);
  color: #fff;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(255, 159, 67, 0.25);
  margin-top: 8px;
  transition: all 0.2s ease;
}

#settings-save:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(255, 159, 67, 0.35);
}

#settings-save:active {
  transform: scale(0.97);
}

/* ========= Avatar Stage ========= */
#stage {
  flex-shrink: 0;
  padding: 14px 10px;
  margin: 8px 0 4px;
  background: var(--surface-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-sm);
  transition: all 0.4s var(--ease-smooth);
  overflow: hidden;
  max-height: 300px;
  opacity: 1;
}

#stage.stage-collapsed {
  max-height: 0;
  opacity: 0;
  margin: 0;
  padding: 0 10px;
  border-width: 0;
}

#avatar-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px 6px;
}

/* ========= Avatar Items ========= */
.avatar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 6px 4px 4px;
  border-radius: var(--radius-sm);
  transition: all 0.3s var(--ease-smooth);
  width: 88px;
}

.avatar-item:active {
  transform: scale(0.9);
}

.avatar-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  transition: all 0.35s var(--ease-spring);
  flex-shrink: 0;
  position: relative;
}

.avatar-circle::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  transition: all 0.3s var(--ease-smooth);
}

.avatar-item:hover .avatar-circle {
  transform: scale(1.06);
}

.avatar-item.selected .avatar-circle {
  box-shadow: 0 0 0 5px var(--accent-dim);
  filter: brightness(1.05);
}

.avatar-item.selected .avatar-circle::after {
  border-color: var(--accent);
}

.avatar-field {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: center;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 88px;
  padding: 0 2px;
}

.avatar-item.selected .avatar-name {
  color: var(--text-primary);
  font-weight: 600;
}

/* ========= Chat Area ========= */
#chat {
  flex: 1;
  overflow-y: auto;
  padding: 8px 2px 4px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#chat::-webkit-scrollbar {
  display: none;
}

#chat::-webkit-scrollbar-track {
  background: transparent;
}

#chat::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.08);
  border-radius: var(--radius-full);
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 20px;
}

/* ========= Placeholder ========= */
.placeholder {
  text-align: center;
  color: var(--text-secondary);
  margin: auto;
  padding: 60px 20px;
}

.placeholder-main {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.placeholder-sub {
  font-size: 13px;
  color: var(--text-tertiary);
}

/* ========= Message Bubbles ========= */
.msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: msgIn 0.35s var(--ease-smooth) both;
}

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

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

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

.msg .msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  margin-top: 4px;
  box-shadow: var(--shadow-sm);
}

.msg.user .msg-avatar {
  background: linear-gradient(135deg, var(--user-msg-from), var(--user-msg-to)) !important;
  font-size: 11px;
}

.msg .bubble {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-body);
}

.msg.user .bubble {
  background: linear-gradient(135deg, var(--user-msg-from), var(--user-msg-to));
  color: #fff;
  border-bottom-right-radius: var(--radius-xs);
  box-shadow: 0 4px 12px rgba(255, 159, 67, 0.2);
}

.msg.ai .bubble {
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-xs);
  box-shadow: var(--shadow-sm);
}

.msg .bubble .label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

/* ========= Markdown Body ========= */
.md-body {
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.md-body p {
  margin: 0 0 8px;
}

.md-body p:last-child {
  margin-bottom: 0;
}

.md-body strong {
  font-weight: 600;
  color: var(--text-primary);
}

.md-body em {
  font-style: italic;
}

.md-body ul, .md-body ol {
  margin: 4px 0 8px;
  padding-left: 20px;
}

.md-body li {
  margin: 2px 0;
}

.md-body code {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}

.md-body pre {
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
}

.md-body pre code {
  background: none;
  padding: 0;
  font-size: 12px;
}

.md-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.md-body h1, .md-body h2, .md-body h3 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 12px 0 6px;
}

.md-body h1 { font-size: 16px; }
.md-body h2 { font-size: 15px; }
.md-body h3 { font-size: 14px; }

.md-body hr {
  border: none;
  border-top: 1px solid var(--border-glass);
  margin: 10px 0;
}

.streaming-text {
  min-height: 1.65em;
}

.streaming-text::after {
  content: '▌';
  animation: blink 1s steps(2) infinite;
  color: var(--accent);
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ========= Input Dock ========= */
#dock {
  flex-shrink: 0;
  padding: 8px 10px 12px;
  margin: 4px 0 8px;
  background: var(--surface-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: var(--shadow-sm);
}

.active-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 20px;
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 0 2px;
  margin-bottom: 6px;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 6px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border-glass);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

#input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  display: flex;
}

textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-body);
  resize: none;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  height: 38px;
  min-height: 38px;
  line-height: 1.5;
}

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

textarea:focus {
  border-color: rgba(0, 0, 0, 0.15);
  box-shadow: none;
}

textarea:disabled {
  opacity: 0.35;
}

button {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #ff6b6b);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s var(--ease-smooth);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(255, 159, 67, 0.25);
}

button:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(255, 159, 67, 0.35);
}

button:active:not(:disabled) {
  transform: scale(0.9);
}

button:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  box-shadow: none;
}

/* ========= Loading bar ========= */
#loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 3px;
}

#loading.hidden {
  display: none;
}

.loading-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, transparent, var(--accent), #a855f7, transparent);
  background-size: 200% 100%;
  animation: loadingSlide 1.2s ease-in-out infinite;
}

@keyframes loadingSlide {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* ========= Sequencing divider ========= */
.msg-sequencing {
  align-self: center;
  font-size: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-tertiary);
  padding: 2px 0;
}

/* ========= Error ========= */
.msg-error {
  align-self: center;
  font-size: 12px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.12);
  color: #ef4444;
  text-align: center;
  max-width: 80%;
}

/* ========= Responsive ========= */
@media (max-width: 480px) {
  #app {
    padding: 0 6px;
  }

  #stage {
    padding: 8px 6px;
  }

  .avatar-item {
    width: 68px;
  }

  .avatar-circle {
    width: 44px;
    height: 44px;
    font-size: 15px;
  }

  .avatar-field {
    font-size: 10px;
    max-width: 68px;
  }

  .msg {
    max-width: 92%;
  }

  #settings-panel {
    width: 100%;
    right: -100%;
  }
}
