/* ============ 基本トークン ============ */
:root {
  --bg: #fdf4ee;
  --bg-deep: #f9e8e4;
  --card: #fffdfa;
  --ink: #4a3538;
  --ink-soft: #8a6f74;
  --primary: #e0637f;
  --primary-deep: #c94a68;
  --primary-soft: #f6c7d3;
  --gold: #d9a441;
  --line: #f0dcd8;
  --radius-lg: 24px;
  --radius-md: 16px;
  --shadow: 0 10px 30px rgba(201, 74, 104, .12);
  --font-round: "M PLUS Rounded 1c", "Zen Kaku Gothic New", sans-serif;
  --font-body: "Zen Kaku Gothic New", "M PLUS Rounded 1c", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(60rem 40rem at 85% -10%, #fde3ec 0%, transparent 60%),
    radial-gradient(50rem 35rem at -10% 110%, #fdeee0 0%, transparent 55%),
    var(--bg);
  min-height: 100dvh;
}

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

/* ============ ヘッダー ============ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 2px 12px;
}
.header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.header-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid #fff;
  box-shadow: 0 4px 14px rgba(201, 74, 104, .25);
  animation: headerPulse 4s ease-in-out infinite;
}
@keyframes headerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
.header-name h1 {
  font-family: var(--font-round);
  font-size: 20px;
  font-weight: 800;
  margin: 0;
  letter-spacing: .04em;
}
.name-kana { font-size: 12px; font-weight: 500; color: var(--ink-soft); }
.header-status {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--primary);
  font-weight: 700;
}
.voice-toggle {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid var(--primary-soft);
  background: #fff;
  color: var(--primary);
  cursor: pointer;
  display: grid; place-items: center;
  transition: transform .15s ease, background .2s ease, color .2s ease;
  flex-shrink: 0;
}
.voice-toggle:hover { transform: scale(1.08); }
.voice-toggle.off { color: #c9b8bb; border-color: #eee2e2; background: #faf6f5; }

/* ============ 好感度 ============ */
.affection {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.affection-label {
  font-size: 12px; font-weight: 700;
  display: flex; gap: 4px; align-items: center;
  color: var(--ink-soft);
}
.heart { color: var(--primary); animation: beat 1.6s ease-in-out infinite; display: inline-block; }
@keyframes beat {
  0%, 100% { transform: scale(1); }
  12% { transform: scale(1.25); }
  24% { transform: scale(1); }
}
#affectionPct { color: var(--primary-deep); margin-left: auto; }
.affection-bar {
  height: 10px;
  background: #f6e3e8;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 6px;
}
.affection-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, #f4a5bb, var(--primary) 60%, var(--primary-deep));
  transition: width .8s cubic-bezier(.22,1,.36,1);
}
.affection-rank {
  font-size: 11px; color: var(--ink-soft); margin-top: 5px;
  text-align: right;
}

/* ============ タブ ============ */
.tabs {
  display: flex;
  gap: 8px;
  margin: 14px 0;
}
.tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  border-radius: 99px;
  font-family: var(--font-round);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  background: rgba(255, 255, 255, .6);
  color: var(--ink-soft);
  transition: all .2s ease;
}
.tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 16px rgba(224, 99, 127, .35);
}

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.panel { display: none; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; }
.panel.active { display: flex; }
#panel-chat { overflow: hidden; }

/* ============ ステージ(ポートレート) ============ */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0 10px;
}
.portrait-wrap {
  position: relative;
  width: min(62%, 240px);
  aspect-ratio: 3 / 4;
  border-radius: 28px;
  overflow: hidden;
  border: 4px solid #fff;
  box-shadow: 0 14px 34px rgba(201, 74, 104, .22);
  animation: breathe 3.8s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-3px) scale(1.012); }
}
.portrait {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  transition: opacity .12s ease;
}
.portrait.hidden { opacity: 0; }
.sparkle {
  position: absolute;
  top: 8px; right: 10px;
  font-size: 20px;
  color: #fff;
  text-shadow: 0 0 8px rgba(255, 255, 255, .9), 0 2px 6px rgba(201, 74, 104, .4);
  animation: twinkle 2.6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes twinkle {
  0%, 100% { opacity: .35; transform: scale(.85) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.1) rotate(15deg); }
}
.stage-caption {
  margin-top: 10px;
  font-size: 13px;
  font-weight: 700;
  color: #8a5f6b;
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--line);
  padding: 6px 16px;
  border-radius: 99px;
  max-width: 100%;
  text-align: center;
}

/* ============ チャット ============ */
.chat-log {
  flex: 1;
  min-height: 80px;
  overflow-y: auto;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
}
.msg {
  max-width: 82%;
  padding: 10px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.65;
  animation: popIn .3s cubic-bezier(.22,1,.36,1);
  white-space: pre-wrap;
  word-break: break-word;
}
@keyframes popIn {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to { opacity: 1; transform: none; }
}
.msg.her {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px 18px 18px 6px;
  box-shadow: 0 4px 12px rgba(201, 74, 104, .08);
}
.msg.you {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 6px 16px rgba(224, 99, 127, .3);
}
.msg.typing { color: var(--primary); font-weight: 700; letter-spacing: .2em; }

/* ============ チップ & 入力 ============ */
.chips-wrap {
  position: relative;
  margin: 0 -14px;
  padding: 0 14px;
}
.chips-wrap::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 44px;
  background: linear-gradient(90deg, transparent, var(--bg));
  pointer-events: none;
}
.chips {
  display: flex;
  gap: 8px;
  padding: 8px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  border: 1.5px solid var(--primary-soft);
  background: #fff;
  color: var(--primary-deep);
  font-family: var(--font-round);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 99px;
  cursor: pointer;
  transition: all .18s ease;
}
.chip:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

