/* app.css — 「おうち映画館」コンセプト (design.md §7-B)
   劇場の暗がりの温かさ。ダークだが冷たいテックダークではない。
   トークン厳守: bg-0 #14101C / surface #241B2F / accent(電球) #FFC24B /
   coral(こはる) #FF7A88 / screen(文字) #F6EFE4 / muted #8B7FA8 / travel-sora #4FC3D9 */

:root {
  --bg-0: #14101c;
  --surface: #241b2f;
  --surface-2: #2f2440;
  --accent: #ffc24b;
  --coral: #ff7a88;
  --sora: #4fc3d9;
  --screen: #f6efe4;
  --muted: #8b7fa8;
  --theme-accent: var(--accent);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font-heading: "Zen Maru Gothic", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-body: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-count: "DotGothic16", "Zen Maru Gothic", monospace;
}

* {
  box-sizing: border-box;
}

/* display:flex 等の指定より hidden 属性を常に優先 (書き出しUI等の表示制御) */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--screen);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(120% 90% at 50% -10%, #221a2e 0%, var(--bg-0) 55%);
}

/* --- 品質床: フォーカスリング可視 (design.md §7-B B5) --- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
label:focus-within {
  outline: 3px solid var(--theme-accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* --- 品質床: reduced-motion (design.md §7-B B2/B5) --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- オフライン案内 (design.md §7-B B5) --- */
.offline-banner {
  background: var(--surface-2);
  color: var(--screen);
  font-size: 0.82rem;
  line-height: 1.5;
  padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
  text-align: center;
  border-bottom: 1px solid rgba(255, 194, 75, 0.25);
}

.screen {
  display: none;
  flex: 1;
  padding-top: calc(var(--safe-top) + 16px);
  padding-bottom: calc(var(--safe-bottom) + 24px);
}

.screen.active {
  display: flex;
  flex-direction: column;
  animation: fadein 0.25s ease-out;
}

@keyframes fadein {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen-inner {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.center-column {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 18px;
}

/* 下部固定の主ボタン領域 (design.md B1: 親指リーチ) — flexの余白吸収でスクリーン下部に押し付ける */
.screen-footer {
  margin-top: auto;
  padding-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

/* --- ヒーロー: マーキー看板ロゴ --- */
.marquee-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.logo {
  font-family: var(--font-heading);
  font-weight: 900;
  font-size: 2.1rem;
  margin: 0;
  letter-spacing: 0.04em;
  color: var(--screen);
  text-shadow: 0 0 18px rgba(255, 194, 75, 0.35);
}

.marquee-row {
  display: flex;
  gap: 9px;
  justify-content: center;
}

.bulb {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--theme-accent);
  opacity: 0.5;
  box-shadow: 0 0 6px rgba(255, 194, 75, 0.4);
}

@media (prefers-reduced-motion: no-preference) {
  .marquee-row.chase .bulb {
    animation: bulbChase 1.6s ease-in-out infinite;
    animation-delay: calc(var(--i, 0) * 0.12s);
  }
  .marquee-row.lightup .bulb {
    animation: bulbOn 0.45s ease forwards;
    animation-delay: calc(var(--i, 0) * 0.07s);
  }
}

.marquee-row.lightup .bulb {
  opacity: 1;
}

@keyframes bulbChase {
  0%, 100% { opacity: 0.3; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}

@keyframes bulbOn {
  from { opacity: 0.2; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); box-shadow: 0 0 10px rgba(255, 194, 75, 0.75); }
}

.tagline {
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--muted);
  margin: 0;
}

.empty-hint {
  color: var(--coral);
  font-size: 0.95rem;
  margin: 0;
}

.step-title {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.35rem;
  margin: 8px 0 4px;
  color: var(--screen);
}

.step-hint {
  color: var(--muted);
  margin: 0 0 16px;
  font-size: 0.92rem;
}

.privacy-note {
  color: var(--muted);
  font-size: 0.82rem;
  max-width: 360px;
  line-height: 1.6;
  margin: 0;
}

/* --- ボタン共通 (44px+タップ領域、親指リーチを意識し大きめ) --- */
.big-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 60px;
  padding: 14px 28px;
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: var(--radius);
  border: none;
  background: var(--surface-2);
  color: var(--screen);
  cursor: pointer;
  width: 100%;
  max-width: 420px;
  transition: transform 0.08s ease, background 0.15s ease;
}

.big-button:active {
  transform: scale(0.97);
}

