:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e6ea;
  --text: #1a1d21;
  --text-mute: #6b7280;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --user-bubble: #2563eb;
  --user-bubble-text: #ffffff;
  --ai-bubble: #ffffff;
  --ai-bubble-text: #1a1d21;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --radius: 18px;
  --header-h: 56px;
  --composer-h: 96px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", Meiryo, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

body {
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px env(safe-area-inset-top) 16px;
  padding-top: max(8px, env(safe-area-inset-top));
}

.header__title {
  font-weight: 700;
  font-size: 15px;
}

.header__sub {
  font-size: 11px;
  color: var(--text-mute);
  margin-top: 2px;
}

.thread {
  flex: 1 1 auto;
  padding: 16px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.55;
}

.bubble--ai {
  align-self: flex-start;
  background: var(--ai-bubble);
  color: var(--ai-bubble-text);
  border-bottom-left-radius: 6px;
}

.bubble--user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 6px;
}

.bubble--pending {
  opacity: 0.6;
}

.bubble--typing {
  background: var(--ai-bubble);
  color: var(--text-mute);
  font-style: italic;
  align-self: flex-start;
}

.composer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}

.composer__form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.composer__input {
  flex: 1 1 auto;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px 14px;
  font-size: 16px;
  line-height: 1.4;
  background: #fff;
  font-family: inherit;
  max-height: 40vh;
  min-height: 40px;
  outline: none;
}

.composer__input:focus {
  border-color: var(--accent);
}

.composer__send {
  flex: 0 0 auto;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  padding: 0 16px;
  height: 40px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.composer__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer__hint {
  font-size: 11px;
  color: var(--text-mute);
  margin-top: 4px;
  min-height: 14px;
}

.composer__hint--error {
  color: #b91c1c;
}

.errorpage {
  max-width: 480px;
  margin: 0 auto;
  padding: 48px 24px;
  text-align: center;
}

.errorpage h1 {
  font-size: 20px;
  margin-bottom: 12px;
}

.errorpage p {
  color: var(--text-mute);
  font-size: 14px;
}

@media (min-width: 720px) {
  .app {
    max-width: 720px;
    margin: 0 auto;
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--border);
  }
}
