/* ==========================================
   テーマ定義（デフォルト：ライトモード）
   ========================================== */
:root {
  --bg-color: #ffffff;
  --win-color: #fa4204;
  --lose-color: #474545;

  --text-main: #2d3748;
  --text-sub: #fe5b5b;
  --text-id: #646464;

  --badge-bg: rgba(0, 0, 0, 0.08);
  --badge-border: rgba(0, 0, 0, 0.1);
  --badge-color: rgba(0, 0, 0, 0.6);

  --history-panel-bg: rgba(255, 255, 255, 0.6);
  --history-item-color: rgba(0, 0, 0, 0.85);
  --history-item-border: rgba(0, 0, 0, 0.1);
  --history-miss-color: rgba(0, 0, 0, 0.45);

  --roulette-text-color: #ff1100;
  --roulette-text-shadow: rgba(88, 47, 47, 0.6);
  --outer-bg: #e2e8f0; /* PCアクセス時の余白背景色（ライト用） */
}

/* ==========================================
   ダークモード定義（body.theme-dark 指定時）
   ========================================== */
body.theme-dark {
  --bg-color: #4e596f;
  --win-color: #ffb400;
  --lose-color: #ffffff;

  --text-main: #ffffff;
  --text-sub: #cbd5e1;
  --text-id: #94a3b8;

  --badge-bg: rgba(0, 0, 0, 0.35);
  --badge-border: rgba(255, 255, 255, 0.1);
  --badge-color: rgba(255, 255, 255, 0.5);

  --history-panel-bg: rgba(0, 0, 0, 0.4);
  --history-item-color: rgba(255, 255, 255, 0.95);
  --history-item-border: rgba(255, 255, 255, 0.1);
  --history-miss-color: rgba(255, 255, 255, 0.55);

  --roulette-text-color: #ffb400;
  --roulette-text-shadow: rgba(255, 180, 0, 0.6);
  --outer-bg: #1a1a1a; /* PCアクセス時の余白背景色（ダーク用） */
}

* { box-sizing: border-box; }

body {
  color: var(--text-main);
  background-color: var(--outer-bg);
  margin: 0;
  padding: 0;
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", sans-serif;
  user-select: none;
  -webkit-user-select: none;

  /* PC等の画面でも中央にスマホ（縦型）画面を配置 */
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
}

/* 📱 スマホ画面枠（縦型）を中央に作成 */
#stage {
  width: 100vw;
  max-width: 430px; /* スマホ画面幅 */
  height: 100vh;
  max-height: 932px; /* スマホ縦長高さ */
  margin: 0 auto;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  overflow: hidden;

  /* 背景画像の表示領域 */
  background-color: var(--bg-color);
  background-image: url('../assets/bg.jpg');
  background-blend-mode: multiply;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}

/* 背景動画（index.html の CONFIG_BG_VIDEO が true のときだけ生成される）
   #stage（スマホ縦長枠）と同じ大きさ・位置に合わせる */
:root {
  --bg-video-fit: cover;
}
#win-bg-video,
#lose-bg-video {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(100vw, 430px);
  height: min(100vh, 932px);
  object-fit: var(--bg-video-fit);
  object-position: center center;
  z-index: 0;
  pointer-events: none;
  background: #000;
}

/* ステータス別背景画像の切り替え */
body.state-win #stage { background-image: url('../assets/bg_win.jpg'); }
body.state-lose #stage { background-image: url('../assets/bg_lose.jpg'); }
body.state-ready #stage { background-image: url('../assets/bg_ready.jpg'); }
body.state-roulette #stage { background-image: url('../assets/bg_roulette.jpg'); }
body.state-ended #stage { background-image: url('../assets/bg_ended.jpg'); }

/* 動画モード時（html.win-video / html.lose-video） */
html.win-video body.state-win #stage,
html.lose-video body.state-lose #stage {
  background-color: transparent !important;
  background-image: none !important;
}

/* 端末IDバッジ */
#device-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: var(--badge-bg);
  backdrop-filter: blur(4px);
  border: 1px solid var(--badge-border);
  color: var(--badge-color);
  font-family: monospace;
  font-size: 11px;
  padding: 3px 12px;
  border-radius: 12px;
  pointer-events: none;
  letter-spacing: 0.5px;
}

/* スタート画面 */
#start-screen { z-index: 1; }
#start-screen h1 {
  font-size: 24px;
  margin-bottom: 40px;
  text-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

/* ==========================================
   くじ引き画面 & ボタン配置
   ========================================== */