.composer {
  display: flex;
  gap: 10px;
  padding: 6px 0 0;
}
#msgInput {
  flex: 1;
  border: 2px solid var(--line);
  border-radius: 99px;
  padding: 12px 20px;
  font-size: 15px;
  font-family: var(--font-body);
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
  min-width: 0;
}
#msgInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(224, 99, 127, .12);
}
#msgInput::placeholder { color: #cbb6ba; }
.send {
  width: 48px; height: 48px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-deep));
  color: #fff;
  cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 8px 18px rgba(224, 99, 127, .4);
  transition: transform .15s ease;
}
.send:hover { transform: scale(1.06) rotate(-6deg); }
.send:active { transform: scale(.96); }

/* ============ プロフィール ============ */
.profile-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px 20px;
  margin-bottom: 20px;
}
.profile-photo {
  width: 140px; height: 140px;
  object-fit: cover;
  border-radius: 50%;
  border: 4px solid #fff;
  box-shadow: 0 8px 22px rgba(201, 74, 104, .25);
  display: block;
  margin: 0 auto 14px;
}
.profile-card h2 {
  font-family: var(--font-round);
  text-align: center;
  margin: 0 0 6px;
  font-size: 24px;
}
.profile-card h2 small { font-size: 13px; color: var(--ink-soft); font-weight: 500; }
.profile-catch {
  text-align: center;
  color: var(--primary-deep);
  font-size: 14px;
  font-weight: 700;
  background: linear-gradient(transparent 60%, var(--primary-soft) 60%);
  padding: 2px 4px;
  margin: 0 0 18px;
  line-height: 1.8;
}
.profile-list { margin: 0; }
.profile-list > div {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
  line-height: 1.7;
}
.profile-list > div:last-child { border-bottom: none; }
.profile-list dt {
  flex-shrink: 0;
  width: 96px;
  font-weight: 700;
  color: var(--primary-deep);
  font-family: var(--font-round);
}
.profile-list dd { margin: 0; }
.profile-notes { margin-top: 18px; }
.profile-notes h3 {
  font-family: var(--font-round);
  font-size: 15px;
  color: var(--primary-deep);
  margin: 0 0 8px;
}
.profile-notes ul { margin: 0; padding-left: 20px; }
.profile-notes li { font-size: 13px; line-height: 1.9; color: var(--ink-soft); }

/* ============ ギャラリー ============ */
.gallery-title {
  font-family: var(--font-round);
  font-size: 18px;
  margin: 6px 0 12px;
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding-bottom: 20px;
}
.gallery-item {
  margin: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(201, 74, 104, .1);
  cursor: zoom-in;
  transition: transform .18s ease;
}
.gallery-item:hover { transform: translateY(-3px); }
.gallery-item img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
}
.gallery-item figcaption {
  font-size: 12px;
  padding: 8px 10px;
  text-align: center;
  color: var(--ink-soft);
  font-family: var(--font-round);
  font-weight: 700;
}

/* ============ ライトボックス ============ */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(74, 53, 56, .82);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 24px;
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: min(92vw, 480px);
  max-height: 86vh;
  border-radius: 18px;
  border: 4px solid #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.lightbox-close {
  position: absolute;
  top: 16px; right: 18px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, .9);
  color: var(--primary-deep);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

/* ============ フッター ============ */
.app-footer {
  text-align: center;
  font-size: 11px;
  color: #a5848c;
  padding: 14px 0 2px;
}

@media (max-width: 380px) {
  .portrait-wrap { width: 58%; }
  .profile-list dt { width: 84px; }
}

@media (max-height: 900px) {
  .portrait-wrap { width: min(42%, 160px); }
  .stage-caption { margin-top: 6px; font-size: 12px; }
  .app-header { padding-top: 10px; }
  .header-avatar { width: 44px; height: 44px; }
  .tabs { margin: 10px 0; }
}

/* ===== v2 追加 ===== */
.portrait-wrap{animation:breathe 4.5s ease-in-out infinite}
@keyframes breathe{0%,100%{transform:translateY(0)}50%{transform:translateY(-4px)}}
.fx{position:absolute;bottom:22%;pointer-events:none;color:#ff7aa8;font-size:20px;animation:rise 1.6s ease-out forwards;z-index:3}
@keyframes rise{to{transform:translateY(-150px) rotate(14deg);opacity:0}}
.msg.typing{animation:pulse 1s infinite}@keyframes pulse{50%{opacity:.4}}
#settingsModal{position:fixed;inset:0;background:rgba(0,0,0,.45);display:flex;align-items:center;justify-content:center;z-index:60}
#settingsModal .box{background:var(--card);border-radius:var(--radius-md);padding:20px;width:min(92vw,380px);display:grid;gap:10px;font-size:14px;color:var(--ink)}
#settingsModal input,#panel-diary textarea{padding:10px;border:1px solid var(--line);border-radius:12px;font:inherit;width:100%;box-sizing:border-box}
#panel-diary{gap:10px;padding-bottom:12px}
#panel-diary textarea{min-height:90px;resize:vertical}
.btn{padding:10px 14px;border:none;border-radius:99px;background:var(--primary);color:#fff;font:inherit;font-weight:700;cursor:pointer}
.btn.sub{background:var(--primary-soft);color:var(--primary-deep)}
#diaryComment{color:var(--primary-deep);font-size:14px;min-height:1.2em}
#diaryList{list-style:none;margin:0;padding:0;display:grid;gap:8px}
#diaryList li{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:10px;font-size:13px;white-space:pre-wrap}
#diaryList time{display:block;color:var(--ink-soft);font-size:11px;margin-bottom:4px}
.gear{margin-left:8px}
