/* ==========================================================================
   OITEKU /place — 置いていく体験（5つのStage）
   画面ごとに主役を一つ、主要操作を一つ。進捗表示は置かない。
   ========================================================================== */

.page-place {
  overflow-x: hidden;
}

.place {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Stageに応じて背景の明暗をごく緩やかに変える */
.place__backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse 70% 55% at 50% 45%, rgba(23, 35, 45, 0.8), rgba(11, 17, 24, 0) 75%);
  opacity: 0.6;
  transition: opacity 2000ms var(--ease-fade), background-color 2000ms var(--ease-fade);
}

.place[data-stage-current="release"] .place__backdrop {
  background-color: var(--color-bg-deep);
  opacity: 1;
}

.place[data-stage-current="words"] .place__backdrop {
  opacity: 0.9;
}

.place[data-stage-current="end"] .place__backdrop {
  background-color: var(--color-bg-deep);
  opacity: 0.8;
}

/* 終了画面は一定時間後に少し暗くする（自動でトップへは戻さない） */
.place.is-dim .place__backdrop {
  background-color: #080d12;
  opacity: 1;
  transition-duration: 6000ms;
}

.place.is-dim .stage--end {
  opacity: 0.7;
  transition: opacity 6000ms var(--ease-fade);
}

/* ---------- ヘッダー ---------- */

.place__header {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 56px;
  padding: var(--space-2) var(--gutter) 0;
}

.place__close {
  position: absolute;
  right: calc(var(--gutter) - var(--space-3));
  top: 50%;
  transform: translateY(-50%);
  margin-top: calc(var(--space-2) / 2);
}

/* 幅の狭い画面では、ロゴと「静かに閉じる」が重ならないよう左右に分ける */
@media (max-width: 519px) {
  .place__header {
    justify-content: space-between;
    padding-left: var(--space-4);
    padding-right: var(--space-2);
  }

  .place__close {
    position: static;
    transform: none;
    margin-top: 0;
  }
}

/* ---------- メイン ---------- */

.place__main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5) var(--gutter) var(--space-7);
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-5);
  width: 100%;
  text-align: center;
  animation: stage-in var(--motion-slow) var(--ease-soft) both;
}

.stage.is-leaving {
  animation: stage-out var(--motion-base) var(--ease-fade) both;
}

@keyframes stage-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes stage-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.stage__title {
  font-size: var(--text-lg);
  font-weight: 400;
  line-height: 1.6;
  letter-spacing: 0.02em;
}

/* Stage切り替え時にJSでフォーカスを移す見出し（操作対象ではないためリングは出さない） */
.stage__title[tabindex="-1"]:focus,
[data-release-message]:focus {
  outline: none;
}

.stage__note {
  color: var(--color-text-muted);
  font-size: var(--text-base);
  margin-top: calc(var(--space-3) * -1);
}

.stage__actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  margin-top: var(--space-4);
}

/* ---------- Stage 1：感情選択 ---------- */

.emotion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  width: 100%;
  margin-top: var(--space-3);
}

@media (min-width: 768px) {
  .emotion-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.emotion {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  min-height: 56px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-base);
  line-height: 1.5;
  transition:
    background-color var(--motion-base) var(--ease-soft),
    border-color 500ms var(--ease-soft),
    color 500ms var(--ease-soft),
    opacity 450ms var(--ease-fade),
    transform 120ms var(--ease-soft);
  -webkit-tap-highlight-color: transparent;
}

/* 触れた位置から広がる、小さな灯り（位置は JS が --tap-x / --tap-y で渡す） */
.emotion::after {
  content: "";
  position: absolute;
  inset: -40%;
  z-index: -1;
  background: radial-gradient(
    circle at var(--tap-x, 50%) var(--tap-y, 50%),
    rgba(216, 178, 114, 0.30) 0%,
    rgba(216, 178, 114, 0.12) 28%,
    rgba(216, 178, 114, 0) 62%
  );
  opacity: 0;
  transform: scale(0.4);
  transform-origin: var(--tap-x, 50%) var(--tap-y, 50%);
  transition: opacity 650ms var(--ease-soft), transform 900ms var(--ease-soft);
  pointer-events: none;
}

