/* Flutter 版 AI Post に寄せたダーク + グラス調 / Poppins。 */
:root {
  --bg: #121212;
  --accent: #6dccc8; /* アプリ primaryColor */
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.7);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.25);
  --radius-btn: 22px;
  --radius-card: 12px;
  --radius-chip: 20px;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  background: #000;
  color: var(--text);
  font-family: "Poppins", "Noto Sans JP", system-ui, -apple-system, sans-serif;
}

#app {
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen {
  position: relative;
  width: 100%;
  max-width: 460px;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}
@media (min-width: 480px) {
  .screen {
    height: min(100dvh, 820px);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  }
}

/* ---- typography / layout helpers ---- */
.title {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.35;
  letter-spacing: -0.4px;
  margin: 0;
}
.kicker {
  font-size: 0.78rem;
  letter-spacing: 0.22em;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
}
.muted {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.7;
  font-weight: 500;
  margin: 0;
}
.center-text {
  text-align: center;
}
.center {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.pad {
  padding: 32px;
  padding-top: max(32px, env(safe-area-inset-top));
  padding-bottom: max(32px, env(safe-area-inset-bottom));
}
.gap > * + * {
  margin-top: 18px;
}

/* ---- intro + help modal ---- */
.intro-wrap {
  position: relative;
  width: 100%;
  height: 100%;
}
.intro-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.intro-actions {
  width: 100%;
  margin-top: 4px;
}
.intro-actions.gap > * + * {
  margin-top: 12px;
}
.help-modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.help-modal-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(0, 0, 0, 0.72);
  cursor: pointer;
}
.help-modal-sheet {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: min(92%, 720px);
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  border: 1px solid var(--glass-border);
  border-bottom: none;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.help-modal-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 8px;
}
.help-modal-footer {
  flex-shrink: 0;
  padding: 12px 16px max(16px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--glass-border);
  background: var(--bg);
}
.help-modal-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}

/* ---- buttons (Flutter action button 風) ---- */
.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius-btn);
  padding: 0 28px;
  height: 52px;
  line-height: 52px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  transition: transform 0.1s ease, opacity 0.1s ease;
}
.btn:active {
  transform: scale(0.97);
}
.btn.wide {
  width: 100%;
}
.btn.filled {
  background: #fff;
  color: #000;
}
.btn.outline {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.6);
}
.btn:disabled {
  opacity: 0.5;
}
.linklike {
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  text-decoration: underline;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px;
  cursor: pointer;
}

/* ---- spinner ---- */
.spinner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
.gen-screen {
  background: radial-gradient(ellipse at center, rgba(109, 204, 200, 0.1) 0%, var(--bg) 68%);
}
.gen-spinner {
  box-shadow: 0 0 28px rgba(109, 204, 200, 0.22);
}
.gen-msg {
  min-height: 2.8em;
  text-align: center;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---- stage（全画面画像 + 上下グラデ + 下部操作） ---- */
.stage {
  position: relative;
  height: 100%;
  background: #000;
}
.bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.bg.dim {
  opacity: 0.35;
}
#cam-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
/* 上 80px と 下 180px のダークグラデーション（Flutter 版に合わせる） */
.grad {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.5) 0,
    rgba(0, 0, 0, 0) 80px,
    rgba(0, 0, 0, 0) calc(100% - 180px),
    rgba(0, 0, 0, 0.6) 100%
  );
}
.stage-inner {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  transition: padding-bottom 0.32s ease;
}
.stage-inner.has-answer {
  padding-bottom: max(32px, calc(env(safe-area-inset-bottom) + 12px));
}
.stage-inner.center-items {
  align-items: center;
}

/* 結果画面: 画像を長押し（右クリック）で保存できるよう、操作レイヤーは透過しボタンだけ受ける */
.result .stage-inner {
  pointer-events: none;
}
.result .stage-inner .btn,
.result .stage-inner .linklike {
  pointer-events: auto;
}
.hint {
  background: rgba(0, 0, 0, 0.55);
  color: #ffe9a8;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  text-align: center;
}

