* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #000;
  overflow: hidden;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
  border-bottom: 1px solid #000;
  padding-bottom: 10px;
  background: #fff;
}

.head-gif {
  height: 64px;
  width: 64px;
  object-fit: contain;
  flex: 0 0 auto;
}

.header-text {
  flex: 1 1 auto;
  min-width: 0;
}

.app-header h1 {
  margin: 0 0 2px;
  font-size: 1.25rem;
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.3;
  color: #000;
}

.info-link {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.78rem;
  color: #000;
  text-decoration: underline;
  cursor: pointer;
}

.info-link:hover {
  background: #000;
  color: #fff;
  text-decoration: none;
}

.chat {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #000;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble {
  max-width: 80%;
  padding: 8px 12px;
  border: 1px solid #000;
  line-height: 1.4;
  word-wrap: break-word;
  font-size: 0.95rem;
  white-space: pre-wrap;
}

.bubble.user {
  align-self: flex-end;
  background: #000;
  color: #fff;
}

.bubble.bot {
  align-self: flex-start;
  background: #fff;
  color: #000;
}

.bubble.system {
  align-self: center;
  background: transparent;
  border: none;
  color: #000;
  font-size: 0.8rem;
  font-style: italic;
}

.bubble.bot.typing::after {
  content: "▍";
  display: inline-block;
  margin-left: 1px;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

.input-row {
  display: flex;
  gap: 6px;
  align-items: stretch;
  flex: 0 0 auto;
}

#user-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  font-size: 1rem;
  outline: none;
}

#user-input:focus {
  outline: 2px solid #000;
  outline-offset: -2px;
}

button {
  padding: 0 14px;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

button:hover:not(:disabled) {
  background: #000;
  color: #fff;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#send-btn {
  background: #000;
  color: #fff;
}

#send-btn:hover:not(:disabled) {
  background: #fff;
  color: #000;
}

@media (max-width: 480px) {
  .app {
    padding: 8px;
    gap: 8px;
  }

  .head-gif {
    height: 56px;
    width: 56px;
  }

  .app-header h1 {
    font-size: 1.1rem;
  }

  .subtitle {
    font-size: 0.78rem;
  }

  button {
    padding: 10px 12px;
  }
}

/* ---- Info modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.modal-panel {
  position: relative;
  background: #fff;
  color: #000;
  border: 1px solid #000;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 20px 22px 18px;
  font-size: 0.95rem;
  line-height: 1.45;
}

.modal-panel h2 {
  margin: 0 0 12px;
  padding-right: 32px;
  font-size: 1.15rem;
}

.modal-panel h3 {
  margin: 16px 0 4px;
  font-size: 0.95rem;
}

.modal-panel p {
  margin: 0 0 8px;
}

.modal-panel pre {
  background: #000;
  color: #fff;
  padding: 8px 10px;
  margin: 6px 0 10px;
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre;
}

.modal-panel code {
  background: #000;
  color: #fff;
  padding: 1px 5px;
  font-size: 0.85em;
}

.modal-footnote {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid #000;
  font-style: italic;
}

.modal-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
  border: 1px solid #000;
  background: #fff;
  color: #000;
  cursor: pointer;
}

.modal-close:hover {
  background: #000;
  color: #fff;
}

@media (max-width: 480px) {
  .modal {
    padding: 8px;
  }

  .modal-panel {
    padding: 16px 16px 14px;
    font-size: 0.9rem;
  }
}