.emotion:hover {
  background: var(--color-surface-hover);
}

.emotion:active {
  transform: scale(0.985);
}

.emotion:focus-visible {
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

/* 選択状態：灯り・琥珀色の境界・文字の温かさで示す（ほかの項目は薄くなる） */
.emotion[aria-pressed="true"] {
  background: #1e2a31;
  border-color: var(--color-light-soft);
  color: #f4eee2;
}

.emotion[aria-pressed="true"]::after {
  opacity: 1;
  transform: scale(1);
}

.emotion-escape {
  margin-top: var(--space-2);
  transition: color 500ms var(--ease-soft), opacity 450ms var(--ease-fade);
}

.emotion-escape[aria-pressed="true"] {
  color: var(--color-light);
  text-decoration: underline;
  text-decoration-color: var(--color-light-soft);
  text-underline-offset: 0.3em;
}

.stage--emotion.is-choosing .emotion:not([aria-pressed="true"]),
.stage--emotion.is-choosing .emotion-escape:not([aria-pressed="true"]) {
  opacity: 0.35;
}

.stage--emotion.is-choosing .stage__note {
  opacity: 0.6;
  transition: opacity 450ms var(--ease-fade);
}

/* ---------- Stage 2：任意入力 ---------- */

.stage--write .assurance {
  margin-top: calc(var(--space-2) * -1);
}

.burden {
  position: relative;
  width: 100%;
  max-width: var(--quote-max);
}

.burden__input {
  display: block;
  width: 100%;
  min-height: 152px;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: rgba(23, 35, 45, 0.72);
  color: var(--color-text);
  font-size: 16px; /* iOSの自動ズームを防ぐため16px以上 */
  line-height: 1.8;
  resize: vertical;
  transition: border-color var(--motion-fast) var(--ease-soft);
}

@media (max-width: 767px) {
  .burden__input { resize: none; }
}

.burden__input::placeholder {
  color: var(--color-text-faint);
}

.burden__input:focus {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
  border-color: var(--color-text-faint);
}

.burden__count {
  position: absolute;
  right: var(--space-3);
  bottom: var(--space-2);
  color: var(--color-text-faint);
  font-size: var(--text-xs);
  pointer-events: none;
}

.burden__count.is-limit {
  color: var(--color-danger);
}

/* ---------- Stage 3：手放す演出 ---------- */

.stage--release {
  position: relative;
  justify-content: center;
  min-height: 320px;
}

.release__message.is-fading {
  opacity: 0;
}

.release__message {
  color: var(--color-text-muted);
  font-size: var(--text-md);
  min-height: 1.8em;
  transition: opacity var(--motion-slow) var(--ease-fade);
}

.release__canvas {
  position: relative;
  width: 100%;
  max-width: var(--quote-max);
  max-height: 44vh;
  overflow: hidden;
  color: var(--color-text);
  font-size: var(--text-base);
  line-height: 1.9;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

.release__canvas.is-long {
  font-size: var(--text-sm);
  -webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent);
  mask-image: linear-gradient(to bottom, #000 70%, transparent);
}

.release__canvas.is-short {
  text-align: center;
}

.release__char {
  display: inline-block;
  white-space: pre;
  will-change: opacity, transform, filter;
}

.release__skip {
  position: fixed;
  right: calc(var(--gutter) - var(--space-3));
  bottom: max(var(--space-4), env(safe-area-inset-bottom));
}

/* ---------- Stage 4：一つの言葉 ---------- */

.words__loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  animation: words-in 900ms var(--ease-soft) both;
  transition: opacity 500ms var(--ease-fade);
}

.words__loading.is-leaving {
  opacity: 0;
}

/* 温かい光の輪をまとった灯りが、ゆっくり呼吸する */
.loading-light {
  position: relative;
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-light);
  box-shadow: 0 0 10px 2px rgba(216, 178, 114, 0.45);
  animation: loading-breathe 4.2s var(--ease-fade) infinite;
}

