:root {
  --ink: #1d2433;
  --ink-soft: #4a5163;
  --paper: #fffaf0;
  --sand: #f6e9cf;
  --navy: #14213d;
  --teal: #12857a;
  --orange: #e2701f;
  --blue: #2c66cc;
  --purple: #7446bd;
  --pink: #cf4a7d;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-pop: cubic-bezier(0.34, 1.45, 0.64, 1);
}

* { box-sizing: border-box; }
html { font-size: 106.25%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% 0%, #22345c 0%, var(--navy) 60%, #0b1326 100%);
  color: var(--ink);
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; }
[hidden] { display: none !important; }

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--navy);
}
@media (min-width: 520px) {
  #app { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 30px 80px rgba(0, 0, 0, 0.5); }
}

/* ── 遊ぶ画面 ───────────────────────── */
.play { display: flex; flex-direction: column; height: 100%; }

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  container-type: size;
  background: var(--navy);
}
.bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center 64%;
  opacity: 0;
  transition: opacity 0.7s ease, filter 0.6s ease;
}
.bg.show { opacity: 1; }
.bg.drift { animation: drift 16s var(--ease-out) forwards; }
@keyframes drift { from { transform: scale(1.08) translateY(1.5%); } to { transform: none; } }

.chars { position: absolute; inset: 0; transition: filter 0.6s ease; }
.char {
  position: absolute;
  bottom: 2cqh;
  /* 幅の狭い画面でも端の人が切れないよう、絵の幅の 15% までしか舞台の外に出さない（--ar＝絵の横/縦） */
  --edge: calc(var(--h) * var(--ar, 0.55) * 0.35cqh);
  left: clamp(var(--edge), calc(var(--x) * 1%), calc(100% - var(--edge)));
  height: calc(var(--h) * 1cqh);
  translate: -50% 0;
  animation: charIn 0.6s var(--ease-pop) var(--d) both;
  transition: opacity 0.25s ease;
  pointer-events: none; /* 絵の透明な所で指を取らない。押せるのは talkable の ::after だけ */
}
.char.exit { animation: charExit 0.45s var(--ease-out) forwards; }
@keyframes charExit { to { opacity: 0; transform: translateX(-28px) scale(0.96); } }
.char img {
  display: block;
  height: 100%;
  width: auto;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.28));
  animation: idle 3.2s ease-in-out var(--idle) infinite alternate;
  transition: filter 0.3s ease, scale 0.3s var(--ease-out);
  user-select: none;
  -webkit-user-select: none;
}
.char img.flip { rotate: y 180deg; }
@keyframes charIn { from { opacity: 0; transform: translateY(22px) scale(0.92); } to { opacity: 1; transform: none; } }
@keyframes idle { from { transform: none; } to { transform: scaleY(1.02) translateY(-1px); } }
.chars.leaving .char { opacity: 0; }
.chars.has-focus .char:not(.focus) img { filter: drop-shadow(0 6px 6px rgba(0, 0, 0, 0.28)) brightness(0.68) saturate(0.75); }
.char.focus { z-index: 10 !important; }
.char.focus img { scale: 1.04; }

