:root {
  --bg-deep: #0b0d17;
  --bg-card: #15192b;
  --bg-slot: #1c2238;
  --bg-slot-hover: #262e4b;
  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-glow: rgba(100, 210, 255, 0.5);

  --text-main: #f3f6ff;
  --text-muted: #8f9bb8;

  --accent-cyan: #38bdf8;
  --accent-gold: #fbbf24;
  --accent-red: #f43f5e;
  --accent-green: #22c55e;
  --accent-purple: #a855f7;
  --accent-orange: #f97316;

  --rarity-n: #94a3b8;
  --rarity-r: #38bdf8;
  --rarity-sr: #c084fc;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #05060b;
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.app-shell {
  position: relative;
  width: 100%;
  max-width: 460px;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  background: linear-gradient(180deg, #101426 0%, #0b0d17 60%, #090b12 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.bg-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 15%, rgba(56, 189, 248, 0.12), transparent 55%),
    radial-gradient(circle at 80% 75%, rgba(168, 85, 247, 0.1), transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.hidden {
  display: none !important;
}

/* ==================== 画面切り替え ==================== */
.screen {
  position: relative;
  z-index: 1;
  display: none;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 10px 12px 12px;
}

.screen.active {
  display: flex;
}

/* ==================== ボタン共通 ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 14px;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease, opacity 0.15s ease;
  touch-action: manipulation;
  font-family: inherit;
}

.btn:active:not(:disabled) {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.btn-warning {
  background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn-x {
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.btn-xl {
  width: 100%;
  min-height: 58px;
  font-size: 1.2rem;
  border-radius: 18px;
}

.btn-lg {
  min-height: 50px;
  font-size: 1.05rem;
  padding: 0 18px;
}

.btn-sm {
  min-height: 38px;
  font-size: 0.85rem;
  padding: 0 14px;
  border-radius: 10px;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.pulse-btn {
  animation: pulseBtn 2s infinite;
}

@keyframes pulseBtn {
  0%, 100% { box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4); }
  50% { box-shadow: 0 6px 30px rgba(139, 92, 246, 0.75); }
}

/* ==================== タイトル画面 ==================== */
#screen-title {
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.title-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 18px;
}

.title-badge {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  padding: 5px 14px;
  border-radius: 999px;
}

.title-logo {
  margin: 0;
  font-size: 2.15rem;
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: -0.02em;
  text-shadow: 0 4px 24px rgba(56, 189, 248, 0.3);
}

.title-accent {
  background: linear-gradient(90deg, #38bdf8, #fbbf24);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title-sub {
  margin: -10px 0 0;
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  font-weight: 700;
}

.title-preview-slots {
  display: flex;
  gap: 8px;
  margin: 4px 0;
}

.preview-chip {
  width: 48px;
  height: 54px;
  background: var(--bg-slot);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.4);
  animation: floatChip 2.4s ease-in-out infinite;
}

.preview-chip:nth-child(2) { animation-delay: 0.2s; }
.preview-chip:nth-child(3) { animation-delay: 0.4s; }
.preview-chip:nth-child(4) { animation-delay: 0.6s; }
.preview-chip:nth-child(5) { animation-delay: 0.8s; }

@keyframes floatChip {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.title-rules {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: #dbe4ff;
}

.rule-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

/* ==================== ゲーム画面ヘッダー ==================== */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.wave-info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.wave-badge {
  font-size: 0.85rem;
  font-weight: 800;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: var(--accent-cyan);
  padding: 4px 10px;
  border-radius: 8px;
}

.gimmick-badge {
  font-size: 0.7rem;
  font-weight: 700;
  background: rgba(244, 63, 94, 0.18);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fda4af;
  padding: 3px 7px;
  border-radius: 6px;
}

.timer-box {
  display: flex;
  align-items: baseline;
  gap: 3px;
  background: rgba(0, 0, 0, 0.35);
  padding: 3px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
}

.timer-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.timer-value {
  font-size: 1.25rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--accent-gold);
  min-width: 44px;
  text-align: right;
}

.timer-value.urgent {
  color: var(--accent-red);
  animation: timerBlink 0.4s infinite alternate;
}

@keyframes timerBlink {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

.timer-unit {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.timer-bar-wrap {
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin: 6px 0 8px;
  flex-shrink: 0;
}

.timer-bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #f43f5e, #fbbf24, #38bdf8);
  transform-origin: left;
  transition: width 0.05s linear;
}

/* ==================== 敵バトルステージ ==================== */
.battle-stage {
  position: relative;
  flex: 1;
  min-height: 110px;
  background: radial-gradient(circle at 50% 45%, rgba(30, 41, 75, 0.7), rgba(15, 20, 36, 0.9));
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.enemy-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.enemy-name {
  font-size: 0.95rem;
  font-weight: 800;
}

.enemy-trait {
  font-size: 0.72rem;
  color: #fca5a5;
  background: rgba(244, 63, 94, 0.14);
  padding: 2px 8px;
  border-radius: 6px;
}

.enemy-arena {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.enemy-sprite-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.enemy-sprite {
  font-size: 4.2rem;
  line-height: 1;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.6));
  transition: transform 0.06s ease;
}

.enemy-sprite.hit {
  animation: enemyHit 0.14s ease;
  filter: drop-shadow(0 0 18px rgba(255, 255, 255, 0.9)) brightness(1.6);
}

.enemy-sprite.dead {
  animation: enemyDead 0.45s ease forwards;
}

@keyframes enemyHit {
  0% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(-7px, -4px) scale(0.92); }
  50% { transform: translate(7px, 3px) scale(1.04); }
  75% { transform: translate(-4px, 2px) scale(0.96); }
  100% { transform: translate(0, 0) scale(1); }
}

@keyframes enemyDead {
  0% { transform: scale(1) rotate(0deg); opacity: 1; }
  40% { transform: scale(1.2) rotate(-8deg); opacity: 0.9; }
  100% { transform: scale(0.2) rotate(25deg); opacity: 0; }
}

/* ダメージ数値ポップアップ */
.damage-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.dmg-pop {
  position: absolute;
  left: 50%;
  top: 45%;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  white-space: nowrap;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9), 0 0 2px #000;
  animation: dmgFloat 0.68s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

.dmg-pop.dmg-sm {
  font-size: 1.05rem;
  color: #ffffff;
}

.dmg-pop.dmg-md {
  font-size: 1.45rem;
  color: #fde047;
}

.dmg-pop.dmg-lg {
  font-size: 2rem;
  color: #ff3b5c;
  text-shadow: 0 0 14px rgba(255, 59, 92, 0.8), 0 3px 6px #000;
  animation: dmgFloatLg 0.78s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

.dmg-pop.dmg-poison {
  font-size: 1.05rem;
  color: #4ade80;
}

.dmg-pop.dmg-heal {
  font-size: 0.95rem;
  color: #60a5fa;
}

@keyframes dmgFloat {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.6); }
  20% { opacity: 1; transform: translate(calc(-50% + var(--dx, 0px)), -18px) scale(1.15); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), -64px) scale(0.9); }
}