.loading-light::before {
  content: "";
  position: absolute;
  inset: -34px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(216, 178, 114, 0.22) 0%, rgba(216, 178, 114, 0.08) 38%, rgba(216, 178, 114, 0) 70%);
  animation: loading-halo 4.2s var(--ease-fade) infinite;
}

@keyframes loading-breathe {
  0%, 100% { opacity: 0.7; transform: scale(0.94); }
  50% { opacity: 1; transform: scale(1.04); }
}

@keyframes loading-halo {
  0%, 100% { opacity: 0.55; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.12); }
}

.loading-text {
  display: inline-flex;
  align-items: baseline;
  letter-spacing: 0.06em;
}

/* 三つの点が、ゆっくり灯っては消える */
.loading-dots {
  display: inline-flex;
  gap: 3px;
  margin-left: 4px;
}

.loading-dots span {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--color-light-soft);
  opacity: 0.2;
  animation: loading-dot 2.4s var(--ease-fade) infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.4s; }
.loading-dots span:nth-child(3) { animation-delay: 0.8s; }

@keyframes loading-dot {
  0%, 100% { opacity: 0.2; }
  35% { opacity: 1; }
  70% { opacity: 0.2; }
}

.words__body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  width: 100%;
  animation: words-in var(--motion-breathe) var(--ease-soft) both;
}

@keyframes words-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.words__lead {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.words__lead:focus {
  outline: none;
}

.quote {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  width: 100%;
  max-width: var(--quote-max);
}

.quote__text {
  font-family: var(--font-quote);
  font-size: var(--text-quote);
  font-weight: 400;
  line-height: 1.9;
  letter-spacing: 0.03em;
  text-align: center;
}

/* 一文が長い場合は左揃え */
.quote__text.is-long {
  text-align: left;
}

.quote__caption {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
}

.quote__author {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.quote__attribution {
  color: var(--color-text-faint);
  font-size: var(--text-xs);
}

.words__reflection {
  max-width: 30em;
  color: var(--color-text);
  font-size: var(--text-base);
  line-height: 1.9;
  opacity: 0.92;
}

.quote-source {
  width: 100%;
  max-width: var(--quote-max);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.quote-source summary {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--space-3);
  cursor: pointer;
  list-style: none;
  color: var(--color-text-muted);
}

.quote-source summary::-webkit-details-marker {
  display: none;
}

.quote-source summary:hover {
  text-decoration: underline;
  text-underline-offset: 0.3em;
  text-decoration-color: var(--color-text-faint);
}

.quote-source[open] summary {
  color: var(--color-text);
}

.quote-source__list {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--space-2) var(--space-4);
  margin-top: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-align: left;
}

.quote-source__list dt {
  color: var(--color-text-faint);
  font-size: var(--text-xs);
  line-height: 2;
}

.quote-source__list dd {
  color: var(--color-text-muted);
  line-height: 1.8;
  word-break: break-word;
}

.quote-source__original {
  font-family: var(--font-quote);
}

.words__error {
  color: var(--color-text);
  font-size: var(--text-md);
  line-height: 1.9;
}

.words__error p:focus {
  outline: none;
}

/* ---------- Stage 5：終了 ---------- */

/* ---------- 水滴と波紋（手放す演出のあと、言葉が届く前） ---------- */

.drop-layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.place__header,
.place__main {
  position: relative;
  z-index: 1;
}

.drop {
  position: absolute;
  left: 50%;
  top: 0;
  width: 11px;
  height: 16px;
  fill: #f3efe6;
  filter: drop-shadow(0 0 6px rgba(216, 178, 114, 0.55));
  will-change: transform, opacity;
}

.water {
  position: absolute;
  left: 50%;
  width: 0;
  height: 0;
}

/* ロゴと同じ、平たい楕円の波紋 */
.water__ring {
  position: absolute;
  left: 0;
  top: 0;
  width: min(560px, 92vw);
  aspect-ratio: 4 / 1;
  border: 1.5px solid rgba(215, 223, 220, 0.72);
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.04);
  will-change: transform, opacity;
}

