:root {
  color-scheme: light dark;
  --bg: #f7f5f2;
  --fg: #23241f;
  --accent: #d97757;
  --accent-contrast: #ffffff;
  --surface: #ffffff;
  --border: #e2ddd6;
  --muted: #6b6a63;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a17;
    --fg: #f2efe9;
    --surface: #26241f;
    --border: #3a372f;
    --muted: #a29f96;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", system-ui, sans-serif;
  display: flex;
  justify-content: center;
  padding: 1.5rem;
}

.app {
  width: 100%;
  max-width: 32rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.app-header {
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.75rem;
}

.tagline {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.persona-stage {
  position: relative;
  width: 100%;
  max-width: 16rem;
  aspect-ratio: 4 / 5;
  margin: 0 auto;
}

/*
 * 表情差分は同じ position で重ねて配置し、is-active の opacity だけを
 * 切り替えることでクロスフェードさせる (hidden/display:none は
 * transition が発火しないため使わない)。非アクティブな差分は
 * pointer-events を切って誤タップを防ぐ。
 */
.persona-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 4px 12px rgb(0 0 0 / 12%));
  transition: opacity 0.4s ease;
}

.persona-face.is-active {
  opacity: 1;
  pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
  .persona-face {
    transition: none;
  }
}

.chat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.start-button {
  align-self: center;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 999px;
  padding: 0.5rem 1.25rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.start-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.chat-log {
  min-height: 6rem;
  max-height: 20rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-message {
  padding: 0.6rem 0.85rem;
  border-radius: 0.75rem;
  max-width: 85%;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-message.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-contrast);
}

.chat-message.persona {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--border);
}

.chat-message.error {
  align-self: flex-start;
  background: #fdeceb;
  color: #8a2c22;
  border: 1px solid #f2b8b1;
}

.quota {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.turnstile-widget {
  display: flex;
  justify-content: center;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
}

.chat-form input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
}

.chat-form button {
  padding: 0.6rem 1rem;
  border-radius: 0.6rem;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 1rem;
  cursor: pointer;
}

.chat-form button:disabled {
  opacity: 0.6;
  cursor: default;
}

.disclaimer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}