.char.talkable { cursor: pointer; }
.char.talkable::after { content: ""; position: absolute; left: 20%; right: 20%; top: 4%; bottom: 0; min-width: 44px; min-height: 44px; pointer-events: auto; }
.char.talkable::before {
  content: "…";
  position: absolute;
  left: 50%;
  top: -4px;
  translate: -50% -100%;
  display: grid;
  place-items: center;
  width: 44px;
  height: 36px;
  border-radius: 18px;
  background: #fff;
  border: 2.5px solid var(--ink);
  color: var(--ink);
  font-weight: 900;
  font-size: 18px;
  line-height: 1;
  padding-bottom: 6px;
  box-shadow: 0 3px 0 var(--ink);
  animation: bubble 1.3s ease-in-out infinite alternate;
  pointer-events: auto;
}
.char.talkable.visited::before { content: "✓"; background: var(--teal); color: #fff; padding-bottom: 0; animation: none; }
.char.talkable:focus-visible { outline: 3px solid #fff; outline-offset: 4px; border-radius: 12px; }
@keyframes bubble { from { transform: translateY(0); } to { transform: translateY(-6px); } }

.hud {
  position: absolute;
  z-index: 20;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.clock, .sun {
  background: rgba(20, 33, 61, 0.78);
  color: #fff;
  border-radius: 999px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.clock { padding: 7px 14px; font-weight: 900; font-size: 16px; white-space: nowrap; }
.sun { flex: 1; display: flex; align-items: center; gap: 10px; padding: 9px 14px; min-width: 0; }
.sun-track { position: relative; flex: 1; height: 6px; border-radius: 99px; background: linear-gradient(90deg, #ffd66b, #ff9a3c 70%, #b05ad8); opacity: 0.9; }
.sun-dot {
  --t: 0;
  position: absolute;
  top: 50%;
  left: calc(var(--t) * 100%);
  width: 16px;
  height: 16px;
  translate: -50% -50%;
  border-radius: 50%;
  background: #fff3c4;
  box-shadow: 0 0 0 3px rgba(255, 214, 107, 0.45), 0 0 14px #ffd66b;
  transition: left 1.2s var(--ease-out);
}
.sun-end { font-size: 16px; font-weight: 700; white-space: nowrap; }

.observe { position: absolute; z-index: 20; left: 16px; right: 16px; bottom: 40px; height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.3); overflow: hidden; }
.observe-bar { height: 100%; background: #fff; transform-origin: 0 50%; transition-property: transform; transition-timing-function: linear; }
.stage.veiled .bg, .stage.veiled .chars { filter: blur(12px) brightness(0.5); }

.panel {
  position: relative;
  z-index: 30;
  flex: 0 0 auto;
  /* ふだんは同じ高さ。小さい画面で選択肢が入りきらない時だけ、画面の 64% まで伸びる */
  min-height: clamp(250px, 41dvh, 370px);
  max-height: 64dvh;
  margin-top: -22px;
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.28);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
/* 選択肢が3つ以上の時は、ボタンを少し詰めて全部を一度に見せる */
.panel.tall .btn { min-height: 52px; padding: 10px 16px; }
.speaker {
  align-self: flex-start;
  padding: 5px 14px;
  border-radius: 999px;
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 0.02em;
  background: var(--ink);
  animation: pop 0.35s var(--ease-pop);
}
.speaker[data-color="teal"] { background: var(--teal); }
.speaker[data-color="orange"] { background: var(--orange); }
.speaker[data-color="blue"] { background: var(--blue); }
.speaker[data-color="purple"] { background: var(--purple); }
.speaker[data-color="pink"] { background: var(--pink); }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }

.line { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.75; color: var(--ink); min-height: 1.75em; }
.line.narr { color: var(--ink-soft); }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choices.grid { display: grid; grid-template-columns: 1fr 1fr; }
.choices.grid .go { grid-column: 1 / -1; }

.btn {
  min-height: 56px;
  padding: 12px 16px;
  border: 2.5px solid var(--ink);
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  font-size: 17px;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.2s ease, opacity 0.2s ease;
}
.choices .btn { animation: choiceIn 0.42s var(--ease-pop) calc(var(--i) * 60ms) both; }
@keyframes choiceIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.btn:active:not(:disabled) { transform: translateY(3px) scale(0.98); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.btn.picked { background: var(--sand); transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled:not(.picked) { opacity: 0.4; }
.btn.go { background: var(--teal); color: #fff; text-align: center; }
.btn.done { background: #e6f4f1; color: var(--teal); border-color: var(--teal); box-shadow: 0 4px 0 var(--teal); }
.grid .btn { font-size: 16px; padding: 10px 12px; }

.next { position: absolute; right: 18px; bottom: calc(14px + env(safe-area-inset-bottom)); color: var(--orange); font-size: 18px; opacity: 0; transition: opacity 0.2s; }
.next.on { opacity: 1; animation: nextBob 0.9s ease-in-out infinite alternate; }
.next.hint::before { content: "タップで次へ "; font-size: 16px; font-weight: 900; }
@keyframes nextBob { from { transform: translateY(-2px); } to { transform: translateY(3px); } }

/* ── 表紙 ───────────────────────── */
.title { position: absolute; inset: 0; z-index: 50; color: #fff; overflow: hidden; }
.title-bg {
  position: absolute;
  inset: 0;
  background: url("../assets/img/bg-lighthouse.webp") center 40% / cover;
  animation: drift 18s var(--ease-out) forwards;
}
.title-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(10, 18, 40, 0) 30%, rgba(10, 18, 40, 0.55) 55%, rgba(10, 18, 40, 0.92) 85%);
}
.beam {
  position: absolute;
  z-index: 1;
  width: 0;
  height: 0;
  pointer-events: none;
}
.beam::before, .beam::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  translate: -50% -50%;
  border-radius: 50%;
}
.beam::before { width: 70px; height: 70px; background: radial-gradient(circle, rgba(255, 244, 200, 0.95) 0%, rgba(255, 214, 107, 0.45) 35%, rgba(255, 214, 107, 0) 70%); animation: glow 2.4s ease-in-out infinite alternate; }
.beam::after {
  width: 900px;
  height: 900px;
  background: conic-gradient(from 0deg, rgba(255, 236, 170, 0.32) 0deg, rgba(255, 236, 170, 0) 16deg, rgba(255, 236, 170, 0) 344deg, rgba(255, 236, 170, 0.32) 360deg);
  -webkit-mask: radial-gradient(circle, #000 0%, #000 30%, transparent 70%);
  mask: radial-gradient(circle, #000 0%, #000 30%, transparent 70%);
  animation: sweep 7s linear infinite;
}
@keyframes glow { from { scale: 0.85; opacity: 0.8; } to { scale: 1.1; opacity: 1; } }
@keyframes sweep { from { rotate: 0deg; } to { rotate: 360deg; } }

.title-body {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 24px 22px calc(26px + env(safe-area-inset-bottom));
}
.title-body > * { animation: rise 0.8s var(--ease-out) both; }
.title-body > :nth-child(2) { animation-delay: 0.12s; }
.title-body > :nth-child(3) { animation-delay: 0.24s; }
.title-body > :nth-child(4) { animation-delay: 0.32s; }
.title-body > :nth-child(5) { animation-delay: 0.4s; }
.title-body > :nth-child(6) { animation-delay: 0.48s; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
.title-kicker { display: inline-block; margin: 0; padding: 6px 14px; border-radius: 999px; background: var(--orange); font-weight: 900; font-size: 16px; letter-spacing: 0.04em; }
.title-name { margin: 12px 0 10px; font-weight: 900; font-size: clamp(46px, 15vw, 66px); line-height: 1.08; letter-spacing: 0.02em; text-shadow: 0 4px 24px rgba(0, 0, 0, 0.45); }
.title-lead { margin: 0 0 18px; font-size: 17px; font-weight: 700; line-height: 1.8; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5); }
.title-lead strong { color: #ffd66b; font-weight: 900; }
.title-friend { margin: 0 0 14px; padding: 10px 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.14); font-weight: 700; font-size: 17px; line-height: 1.6; }
.btn-primary { display: block; width: 100%; min-height: 62px; background: var(--orange); color: #fff; text-align: center; font-size: 21px; letter-spacing: 0.06em; border-color: #fff; box-shadow: 0 5px 0 #8a3a07; }
.btn-primary:active:not(:disabled) { box-shadow: 0 1px 0 #8a3a07; }
.title-note { margin: 12px 0 0; text-align: center; font-size: 17px; font-weight: 700; opacity: 0.85; }

/* ── 結果 ───────────────────────── */
.result { position: absolute; inset: 0; z-index: 60; overflow-y: auto; overscroll-behavior: contain; background: var(--paper); }
.res-hero {
  position: relative;
  padding: calc(env(safe-area-inset-top) + 28px) 20px 30px;
  color: #fff;
  text-align: center;
  background: linear-gradient(180deg, rgba(14, 22, 48, 0.55), rgba(14, 22, 48, 0.88)), url("../assets/img/bg-lighthouse.webp") center 30% / cover;
}
.res-kicker { margin: 0; font-size: 17px; font-weight: 700; opacity: 0.9; }
.res-code { margin: 10px 0 2px; font-size: 64px; font-weight: 900; letter-spacing: 0.08em; line-height: 1.1; }
.res-code span { display: inline-block; animation: letterIn 0.7s var(--ease-pop) calc(0.25s + var(--i) * 0.12s) both; }
@keyframes letterIn { from { opacity: 0; transform: translateY(16px) scale(0.6); filter: blur(8px); } to { opacity: 1; transform: none; filter: none; } }
.res-name { margin: 4px 0 6px; font-size: 32px; font-weight: 900; line-height: 1.3; animation: rise 0.8s var(--ease-out) 0.85s both; }
.res-catch { margin: 0; font-size: 18px; font-weight: 700; color: #ffe39a; animation: rise 0.8s var(--ease-out) 1s both; }
.res-hero[data-group="teal"] .res-code { color: #7fe3d5; }
.res-hero[data-group="orange"] .res-code { color: #ffbe86; }
.res-hero[data-group="blue"] .res-code { color: #a9c6ff; }
.res-hero[data-group="purple"] .res-code { color: #d2b6ff; }

.res-sec { padding: 26px 20px 4px; }
.res-sec h2 { display: inline; margin: 0; font-size: 22px; font-weight: 900; line-height: 1.5; background: linear-gradient(transparent 62%, #ffd66b 62%); }
.res-sec h2 + * { margin-top: 16px; }
.res-desc { font-size: 17px; font-weight: 700; line-height: 1.85; margin: 16px 0 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.chips li { padding: 6px 14px; border-radius: 999px; background: var(--sand); font-weight: 900; font-size: 16px; }

.axis { margin: 18px 0 0; }
.axis-head { display: flex; justify-content: space-between; gap: 10px; font-size: 16px; font-weight: 700; color: var(--ink-soft); }
.axis-head .win { color: var(--c); font-weight: 900; }
.axis-track { position: relative; height: 16px; margin-top: 8px; border-radius: 99px; background: #ebe3d3; overflow: hidden; }
.axis-fill { position: absolute; top: 0; bottom: 0; width: calc(var(--p) * 1%); background: var(--c); border-radius: 99px; transform: scaleX(0); animation: fill 1s var(--ease-out) calc(1.1s + var(--i) * 0.12s) forwards; }
.axis-fill.a { left: 0; transform-origin: 0 50%; }
.axis-fill.b { right: 0; transform-origin: 100% 50%; }
@keyframes fill { to { transform: scaleX(1); } }
.axis-pct { margin-top: 6px; font-size: 17px; font-weight: 900; color: var(--c); }
.axis-pct.b { text-align: right; }
[data-c="teal"] { --c: var(--teal); }
[data-c="orange"] { --c: var(--orange); }
[data-c="blue"] { --c: var(--blue); }
[data-c="purple"] { --c: var(--purple); }

.reasons { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.reasons li { padding: 12px 14px; border-radius: 14px; background: #fff; border: 2px solid #ebe3d3; font-size: 17px; font-weight: 700; line-height: 1.65; }
.reasons .to { display: inline-block; margin-top: 4px; padding: 2px 10px; border-radius: 999px; background: var(--c); color: #fff; font-size: 16px; font-weight: 900; }

.res-actions { display: grid; gap: 12px; padding: 26px 20px 8px; }
.res-actions .btn { text-align: center; }
.btn-share { background: var(--orange); color: #fff; }
.btn-ghost { background: var(--paper); }
.link-box { width: 100%; min-height: 52px; padding: 10px 14px; border: 2.5px solid var(--ink); border-radius: 14px; background: #fff; color: var(--ink); font: 700 17px/1.4 inherit; font-family: inherit; }
.card-preview { display: none; margin: 4px 20px 0; }
.card-preview.on { display: block; animation: rise 0.6s var(--ease-out); }
.card-preview img { display: block; width: 100%; border-radius: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); }
.card-preview p { margin: 10px 0 0; font-size: 17px; font-weight: 700; color: var(--ink-soft); text-align: center; }

.compare { margin: 0; display: grid; gap: 10px; }
.compare-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 14px; background: #fff; border: 2px solid #ebe3d3; font-weight: 900; font-size: 17px; text-align: center; }
.compare-row .mid { font-size: 16px; color: var(--ink-soft); }
.compare-row.same { border-color: var(--teal); }
.compare-sum { font-size: 18px; font-weight: 900; margin: 0; }

.res-note { margin: 20px 20px 0; padding: 14px 16px; border-radius: 14px; background: #f1ece2; color: var(--ink-soft); font-size: 17px; font-weight: 700; line-height: 1.7; }
.res-foot { height: calc(40px + env(safe-area-inset-bottom)); }

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  translate: -50% 0;
  width: max-content; /* left:50% のままだと画面の半分の幅で折り返すため */
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--ink);
  color: #fff;
  font-weight: 900;
  font-size: 17px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s var(--ease-out);
  pointer-events: none;
}
.toast.on { opacity: 1; transform: none; }
