:root {
  --bg: #0f0e0d;
  --bg-soft: #171514;
  --line: #2a2624;
  --ink: #efe9e3;
  --ink-dim: #9c948c;
  --ink-faint: #6b625b;
  --accent: #c2603f;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

.screen {
  min-height: 100dvh;
}

.hidden {
  display: none !important;
}

/* ------------------------------------------------------------- 選択画面 -- */

#select {
  max-width: 1080px;
  margin: 0 auto;
  padding: 8vh 24px 60px;
}

.hero {
  text-align: center;
  margin-bottom: 56px;
}

.hero-eyebrow {
  margin: 0 0 14px;
  font-size: 11px;
  letter-spacing: 0.34em;
  color: var(--ink-faint);
}

.hero-title {
  margin: 0 0 20px;
  font-size: clamp(38px, 8vw, 62px);
  font-weight: 500;
  letter-spacing: 0.16em;
}

.hero-lead {
  margin: 0 auto;
  max-width: 32em;
  font-size: 15px;
  line-height: 2;
  color: var(--ink-dim);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}

.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-soft);
  cursor: pointer;
  text-align: left;
  padding: 0;
  color: inherit;
  font: inherit;
  transition: transform 0.25s ease, border-color 0.25s ease;
}

.card:hover {
  transform: translateY(-4px);
  border-color: var(--card-accent, var(--accent));
}

.card-photo {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: #211d1b;
}

.card-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: saturate(0.95);
}

.card-photo::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 45%, rgba(15, 14, 13, 0.92) 100%);
}

.card-seen {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 2;
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(15, 14, 13, 0.72);
  border: 1px solid var(--card-accent, var(--accent));
  color: var(--ink);
  backdrop-filter: blur(6px);
}

.card-body {
  position: relative;
  margin-top: -70px;
  padding: 0 20px 22px;
  z-index: 1;
}

.card-name {
  font-size: 22px;
  letter-spacing: 0.06em;
  margin-bottom: 3px;
}

.card-kana {
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.14em;
  margin-bottom: 12px;
}

.card-title {
  font-size: 12px;
  color: var(--card-accent, var(--accent));
  letter-spacing: 0.1em;
  margin-bottom: 10px;
}

.card-tagline {
  font-size: 13.5px;
  line-height: 1.85;
  color: var(--ink-dim);
  margin-bottom: 14px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.card-tags span {
  font-size: 11px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-faint);
}

.disclaimer {
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  line-height: 2;
  color: var(--ink-faint);
  text-align: center;
}

.disclaimer strong {
  color: var(--ink-dim);
  font-weight: 600;
}

/* ------------------------------------------------------------- 会話画面 -- */

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

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}

.back,
.memory-toggle,
.memory-close {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  padding: 7px 13px;
  font-size: 13px;
  transition: color 0.2s, border-color 0.2s;
}

.back:hover,
.memory-toggle:hover,
.memory-close:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
}

.memory-toggle {
  margin-left: auto;
}

.memory-toggle.pulse {
  color: var(--accent);
  border-color: var(--accent);
}

.chat-portrait {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 22%;
}

.chat-name {
  font-size: 15px;
  letter-spacing: 0.06em;
}

.chat-title {
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
}

.chat-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  gap: 12px;
  animation: rise 0.35s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 22%;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-text {
  font-size: 15px;
  line-height: 1.95;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user {
  justify-content: flex-end;
}

.msg.user .msg-text {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-width: 82%;
}

.msg.assistant .msg-text {
  padding-top: 3px;
}

.typing span {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--ink-faint);
  animation: blink 1.2s infinite;
}
.typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes blink {
  0%,
  60%,
  100% {
    opacity: 0.25;
  }
  30% {
    opacity: 1;
  }
}

/* -------------------------------------------------------------- 記憶欄 -- */

.memory {
  width: 330px;
  flex-shrink: 0;
  border-left: 1px solid var(--line);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
}

.memory-head {
  display: flex;
  align-items: center;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}

.memory-head h2 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  font-weight: 500;
}

.memory-close {
  margin-left: auto;
  display: none;
  padding: 3px 10px;
}

