/* 論理サイズ 1080×1920。--scale・--stage-x・--stage-y（左上）は app.js がウィンドウに合わせて入れる（実ピクセルの整数にそろえる） */
:root { --scale: 1; --stage-x: 0px; --stage-y: 0px; }

html, body {
  touch-action: manipulation; /* スマホでダブルタップの拡大をしない */
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: "Noto Sans CJK JP", "Noto Sans JP", sans-serif;
}

/* ステージ（1080px 幅）がレイアウト上はみ出すと、スマホのブラウザはページの幅を広げてしまうので、
   画面に固定した入れ物で切り取る */
#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #000;
}

#stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1080px;
  height: 1920px;
  transform-origin: 0 0;
  transform: translate(var(--stage-x), var(--stage-y)) scale(var(--scale));
  overflow: hidden;
  background: #000;
}

/* レイヤー1: 背景動画 */
#video-layer, #video-layer video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#video-layer video {
  object-fit: cover;
  opacity: 0;
}

/* 字幕帯: 画面の端から端まで、y と高さは config.subtitle.top・height（app.js が --subtitle-top・--subtitle-height に入れる）。
   既定は画面の下（y 1712〜1908。顔にかからず、拡大したカード 860〜1700 の下）
   帯の高さは3行ぶんで固定（1行でも変えない）。文字は上下中央 */
:root { --subtitle-bg-opacity: 0.55; --subtitle-top: 1712px; --subtitle-height: 196px; }
#subtitle {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--subtitle-top);
  height: var(--subtitle-height);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 48px;
  box-sizing: border-box;
  background: rgba(0, 0, 0, var(--subtitle-bg-opacity));
  color: #fff;
  font-size: 46px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  text-wrap: balance;
  /* 明るい背景（白いシャツ・壁）の上でも読めるように、薄い縁取りと影 */
  text-shadow:
    0 0 3px rgba(0, 0, 0, 0.9),
    0 2px 6px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.2s ease-out;
  z-index: 15;
  pointer-events: none;
}
#subtitle.show {
  opacity: 1;
}
/* BudouX: 文節の間（<wbr>）でだけ折り返す。1文節が1行に収まらないときだけ途中で折る */
#subtitle-text.budoux {
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* 散らばったカード（pick。config.scatter）: 位置と角度は app.js が --x・--y（左上）・--a に入れる。
   中央に重ねて置いてから、--delay ずつずらして散らす（dealMs。着地で少し弾む）。
   当たり判定は .scard そのもの（回っていても見えている形のとおり。重なっていれば上の札）。
   浮かせるのは中の img だけ（当たり判定の形は変えない） */
:root { --scard-w: 220px; --deal-ms: 700ms; --scard-lift: 14px; }
#deck {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}
#deck[hidden] {
  display: none;
}
#deck .scard {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--scard-w);
  aspect-ratio: 2 / 3;
  transform: translate(var(--x), var(--y)) rotate(var(--a));
  transition:
    transform var(--deal-ms) cubic-bezier(0.25, 1.3, 0.5, 1) var(--delay, 0ms),
    opacity var(--card-fade-ms) linear;
  pointer-events: auto;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
#deck .scard img {
  display: block;
  width: 100%;
  height: 100%;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  transition: transform 0.12s ease-out, box-shadow 0.12s ease-out;
  pointer-events: none;
}
/* マウスはホバーで、タッチは押した瞬間（.lift）に浮かせる */
@media (hover: hover) {
  #deck.ready .scard:hover img {
    transform: translateY(calc(-1 * var(--scard-lift))) scale(1.04);
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.6);
  }
}
#deck .scard.lift img {
  transform: translateY(calc(-1 * var(--scard-lift))) scale(1.04);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.6);
}
#deck .scard.gone {
  opacity: 0;
}

/* 拡大してめくるカード（縦横比 2:3）: 選んだ札と同じ位置・角度に置き換えてから、left・top・width と回転（--rot）を
   config.result の位置・0°（逆位置は ±180°）へ動かす（moveMs）。めくりは #card-flip の rotateY（flipMs）。
   出す・消すは opacity（fadeMs） */
:root { --card-move-ms: 500ms; --card-flip-ms: 700ms; --card-fade-ms: 600ms; }
#card {
  position: absolute;
  aspect-ratio: 2 / 3;
  opacity: 0;
  perspective: 2400px;
  transform: rotate(var(--rot, 0deg));
  transition:
    left var(--card-move-ms) ease-in-out,
    top var(--card-move-ms) ease-in-out,
    width var(--card-move-ms) ease-in-out,
    transform var(--card-move-ms) ease-in-out,
    opacity var(--card-fade-ms) linear;
  z-index: 25;
  user-select: none;
  -webkit-user-select: none;
}
#card[hidden] {
  display: none;
}
#card.shown {
  opacity: 1;
}
#card-flip {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--card-flip-ms) ease-in-out;
}
#card.flipped #card-flip {
  transform: rotateY(180deg);
}
/* めくり終わったら（.settled。config.result.wobble）小さく揺らし続ける: rotateY ±--wobble-deg・上下 ±--wobble-px、--wobble-sec で 1 往復。
   止まると Chromium が描き方を変えて表がボケる（order 2026-10-22-004）ので、止まる瞬間を作らない。
   0%・100% はめくり終わりの向き（rotateY(180deg)）にそろえて、切り替わりで跳ばないようにする */
