:root {
  --bg-1: #f7f4ee;
  --bg-2: #e9f0f5;
  --ink: #1f1a15;
  --muted: #6e645b;
  --accent: #f2c572;
  --accent-2: #c7a27d;
  --bubble-ai: #ffffff;
  --bubble-user: #ffe9c8;
  --shadow: 0 10px 30px rgba(36, 28, 21, 0.1);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "UD Digi Kyokasho NK-R", "Yu Gothic", "Meiryo", "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 10% 20%, rgba(255, 220, 170, 0.45), transparent 45%),
    radial-gradient(circle at 90% 10%, rgba(180, 210, 230, 0.45), transparent 55%),
    linear-gradient(160deg, var(--bg-1), var(--bg-2));
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  height: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 6px 4px;
}

.title h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--muted);
}

.gear-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
}

.gear-btn:active {
  transform: scale(0.96);
}

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 6px 16px;
  overflow-y: auto;
  min-height: 0;
}

.msg {
  max-width: min(75%, 480px);
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.98rem;
  line-height: 1.6;
  word-break: break-word;
}

.msg.ai {
  align-self: flex-start;
  background: var(--bubble-ai);
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
}

.msg .meta {
  display: block;
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--muted);
}

.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  height: 1rem;
}

.typing span {
  width: 6px;
  height: 6px;
  background: var(--accent-2);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}

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

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

.input-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 10px 6px 6px;
  background: rgba(247, 244, 238, 0.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(36, 28, 21, 0.08);
}

.input-bar input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 999px;
  border: 1px solid rgba(36, 28, 21, 0.18);
  font-size: 1rem;
  background: #fff;
}

.input-bar button {
  border: none;
  background: var(--accent);
  color: #4a3112;
  font-weight: 600;
  border-radius: 999px;
  padding: 0 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.ad-slot {
  position: relative;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  padding: 12px;
  margin-top: 8px;
}

.ad-slot iframe {
  border: none;
  border-radius: 10px;
  display: block;
}

.ad-slot .pr {
  margin-top: 6px;
  text-align: right;
  font-size: 0.65rem;
  color: var(--muted);
}

.input-bar button:active {
  transform: translateY(1px);
}

@media (max-width: 640px) {
  .msg {
    max-width: 88%;
    font-size: 0.95rem;
  }

  .top {
    flex-direction: row;
    align-items: center;
  }
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.6;
  }
  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