.memory-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
}

.memory-empty {
  font-size: 12.5px;
  line-height: 2;
  color: var(--ink-faint);
}

.memory-name {
  font-size: 13px;
  color: var(--ink);
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.memory-name span {
  color: var(--ink-faint);
  font-size: 11px;
  letter-spacing: 0.1em;
  display: block;
  margin-bottom: 4px;
}

.fact-group {
  margin-bottom: 18px;
}

.fact-group h3 {
  margin: 0 0 8px;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  color: var(--accent);
  font-weight: 500;
}

.fact {
  font-size: 12.5px;
  line-height: 1.85;
  color: var(--ink-dim);
  padding: 7px 0 7px 12px;
  border-left: 2px solid var(--line);
  margin-bottom: 4px;
  position: relative;
  transition: border-color 0.4s, color 0.4s;
}

.fact.fresh {
  border-left-color: var(--accent);
  color: var(--ink);
  animation: rise 0.4s ease both;
}

.fact-badge {
  display: inline-block;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 7px;
  vertical-align: 1px;
  background: var(--accent);
  color: #14100e;
}

.fact-followup {
  display: block;
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 3px;
}

.fact-followup.due {
  color: var(--accent);
}

.memory-summary {
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  line-height: 2;
  color: var(--ink-faint);
}

.memory-summary strong {
  display: block;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  font-weight: 500;
  margin-bottom: 8px;
}

.memory-demo {
  border-top: 1px solid var(--line);
  padding: 14px 18px 18px;
  flex-shrink: 0;
}

.memory-demo-label {
  margin: 0 0 10px;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
}

.memory-demo-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.memory-demo-buttons button {
  flex: 1;
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  border-radius: 8px;
  padding: 8px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.memory-demo-buttons button:hover {
  color: var(--ink);
  border-color: var(--ink-faint);
}

.memory-demo-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.8;
  color: var(--ink-faint);
}

/* -------------------------------------------------------------- 入力欄 -- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.composer textarea {
  flex: 1;
  max-width: 640px;
  margin: 0 auto;
  resize: none;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  line-height: 1.7;
  padding: 12px 14px;
  max-height: 30vh;
  outline: none;
}

.composer textarea:focus {
  border-color: var(--ink-faint);
}

.composer button {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #14100e;
  font-size: 18px;
  cursor: pointer;
}

.composer button:disabled {
  opacity: 0.35;
  cursor: default;
}

/* ------------------------------------------------------------ 顔ステージ -- */

.main-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.stage {
  position: relative;
  flex-shrink: 0;
  height: min(52vh, 430px);
  border-bottom: 1px solid var(--line);
  background: #0b0a09;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

/* 元画像と同じ3:4の器に収めるので、顔が切れずに全身の構図が出る */
.stage-frames {
  position: relative;
  height: 100%;
  aspect-ratio: 3 / 4;
  will-change: transform;
  /* 呼吸と首のわずかな揺れ。止まった写真に見せないための最小限の動き */
  animation: breathe 7.5s ease-in-out infinite;
}

.stage-frames.speaking {
  animation: breathe-talk 3.4s ease-in-out infinite;
}

@keyframes breathe {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1) rotate(0deg);
  }
  30% {
    transform: translate3d(-0.25%, -0.35%, 0) scale(1.004) rotate(-0.12deg);
  }
  62% {
    transform: translate3d(0.2%, 0.15%, 0) scale(1.002) rotate(0.1deg);
  }
}

@keyframes breathe-talk {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1.002) rotate(0deg);
  }
  22% {
    transform: translate3d(-0.4%, -0.5%, 0) scale(1.007) rotate(-0.22deg);
  }
  48% {
    transform: translate3d(0.3%, 0.25%, 0) scale(1.003) rotate(0.18deg);
  }
  74% {
    transform: translate3d(-0.15%, 0.35%, 0) scale(1.005) rotate(-0.08deg);
  }
}

.stage-frames img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* 口のフレーム: 口以外はピクセル一致しているので、重ねて薄く送っても顔は揺れない */
.stage-frames img.viseme {
  opacity: 0;
  transition: opacity 85ms ease-out;
}