:root { --wobble-deg: 2deg; --wobble-px: 4px; --wobble-sec: 4s; }
@keyframes card-wobble {
  0%, 100% { transform: rotateY(180deg) translateY(0); }
  25% { transform: rotateY(calc(180deg + var(--wobble-deg))) translateY(calc(-1 * var(--wobble-px))); }
  75% { transform: rotateY(calc(180deg - var(--wobble-deg))) translateY(var(--wobble-px)); }
}
#card.settled #card-flip {
  animation: card-wobble var(--wobble-sec) ease-in-out infinite;
}
/* 選んだ札と入れ替えるときは動かさない */
#card.instant, #card.instant #card-flip {
  transition: none;
}
#card .face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}
#card .front {
  transform: rotateY(180deg);
}

/* 開始画面（入口。config.startScreen.enabled）: 初回は読み込みの進み具合、占いが終わるとまたここに戻る */
#start-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 300px;
  box-sizing: border-box;
  background: linear-gradient(to bottom, rgba(10, 6, 18, 0) 0%, rgba(10, 6, 18, 0.35) 40%, rgba(10, 6, 18, 0.85) 75%);
  color: #fff;
  text-align: center;
  z-index: 50;
}
#start-screen[hidden] {
  display: none;
}
#start-screen h1 {
  margin: 0 0 24px;
  font-size: 110px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-shadow: 0 4px 24px rgba(0, 0, 0, 0.7);
}
#start-screen .lead {
  margin: 0 0 64px;
  font-size: 46px;
  line-height: 1.5;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}
/* トップへ戻るリンク（config.startScreen.backLink）: ステージの左上のすみに控えめに。論理 46px の字で、スマホでも指で押せる高さ */
#back-link {
  position: absolute;
  left: 24px;
  top: 24px;
  padding: 40px 48px;
  font-size: 46px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
  -webkit-tap-highlight-color: transparent;
}
#back-link:hover {
  color: #fff;
}
#start-button {
  font: 800 60px/1 "Noto Sans CJK JP", "Noto Sans JP", sans-serif;
  padding: 40px 80px;
  border-radius: 999px;
  border: none;
  background: #e8a33a;
  color: #241a10;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}
#start-button:disabled {
  background: rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.8);
  cursor: default;
}
#start-progress {
  margin: 40px 0 0;
  font-size: 36px;
  color: rgba(255, 255, 255, 0.85);
}

/* 設定メニュー（config.control.enabled のときだけ js/control.js が作る） */
/* 長押しを受ける左上の隅（見えない）。開始画面（z 50）より上（開始画面でも開けるように）、パネル（z 60）より下 */
#ctl-hotspot {
  position: absolute;
  left: 0;
  top: 0;
  width: 120px;
  height: 120px;
  z-index: 55;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
/* 開いている間はステージ全体に被せて、カードなどの操作を受け止める */
#ctl-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
#ctl-overlay[hidden], #ctl-panel [hidden] {
  display: none;
}
#ctl-panel {
  width: 940px;
  padding: 48px 56px 40px;
  box-sizing: border-box;
  border-radius: 32px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-weight: 700;
  text-align: center;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.9), 0 2px 6px rgba(0, 0, 0, 0.6);
  user-select: none;
  -webkit-user-select: none;
}
#ctl-panel h2 {
  margin: 0 0 40px;
  font-size: 56px;
}
#ctl-panel h3 {
  margin: 0 0 20px;
  font-size: 40px;
  color: rgba(255, 255, 255, 0.85);
}
#ctl-panel button {
  font: 700 46px/1 "Noto Sans CJK JP", "Noto Sans JP", sans-serif;
  padding: 30px 0;
  border-radius: 20px;
  border: 3px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
}
#ctl-panel button:hover {
  background: rgba(255, 255, 255, 0.25);
}
#ctl-panel button.current {
  background: #e8a33a;
  border-color: #e8a33a;
  color: #241a10;
  text-shadow: none;
}
#ctl-panel button:disabled {
  opacity: 0.5;
  cursor: default;
}
.ctl-row {
  display: flex;
  gap: 20px;
  margin-bottom: 48px;
}
.ctl-row button {
  flex: 1;
  white-space: nowrap; /* 「縦（下が左）」を 2 行に折らない */
}
#ctl-panel .ctl-row button[data-rotate] {
  font-size: 40px;
}
#ctl-panel .ctl-wide {
  display: block;
  width: 100%;
  margin-top: 20px;
}
.ctl-ask {
  margin: 0 0 40px;
  font-size: 52px;
}
#ctl-message {
  min-height: 1.3em;
  margin: 28px 0 0;
  font-size: 38px;
  color: #ffb4a0;
}
