* {
  box-sizing: border-box;
}

:root {
  --bg: #08090c;
  --panel: rgba(23, 26, 33, 0.6);
  --panel-solid: #171a21;
  --panel-2: #1c1f28;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f2f3f6;
  --text-dim: #9198a6;
  --accent: #8b9dff;
  --accent-2: #d18bff;
  --accent-3: #6ee7c8;
  --user-bubble: linear-gradient(135deg, #3a4a8f, #55408f);
  --fly-bubble: #181b23;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.55);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(640px 420px at 12% -8%, rgba(139, 157, 255, 0.18), transparent 60%),
    radial-gradient(520px 420px at 92% 6%, rgba(209, 139, 255, 0.14), transparent 60%),
    radial-gradient(760px 520px at 50% 112%, rgba(110, 231, 200, 0.09), transparent 60%);
}

.shell {
  position: relative;
  z-index: 1;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 26px;
}

.app {
  width: 100%;
  max-width: 760px;
  height: 100%;
  max-height: 900px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0));
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  padding: 18px 24px;
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-badge {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  background: linear-gradient(145deg, rgba(139, 157, 255, 0.18), rgba(209, 139, 255, 0.14));
  border: 1px solid var(--border-strong);
  animation: hover-fly 3s ease-in-out infinite;
}

@keyframes hover-fly {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-2px) rotate(-6deg); }
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtitle a {
  color: var(--accent);
  text-decoration: none;
}

.subtitle a:hover {
  text-decoration: underline;
}

.stats-bar {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--accent-3);
  background: rgba(110, 231, 200, 0.08);
  border: 1px solid rgba(110, 231, 200, 0.22);
  border-radius: 20px;
  padding: 6px 13px 6px 10px;
}

.stats-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-3);
  box-shadow: 0 0 0 3px rgba(110, 231, 200, 0.18);
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.menu-cerveau {
  position: relative;
}

.menu-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.menu-btn:hover {
  border-color: var(--accent);
  transform: rotate(25deg);
}

.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 250px;
  background: var(--panel-solid);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  z-index: 20;
  animation: fade-in 0.15s ease;
}

.menu-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  padding: 6px 8px 8px;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s ease;
}

.menu-item:hover:not(:disabled) {
  background: var(--panel-2);
}

.menu-item:disabled {
  opacity: 0.4;
  cursor: default;
}

.menu-item-file {
  cursor: pointer;
}

.menu-sep {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}

.enseigner-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 2px 8px 4px;
}

.enseigner-input,
.enseigner-select {
  width: 100%;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
}

.enseigner-input:focus,
.enseigner-select:focus {
  border-color: var(--accent);
}

.enseigner-btn {
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #10121a;
  font-family: inherit;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.enseigner-btn:hover {
  filter: brightness(1.1);
}

.menu-msg {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgba(110, 231, 200, 0.08);
  border: 1px solid rgba(110, 231, 200, 0.22);
  color: var(--accent-3);
  font-size: 12px;
}

.menu-msg.menu-msg-erreur {
  background: rgba(255, 154, 154, 0.08);
  border-color: rgba(255, 154, 154, 0.25);
  color: #ff9a9a;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar {
  width: 8px;
}
.chat::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.msg {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: fade-in 0.28s ease;
}

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

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

.msg-avatar {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  box-shadow: var(--shadow);
}

.msg-body {
  max-width: 78%;
  display: flex;
  flex-direction: column;
}

.msg.user .msg-body {
  align-items: flex-end;
}

.bubble {
  padding: 12px 15px;
  border-radius: 16px;
  background: var(--fly-bubble);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.msg.user .bubble {
  background: var(--user-bubble);
  border-color: transparent;
}

.bubble-text {
  line-height: 1.55;
  font-size: 14.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.fly .bubble-text {
  font-size: 15px;
  font-weight: 500;
}

.msg.fly .bubble-text strong {
  color: var(--accent);
  font-weight: 700;
}

.tips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.tip {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px;
}

.fly-video {
  margin-top: 8px;
  width: 100%;
  max-width: 300px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0d0f14;
  box-shadow: var(--shadow);
  display: block;
}

.fly-audio {
  display: none;
}

.reaction-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.replay-btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-dim);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.replay-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.feedback-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.feedback-label {
  font-size: 12px;
  color: var(--text-dim);
}

.feedback-btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 4px 9px;
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
  transition: transform 0.1s ease, border-color 0.15s ease;
}

.feedback-btn:hover:not(:disabled) {
  border-color: var(--accent);
  transform: scale(1.1);
}

.feedback-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.feedback-confirm {
  font-size: 12px;
  color: var(--accent-3);
}

.sound-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 20px;
  background: rgba(110, 231, 200, 0.1);
  border: 1px solid rgba(110, 231, 200, 0.3);
  color: var(--accent-3);
  font-size: 12px;
  width: fit-content;
}