.stage-frames img.viseme.on {
  opacity: 1;
}

/* まばたき: 目のまわりだけを切り抜いた透過画像を上に重ねる */
.stage-frames img.blink {
  opacity: 0;
  transition: opacity 55ms ease-in;
  pointer-events: none;
}

.stage-frames img.blink.on {
  opacity: 1;
  transition: opacity 40ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .stage-frames,
  .stage-frames.speaking {
    animation: none;
  }
}

.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom, transparent 62%, rgba(11, 10, 9, 0.9) 100%);
}

.stage-status {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  z-index: 2;
}

.stage-play {
  position: absolute;
  right: 14px;
  bottom: 12px;
  z-index: 3;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(15, 14, 13, 0.72);
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.stage-play.needs-tap {
  border-color: var(--accent);
  color: var(--accent);
  animation: pulse-play 1.4s ease-in-out infinite;
}

@keyframes pulse-play {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.face-toggle {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-dim);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  padding: 7px 13px;
  font-size: 13px;
  margin-left: auto;
  transition: color 0.2s, border-color 0.2s;
}

.face-toggle.active {
  color: var(--accent);
  border-color: var(--accent);
}

.memory-toggle {
  margin-left: 8px;
}

/* ---------------------------------------------------------------- プラン -- */

.plan-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 12px;
  line-height: 1.9;
  color: var(--ink-dim);
}

.plan-box .plan-name {
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.plan-box .plan-name em {
  font-style: normal;
  color: var(--accent);
}

.plan-box button {
  margin-top: 10px;
  width: 100%;
  background: var(--accent);
  border: none;
  color: #14100e;
  border-radius: 8px;
  padding: 9px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

/* ------------------------------------------------------------ モーダル -- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 7, 6, 0.82);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: rise 0.25s ease both;
}

.modal.hidden {
  display: none;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 26px 24px;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

.modal-eyebrow {
  margin: 0 0 10px;
  font-size: 10.5px;
  letter-spacing: 0.24em;
  color: var(--accent);
}

.modal-title {
  margin: 0 0 12px;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0.06em;
}

.modal-reason {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.9;
  color: var(--ink-dim);
}

.plan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-bottom: 20px;
}

.plan-table th,
.plan-table td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
  text-align: center;
  color: var(--ink-dim);
}

.plan-table th {
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

.plan-table th:last-child {
  color: var(--accent);
}

.plan-table td:first-child {
  text-align: left;
  color: var(--ink-faint);
}

.plan-table td:last-child {
  color: var(--ink);
}

.modal-price {
  margin: 0 0 16px;
  text-align: center;
  font-size: 19px;
  letter-spacing: 0.06em;
}

.modal-price span {
  display: block;
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.08em;
  margin-top: 5px;
}

.modal-cta {
  width: 100%;
  background: var(--accent);
  border: none;
  color: #14100e;
  border-radius: 10px;
  padding: 14px;
  font: inherit;
  font-size: 15px;
  cursor: pointer;
}

.modal-cta:disabled {
  opacity: 0.4;
  cursor: default;
}

.gate-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  padding: 13px 14px;
  margin-bottom: 14px;
  outline: none;
  text-align: center;
  letter-spacing: 0.1em;
}

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

.modal-note {
  margin: 12px 0 0;
  font-size: 11px;
  line-height: 1.8;
  color: var(--ink-faint);
  text-align: center;
}

/* -------------------------------------------------------------- トースト -- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: 90vw;
  padding: 12px 18px;
  border-radius: 999px;
  background: rgba(35, 30, 27, 0.96);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.6;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: rise 0.3s ease both;
  transition: opacity 0.6s ease;
}

.toast.fade {
  opacity: 0;
}

/* -------------------------------------------------------------- モバイル -- */

@media (max-width: 860px) {
  .memory {
    position: fixed;
    inset: 0;
    width: 100%;
    z-index: 20;
    border-left: none;
  }
  .memory:not(.open) {
    display: none;
  }
  .memory-close {
    display: block;
  }
}

@media (min-width: 861px) {
  .memory-toggle {
    display: none;
  }
}
