#chat9-embed {
  --line-bg: #bfe7b6;
  --line-panel: #d5f0cc;
  --line-text: #0b1220;
  --line-muted: #4a5568;
  --line-accent: #06c755;
  --line-bubble-in: #ffffff;
  --line-bubble-out: #7cfc00;
  --line-bubble-border: rgba(0, 0, 0, 0.06);
  --line-input-bg: #ffffff;
  --line-input-border: rgba(0, 0, 0, 0.12);
  --line-btn: #06c755;
  --line-btn-text: #ffffff;
  --line-font-size: 16px;
  --line-line-height: 1.5;
  --line-radius: 18px;
  --line-input-height: 56px;
}

#chat9-embed * {
  box-sizing: border-box;
}

#chat9-embed {
  margin: 0;
  padding: 0;
  color: var(--line-text);
  font: var(--line-font-size)/var(--line-line-height) system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans JP", sans-serif;
  background: var(--line-bg);
  border-radius: 16px;
  overflow: hidden;
}

#chat9-embed p {
  color: inherit;
}

#chat9-embed h1 {
  margin: 0 0 6px;
  font-size: 18px;
  font-family: inherit;
}

#chat9-embed textarea {
  width: 100%;
  border-radius: var(--line-radius);
  border: 1px solid var(--line-input-border);
  background: var(--line-input-bg);
  color: var(--line-text);
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.4;
}

#chat9-embed textarea::placeholder {
  color: #8a94a4;
}

#chat9-embed button {
  border: none;
  border-radius: var(--line-radius);
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--line-btn);
  color: var(--line-btn-text);
  transition: filter 120ms ease, transform 120ms ease;
}

#chat9-embed button:active {
  transform: translateY(1px);
}

#chat9-embed button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#chat9-embed .focus-toggle {
  background: transparent;
  color: var(--line-text);
  border: 1px solid var(--line-input-border);
  padding: 8px 12px;
  border-radius: var(--line-radius);
  min-width: 88px;
}

#chat9-embed .reset-guard {
  margin: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid #f59e0b;
  background: #fffbeb;
  color: #92400e;
  font-weight: 600;
}

#chat9-embed .auth-guard {
  margin: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid #60a5fa;
  background: #eff6ff;
  color: #1e3a8a;
  font-weight: 600;
}

#chat9-embed #chat9-main {
  display: flex;
  flex-direction: column;
  background: var(--line-bg);
}

#chat9-embed #chat9-sections-panel {
  padding: 12px 12px 8px;
  background: var(--line-bg);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

#chat9-embed #sections-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

#chat9-embed .chat9-block {
  border: 1px solid var(--line-bubble-border);
  border-radius: var(--line-radius);
  padding: 12px;
  background: #f6fff0;
}

#chat9-embed .block-header {
  font-weight: 700;
  margin-bottom: 6px;
  cursor: pointer;
}

#chat9-embed .block-header.active {
  color: var(--line-accent);
}

#chat9-embed .sys-area {
  margin-top: 6px;
}

#chat9-embed #chat9-chat-window {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 0 8px 0;
  min-height: 0;
}

#chat9-embed #chat9-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line-bubble-border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#chat9-embed #chat9-conversation {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}

#chat9-embed .chat9-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  line-height: var(--line-line-height);
  font-size: var(--line-font-size);
}

#chat9-embed .chat9-msg-section-label {
  font-size: 12px;
  opacity: 0.65;
  margin-bottom: 2px;
  align-self: flex-start;
  color: var(--line-muted);
}

#chat9-embed .msg__bubble {
  padding: 2px 2px;
  font-size: 1.2rem;
  border-radius: var(--line-radius);
  line-height: var(--line-line-height);
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line-bubble-border);
  background: var(--line-bubble-in);
  max-width: 98%;
  box-shadow: none;
  color: var(--line-text);
}

#chat9-embed .chat9-msg.user {
  align-items: flex-end;
  color: var(--line-text);
  white-space: pre-wrap;
}

#chat9-embed .chat9-msg.user .chat9-msg-section-label {
  align-self: flex-end;
  text-align: right;
}

#chat9-embed .chat9-msg.user .msg__bubble {
  background: var(--line-bubble-out);
  color: #0a3a10;
  border-color: rgba(0, 0, 0, 0.08);
}

/* chat9: 複数行対応・CSS疑似タイプライター */
#chat9-embed .msg__bubble.typewriter-reveal {
  position: relative;
  overflow: hidden;
  animation: chat9-reveal var(--tw-duration, 1.8s) steps(var(--tw-steps, 30), end) forwards;
}

@keyframes chat9-reveal {
  from { clip-path: inset(0 100% 0 0); }
  to { clip-path: inset(0 0 0 0); }
}

#chat9-embed .chat9-msg.assistant {
  align-items: flex-start;
  color: var(--line-text);
  white-space: pre-wrap;
}

#chat9-embed #chat9-footer,
#chat9-embed .chat9-footer {
  position: static;
  padding: 6px 0 8px 0;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  z-index: 10;
}

#chat9-embed .chat9-footer-inner {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 8px;
}

#chat9-embed .chat9-active-section {
  color: var(--line-muted);
  font-size: 13px;
}

#chat9-embed .chat9-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

#chat9-embed #chat9-input {
  flex: 1;
  resize: none;
  padding: 12px;
  border-radius: var(--line-radius);
  border: 1px solid var(--line-input-border);
  background: var(--line-input-bg);
  color: var(--line-text);
  min-height: 40px;
  max-height: 120px;
  font-size: var(--line-font-size);
  line-height: var(--line-line-height);
}

#chat9-embed #chat9-send {
  flex-shrink: 0;
  padding: 10px 18px;
  border-radius: var(--line-radius);
  border: none;
  cursor: pointer;
  background: var(--line-btn);
  color: var(--line-btn-text);
  min-height: 40px;
}

@media (max-width: 600px) {
  #chat9-embed .chat9-input-row { flex-direction: row; }
  #chat9-embed #chat9-main { padding-bottom: 0; }
  #chat9-embed #chat9-chat-window { padding: 0 0 6px 0; }
  #chat9-embed #chat9-scroll { padding: 8px 6px; }
}

#chat9-embed .debug-panels { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
#chat9-embed .debug-panel {
  flex: 1 1 0;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #f6fff0;
  border: 1px solid var(--line-bubble-border);
  border-radius: 10px;
  padding: 8px;
}

#chat9-embed .debug-panel h3 {
  margin: 0;
  font-size: 14px;
  color: var(--line-muted);
}

#chat9-embed .debug-panel textarea {
  min-height: 220px;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  background: #fff;
  color: var(--line-text);
  border: 1px solid var(--line-input-border);
  border-radius: 8px;
  padding: 8px;
}

#chat9-embed .tr-fileio {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

@media (max-width: 768px) {
  #chat9-embed .debug-panels { flex-direction: column; }
}

#chat9-embed.focus-chat9 header,
#chat9-embed.focus-chat9 nav,
#chat9-embed.focus-chat9 .site-header,
#chat9-embed.focus-chat9 .global-nav {
  display: none !important;
}

#chat9-embed.focus-chat9 #chat9-main {
  max-width: none;
  padding: 0;
}

#chat9-embed.focus-chat9 #chat9-sections-panel {
  padding-left: 8px;
  padding-right: 8px;
}

#chat9-embed.focus-chat9 #chat9-chat-window {
  padding: 0;
}