#ready-screen {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 20px;
}

.ready-message {
  font-size: 24px;
  font-weight: 900;
  color: var(--text-main);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  line-height: 1.4;
  margin-top: 100px;
}

/* 「くじを引く」「前回の結果を見る」ボタンの配置（画面下部から全体の約1/4 = 25%） */
#draw-button,
#previous-button {
  position: absolute;
  bottom: 25%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 22px;
  padding: 0.8em 2.5em;
  border-radius: 50px;
  border: none;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  outline: none;
  transition: transform 0.15s;
}

#draw-button {
  background: linear-gradient(135deg, #ff416c, #ff4b2b);
  color: #fff;
  box-shadow: 0 10px 40px rgba(255, 60, 60, 0.5);
}
#draw-button:active {
  transform: translateX(-50%) scale(0.95);
}

#previous-button {
  background: linear-gradient(135deg, #2b8cff, #00c6ff);
  color: #fff;
  box-shadow: 0 10px 40px rgba(0, 140, 255, 0.45);
}
#previous-button:active {
  transform: translateX(-50%) scale(0.95);
}

/* ==========================================
   結果表示画面（#result-screen）
   ========================================== */
#result-screen {
  display: none; /* JS側で display: grid に切り替える */
  z-index: 2;
  position: absolute;
  inset: 0;
  padding: 30px 20px;

  /* 上段・中段・下段の3行構成。中段が常に画面の中央に配置される */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 1fr auto 1fr;
  align-items: center;
  justify-items: center;
  text-align: center;
}
#result-screen.win .result-box { color: var(--win-color); }
#result-screen.lose .result-box { color: var(--lose-color); }

/* 上段：見出し（中段のすぐ上） */
#result-head {
  grid-row: 1;
  align-self: end;
  margin-bottom: 20px;
}

/* 中段：結果（画面垂直中央） */
#result-main {
  grid-row: 2;
  align-self: center;
}

/* 下段：ボタン・ID・補足（中段のすぐ下） */
.result-footer {
  grid-row: 3;
  align-self: start;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 25px;
  min-width: 0;
}

/* くじ引き結果のテキスト装飾 */
.result-box {
  font-size: 42px;
  font-weight: 900;
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", sans-serif;
  letter-spacing: 2px;
  line-height: 1.2;
  word-break: keep-all; 
  animation: pop 0.4s ease-out forwards;
}

.result-sub {
  font-size: 20px;
  font-weight: bold;
  color: var(--text-sub);
}

.result-id {
  font-size: 14px;
  margin-top: 10px;
  font-family: monospace;
  color: var(--text-id);
}

.result-note {
  font-size: 14px;
  margin-top: 12px;
  color: var(--text-id);
  line-height: 1.4;
}

#close-button {
  font-size: 18px;
  padding: 0.6em 2.2em;
  margin-bottom: 5px;
  border-radius: 30px;
  border: none;
  background: #666666;
  color: #ffffff;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s, background-color 0.15s;
  outline: none;
}
#close-button:active {
  transform: scale(0.95);
  background: #555555;
}

@keyframes pop {
  0% { transform: scale(0.3); opacity: 0; }
  70% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ==========================================
   集中線回転アニメーション
   ========================================== */
body.state-win #stage::before {
  content: "";
  position: absolute;
  width: 300vmax;
  height: 300vmax;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 0;
  pointer-events: none;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(255, 242, 0, 0.35) 0deg 12deg,
    rgba(252, 226, 0, 0.15) 12deg 24deg,
    rgba(255, 200, 0, 0.35) 24deg 36deg
  );
  animation: rotate-sunburst 12s linear infinite;
}

@keyframes rotate-sunburst {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

html.win-video body.state-win #stage::before {
  display: none;
}

/* ==========================================
   抽選中画面 & シェイク・フラッシュ
   ========================================== */
#roulette-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
  width: 100%;
  height: 100%;
  position: relative;
}

body.state-roulette #stage {
  will-change: transform;
  animation: stage-shake 0.12s linear infinite;
}
body.state-roulette #stage.tame {
  animation: stage-shake-strong 0.08s linear infinite;
}

@keyframes stage-shake {
  0%   { transform: translate(0, 0) scale(1.04); }
  20%  { transform: translate(-3px, 2px) scale(1.04); }
  40%  { transform: translate(3px, -2px) scale(1.04); }
  60%  { transform: translate(-2px, -3px) scale(1.04); }
  80%  { transform: translate(2px, 3px) scale(1.04); }
  100% { transform: translate(0, 0) scale(1.04); }
}