@keyframes dmgFloatLg {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.5); }
  15% { opacity: 1; transform: translate(calc(-50% + var(--dx, 0px)), -24px) scale(1.3); }
  30% { transform: translate(calc(-50% + var(--dx, 0px) - 4px), -30px) scale(1.22); }
  45% { transform: translate(calc(-50% + var(--dx, 0px) + 4px), -36px) scale(1.22); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), -82px) scale(0.95); }
}

/* HPバー（遅延赤ゲージ） */
.hp-section {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.hp-bar-outer {
  position: relative;
  width: 100%;
  height: 22px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  overflow: hidden;
}

.hp-bar-trail {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  background: #ef4444;
  transition: width 0.32s ease-out 0.12s;
}

.hp-bar-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  background: linear-gradient(90deg, #16a34a, #4ade80);
  transition: width 0.08s linear;
}

.hp-bar-text {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px #000;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 0;
  margin-top: 0;
  flex-wrap: wrap;
}
.status-row:has(.status-pill:not(.hidden)) {
  margin-top: 4px;
}

.status-pill {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.status-pill.poison {
  background: rgba(34, 197, 94, 0.18);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: #86efac;
}

.status-pill.charge {
  background: rgba(249, 115, 22, 0.2);
  border: 1px solid rgba(249, 115, 22, 0.45);
  color: #fdba74;
}

.status-pill.shield {
  background: rgba(56, 189, 248, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #7dd3fc;
}

.status-pill.combo {
  margin-left: auto;
  background: rgba(251, 191, 36, 0.2);
  border: 1px solid rgba(251, 191, 36, 0.5);
  color: #fde047;
}

/* ==================== レリックバー ==================== */
.relic-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 6px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  min-height: 36px;
  flex-shrink: 0;
}

.relic-bar-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

.relic-list {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.relic-list::-webkit-scrollbar { display: none; }

.relic-empty {
  font-size: 0.72rem;
  color: #64748b;
}

.relic-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.35);
  color: #fde68a;
  white-space: nowrap;
  cursor: pointer;
}

/* ==================== 5スロットレーン ==================== */
.slots-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.slots-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}

