:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #9ca3af;
  --border: #e5e7eb;
  --accent-start: #6366f1;
  --accent-end: #a855f7;
  --accent-soft: #c4b5fd;
  --accent-soft-active: #a78bfa;
  --user-bubble-start: #6366f1;
  --user-bubble-end: #8b5cf6;
  --user-text: #ffffff;
  --assistant-bubble: #ffffff;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #b91c1c;
  --progress: #9ca3af;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(99, 102, 241, 0.08);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", Meiryo, sans-serif;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ===== Header ===== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: linear-gradient(90deg, var(--accent-start) 0%, var(--accent-end) 100%);
  color: #fff;
  box-shadow: 0 2px 4px rgba(99, 102, 241, 0.12);
}

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

.reset {
  background: transparent;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  color: #fff;
  padding: 7px 22px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.reset:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ===== Messages area ===== */

.main {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 56px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  margin: 0 auto;
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  pointer-events: none;
}

.empty.hidden {
  display: none;
}

/* ===== Bubbles ===== */

.message {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.message.user {
  align-self: flex-end;
  max-width: 44%;
}

.message.assistant {
  align-self: flex-start;
  max-width: 64%;
}

.bubble {
  padding: 18px 22px;
  border-radius: 16px;
  line-height: 1.7;
  font-size: 15px;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}

.bubble-label {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 6px;
  letter-spacing: 0.04em;
  opacity: 0.85;
}

.bubble-time {
  font-size: 12px;
  margin-top: 10px;
  opacity: 0.75;
}

/* User */

.message.user .bubble {
  background: linear-gradient(135deg, var(--user-bubble-start) 0%, var(--user-bubble-end) 100%);
  color: var(--user-text);
  white-space: pre-wrap;
}

.message.user .bubble-label {
  color: rgba(255, 255, 255, 0.85);
}

.message.user .bubble-time {
  color: rgba(255, 255, 255, 0.75);
}

/* Assistant */

.message.assistant .bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(99, 102, 241, 0.06);
}

.message.assistant .bubble-label {
  color: #6b7280;
}

.message.assistant .bubble .markdown {
  white-space: normal;
}

.message.assistant .bubble .markdown > *:first-child {
  margin-top: 0;
}

.message.assistant .bubble .markdown > *:last-child {
  margin-bottom: 0;
}

.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3,
.message.assistant .bubble h4 {
  margin: 18px 0 8px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
}

.message.assistant .bubble h3 { font-size: 20px; }
.message.assistant .bubble h4 { font-size: 16px; }
.message.assistant .bubble h5 { font-size: 15px; margin: 14px 0 6px; font-weight: 700; }

.message.assistant .bubble p {
  margin: 8px 0;
}

.message.assistant .bubble strong {
  font-weight: 700;
  color: var(--text);
}

.message.assistant .bubble ul,
.message.assistant .bubble ol {
  margin: 8px 0 8px 4px;
  padding-left: 22px;
}

.message.assistant .bubble li {
  margin: 4px 0;
}

.message.assistant .bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.message.assistant .bubble blockquote {
  margin: 12px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--accent-soft);
  background: #f9fafb;
  border-radius: 8px;
  color: #4b5563;
}

.message.assistant .bubble blockquote p {
  margin: 0;
}

.message.assistant .bubble table {
  border-collapse: collapse;
  margin: 14px 0;
  width: 100%;
  font-size: 14px;
}

.message.assistant .bubble th,
.message.assistant .bubble td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

.message.assistant .bubble thead th {
  background: #f3f4f6;
  font-weight: 600;
  color: var(--text);
}

.message.assistant .bubble tbody tr:nth-child(even) td {
  background: #fafbfc;
}

.message.assistant .bubble a {
  color: var(--accent-start);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message.assistant .bubble code {
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.message.assistant .bubble pre {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  overflow-x: auto;
  margin: 10px 0;
}

.message.assistant .bubble pre code {
  background: transparent;
  padding: 0;
  font-size: 13px;
}

/* Progress line above an assistant bubble */
.progress {
  font-size: 13px;
  color: var(--progress);
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.progress::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-soft);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.1); }
}

.error {
  color: var(--error-text);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
}

/* ===== Composer ===== */

.composer {
  display: flex;
  gap: 12px;
  padding: 16px 28px 20px;
  background: var(--bg);
  align-items: center;
  width: 100%;
}

.composer input {
  flex: 1;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 22px;
  font-family: inherit;
  font-size: 15px;
  outline: none;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer input::placeholder {
  color: var(--muted);
}

.composer input:focus {
  border-color: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(196, 181, 253, 0.25);
}

.composer button {
  background: var(--accent-soft);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  height: 48px;
  min-width: 96px;
  transition: background 0.15s ease, transform 0.05s ease;
}

.composer button:hover:not(:disabled) {
  background: var(--accent-soft-active);
}

.composer button:active:not(:disabled) {
  transform: scale(0.98);
}

.composer button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Scrollbar polish */
.messages::-webkit-scrollbar {
  width: 8px;
}
.messages::-webkit-scrollbar-thumb {
  background: rgba(99, 102, 241, 0.18);
  border-radius: 4px;
}
.messages::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 900px) {
  .messages { padding: 24px 20px 16px; }
  .message.user { max-width: 70%; }
  .message.assistant { max-width: 88%; }
}

@media (max-width: 640px) {
  .topbar { padding: 14px 18px; }
  .topbar h1 { font-size: 15px; }
  .reset { padding: 5px 14px; font-size: 12px; }
  .messages { padding: 20px 14px 12px; gap: 16px; }
  .composer { padding: 12px 14px 14px; }
  .composer button { min-width: 72px; padding: 0 16px; }
  .bubble { padding: 14px 16px; font-size: 14px; }
}