.sound-badge .bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.sound-badge .bars span {
  width: 2.5px;
  background: var(--accent-3);
  border-radius: 2px;
  animation: bar-bounce 0.9s ease-in-out infinite;
}
.sound-badge .bars span:nth-child(1) { height: 40%; animation-delay: 0s; }
.sound-badge .bars span:nth-child(2) { height: 100%; animation-delay: 0.15s; }
.sound-badge .bars span:nth-child(3) { height: 65%; animation-delay: 0.3s; }
.sound-badge .bars span:nth-child(4) { height: 85%; animation-delay: 0.45s; }

@keyframes bar-bounce {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}


details.tech-details {
  margin-top: 10px;
}

details.tech-details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  user-select: none;
}

details.tech-details summary::-webkit-details-marker {
  display: none;
}

details.tech-details summary:hover {
  color: var(--accent);
}

details.tech-details summary::before {
  content: "▸";
  font-size: 10px;
  transition: transform 0.15s ease;
}

details.tech-details[open] summary::before {
  transform: rotate(90deg);
}

.tech-body {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #10131a;
  border: 1px dashed var(--border);
  font-size: 12.5px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tech-body .trace {
  font-family: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px;
  color: var(--accent-2);
  overflow-x: auto;
  white-space: pre;
}

.tech-body b {
  color: var(--text);
}

.composer {
  margin: 0 24px 22px;
}

.composer-box {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  box-shadow: var(--shadow);
  padding: 12px 14px 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(139, 157, 255, 0.14), var(--shadow);
}

#prompt-input {
  width: 100%;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.5;
  outline: none;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
  padding: 0;
}

#prompt-input::placeholder {
  color: var(--text-dim);
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.composer-hint {
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.75;
}

#send-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-solid);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.1s ease, background 0.15s ease, color 0.15s ease;
}

#send-btn:not(:disabled) {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #10121a;
}

#send-btn:disabled {
  cursor: default;
}

#send-btn:hover:not(:disabled) {
  filter: brightness(1.1);
}

#send-btn:active:not(:disabled) {
  transform: scale(0.92);
}

.thinking {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px 0;
  min-width: 200px;
}

.thinking-stages {
  display: flex;
  align-items: center;
  gap: 5px;
}

.stage {
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 9px;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.stage.active {
  color: var(--bg);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  transform: scale(1.08);
  box-shadow: 0 0 0 4px rgba(139, 157, 255, 0.14);
}

.stage.done {
  color: var(--accent-3);
  border-color: rgba(110, 231, 200, 0.3);
  background: rgba(110, 231, 200, 0.06);
}

.stage-arrow {
  color: var(--text-dim);
  font-size: 11px;
  opacity: 0.5;
}

.thinking-status {
  font-size: 12px;
  color: var(--text-dim);
  min-height: 15px;
}

.thinking-status.fade {
  animation: thinking-fade 0.48s ease;
}

@keyframes thinking-fade {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

.error-text {
  color: #ff9a9a;
}

@media (max-width: 560px) {
  .shell {
    padding: 0;
  }
  .app {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }
  .composer {
    margin: 0 14px 16px;
  }
  .chat {
    padding: 20px 16px;
  }
  .app-header {
    padding: 14px 16px;
  }
  .msg-body {
    max-width: 88%;
  }
}

.fly-pet {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  pointer-events: none;
  will-change: transform;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.5));
}

.fly-pet-direction {
  display: block;
  transform-origin: center;
}

.fly-pet-rig {
  position: relative;
  width: 32px;
  height: 20px;
}

.fly-pet-wing {
  position: absolute;
  top: 1px;
  width: 17px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(120deg, rgba(220, 227, 250, 0.75), rgba(180, 190, 230, 0.35));
  will-change: transform;
}

.fly-pet-wing-left {
  left: 3px;
  transform-origin: 100% 50%;
}

.fly-pet-wing-right {
  left: 12px;
  transform-origin: 0% 50%;
}

.fly-pet-leg {
  position: absolute;
  bottom: 1px;
  left: 14px;
  width: 1.5px;
  height: 8px;
  background: #1c1512;
  transform-origin: top center;
}

.fly-pet-leg-1 {
  left: 12px;
}

.fly-pet-leg-2 {
  left: 18px;
}

.fly-pet-abdomen {
  position: absolute;
  left: 12px;
  top: 6px;
  width: 16px;
  height: 10px;
  border-radius: 50% 50% 45% 45%;
  background: linear-gradient(160deg, #5c3c33, #241715);
}

.fly-pet-thorax {
  position: absolute;
  left: 7px;
  top: 4px;
  width: 10px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(160deg, #6b483d, #2c1c18);
}

.fly-pet-head {
  position: absolute;
  left: 1px;
  top: 5px;
  width: 8px;
  height: 7px;
  border-radius: 50%;
  background: #241715;
}

.fly-pet-eye {
  position: absolute;
  left: 1px;
  top: 1px;
  width: 3.5px;
  height: 3.5px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #e0524f, #7a1a18);
}

@media (max-width: 480px) {
  .fly-pet {
    display: none;
  }
}