.slots-container {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  padding: 4px 0;
  touch-action: none;
  width: 100%;
}

.chain-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.chain-beam {
  stroke: #38bdf8;
  stroke-width: 3.5;
  stroke-linecap: round;
  filter: drop-shadow(0 0 6px #38bdf8);
  animation: beamFade 0.28s ease-out forwards;
}

.chain-beam.buff {
  stroke: #fbbf24;
  filter: drop-shadow(0 0 6px #fbbf24);
}

@keyframes beamFade {
  0% { opacity: 1; stroke-width: 4.5; }
  100% { opacity: 0; stroke-width: 1; }
}

.slot-card {
  position: relative;
  height: 92px;
  background: var(--bg-slot);
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  border-radius: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 5px 3px 6px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  touch-action: none;
}

.slot-card.empty {
  background: rgba(255, 255, 255, 0.02);
  border-style: dashed;
  border-color: rgba(255, 255, 255, 0.15);
}

.slot-card.rarity-N { border-color: rgba(148, 163, 184, 0.45); }
.slot-card.rarity-R { border-color: rgba(56, 189, 248, 0.65); }
.slot-card.rarity-SR {
  border-color: rgba(192, 132, 252, 0.8);
  box-shadow: inset 0 0 12px rgba(168, 85, 247, 0.18);
}

.slot-card.selected {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.45);
  transform: translateY(-3px);
}

.slot-card.drag-source {
  opacity: 0.35;
}

.slot-card.drag-over {
  border-color: var(--accent-cyan);
  background: var(--bg-slot-hover);
  transform: scale(1.05);
}

.slot-card.active-cursor {
  border-color: #fde047;
  box-shadow: 0 0 16px rgba(250, 204, 21, 0.65);
}

.slot-card.triggered {
  animation: slotPop 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes slotPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.13) translateY(-4px); }
  100% { transform: scale(1); }
}

.slot-card.frozen::after {
  content: "❄️";
  position: absolute;
  inset: 0;
  background: rgba(56, 189, 248, 0.45);
  backdrop-filter: blur(1px);
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  z-index: 5;
}

.slot-num {
  font-size: 0.62rem;
  font-weight: 800;
  color: var(--text-muted);
  line-height: 1;
}

.slot-emoji {
  font-size: 1.75rem;
  line-height: 1;
}

.slot-name {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-main);
  text-align: center;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-stars {
  font-size: 0.64rem;
  font-weight: 900;
  color: var(--accent-gold);
  line-height: 1;
}

.slot-buff-badge {
  position: absolute;
  top: -5px;
  right: -4px;
  background: #f59e0b;
  color: #000;
  font-size: 0.58rem;
  font-weight: 900;
  padding: 1px 4px;
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* ドラッグ中のゴースト */
.drag-ghost {
  position: fixed;
  width: 68px;
  height: 86px;
  background: var(--bg-slot-hover);
  border: 2px solid var(--accent-gold);
  border-radius: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  pointer-events: none;
  z-index: 1000;
  transform: translate(-50%, -65%) scale(1.08);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.65);
}