@keyframes stage-shake-strong {
  0%   { transform: translate(0, 0) scale(1.06); }
  20%  { transform: translate(-7px, 4px) scale(1.06); }
  40%  { transform: translate(7px, -4px) scale(1.06); }
  60%  { transform: translate(-5px, -6px) scale(1.06); }
  80%  { transform: translate(5px, 6px) scale(1.06); }
  100% { transform: translate(0, 0) scale(1.06); }
}

#flash-layer {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 50%, #ffffff 0%, #fffbe0 60%, #fff3b0 100%);
}
#flash-layer.charge {
  animation: flash-charge var(--flash-ms, 2000ms) cubic-bezier(0.5, 0, 0.9, 0.4) forwards;
}
#flash-layer.release {
  opacity: 1;
  animation: flash-release 0.6s ease-out forwards;
}

@keyframes flash-charge {
  0%, 55% { opacity: 0; }
  100%    { opacity: 1; }
}
@keyframes flash-release {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

.roulette-text {
  font-size: 50px;
  font-weight: 900;
  color: var(--roulette-text-color);
  text-shadow: 0 0 20px var(--roulette-text-shadow);
  animation: pulse-shake 0.3s infinite ease-in-out alternate;
}

@keyframes pulse-shake {
  0% { transform: scale(0.95) translate(-2px, 1px); opacity: 0.8; }
  50% { transform: scale(1.05) translate(2px, -1px); opacity: 1; }
  100% { transform: scale(1) translate(-1px, -2px); opacity: 0.9; }
}

#confetti-layer {
  position: absolute; 
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  inset: 0; 
  pointer-events: none; 
  overflow: hidden; 
  display: none;
  z-index: 5;
}
.confetti {
  position: absolute; top: -10px; width: 10px; height: 16px; opacity: 0.9;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.6; }
}

#interaction-shield {
  position: absolute;
  inset: 0;
  background: transparent;
  z-index: 10;
  display: none;
}

#history-panel {
  position: absolute;
  bottom: 15px;
  left: 15px;
  right: 15px;
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--history-panel-bg);
  backdrop-filter: blur(4px);
  border-radius: 16px;
  padding: 8px 12px;
  z-index: 15;
}
#history-panel-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  flex: 0 0 auto;
}

#history-list {
  display: flex;
  flex-direction: row;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-width: 0;
}
#history-list li {
  flex: 0 0 calc((100% - 32px) / 5);
  box-sizing: border-box;
  text-align: center;
  font-size: 12px;
  padding: 4px;
  color: var(--history-item-color);
  border-right: 1px solid var(--history-item-border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#history-list li:last-child {
  border-right: none;
}
#history-list li.win { color: var(--win-color); font-weight: bold; }
#history-list li.miss { color: var(--history-miss-color); }

/* ==========================================
   景品引き換えモーダル（当選時の「もどる」で表示）
   #stage と同じ枠（スマホ縦長）に重ねる。カードは角丸＋淡い影の白系パネル
   ========================================== */
#redeem-modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(100vw, 430px);
  height: min(100vh, 932px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}

.redeem-card {
  width: 100%;
  max-width: 360px;
  padding: 26px 20px 24px;
  border-radius: 24px;
  background: var(--bg-color);
  color: var(--text-main);
  border: 1px solid var(--history-item-border);
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}

.redeem-lead {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-main);
}
.redeem-lead strong { font-weight: 900; }

.redeem-qr {
  width: 210px;
  height: 210px;
  margin: 18px auto 12px;
  background: #ffffff; /* QRは常に白地（ダークテーマでも読み取れるように） */
}
.redeem-qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.redeem-label {
  font-size: 12px;
  color: var(--text-id);
}

/* 引き換え番号：大きく太字、アクセント色 */
.redeem-code {
  margin-top: 2px;
  font-size: 36px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
  color: var(--win-color);
  white-space: nowrap;
}

/* 景品名（等級） */
.redeem-prize {
  margin-top: 14px;
  font-size: 26px;
  font-weight: 900;
  line-height: 1.3;
  color: var(--text-main);
}

#redeem-close {
  margin-top: 20px;
  font-size: 17px;
  padding: 0.6em 2.4em;
  border-radius: 30px;
  border: none;
  background: #666666;
  color: #ffffff;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s, background-color 0.15s;
  outline: none;
}
#redeem-close:active {
  transform: scale(0.95);
  background: #555555;
}
