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

body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #ffffff;
  color: #1f1f1f;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: #ffffff;
  border-bottom: 1px solid #e5e5e5;
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.header-logo img {
  border-radius: 4px;
  flex-shrink: 0;
}

.header-logo h1 {
  font-size: 1rem;
  font-weight: 600;
  color: #1f1f1f;
}

#share-btn {
  background: none;
  border: 1px solid #e5e5e5;
  color: #5f5f5f;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  transition: background 0.15s;
  line-height: 1;
}

#share-btn:hover {
  background: #f5f5f5;
}

#chat {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
}

#messages {
  padding: 0;
}

.message {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 24px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.message-label {
  font-size: 0.75rem;
  color: #8e8e8e;
  margin-bottom: 6px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.message-content {
  line-height: 1.65;
  font-size: 0.95rem;
  color: #1f1f1f;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  -webkit-hyphenate-limit-before: 3;
  -webkit-hyphenate-limit-after: 3;
  hyphenate-limit-chars: 6 3 3;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message-content p {
  margin-bottom: 10px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  font-weight: 600;
  color: #1f1f1f;
  margin: 20px 0 10px;
  line-height: 1.3;
}

.message-content h1 { font-size: 1.15rem; text-align: left; }
.message-content h2 { font-size: 1.05rem; text-align: left; }
.message-content h3 { font-size: 1rem; text-align: left; }

.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child {
  margin-top: 0;
}

.message-content strong {
  font-weight: 600;
}

.message-content blockquote {
  border-left: 3px solid #e0e0e0;
  padding-left: 16px;
  margin: 12px 0;
  color: #5f5f5f;
  font-style: italic;
}

.message-content ul,
.message-content ol {
  padding-left: 22px;
  margin: 10px 0;
}

.message-content li {
  margin-bottom: 6px;
}

.message-content code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.85em;
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 4px;
  color: #1f1f1f;
}

#loading {
  max-width: 720px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #8e8e8e;
  font-size: 0.875rem;
}

#loading.hidden {
  display: none;
}

.dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.dots span {
  width: 5px;
  height: 5px;
  background: #d0d0d0;
  border-radius: 50%;
  animation: dotPulse 1.4s ease-in-out infinite;
}

.dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.2); }
}

footer {
  padding: 16px 24px 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background: #ffffff;
  flex-shrink: 0;
}

#form {
  display: flex;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  align-items: flex-end;
}

#input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #d0d0d0;
  border-radius: 12px;
  background: #ffffff;
  color: #1f1f1f;
  font-size: 0.925rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 48px;
  max-height: 200px;
  line-height: 1.5;
  resize: none;
  overflow-y: auto;
}

#input:focus {
  border-color: #b0b0b0;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05);
}

#input::placeholder {
  color: #acacac;
}

#send-btn {
  padding: 12px 20px;
  background: #1f1f1f;
  color: #ffffff;
  border: none;
  border-radius: 10px;
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
  font-weight: 500;
  min-height: 48px;
}

#send-btn:hover {
  opacity: 0.8;
}

#send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 24px 16px;
  max-width: 720px;
  margin: 0 auto;
}

.suggestion-btn {
  background: #ffffff;
  border: 1px solid #d0d0d0;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-family: inherit;
  color: #5f5f5f;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: normal;
  text-align: left;
  line-height: 1.3;
}

.suggestion-btn:hover {
  border-color: #1f1f1f;
  color: #1f1f1f;
}

.suggestion-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

@media (max-width: 600px) {
  header {
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }

  .message {
    padding: 14px 16px;
  }

  .message-content {
    font-size: 0.9rem;
    text-align: justify;
    overflow-wrap: break-word;
    word-break: break-word;
  }

  footer {
    padding: 12px 16px 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  #form {
    gap: 6px;
  }

  #send-btn {
    padding: 12px 16px;
    font-size: 0.8rem;
    min-height: 44px;
  }

  #input {
    padding: 10px 14px;
    font-size: 0.9rem;
    min-height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .message { animation: none; }
  .dots span { animation: none; opacity: 1; }
}