/* ==================== 下部詳細・アクション ==================== */
.game-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.symbol-detail {
  min-height: 62px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

.detail-empty {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

.detail-top {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 800;
}

.detail-tag {
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  color: #cbd5e1;
}

.detail-desc {
  font-size: 0.78rem;
  color: #dbe4ff;
  line-height: 1.35;
}

.footer-actions {
  display: flex;
  gap: 8px;
}

/* ==================== モーダル（報酬3択 / 入れ替え） ==================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 14, 0.82);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  max-height: 90dvh;
  overflow-y: auto;
  background: #14192b;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 20px;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.75);
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  text-align: center;
}

.modal-subtitle {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--accent-gold);
}

.modal-title {
  margin: 4px 0 0;
  font-size: 1.2rem;
  font-weight: 900;
}

.reward-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reward-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  background: var(--bg-slot);
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  color: var(--text-main);
  text-align: left;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s ease;
  font-family: inherit;
}

.reward-card:active {
  transform: scale(0.98);
}

.reward-card.rarity-R { border-color: rgba(56, 189, 248, 0.65); }
.reward-card.rarity-SR {
  border-color: rgba(192, 132, 252, 0.85);
  background: linear-gradient(135deg, #1f1b38, #181c30);
}

.reward-card.is-upgrade {
  border-color: var(--accent-gold);
  box-shadow: 0 0 14px rgba(251, 191, 36, 0.25);
}

.reward-emoji {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  flex-shrink: 0;
}

.reward-body {
  flex: 1;
  min-width: 0;
}

.reward-top {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.reward-name {
  font-size: 0.98rem;
  font-weight: 800;
}

.rarity-tag {
  font-size: 0.65rem;
  font-weight: 900;
  padding: 1px 6px;
  border-radius: 5px;
}

.rarity-tag.N { background: rgba(148, 163, 184, 0.25); color: #e2e8f0; }
.rarity-tag.R { background: rgba(56, 189, 248, 0.25); color: #7dd3fc; }
.rarity-tag.SR { background: rgba(192, 132, 252, 0.3); color: #e9d5ff; }

.upgrade-tag {
  font-size: 0.65rem;
  font-weight: 900;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--accent-gold);
  color: #000;
}

.reward-cat {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.reward-desc {
  font-size: 0.8rem;
  color: #e2e8f0;
  margin-top: 4px;
  line-height: 1.35;
}

.modal-footer {
  display: flex;
  justify-content: center;
}

/* 満杯時入れ替え */
.replace-preview {
  padding: 10px;
  border-radius: 12px;
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.35);
  font-size: 0.85rem;
  text-align: center;
}

.replace-slots {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.replace-slot-btn {
  height: 82px;
  background: var(--bg-slot);
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px;
  cursor: pointer;
  font-family: inherit;
}

.replace-slot-btn:active {
  transform: scale(0.95);
  border-color: var(--accent-red);
}

/* ==================== リザルト画面 ==================== */
#screen-result {
  justify-content: center;
  padding: 16px;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 22px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

.result-badge {
  align-self: center;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.18);
  border: 1px solid rgba(34, 197, 94, 0.5);
  color: #86efac;
}

.result-badge.defeat {
  background: rgba(244, 63, 94, 0.18);
  border-color: rgba(244, 63, 94, 0.5);
  color: #fda4af;
}

.result-title {
  margin: -6px 0 0;
  text-align: center;
  font-size: 1.45rem;
  font-weight: 900;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-box {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 900;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.stat-value.accent {
  color: var(--accent-gold);
}

.result-deck-section {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 10px;
}

.result-deck-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-align: center;
}

.result-deck {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.res-slot-chip {
  background: var(--bg-slot);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 6px 2px;
  text-align: center;
  font-size: 0.65rem;
}

.res-slot-chip .emoji {
  font-size: 1.35rem;
  display: block;
}

.result-relics {
  margin-top: 8px;
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: #fde68a;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ==================== トースト ==================== */
.toast {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.5);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

/* 小さい画面向けの微調整（iPhone SEなど） */
@media (max-height: 680px) {
  .battle-stage {
    min-height: 135px;
    padding: 8px 10px;
  }
  .enemy-sprite {
    font-size: 3.3rem;
  }
  .slot-card {
    height: 82px;
  }
  .slot-emoji {
    font-size: 1.5rem;
  }
  .symbol-detail {
    min-height: 54px;
    padding: 6px 10px;
  }
  .btn-lg {
    min-height: 44px;
  }
}

/* ==================== ポータル戻るボタン & 広告・スマホ最適化 ==================== */
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* ポータルへ戻るボタン (PC表示時左上にフロート) */
.portal-back-btn {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.85);
  color: #f1f5f9;
  text-decoration: none;
  padding: 7px 14px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.portal-back-btn:hover {
  background: rgba(30, 41, 59, 0.95);
  border-color: #38bdf8;
  color: #38bdf8;
  transform: translateX(-2px);
}

.mobile-portal-btn,
.title-portal-link {
  display: none;
}

/* タイトル画面＆リザルト画面＆モーダルのスマホスクロール安全性確保 */
#screen-title,
#screen-result {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}
#screen-title *,
#screen-result * {
  touch-action: pan-y;
}
.result-card {
  margin: auto 0;
}

/* PC表示 (860px以上: 左にゲーム、右にPC広告サイドバー) */
.ad-pc-only { display: none; }
.ad-sp-only { display: flex; }

@media (min-width: 960px) {
  body {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 16px;
  }
  .app-shell {
    margin: 0;
    max-height: 860px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
  }
  .ad-pc-only { display: flex; }
  .ad-sp-only { display: none !important; }

  .game5-pc-ad {
    flex-direction: column;
    align-items: center;
    margin-left: 24px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: 14px;
    padding: 12px 10px;
    width: 320px;
    min-height: 280px;
    box-sizing: border-box;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
  .game5-pc-ad .ad-label {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.5px;
    color: #94a3b8;
    margin-bottom: 8px;
  }
  .game5-pc-ad .ad-slot-pc {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 250px;
  }
}

/* スマホ表示 (859px以下: 下部にスリム広告バー＋ヘッダー内戻り導線) */
@media (max-width: 959px) {
  body {
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
  }
  .app-shell {
    flex: 1;
    min-height: 0;
    height: auto;
    max-width: 100%;
    padding-bottom: 0;
    box-shadow: none;
  }
  .portal-back-btn {
    display: none;
  }
  .mobile-portal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .title-portal-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    position: absolute;
    top: max(10px, var(--safe-top));
    left: 12px;
    background: rgba(15, 23, 42, 0.85);
    color: #f1f5f9;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid rgba(255, 255, 255, 0.2);
    z-index: 20;
  }
  .game5-sp-ad {
    width: 100%;
    flex-shrink: 0;
    background: #070910;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding: 2px 0 max(2px, var(--safe-bottom));
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 54px;
    z-index: 50;
  }
  .ad-slot-sp {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    min-height: 50px;
  }
  /* 全要素を上にギュッと詰めて余分な隙間をゼロにし、大きい広告が来てもバトルボタンまで確実に収める */
  #screen-game {
    padding: 4px 10px 6px;
    gap: 4px;
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .timer-bar-wrap {
    margin: 2px 0 2px;
    height: 4px;
  }
  .battle-stage {
    flex: 0 0 auto;
    min-height: 0;
    padding: 5px 10px 4px;
  }
  .enemy-arena {
    flex: 0 0 auto;
    min-height: 54px;
    height: 54px;
  }
  .enemy-sprite {
    font-size: 3.1rem;
    line-height: 1.05;
  }
  .hp-bar-outer {
    height: 18px;
  }
  .hp-bar-text {
    font-size: 0.74rem;
  }
  .relic-bar {
    margin: 0;
    padding: 3px 8px;
    min-height: 26px;
  }
  .slots-section {
    gap: 2px;
    margin-bottom: 0;
  }
  .slots-container {
    padding: 2px 0;
  }
  .slot-card {
    height: 70px;
  }
  .game-footer {
    gap: 4px;
  }
  .symbol-detail {
    min-height: 40px;
    padding: 4px 8px;
    font-size: 0.74rem;
  }
  .game-footer .btn-lg {
    min-height: 44px;
    padding: 6px 12px;
  }
}

/* さらに狭いスマホ画面向け調整 */
@media (max-width: 380px) {
  .slots-container {
    gap: 4px;
  }
  .slot-card {
    height: 68px;
  }
  .slot-emoji {
    font-size: 1.45rem;
  }
  .result-card {
    padding: 14px 12px;
    gap: 12px;
  }
}