/* 着水した瞬間に、小さな温かい光がにじむ */
.water__glow {
  position: absolute;
  left: 0;
  top: 0;
  width: 120px;
  height: 44px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(216, 178, 114, 0.45) 0%, rgba(216, 178, 114, 0.12) 45%, rgba(216, 178, 114, 0) 72%);
  opacity: 0;
  transform: translate(-50%, -50%);
}

/* ---------- 終了：静かな水面に浮かぶ灯り ---------- */

.end-scene {
  position: relative;
  width: 240px;
  height: 120px;
  margin-bottom: var(--space-4);
}

.end-scene__light {
  position: absolute;
  left: 50%;
  top: 34px;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  border-radius: 50%;
  background: var(--color-light);
  box-shadow: 0 0 12px 3px rgba(216, 178, 114, 0.45);
  animation: end-breathe 6s var(--ease-fade) infinite;
}

/* 灯りをつつむ光の輪（終了画面のみ、最大64px程度） */
.end-scene__halo {
  position: absolute;
  left: 50%;
  top: 42px;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(216, 178, 114, 0.28) 0%, rgba(216, 178, 114, 0.1) 40%, rgba(216, 178, 114, 0) 70%);
  animation: end-halo 6s var(--ease-fade) infinite;
}

/* 水面への映り込み */
.end-scene__reflection {
  position: absolute;
  left: 50%;
  top: 86px;
  width: 70px;
  height: 12px;
  margin-left: -35px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(216, 178, 114, 0.35) 0%, rgba(216, 178, 114, 0) 70%);
  filter: blur(1px);
  animation: end-halo 6s var(--ease-fade) infinite;
}

/* ゆっくり広がっては消える、ロゴのような波紋 */
.end-scene__ring {
  position: absolute;
  left: 50%;
  top: 92px;
  width: 240px;
  height: 36px;
  margin: -18px 0 0 -120px;
  border: 1px solid rgba(215, 223, 220, 0.3);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.2);
  animation: end-ripple 9s var(--ease-soft) infinite;
}

.end-scene__ring:nth-of-type(5) { animation-delay: 3s; }
.end-scene__ring:nth-of-type(6) { animation-delay: 6s; }

@keyframes end-breathe {
  0%, 100% { opacity: 0.8; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1.04); }
}

@keyframes end-halo {
  0%, 100% { opacity: 0.6; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.1); }
}

@keyframes end-ripple {
  0% { opacity: 0; transform: scale(0.2); }
  15% { opacity: 0.7; }
  100% { opacity: 0; transform: scale(1); }
}

/* ---------- 確認（入力中に閉じる場合のみ） ---------- */

.confirm {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
  background: rgba(11, 17, 24, 0.82);
  animation: stage-in var(--motion-base) var(--ease-soft) both;
}

.confirm__panel {
  width: 100%;
  max-width: 420px;
  padding: var(--space-6) var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg);
  text-align: center;
}

.confirm__title {
  font-size: var(--text-md);
  line-height: 1.8;
}

/* ---------- モーション軽減 ---------- */

@media (prefers-reduced-motion: reduce) {
  .end-scene__light,
  .end-scene__halo,
  .end-scene__reflection {
    animation: none;
  }

  .end-scene__ring {
    animation: none;
    opacity: 0.35;
    transform: scale(0.6);
  }

  .end-scene__ring + .end-scene__ring {
    display: none;
  }

  .loading-light,
  .loading-light::before,
  .loading-dots span {
    animation: none;
    opacity: 1;
  }

  .emotion::after {
    transform: none;
    transition: opacity 200ms linear;
  }

  .stage,
  .stage.is-leaving,
  .words__body,
  .confirm {
    animation: none;
  }
  .place__backdrop {
    transition: none;
  }
}
