:root {
  --bg-deep: #070e0b;
  --bg-card: rgba(15, 29, 23, 0.94);
  --border-subtle: rgba(255, 255, 255, 0.12);
  --text-main: #f3f7f4;
  --text-muted: #9eb3a8;
  --gold: #f5c542;
  --gold-soft: rgba(245, 197, 66, 0.16);
  --emerald: #10b981;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 0%, #132c21 0%, var(--bg-deep) 68%);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  line-height: 1.35;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding: 6px 10px 8px;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.app-shell.shake { animation: shakeScreen 0.30s ease-in-out; }
@keyframes shakeScreen {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-5px, 3px); }
  40% { transform: translate(5px, -3px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(4px, 2px); }
}

/* 覚醒RUSH背景炎上 */
.app-shell.is-rush {
  background: radial-gradient(circle at 50% 25%, rgba(220, 38, 38, 0.28) 0%, rgba(245, 158, 11, 0.10) 45%, transparent 75%);
}

.top-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border-subtle);
}
.brand-mini { font-size: 13px; font-weight: 800; color: var(--gold); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  min-height: 28px;
  white-space: nowrap;
  flex-shrink: 0;
}
.icon-btn.is-off { opacity: 0.55; }

/* 共通スクリーン */
.screen {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  padding-top: 6px;
}
.screen.active { display: flex; animation: fadeSlideIn 0.14s ease-out; }
@keyframes fadeSlideIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.screen-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 6px;
}

/* 画面② プレイ画面：4ブロック完全固定比率 (19% / 21% / 47% / 13%) */
#screen-play.active {
  display: grid;
  grid-template-rows: minmax(0, 19%) minmax(0, 21%) minmax(0, 47%) minmax(0, 13%);
  grid-template-columns: 100%;
  gap: 0;
  padding-top: 5px;
  overflow: hidden;
}