.big-button.primary {
  /* テーマアクセントが growth/travel/birthday のどれでも破綻しないよう、
     固定の橙色ではなく screen(白)の低不透明度でグロス感を足すだけにする (トークン外の色を増やさない) */
  background: linear-gradient(180deg, rgba(246, 239, 228, 0.22), rgba(246, 239, 228, 0) 65%), var(--theme-accent);
  color: #241205;
  box-shadow: 0 8px 24px -8px rgba(20, 16, 28, 0.55);
}

.text-button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.92rem;
  min-height: 44px;
  padding: 8px 12px;
  cursor: pointer;
}

.text-button-strong {
  background: var(--surface);
  border: 1px solid rgba(139, 127, 168, 0.35);
  color: var(--screen);
  font-size: 0.95rem;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  flex: 1;
}

.text-button-strong:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chip-button {
  background: var(--surface);
  border: 1px solid rgba(139, 127, 168, 0.35);
  color: var(--screen);
  font-size: 0.85rem;
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}

.btn-back {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.95rem;
  min-height: 44px;
  padding: 8px 4px;
  cursor: pointer;
}

/* --- 劇場の座席シルエット (design.md §7-B: ヒーロー画面の前景) --- */
.cinema-seats {
  position: relative;
  height: 64px;
  margin-top: 8px;
  pointer-events: none;
  background:
    linear-gradient(to bottom, transparent 0%, #0a0713 60%),
    repeating-radial-gradient(circle at 16px -8px, transparent 0 11px, #0a0713 11px 22px);
  background-size: 100% 100%, 32px 32px;
}

/* --- イベントカード --- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  padding-bottom: 24px;
}

.event-card {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  min-height: 44px;
  color: var(--screen);
  display: flex;
  flex-direction: column;
}

.event-card:active {
  border-color: var(--theme-accent);
}

.event-card-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.event-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.event-card-label {
  padding: 8px 10px 12px;
  text-align: left;
}

.event-card-date {
  font-weight: 700;
  font-size: 1rem;
}

.event-card-count {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

/* --- テーマ選択 (チケット風カード) --- */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 8px;
}

.theme-card {
  position: relative;
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 2px solid transparent;
  border-radius: 14px;
  min-height: 110px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  color: var(--screen);
}

.theme-card::before,
.theme-card::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--bg-0);
  transform: translateY(-50%);
}

.theme-card::before { left: -7px; }
.theme-card::after { right: -7px; }

.theme-card[data-theme="growth"] .theme-swatch { background: #ffc24b; }
.theme-card[data-theme="travel"] .theme-swatch { background: #4fc3d9; }
.theme-card[data-theme="birthday"] .theme-swatch { background: #ff7a88; }

.theme-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.15);
}

.theme-card.selected {
  border-color: var(--theme-accent);
  background: linear-gradient(160deg, var(--surface-2), var(--surface-2));
}

.theme-name {
  font-size: 0.92rem;
  font-weight: 700;
}

/* --- つくる確認 --- */
.summary {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px 20px;
  width: 100%;
  max-width: 420px;
}

.summary-line {
  margin: 6px 0;
  font-size: 1rem;
}

.summary-note {
  margin-top: 12px;
  font-size: 0.78rem;
  color: var(--muted);
}

/* --- フィルムリール・カウントダウン (design.md §7-B シグネチャー演出) --- */
.reel-countdown {
  position: relative;
  width: 176px;
  height: 176px;
  margin: 0 auto 4px;
  display: none;
}

@media (prefers-reduced-motion: no-preference) {
  .reel-countdown { display: flex; align-items: center; justify-content: center; }
  #screen-progress .progress-bar { opacity: 0.45; height: 8px; }
}

.reel-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.reel-ring-spokes {
  fill: none;
  stroke: var(--muted);
  stroke-opacity: 0.3;
  stroke-width: 2;
  stroke-dasharray: 4 14;
  animation: reelSpin 7s linear infinite;
  transform-origin: 60px 60px;
}

.reel-ring-progress {
  fill: none;
  stroke: var(--theme-accent);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 0.2s ease;
  filter: drop-shadow(0 0 6px rgba(255, 194, 75, 0.6));
}

@keyframes reelSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.reel-number {
  position: absolute;
  font-family: var(--font-count);
  font-size: 3.4rem;
  color: var(--screen);
  animation: reelFlicker 2.4s ease-in-out infinite;
}

@keyframes reelFlicker {
  0%, 100% { opacity: 1; }
  48% { opacity: 1; }
  50% { opacity: 0.82; }
  52% { opacity: 1; }
  76% { opacity: 0.9; }
}

.progress-caption {
  color: var(--muted);
  margin: 4px 0 14px;
  font-size: 0.95rem;
}

.progress-bar {
  width: 100%;
  max-width: 360px;
  height: 14px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--coral), var(--theme-accent));
  transition: width 0.2s ease;
}