/* ---- 質問チップ（ガラスの白ピル / 濃色テキスト） ---- */
.top-chip {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  z-index: 2;
  display: flex;
  justify-content: center;
}
.qchip {
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #111;
  font-weight: 800;
  font-size: 1.15rem;
  line-height: 1.2;
  /* 上下非対称: 日本語フォントのメトリクスで上に寄るのを光学的に中央へ補正 */
  padding: 16px 18px 12px;
  border-radius: var(--radius-chip);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  text-align: center;
}

/* ---- 丸ボタン（戻る等） ---- */
.circle-btn {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  cursor: pointer;
}
.circle-btn svg {
  display: block;
}
.circle-btn.top-left {
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
}

/* ---- camera ---- */
.cam-note {
  position: absolute;
  inset: auto 16px 120px 16px;
  z-index: 2;
  background: rgba(0, 0, 0, 0.6);
  padding: 12px;
  border-radius: var(--radius-card);
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}
.shutter {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid #fff;
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  flex-shrink: 0;
}
.shutter:active {
  transform: scale(0.95);
}

/* ---- 回答ドック（CTA 出現時に下端へ寄せる / キーボード追従） ---- */
.choice-dock {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0;
  --choice-keyboard-inset: 0px;
  --choice-dock-lift: 0px;
  transform: translateY(calc((-1 * var(--choice-keyboard-inset)) - var(--choice-dock-lift)));
  transition: transform 0.2s ease;
}
.choice-dock.is-anchored {
  --choice-dock-lift: 10px;
}
.stage-inner.is-keyboard-open {
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

/* ---- 2択カード（横並びのガラスカード） ---- */
.answers-wrap {
  display: grid;
  grid-template-rows: 1fr;
  opacity: 1;
  transition:
    grid-template-rows 0.28s ease,
    opacity 0.22s ease;
}
.answers-wrap.is-collapsed {
  grid-template-rows: 0fr;
  opacity: 0;
  pointer-events: none;
}
.answers-inner {
  min-height: 0;
  overflow: hidden;
}
.answers {
  display: flex;
  gap: 10px;
}
.answer-card {
  flex: 1;
  aspect-ratio: 3 / 2;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px 12px;
  color: #fff;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  background: var(--glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}
.answer-card:active {
  transform: scale(0.98);
}
.answer-card:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.5);
}
.answer-card:disabled {
  opacity: 0.5;
}
.answer-card.is-pulse {
  animation: answer-pulse 0.45s ease;
}
@keyframes answer-pulse {
  0% {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  }
  45% {
    border-color: rgba(109, 204, 200, 0.8);
    box-shadow: 0 0 22px rgba(109, 204, 200, 0.5);
  }
  100% {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  }
}

.choice-divider {
  height: 1px;
  margin-top: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.18);
  transition:
    opacity 0.26s ease,
    max-height 0.26s ease,
    margin-top 0.26s ease;
}
.choice-divider.is-visible {
  margin-top: 12px;
  max-height: 1px;
  opacity: 1;
}

