.academy-chat-open {
  position: fixed;
  inset: auto 22px 22px auto;
  z-index: 20;
  min-height: 44px;
  box-shadow: 0 8px 25px #0004;
}
.academy-chat-open[hidden] { display: none }
.academy-chat {
  position: fixed;
  inset: auto 22px 22px auto;
  margin: 0;
  width: min(400px, calc(100vw - 44px));
  max-width: none;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 16px 55px #0006;
}
.academy-chat::backdrop { background: #0005 }
.academy-chat-content {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  height: min(560px, calc(100dvh - 44px));
}
.academy-chat-header {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px 12px 16px;
  border-bottom: 1px solid var(--border);
}
.academy-chat-header h2 { font-size: 16px; margin: 0 }
.academy-chat-header button { margin-inline-start: auto; font-size: 24px }
.academy-chat-log { overflow-y: auto; padding: 16px; overscroll-behavior: contain }
.academy-chat-message {
  width: fit-content;
  max-width: 100%;
  margin: 0 0 12px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  overflow-wrap: anywhere;
  font-size: 14px;
}
.academy-chat-message p { margin: 0; color: var(--text) }
.academy-chat-message-user {
  margin-inline-start: auto;
  background: color-mix(in srgb, var(--green) 14%, var(--panel));
}
.academy-chat-reply-title { margin: 0 0 6px; font-size: 15px; line-height: 1.4 }
.academy-chat-steps { padding-inline-start: 20px; margin: 10px 0; list-style: decimal }
.academy-chat-steps li { padding-inline-start: 3px; margin-block: 7px }
.academy-chat-message .academy-chat-note { margin-top: 10px; padding-inline-start: 9px; border-inline-start: 2px solid var(--border) }
.academy-chat-links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px }
.academy-chat-topics { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px }
.academy-chat-topics button { min-height: 32px }
.academy-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}
.academy-chat-input {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
@media (max-width: 540px) {
  .academy-chat-open, .academy-chat { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)) }
  .academy-chat { width: calc(100vw - 24px) }
}
@media print {
  .academy-chat-open, .academy-chat { display: none !important }
}

@keyframes chatFabPulse {
  0%, 100% { box-shadow: 0 10px 28px -6px rgba(6, 214, 232, 0.52), 0 0 0 0 rgba(6, 214, 232, 0.42); }
  55% { box-shadow: 0 12px 32px -6px rgba(16, 240, 164, 0.56), 0 0 0 10px rgba(6, 214, 232, 0); }
}

@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.academy-chat-open {
  border-radius: 999px;
  padding: 10px 20px;
  animation: chatFabPulse 3.4s ease-in-out infinite;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

.academy-chat-open:hover {
  transform: translateY(-2px) scale(1.03);
}

.academy-chat[open] {
  animation: dialogPop 0.24s cubic-bezier(0.22, 1, 0.36, 1) both;
  background: rgba(11, 18, 36, 0.96);
  backdrop-filter: blur(20px) saturate(150%);
  -webkit-backdrop-filter: blur(20px) saturate(150%);
  border-color: #06D6E8;
  box-shadow: 0 24px 70px rgba(2, 6, 20, 0.78), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

:root[data-theme="light"] .academy-chat[open] {
  background: #FFFFFF;
  border-color: #0891B2;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.2);
}

.academy-chat-header {
  background: linear-gradient(135deg, rgba(6, 214, 232, 0.14) 0%, rgba(16, 240, 164, 0.08) 100%);
}
:root[data-theme="light"] .academy-chat-header {
  background: linear-gradient(135deg, #0B1324 0%, #0F2038 100%);
  color: #FFFFFF;
}
:root[data-theme="light"] .academy-chat-header h2,
:root[data-theme="light"] .academy-chat-header button {
  color: #FFFFFF;
}

.academy-chat-message {
  animation: chatMsgIn 0.24s cubic-bezier(0.22, 1, 0.36, 1) both;
  border-radius: 11px;
}

.academy-chat-message-user {
  border-color: rgba(6, 214, 232, 0.42);
}
:root[data-theme="light"] .academy-chat-message-user {
  background: #ECFEFF;
  border-color: rgba(8, 145, 178, 0.32);
}

@media (prefers-reduced-motion: reduce) {
  .academy-chat-open,
  .academy-chat[open],
  .academy-chat-message {
    animation: none !important;
    transition: none !important;
  }
}