/* --- 人物ラベルUI (design.md §7-B B3) --- */
.person-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 24px;
}

.person-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 14px;
  padding: 10px 14px;
  min-height: 64px;
}

.person-thumb {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  flex: 0 0 auto;
  border: 2px solid rgba(255, 194, 75, 0.35);
}

.person-thumb-fallback {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface-2);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 1.3rem;
}

.person-name-input {
  flex: 1;
  min-height: 44px;
  background: var(--surface-2);
  border: 1px solid rgba(139, 127, 168, 0.35);
  border-radius: 10px;
  color: var(--screen);
  font-size: 1rem;
  padding: 8px 12px;
  font-family: var(--font-body);
}

.person-name-input::placeholder {
  color: var(--muted);
}

/* --- プレビュー画面 --- */
.preview-inner {
  align-items: center;
  gap: 16px;
}

.marquee-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.completion-title {
  margin: 0;
}

.screen-frame {
  width: 100%;
  max-width: 480px;
  padding: 14px 14px 10px;
  background: linear-gradient(180deg, #0d0a13, #050308);
  border-radius: calc(var(--radius) + 8px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 18px 40px rgba(0, 0, 0, 0.55);
}

#preview-canvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  display: block;
}

#preview-canvas.aspect-9x16 {
  max-width: 260px;
  aspect-ratio: 9 / 16;
  margin: 0 auto;
}

#preview-reflection {
  width: 100%;
  display: block;
  margin-top: 4px;
  border-radius: 0 0 10px 10px;
  opacity: 0.9;
  filter: blur(1.5px);
  /* JSが初回フレームでcanvas実寸を設定するまでの間、ブラウザ既定の300x150比率で
     縦に間延びしないよう暫定の縦横比を明示しておく (design.md B1品質床) */
  aspect-ratio: 5 / 1;
}

/* --- みんな度メーター (design.md §7-B B3) --- */
.people-meter {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 16px 14px;
}

.people-meter-title {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
}

.people-meter-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.people-meter-row {
  display: grid;
  grid-template-columns: 4.5em 1fr 3em;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
}

.people-meter-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--screen);
}

.people-meter-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  display: block;
}

.people-meter-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--coral), var(--theme-accent));
  border-radius: 999px;
}

.people-meter-sec {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* --- カット帯・差し替え (design.md §7-B B4) --- */
.cutstrip-wrap {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cutstrip-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cutstrip-title {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
}

.cut-strip,
.alt-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scroll-snap-type: x proximity;
}

.cut-chip {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--surface);
  overflow: hidden;
  padding: 0;
  cursor: pointer;
  scroll-snap-align: start;
}

.cut-chip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cut-chip-badge {
  position: absolute;
  top: 3px;
  left: 3px;
  background: rgba(20, 16, 28, 0.75);
  color: var(--screen);
  font-size: 0.62rem;
  padding: 1px 5px;
  border-radius: 999px;
  z-index: 1;
}

.cut-chip.active {
  border-color: var(--theme-accent);
  box-shadow: 0 0 0 2px rgba(255, 194, 75, 0.3);
}

.cut-chip-title {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.7rem;
}

.alt-row {
  border-top: 1px dashed rgba(139, 127, 168, 0.3);
  padding-top: 10px;
}

.alt-chip {
  border-color: rgba(139, 127, 168, 0.4);
}

/* --- プレビュー操作 --- */
.preview-controls {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 480px;
}

.preview-controls .big-button {
  min-height: 56px;
  font-size: 1rem;
}

.export-row {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 480px;
}

.export-resolution {
  flex: 0 0 auto;
  max-width: 90px;
  text-align: center;
}

.export-progress-wrap {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.export-result {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.export-result-video {
  width: 100%;
  max-width: 480px;
  border-radius: var(--radius);
  background: #000;
  display: block;
}

/* --- トースト --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 24px);
  transform: translate(-50%, 20px);
  background: var(--surface-2);
  color: var(--screen);
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --- 完成の紙吹雪 (design.md §7-B シグネチャー演出、reduced-motionではJS側で発火しない) --- */
#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 200;
}

@media (min-width: 700px) {
  .theme-grid { max-width: 480px; margin-left: auto; margin-right: auto; }
}