.choice-entry {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 10px;
  transition: margin-top 0.28s ease;
}
.stage-inner.has-answer .choice-entry {
  margin-top: 0;
}
.choice-entry.has-ready-create {
  gap: 10px;
}
.choice-entry.has-ready-create .choice-composer {
  border-color: rgba(109, 204, 200, 0.42);
  box-shadow: 0 4px 22px rgba(109, 204, 200, 0.14);
}
.choice-entry.is-submitting {
  opacity: 0.78;
  transform: scale(0.985);
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.choice-chip-wrap {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  margin-bottom: 0;
  transition:
    max-height 0.26s ease,
    opacity 0.22s ease,
    margin-bottom 0.26s ease;
}
.choice-chip-wrap.is-visible {
  max-height: 40px;
  opacity: 1;
  margin-bottom: 8px;
}
.choice-chip {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  max-width: 100%;
  margin: 0;
  padding: 8px 14px;
  border: 1px solid rgba(109, 204, 200, 0.55);
  border-radius: 999px;
  background: rgba(109, 204, 200, 0.16);
  color: #fff;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.choice-chip:hover:not(:disabled) {
  background: rgba(109, 204, 200, 0.24);
  border-color: rgba(109, 204, 200, 0.75);
}
.choice-chip:active:not(:disabled) {
  transform: scale(0.98);
}

.choice-create-wrap {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}
.choice-create-wrap.is-visible {
  max-height: 72px;
}

.choice-composer {
  padding: 10px 12px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-card);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.25s ease;
}
.choice-composer:focus-within {
  border-color: rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.14);
}
.choice-input {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  resize: none;
  min-height: 48px;
  max-height: 120px;
  background: transparent;
  border: none;
  box-shadow: none;
}
.choice-input::placeholder {
  color: rgba(255, 255, 255, 0.55);
}
.choice-input:focus {
  outline: none;
}

.choice-create {
  display: block;
  width: 100%;
  height: 52px;
  line-height: 52px;
  font-size: 1rem;
  margin: 0 0 4px;
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    transform 0.15s ease,
    opacity 0.15s ease;
}
.choice-create.is-ready {
  background: var(--accent);
  color: #0c1f1e;
  animation:
    create-appear 0.42s ease forwards,
    create-ready-glow 2.2s ease-in-out 0.42s infinite;
}
.choice-create.is-launching {
  pointer-events: none;
  animation: create-launch 0.34s ease forwards;
}
@keyframes create-appear {
  from {
    transform: scale(0.96);
    opacity: 0.5;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes create-ready-glow {
  0%,
  100% {
    box-shadow: 0 4px 18px rgba(109, 204, 200, 0.42);
  }
  50% {
    box-shadow: 0 8px 32px rgba(109, 204, 200, 0.78);
  }
}
@keyframes create-launch {
  to {
    transform: scale(1.02);
    opacity: 0;
    box-shadow: 0 0 36px rgba(109, 204, 200, 0.85);
  }
}

/* ---- Result screen: header meme template (CSS variables) ---- */
.stage.result .bg {
  opacity: 0;
  transform: scale(1.04);
}
.stage.result.is-revealed .bg {
  animation: result-reveal 0.75s ease forwards;
}
.stage.result .result-meme-overlay,
.stage.result .stage-inner {
  opacity: 0;
}
.stage.result.is-revealed .result-meme-overlay,
.stage.result.is-revealed .stage-inner {
  animation: result-ui-reveal 0.55s ease 0.22s forwards;
}
@keyframes result-reveal {
  to {
    opacity: 1;
    transform: scale(1);
  }
}
@keyframes result-ui-reveal {
  to {
    opacity: 1;
  }
}

.stage.result {
  --header-padding-x: 14px;
  --header-padding-top: 24px;
  --header-padding-bottom: 20px;
  --floating-selfie-size: clamp(72px, 20vw, 98px);
  --floating-selfie-offset-y: 18px;
  --header-question-size: clamp(1.04rem, 4.5vw, 1.26rem);
  --header-answer-size: clamp(1.38rem, 6.7vw, 1.78rem);
  --header-text-gap: 10px;
  --brand-badge-height: clamp(36px, 10vw, 44px);
  --brand-badge-icon-size: clamp(22px, 6vw, 26px);
  --brand-badge-font-size: clamp(0.72rem, 2.6vw, 0.82rem);
  --brand-badge-pad-x: 10px;
  --brand-badge-pad-y: 6px;
  --brand-badge-gap: 8px;
  --brand-badge-right: 3.7%;
  --brand-badge-bottom: 3.5%;
}

.result-share-vignette {
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.55) 0,
    rgba(0, 0, 0, 0.2) 120px,
    rgba(0, 0, 0, 0) 45%,
    rgba(0, 0, 0, 0.4) 78%,
    rgba(0, 0, 0, 0.68) 100%
  );
}