/* タイトル画面 */
.hero-box {
  text-align: center;
  padding: 11px 12px;
  border-radius: 14px;
  background: linear-gradient(160deg, rgba(245, 197, 66, 0.14), rgba(16, 185, 129, 0.08));
  border: 1px solid rgba(245, 197, 66, 0.35);
  margin-bottom: 8px;
}
.hero-badge { display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: 0.1em; color: var(--gold); background: rgba(0,0,0,0.45); padding: 2px 9px; border-radius: 999px; margin-bottom: 3px; }
.hero-title { margin: 0; font-size: 21px; font-weight: 900; }
.hero-copy { margin: 3px 0 0; font-size: 11px; color: #d6e4dc; }

.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}
.field-label { display: block; font-size: 11px; font-weight: 700; color: var(--text-muted); margin-bottom: 3px; }
.name-row { display: flex; gap: 8px; }
.text-input {
  flex: 1; min-width: 0; height: 40px; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2); background: rgba(0, 0, 0, 0.42);
  color: #fff; font-size: 14px; font-weight: 700; padding: 0 10px;
}
.sub-btn {
  height: 40px; padding: 0 11px; border-radius: 10px;
  border: 1px solid rgba(245, 197, 66, 0.45); background: var(--gold-soft);
  color: var(--gold); font-size: 12px; font-weight: 800; cursor: pointer;
  white-space: nowrap;
}
.seg-group { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.seg-group.cols-4 { grid-template-columns: repeat(4, 1fr); }
.seg-btn {
  height: 38px; border-radius: 9px; border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.05); color: var(--text-muted);
  font-size: 12px; font-weight: 800; cursor: pointer;
}
.seg-btn.selected { background: linear-gradient(135deg, rgba(245, 197, 66, 0.25), rgba(16, 185, 129, 0.22)); border-color: var(--gold); color: #fff; }
.style-desc { margin-top: 2px; font-size: 10.5px; color: var(--text-muted); }

/* 親指固定・メインCTAエリア（常に最下部・54px完全固定） */
.sticky-bottom-cta {
  flex: 0 0 auto;
  padding-top: 6px;
  z-index: 50;
}
.bottom-block {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sticky-bottom-cta.play-cta {
  width: 100%;
  padding-top: 0;
}

.cta-btn-row {
  display: flex;
  gap: 8px;
  width: 100%;
  height: 54px;
  min-height: 54px;
  max-height: 54px;
}
.tap-main-btn {
  flex: 1;
  width: 100%;
  height: 54px;
  min-height: 54px;
  border: none;
  border-radius: 15px;
  background: linear-gradient(135deg, #f5c542 0%, #e08e1b 100%);
  color: #161003;
  font-size: 15.5px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 18px rgba(245, 197, 66, 0.34);
  transition: transform 0.07s ease;
  padding: 4px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
  overflow: hidden;
  white-space: nowrap;
}
.tap-main-btn:active { transform: scale(0.96); }
.tap-main-btn.is-locked {
  opacity: 0.45;
  pointer-events: none;
  box-shadow: none;
}
.tap-main-btn.is-race { background: linear-gradient(135deg, #fb7185 0%, #e11d48 100%); color: #fff; box-shadow: 0 5px 18px rgba(225, 29, 72, 0.38); }
.tap-main-btn.is-judge { background: linear-gradient(135deg, #34d399 0%, #059669 100%); color: #fff; box-shadow: 0 5px 18px rgba(16, 185, 129, 0.36); }
.tap-main-btn.is-loop1 { background: linear-gradient(135deg, #34d399 0%, #ef4444 100%); color: #fff; box-shadow: 0 5px 18px rgba(239, 68, 68, 0.42); }
.tap-main-btn.is-loop2 { background: linear-gradient(135deg, #f59e0b 0%, #dc2626 100%); color: #fff; box-shadow: 0 5px 22px rgba(245, 158, 11, 0.55); }
.tap-main-btn.is-loop3 { background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 50%, #38bdf8 100%); color: #fff; box-shadow: 0 5px 24px rgba(168, 85, 247, 0.65); }
.tap-main-btn.is-alt {
  background: linear-gradient(135deg, #38bdf8 0%, #0284c7 100%);
  color: #fff;
  box-shadow: 0 5px 16px rgba(2, 132, 199, 0.34);
}
.cta-btn-row.is-split .tap-main-btn { padding: 3px 6px; }
.btn-split-tag { font-size: 9.5px; font-weight: 900; opacity: 0.92; letter-spacing: 0.03em; white-space: nowrap; }
.btn-split-name { font-size: 12.5px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.secondary-btn {
  width: 100%; height: 48px; min-height: 48px; border-radius: 12px;
  border: 1px solid var(--border-subtle); background: rgba(255, 255, 255, 0.08);
  color: var(--text-main); font-size: 13.5px; font-weight: 800; cursor: pointer;
}

/* =====================================================
   Block 1 (19%): ステータスブロック（継続判定・クラス非表示）
   ===================================================== */
.sticky-hud.block-hud {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: rgba(11, 23, 18, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 5px 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.hud-row1 { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.hud-title-wrap { display: flex; align-items: center; gap: 5px; min-width: 0; }
.hud-name { font-size: 13.5px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-agesex { font-size: 10.5px; font-weight: 700; color: var(--text-muted); white-space: nowrap; }
.hud-ovr-pill {
  font-size: 10px; font-weight: 900; padding: 1px 8px; border-radius: 999px;
  background: rgba(245, 197, 66, 0.16); border: 1px solid rgba(245, 197, 66, 0.45);
  color: var(--gold); white-space: nowrap;
}
.hud-row2 { display: flex; justify-content: space-between; font-size: 10.5px; font-weight: 700; color: #d6e4dc; }
.hud-prize { color: var(--gold); font-weight: 900; }

.stats-grid-6 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.stat-cell { background: rgba(0, 0, 0, 0.36); border-radius: 5px; padding: 2px 5px; }
.stat-cell-head { display: flex; justify-content: space-between; font-size: 9.5px; color: var(--text-muted); margin-bottom: 1px; }
.stat-cell-head strong { color: #fff; font-size: 9.5px; }
.stat-track { height: 4px; background: rgba(255, 255, 255, 0.12); border-radius: 999px; overflow: hidden; }
.stat-fill { height: 100%; border-radius: 999px; transition: width 0.22s ease; }

/* =====================================================
   Block 2 (21%): スケジュールブロック（上段:調教/3戦表 + 下段:バフ領域）
   ===================================================== */
.schedule-block {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 5px 0 4px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
}
.schedule-top {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.schedule-pane {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
}

/* 調教スケジュール（練習3セルのみ） */
.career-timeline {
  display: flex;
  gap: 5px;
  width: 100%;
  overflow: hidden;
}
.tl-season {
  flex: 1 1 0;
  min-width: 0;
  background: rgba(9, 19, 15, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 9px;
  padding: 5px 5px 6px;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.tl-season.is-active {
  border-color: var(--gold);
  background: rgba(245, 197, 66, 0.08);
  box-shadow: 0 0 10px rgba(245, 197, 66, 0.16);
}
.tl-season.is-done { border-color: rgba(52, 211, 153, 0.35); }
.tl-season.is-newly-added { animation: seasonPop 0.35s ease-out; }
@keyframes seasonPop {
  from { opacity: 0; transform: translateX(10px) scale(0.95); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
.tl-season-lbl {
  font-size: 10px; font-weight: 900; color: var(--text-muted);
  text-align: center; margin-bottom: 4px; white-space: nowrap; overflow: hidden;
}
.tl-season.is-active .tl-season-lbl { color: var(--gold); }
.tl-season.is-done .tl-season-lbl { color: #34d399; }

.tl-cells {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
}
.tl-cell {
  height: 22px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 900;
  color: rgba(255, 255, 255, 0.48);
  line-height: 1;
}
.tl-cell.is-now {
  border-color: #fff;
  color: #fff;
  box-shadow: 0 0 8px rgba(245, 197, 66, 0.8);
  animation: cellPulse 0.85s infinite alternate;
}
@keyframes cellPulse { from { transform: scale(1); } to { transform: scale(1.06); } }
.tl-cell.t-blue { background: rgba(59, 130, 246, 0.45); border-color: #60a5fa; color: #dbeafe; }
.tl-cell.t-green { background: rgba(16, 185, 129, 0.46); border-color: #34d399; color: #d1fae5; }
.tl-cell.t-red { background: rgba(239, 68, 68, 0.52); border-color: #fb7185; color: #ffe4e6; }
.tl-cell.t-gold { background: linear-gradient(135deg, #f5c542, #d97706); border-color: #fde68a; color: #1a1002; }
.tl-cell.t-rainbow {
  background: linear-gradient(135deg, #ec4899, #f59e0b, #10b981, #3b82f6);
  border-color: #fff; color: #fff;
  box-shadow: 0 0 8px rgba(236, 72, 153, 0.55);
}
.tl-cell.is-looped {
  font-size: 8.5px;
  font-weight: 900;
  box-shadow: 0 0 9px rgba(245, 197, 66, 0.72);
  border-width: 1.5px;
}

/* 4半期/5半期/6〜7半期 自動縮小 */
.career-timeline.compact-45 { gap: 4px; }
.career-timeline.compact-45 .tl-season { padding: 4px 3px 5px; border-radius: 7px; }
.career-timeline.compact-45 .tl-season-lbl { font-size: 8.5px; margin-bottom: 3px; }
.career-timeline.compact-45 .tl-cells { gap: 2px; }
.career-timeline.compact-45 .tl-cell { height: 19px; font-size: 8px; border-radius: 4px; }

.career-timeline.compact-67 { gap: 3px; }
.career-timeline.compact-67 .tl-season { padding: 3px 2px 4px; border-radius: 6px; }
.career-timeline.compact-67 .tl-season-lbl { font-size: 7.5px; letter-spacing: -0.05em; margin-bottom: 3px; }
.career-timeline.compact-67 .tl-cells { gap: 1.5px; }
.career-timeline.compact-67 .tl-cell { height: 17px; font-size: 7px; border-radius: 3px; }

/* 3戦固定の縦型レーススケジュール（[戦数] [レース名] [結果]） */
.race-schedule-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.rs-row {
  display: grid;
  grid-template-columns: 44px 1fr 56px;
  align-items: center;
  gap: 6px;
  height: 25px;
  padding: 0 8px;
  border-radius: 7px;
  background: rgba(9, 19, 15, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.rs-row.is-current {
  border-color: var(--gold);
  background: rgba(245, 197, 66, 0.10);
}
.rs-row.is-tbd {
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.02);
}
.rs-row.is-choice {
  border-color: #fb7185;
  background: rgba(225, 29, 72, 0.12);
}
.rs-slot { font-size: 10px; font-weight: 800; color: var(--text-muted); white-space: nowrap; }
.rs-name { font-size: 11px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rs-name.g-g1 { color: #fde047; }
.rs-name.g-g2 { color: #fb7185; }
.rs-name.g-g3 { color: #4ade80; }
.rs-name.g-op { color: #38bdf8; }
.rs-name.g-low { color: #e2e8f0; }
.rs-name.g-tbd { color: rgba(255, 255, 255, 0.42); font-weight: 700; }

.rs-res {
  justify-self: end;
  font-size: 10px;
  font-weight: 900;
  padding: 1px 7px;
  border-radius: 999px;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}
.rs-res.rk-1 { background: linear-gradient(135deg, #fde047, #d97706); color: #161003; }
.rs-res.rk-2 { background: linear-gradient(135deg, #f1f5f9, #94a3b8); color: #0f172a; }
.rs-res.rk-3 { background: linear-gradient(135deg, #fdba74, #b45309); color: #1c0f02; }
.rs-res.rk-out { background: rgba(100, 116, 139, 0.35); color: #cbd5e1; }
.rs-res.rk-next { background: rgba(251, 113, 133, 0.22); color: #fda4af; border: 1px solid rgba(251, 113, 133, 0.45); }

/* 下段：特殊状態・成長期ループ・イベントバフ領域 */
.buff-strip {
  flex: 0 0 22px;
  height: 22px;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.buff-strip::-webkit-scrollbar { display: none; }
.buff-empty { font-size: 10px; font-weight: 700; color: rgba(158, 179, 168, 0.55); white-space: nowrap; }
.buff-pill {
  flex: 0 0 auto;
  font-size: 9.5px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  background: rgba(56, 189, 248, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #bae6fd;
}
.buff-pill.t-loop1 {
  background: linear-gradient(90deg, #059669, #e11d48);
  border-color: #fda4af; color: #fff;
  box-shadow: 0 0 8px rgba(225, 29, 72, 0.5);
}
.buff-pill.t-loop2 {
  background: linear-gradient(90deg, #d97706, #dc2626);
  border-color: #fde047; color: #fff;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.65);
}
.buff-pill.t-loop3 {
  background: linear-gradient(90deg, #ec4899, #8b5cf6, #38bdf8);
  border-color: #ffffff; color: #fff;
  box-shadow: 0 0 12px rgba(236, 72, 153, 0.8);
}
.buff-pill.t-trouble,
.buff-pill.t-purple {
  background: rgba(88, 28, 135, 0.55);
  border-color: #a855f7;
  color: #e9d5ff;
}
.buff-pill.t-gold { background: rgba(245, 197, 66, 0.22); border-color: var(--gold); color: #fde047; }
.buff-pill.t-good { background: rgba(16, 185, 129, 0.22); border-color: #34d399; color: #a7f3d0; }
.buff-pill.t-rainbow {
  background: linear-gradient(90deg, rgba(236,72,153,0.38), rgba(56,189,248,0.38));
  border-color: #fff; color: #fff;
}

/* =====================================================
   Block 3 (47%): 画面ブロック（100%フィット・ズレ0px）
   ===================================================== */
.stage-block {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 4px;
}
.stage-view {
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* 調教Canvas＋2×3ステUP */
.train-canvas-wrap,
.train-result-panel {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: rgba(8, 16, 12, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 13px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 5px;
}

.train-canvas-box {
  flex: 1;
  min-height: 0;
  position: relative;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
}
#train-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.train-menu-pill {
  position: absolute;
  left: 6px;
  bottom: 6px;
  font-size: 10px;
  font-weight: 900;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #f8fafc;
}
.train-loop-pill {
  position: absolute;
  right: 6px;
  top: 6px;
  font-size: 11px;
  font-weight: 900;
  padding: 3px 10px;
  border-radius: 999px;
  color: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,0.6);
}
.train-loop-pill.s1 { background: linear-gradient(90deg, #059669, #e11d48); border: 1px solid #fda4af; }
.train-loop-pill.s2 { background: linear-gradient(90deg, #d97706, #dc2626); border: 1px solid #fde047; }
.train-loop-pill.s3 { background: linear-gradient(90deg, #ec4899, #8b5cf6, #38bdf8); border: 1px solid #fff; }

/* 2×3 ステータス変動グリッド（調教・イベント完全共通＆規則色） */
.tr-banner {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.tr-banner.tier-blue { border-color: #60a5fa; background: rgba(59, 130, 246, 0.16); }
.tr-banner.tier-green { border-color: #34d399; background: rgba(16, 185, 129, 0.18); }
.tr-banner.tier-red { border-color: #fb7185; background: rgba(239, 68, 68, 0.22); }
.tr-banner.tier-gold { border-color: var(--gold); background: linear-gradient(90deg, rgba(245,197,66,0.28), rgba(217,119,6,0.22)); }
.tr-banner.tier-rainbow { border-color: #fff; background: linear-gradient(90deg, rgba(236,72,153,0.35), rgba(245,197,66,0.3), rgba(56,189,248,0.35)); }

.tr-title { font-size: 13px; font-weight: 900; color: #fff; }
.tr-total { font-size: 14px; font-weight: 900; color: var(--gold); }

.tr-stat-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 5px;
}
.tr-cell {
  border-radius: 9px;
  padding: 4px 5px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.tr-cell.delta-zero {
  opacity: 0.34;
  background: rgba(0, 0, 0, 0.42);
  border-color: rgba(255, 255, 255, 0.06);
}
.tr-cell.delta-zero .tr-cdelta { color: #64748b; }

.tr-cell.delta-lb {
  background: rgba(56, 189, 248, 0.15);
  border-color: #7dd3fc;
}
.tr-cell.delta-lb .tr-cdelta { color: #7dd3fc; }

.tr-cell.delta-gr {
  background: rgba(34, 197, 94, 0.18);
  border-color: #4ade80;
  box-shadow: 0 0 10px rgba(74, 222, 128, 0.28);
  animation: statPop 0.24s ease-out;
}
.tr-cell.delta-gr .tr-cdelta { color: #4ade80; }

.tr-cell.delta-rd {
  background: rgba(244, 63, 94, 0.22);
  border-color: #fb7185;
  box-shadow: 0 0 12px rgba(251, 113, 133, 0.38);
  animation: statPop 0.26s ease-out;
}
.tr-cell.delta-rd .tr-cdelta { color: #fb7185; }

.tr-cell.delta-gd {
  background: linear-gradient(160deg, rgba(245, 197, 66, 0.30), rgba(217, 119, 6, 0.18));
  border-color: #fde047;
  box-shadow: 0 0 15px rgba(253, 224, 71, 0.48);
  animation: statPop 0.28s ease-out;
}
.tr-cell.delta-gd .tr-cdelta { color: #fde047; }

.tr-cell.delta-rb {
  background: linear-gradient(155deg, rgba(244,63,94,0.38), rgba(245,197,66,0.32), rgba(52,211,153,0.32), rgba(56,189,248,0.38));
  border-color: #f8fafc;
  box-shadow: 0 0 18px rgba(236, 72, 153, 0.68), 0 0 6px rgba(255, 255, 255, 0.6);
  animation: statPop 0.32s ease-out;
}
.tr-cell.delta-rb .tr-cdelta { color: #ffffff; text-shadow: 0 0 8px rgba(236, 72, 153, 0.9); }

.tr-cell.delta-pu {
  background: rgba(88, 28, 135, 0.34);
  border-color: #a855f7;
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.35);
}
.tr-cell.delta-pu .tr-cdelta { color: #c084fc; }

@keyframes statPop {
  0% { opacity: 0.35; }
  100% { opacity: 1; }
}
.tr-cname { font-size: 10px; font-weight: 800; color: var(--text-muted); }
.tr-cdelta { font-size: 17px; font-weight: 900; line-height: 1.1; margin: 1px 0; }
.tr-cvals { font-size: 9.5px; font-weight: 800; color: #e2e8f0; white-space: nowrap; }

.tr-hint {
  flex: 0 0 auto;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  color: #d6e4dc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tr-hint.h-gold { color: #f5c542; }
.tr-hint.h-red { color: #fb7185; }
.tr-hint.h-green { color: #34d399; }
.tr-hint.h-blue { color: #60a5fa; }

/* Canvasレースステージ */
.race-stage {
  height: 100%;
  min-height: 0;
  background: rgba(8, 16, 12, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 13px;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.race-meta-bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  font-weight: 800;
  gap: 6px;
  min-height: 16px;
}
.race-meta-bar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.race-canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.16);
}
#race-canvas { display: block; width: 100%; height: 100%; object-fit: cover; }
.race-cutin-banner {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
  background: linear-gradient(90deg, #dc2626, #f59e0b); color: #fff; font-size: 12px; font-weight: 900;
  padding: 2px 12px; border-radius: 999px; display: none; white-space: nowrap; z-index: 10;
}
.commentary-box {
  flex: 0 0 38px;
  height: 38px;
  min-height: 38px;
  max-height: 38px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.5); border-radius: 8px;
  padding: 3px 8px; font-size: 11.5px; font-weight: 800; color: #fff;
  display: flex; align-items: center; justify-content: center; text-align: center;
  line-height: 1.25;
}
.commentary-box.is-hot { color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.5); }

.race-result-banner {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 86%;
  max-width: 310px;
  z-index: 12;
  padding: 7px 10px;
  border-radius: 12px;
  background: rgba(5, 11, 8, 0.92);
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  text-align: center;
  pointer-events: none;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
}
.race-result-banner.is-win {
  border-color: var(--gold);
  background: linear-gradient(160deg, rgba(35, 26, 5, 0.94), rgba(10, 32, 22, 0.94));
  box-shadow: 0 0 26px rgba(245, 197, 66, 0.5);
}
.rr-rank { font-size: 19px; font-weight: 900; color: var(--gold); line-height: 1.15; }
.rr-sub { font-size: 11px; color: #e2e8f0; margin-top: 2px; font-weight: 700; }
.rr-growth { margin-top: 3px; font-size: 10.5px; font-weight: 900; color: #34d399; line-height: 1.25; }

/* インラインイベントカード（大見出し＋2×3ステ＋紫Trouble・虹イベント） */
.event-card {
  height: 100%;
  background: linear-gradient(155deg, rgba(16, 36, 28, 0.97), rgba(10, 20, 16, 0.97));
  border: 2px solid #4ade80;
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  box-shadow: 0 0 20px rgba(74, 222, 128, 0.25);
}
.event-card.is-trouble {
  background: linear-gradient(155deg, #3b0764, #1e0938);
  border-color: #a855f7;
  box-shadow: 0 0 26px rgba(168, 85, 247, 0.48);
}
.event-card.is-rainbow {
  background: linear-gradient(155deg, rgba(55, 18, 82, 0.97), rgba(14, 44, 68, 0.97));
  border-color: #fde047;
  box-shadow: 0 0 28px rgba(236, 72, 153, 0.55);
}
.event-title {
  flex: 0 0 auto;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  margin: 0;
  text-align: center;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.65);
}
.event-card.is-trouble .event-title { color: #e9d5ff; }
.event-card.is-rainbow .event-title {
  background: linear-gradient(90deg, #fda4af, #fde047, #6ee7b7, #7dd3fc);
  -webkit-background-clip: text;
  color: transparent;
}
.event-note {
  flex: 0 0 auto;
  text-align: center;
  font-size: 11px;
  font-weight: 900;
  color: var(--gold);
}
.event-card.is-trouble .event-note { color: #c084fc; }

/* =====================================================
   ブラウン管「プツン！」電源OFF暗転アニメーション
   ===================================================== */
.crt-overlay {
  position: fixed;
  inset: 0;
  z-index: 260;
  background: #000000;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: all;
}
.crt-overlay.active { display: flex; }
.crt-beam {
  width: 0;
  height: 0;
  background: #ffffff;
  border-radius: 2px;
  opacity: 0;
}
.crt-overlay.is-snapping .crt-beam {
  animation: crtSnap 0.34s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes crtSnap {
  0%   { width: 100vw; height: 100vh; opacity: 0.92; border-radius: 0; }
  38%  { width: 100vw; height: 4px;   opacity: 1;    border-radius: 2px; box-shadow: 0 0 18px #ffffff; }
  75%  { width: 12px;  height: 12px;  opacity: 1;    border-radius: 50%; box-shadow: 0 0 24px #ffffff; }
  100% { width: 2px;   height: 2px;   opacity: 0;    border-radius: 50%; }
}

/* =====================================================
   暗転割り込み「遊びギミック」4種UI
   ===================================================== */
.gimmick-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(4, 8, 6, 0.93);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 28px 16px 32px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.gimmick-overlay.active { display: flex; }

.gm-top { width: 100%; max-width: 380px; text-align: center; }
.gm-command {
  font-size: 38px;
  font-weight: 900;
  color: #fde047;
  text-shadow: 0 0 24px rgba(245, 197, 66, 0.75);
  margin-bottom: 10px;
  letter-spacing: 0.04em;
}
.gm-timer-track {
  width: 100%;
  height: 10px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  overflow: hidden;
}
.gm-timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #ef4444, #fde047, #34d399);
  border-radius: 999px;
}

.gm-stage {
  flex: 1;
  width: 100%;
  max-width: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.gm-result {
  min-height: 30px;
  font-size: 18px;
  font-weight: 900;
  text-align: center;
}
.gm-result.is-ok { color: #34d399; text-shadow: 0 0 14px rgba(52, 211, 153, 0.7); }
.gm-result.is-ng { color: #fb7185; }

/* 1. PUSH */
.gm-push-btn {
  width: 176px;
  height: 176px;
  border-radius: 50%;
  border: 6px solid #fecaca;
  background: radial-gradient(circle at 35% 30%, #ff6b6b 0%, #dc2626 65%, #7f1d1d 100%);
  box-shadow: 0 0 42px rgba(239, 68, 68, 0.75), inset 0 -10px 18px rgba(0,0,0,0.45);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  animation: pushGlow 0.4s infinite alternate;
}
@keyframes pushGlow {
  from { box-shadow: 0 0 28px rgba(239, 68, 68, 0.65), inset 0 -10px 18px rgba(0,0,0,0.45); }
  to { box-shadow: 0 0 54px rgba(239, 68, 68, 0.98), inset 0 -10px 18px rgba(0,0,0,0.45); }
}
.gm-push-btn.is-pressed { transform: scale(0.92); }
.gm-push-txt { font-size: 32px; font-weight: 900; letter-spacing: 0.06em; text-shadow: 0 3px 6px rgba(0,0,0,0.6); }

/* 2. MASH */
.gm-mash-wrap { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.gm-mash-meter {
  width: 100%; height: 22px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.12); border: 1.5px solid rgba(255, 255, 255, 0.25); overflow: hidden;
}
.gm-mash-fill { height: 100%; transition: width 0.06s linear; border-radius: 999px; background: #3b82f6; }
.gm-mash-fill.t-green { background: #10b981; }
.gm-mash-fill.t-red { background: #ef4444; }
.gm-mash-fill.t-gold { background: linear-gradient(90deg, #f59e0b, #fde047); }
.gm-mash-fill.t-rainbow { background: linear-gradient(90deg, #ec4899, #fde047, #34d399, #38bdf8); }
.gm-mash-tier { font-size: 16px; font-weight: 900; color: #fff; }
.gm-mash-btn {
  width: 170px; height: 130px; border-radius: 22px;
  border: 4px solid #fde047;
  background: linear-gradient(135deg, #f59e0b, #dc2626);
  color: #fff; font-size: 28px; font-weight: 900; cursor: pointer;
  box-shadow: 0 8px 28px rgba(245, 158, 11, 0.55);
  touch-action: none;
}
.gm-mash-btn.is-pop { transform: scale(0.93); }

/* 3. SPIN */
.gm-spin-pad {
  position: relative;
  width: 180px;
  height: 180px;
  touch-action: none;
  cursor: grab;
}
.gm-spin-svg { width: 180px; height: 180px; }
.gm-spin-orb {
  position: absolute;
  width: 30px;
  height: 30px;
  margin: -15px 0 0 -15px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff, #f5c542 55%, #d97706 100%);
  box-shadow: 0 0 18px #f5c542;
  pointer-events: none;
}
.gm-spin-count {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 900;
  color: #fff;
  pointer-events: none;
}

/* 4. ROULETTE */
.gm-roulette-wrap {
  position: relative;
  width: 210px;
  height: 210px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gm-roulette-pin {
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 22px;
  color: #fff;
  text-shadow: 0 0 10px #fde047;
  z-index: 3;
  pointer-events: none;
}
.gm-stop-btn {
  position: absolute;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  z-index: 4;
  touch-action: none;
}

/* 結果カード（保存画像と完全同一の4:5カード表示） */
.result-scroll {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.result-card-wrap {
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px 0;
}
.rc-card-img {
  display: block;
  max-width: 100%;
  max-height: calc(100dvh - 178px);
  width: auto;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: contain;
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.58);
}
.share-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.btn-x { min-height: 46px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.25); background: #0f1419; color: #fff; font-size: 13.5px; font-weight: 800; cursor: pointer; }
.btn-save { min-height: 46px; border-radius: 12px; border: none; background: linear-gradient(135deg, #10b981, #059669); color: #fff; font-size: 13.5px; font-weight: 800; cursor: pointer; }
.optional-banner { display: block; margin-top: 6px; padding: 8px 10px; border-radius: 11px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border-subtle); text-decoration: none; color: var(--text-main); }

/* オーバーレイ & モーダル */
.fx-overlay { position: fixed; inset: 0 0 76px 0; background: rgba(0,0,0,0.88); z-index: 90; display: none; align-items: center; justify-content: center; flex-direction: column; text-align: center; padding: 20px; pointer-events: none; }
.fx-overlay.active { display: flex; }
.fx-title { font-size: 25px; font-weight: 900; color: var(--gold); text-shadow: 0 0 24px rgba(245, 197, 66, 0.85); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.78); z-index: 130; display: none; align-items: center; justify-content: center; padding: 14px; }
.modal-backdrop.active { display: flex; }
.modal-box { width: 100%; max-width: 440px; max-height: 85dvh; overflow-y: auto; background: #102119; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 16px; padding: 16px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 16px; color: var(--gold); }
.modal-close { background: rgba(255, 255, 255, 0.1); border: none; color: #fff; width: 32px; height: 32px; border-radius: 999px; font-size: 15px; cursor: pointer; }
.modal-body { font-size: 12.5px; color: #d6e4dc; }
.modal-body h3 { margin: 10px 0 4px; font-size: 13.5px; color: #fff; }
.modal-body ul { margin: 4px 0 8px; padding-left: 18px; }

/* ?demo */
.demo-fab { position: fixed; right: 12px; top: 44px; z-index: 96; background: #dc2626; color: #fff; border: 2px solid #fff; border-radius: 999px; padding: 5px 10px; font-size: 11px; font-weight: 900; cursor: pointer; }
.demo-section { margin-bottom: 9px; padding-bottom: 8px; border-bottom: 1px solid var(--border-subtle); }
.demo-section-title { font-size: 11px; font-weight: 800; color: var(--gold); margin-bottom: 5px; }
.demo-grid { display: flex; flex-wrap: wrap; gap: 5px; }
.demo-chip { background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); color: #fff; border-radius: 8px; padding: 5px 8px; font-size: 11px; font-weight: 700; cursor: pointer; }
.demo-chip.active { background: #dc2626; border-color: #fff; }