.result-meme-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.result-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: block;
  padding-top: max(var(--header-padding-top), env(safe-area-inset-top));
  padding-right: var(--header-padding-x);
  padding-bottom: var(--header-padding-bottom);
  padding-left: var(--header-padding-x);
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.78) 0%,
    rgba(0, 0, 0, 0.5) 72%,
    rgba(0, 0, 0, 0) 100%
  );
  pointer-events: none;
}

.result-floating-selfie {
  position: absolute;
  left: var(--header-padding-x);
  top: calc(100% + var(--floating-selfie-offset-y));
  z-index: 3;
  width: var(--floating-selfie-size);
  height: var(--floating-selfie-size);
  border-radius: clamp(12px, 3vw, 16px);
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  background: rgba(0, 0, 0, 0.2);
}
.result-floating-selfie::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.12);
  pointer-events: none;
}
.result-floating-selfie-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
}

.result-header-copy {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--header-text-gap);
  text-align: left;
}

.result-header-question {
  margin: 0;
  max-width: 100%;
  font-size: var(--header-question-size);
  font-weight: 500;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.88);
}

.result-header-answer {
  margin: 0;
  max-width: 100%;
  font-size: var(--header-answer-size);
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: -0.3px;
  color: #fff;
}

.result-answer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  width: fit-content;
  max-width: 88%;
  text-align: left;
  background: rgba(40, 40, 40, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: var(--radius-card);
  padding: 12px 16px;
}

.result-answer-question {
  margin: 0;
  font-size: clamp(0.98rem, 4vw, 1.14rem);
  font-weight: 500;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.88);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.55);
}

.result-answer-text {
  margin: 0;
  font-size: clamp(1.5rem, 7vw, 2rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.3px;
  color: #fff;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
}

.result-brand-badge {
  position: absolute;
  right: var(--brand-badge-right);
  bottom: var(--brand-badge-bottom);
  min-height: var(--brand-badge-height);
  display: inline-flex;
  align-items: center;
  gap: var(--brand-badge-gap);
  padding: var(--brand-badge-pad-y) var(--brand-badge-pad-x);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.36);
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.result-brand-badge-img {
  display: block;
  width: var(--brand-badge-icon-size);
  height: var(--brand-badge-icon-size);
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.result-brand-badge-label {
  font-size: var(--brand-badge-font-size);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.96);
  line-height: 1;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .choice-create.is-ready,
  .choice-create.is-launching,
  .answer-card.is-pulse,
  .stage.result.is-revealed .bg,
  .stage.result.is-revealed .result-meme-overlay,
  .stage.result.is-revealed .stage-inner {
    animation: none;
  }
  .stage.result .bg,
  .stage.result .result-meme-overlay,
  .stage.result .stage-inner {
    opacity: 1;
    transform: none;
  }
  .choice-create-wrap,
  .choice-divider,
  .answers-wrap,
  .choice-entry,
  .choice-dock,
  .choice-chip-wrap,
  .stage-inner {
    transition: none;
  }
  .choice-create-wrap.is-visible {
    max-height: 72px;
  }
  .choice-divider.is-visible {
    margin-top: 12px;
    max-height: 1px;
    opacity: 1;
  }
  .answers-wrap.is-collapsed {
    grid-template-rows: 0fr;
    opacity: 0;
  }
  .choice-chip-wrap.is-visible {
    max-height: 40px;
    opacity: 1;
    margin-bottom: 8px;
  }
  .choice-dock.is-anchored {
    --choice-dock-lift: 10px;
  }
  .stage-inner.has-answer {
    padding-bottom: max(32px, calc(env(safe-area-inset-bottom) + 12px));
  }
  .choice-entry.is-submitting {
    opacity: 1;
    transform: none;
  }
}
