/* ================================================================ */
/* CSS 変数・リセット                                                  */
/* ================================================================ */
:root {
  --primary: #6c5ce7;
  --primary-dark: #5a4ed1;
  --accent: #fd79a8;
  --bg: #ffffff;
  --bg-card: #f8f9fa;
  --bg-card2: #e9ecef;
  --text: #212529;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --success: #00b894;
  --warning: #e17055;
  --danger: #d63031;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --rarity-color: #808080;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ================================================================ */
/* ヘッダー                                                           */
/* ================================================================ */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.site-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

.header-nav a { color: var(--text); font-size: 0.9rem; }

.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.btn-login {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #000;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-login:hover { background: #333; }

/* ================================================================ */
/* フッター                                                           */
/* ================================================================ */
.site-footer {
  margin-top: auto;
  background: #f8f9fa;
  border-top: 1px solid var(--border);
  padding: 24px 16px;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.footer-copy { font-size: 0.85rem; color: var(--text-muted); }
.footer-nav { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.footer-nav a { font-size: 0.8rem; color: var(--text-muted); }

/* ================================================================ */
/* 共通コンポーネント                                                  */
/* ================================================================ */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: opacity 0.2s, transform 0.1s;
}

.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--bg-card2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 0.85rem; }

.hidden { display: none !important; }

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.alert-error { background: #fff5f5; border: 1px solid #feb2b2; color: #c53030; }
.alert-success { background: #f0fff4; border: 1px solid #9ae6b4; color: #276749; }

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.9rem; color: var(--text-muted); margin-bottom: 6px; }

.form-control {
  width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 1rem;
}

.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108,92,231,0.1); }

textarea.form-control { resize: vertical; min-height: 80px; }

/* ================================================================ */
/* マーケットトップ                                                    */
/* ================================================================ */
.market-cover {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 0 0 var(--radius) var(--radius);
}

.market-gacha-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 24px;
}

@media (max-width: 768px) { .market-gacha-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .market-gacha-grid { grid-template-columns: 1fr; } }

.gacha-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  display: block;
  color: var(--text);
  text-decoration: none;
}

.gacha-card:hover { transform: translateY(-4px); box-shadow: 0 8px 24px rgba(0,0,0,0.12); }

.gacha-card.sold-out, .gacha-card.ended { cursor: default; }

.gacha-card__thumbnail {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: var(--bg-card2);
}

.gacha-card__body { padding: 12px; }
.gacha-card__name { font-weight: 700; font-size: 0.95rem; margin-bottom: 8px; }

.gacha-card__gauge { margin-bottom: 8px; }

.gauge-bar-wrap {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}

.gacha-card__gauge-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.gacha-card__gauge-fill.green { background: var(--success); }
.gacha-card__gauge-fill.yellow { background: var(--warning); }
.gacha-card__gauge-fill.red { background: var(--danger); }
.gacha-card__gauge-fill.unlimited { background: #0984e3; width: 100% !important; }

.gacha-card__gauge-text { font-size: 0.75rem; color: var(--text-muted); text-align: right; }
.gacha-card__cost { font-size: 0.85rem; color: var(--text-muted); }

.gacha-card__badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
}

.gacha-card.sold-out::after,
.gacha-card.ended::after {
  content: attr(data-status);
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: #555;
}

/* ================================================================ */
/* ガチャ実行画面                                                      */
/* ================================================================ */
.gacha-draw-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin: 20px 0;
}

.gacha-draw-btn {
  position: relative;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 16px 24px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  transition: transform 0.15s, box-shadow 0.15s;
  min-width: 120px;
  text-align: center;
}

.gacha-draw-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(108,92,231,0.35);
}

.gacha-draw-btn:disabled { opacity: 0.5; transform: none; cursor: not-allowed; }

.draw-label { display: block; font-size: 1rem; }
.draw-cost { display: block; font-size: 0.85rem; opacity: 0.85; margin-top: 2px; }

.discount-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  white-space: nowrap;
}

.gacha-notice-box {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 0.9rem;
  color: #92400e;
  margin: 16px 0;
  line-height: 1.7;
}

/* ================================================================ */
/* 景品一覧                                                           */
/* ================================================================ */
.gacha-rarity-group { margin-bottom: 32px; }

.rarity-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 2px solid;
  padding-bottom: 8px;
  margin-bottom: 12px;
  font-weight: 700;
}

.rarity-label { font-size: 1.1rem; }
.rarity-prob { font-size: 0.9rem; opacity: 0.85; margin-left: auto; }
.rarity-count { font-size: 0.85rem; opacity: 0.7; }

.gacha-prize-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}

.prize-card {
  cursor: pointer;
  text-align: center;
  position: relative;
}

.prize-img-wrap {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  background: var(--bg-card2);
}

.prize-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.prize-card:hover .prize-img-wrap img { transform: scale(1.05); }

.prize-sold-out {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #888;
}

.prize-card.sold-out .prize-img-wrap img { filter: grayscale(1); }
.prize-name { font-size: 0.75rem; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prize-stock { font-size: 0.7rem; color: var(--text-muted); }

/* ================================================================ */
/* ガチャ演出オーバーレイ                                               */
/* ================================================================ */
.gacha-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.gacha-video-overlay {
  background: #000;
  pointer-events: all;
}

.video-unmute-btn {
  position: absolute;
  bottom: 24px;
  right: 24px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.9rem;
  pointer-events: all;
}

.gacha-blackout { background: #000; pointer-events: all; }

.gacha-flash {
  animation: gacha-flash 0.6s ease-out forwards;
  pointer-events: none;
}

.gacha-fade-in-bg {
  background: radial-gradient(circle, var(--rarity-color) 0%, transparent 70%);
  opacity: 0;
  animation: gacha-fade-in 1s ease-out forwards;
}

.gacha-rare-bg {
  background: radial-gradient(circle, var(--rarity-color) 0%, transparent 60%);
  opacity: 0;
  animation: gacha-fade-in 1.5s ease-out forwards;
}

.gacha-sr-bg {
  background: radial-gradient(circle, var(--rarity-color) 0%, transparent 50%);
  animation: gacha-flash 2.5s ease-out forwards;
}

.gacha-aurora-bg {
  background: linear-gradient(135deg, var(--rarity-color), #6c5ce7, #fd79a8, var(--rarity-color));
  background-size: 400% 400%;
  opacity: 0.6;
  animation: gacha-aurora 3.5s ease-in-out forwards;
  pointer-events: none;
}

.shockwave-overlay { pointer-events: none; }

.shockwave-ring {
  position: absolute;
  border: 3px solid;
  border-radius: 50%;
  width: 10px;
  height: 10px;
  animation: gacha-shockwave 1.2s ease-out forwards;
}

.shockwave-ring:nth-child(2) { animation-delay: 0.2s; }
.shockwave-ring:nth-child(3) { animation-delay: 0.4s; }
.shockwave-ring:nth-child(4) { animation-delay: 0.6s; }

.gacha-particles-canvas {
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
}

/* ================================================================ */
/* ガチャ結果カード                                                    */
/* ================================================================ */
.gacha-result-card {
  background: #fff;
  border: 3px solid var(--rarity-color, #808080);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  max-width: 400px;
  margin: 32px auto;
  box-shadow: 0 0 30px rgba(0,0,0,0.15);
  animation: gacha-fade-in 0.5s ease-out forwards;
}

.gacha-result-label {
  font-size: 1.2rem;
  font-weight: 900;
  text-transform: uppercase;
  margin-bottom: 16px;
  text-shadow: 0 0 10px currentColor;
}

.gacha-result-img {
  width: 200px;
  height: 200px;
  object-fit: cover;
  border-radius: 12px;
  margin: 0 auto 16px;
}

.gacha-result-name {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.gacha-result-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* 連続引き結果グリッド */
.gacha-multi-result {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 20px 0;
}

@media (max-width: 600px) { .gacha-multi-result { grid-template-columns: repeat(3, 1fr); } }

.gacha-multi-card {
  background: #fff;
  border: 2px solid var(--rarity-color, #808080);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s;
}

.gacha-multi-card:hover { transform: scale(1.05); }
.gacha-multi-card.highlight {
  box-shadow: 0 0 20px var(--rarity-color, #808080);
  animation: gacha-glow-pulse 2s infinite alternate;
}

.gacha-multi-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
}

.gacha-multi-card-label { font-size: 0.7rem; font-weight: 700; margin-top: 4px; }
.gacha-multi-card-name { font-size: 0.65rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ローディング */
#gacha-loading {
  text-align: center;
  padding: 40px;
  font-size: 1.2rem;
  color: var(--text-muted);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

/* ================================================================ */
/* 管理画面                                                           */
/* ================================================================ */
.admin-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 56px);
}

.admin-sidebar {
  background: #f8f9fa;
  border-right: 1px solid var(--border);
  padding: 24px 0;
}

.admin-sidebar nav a {
  display: block;
  padding: 10px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.admin-sidebar nav a:hover,
.admin-sidebar nav a.active { background: rgba(108,92,231,0.08); color: var(--primary); text-decoration: none; }

.admin-content { padding: 24px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }

table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 2px solid var(--border); }
th { padding: 10px 14px; text-align: left; font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }
td { padding: 10px 14px; font-size: 0.9rem; border-bottom: 1px solid var(--border); }
tr:hover td { background: #f8f9fa; }

/* アップロード */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  color: var(--text-muted);
  background: #fafafa;
}

.dropzone:hover, .dropzone.drag-over {
  border-color: var(--primary);
  background: rgba(108,92,231,0.04);
}

.upload-progress {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.upload-progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: #fff;
}

/* モーダル */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,0.15);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.4rem; }

/* ================================================================ */
/* キーフレームアニメーション                                           */
/* ================================================================ */
@keyframes gacha-fade-in {
  from { opacity: 0; transform: scale(0.8); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes gacha-slide-bounce {
  0%   { opacity: 0; transform: translateY(60px) scale(0.7); }
  60%  { transform: translateY(-10px) scale(1.05); }
  80%  { transform: translateY(5px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes gacha-flash {
  0%   { opacity: 0.9; }
  30%  { opacity: 0.6; }
  100% { opacity: 0; }
}

@keyframes gacha-spin-scale {
  0%   { transform: rotateY(0) scale(0.3); opacity: 0; }
  50%  { transform: rotateY(180deg) scale(1.1); opacity: 1; }
  100% { transform: rotateY(360deg) scale(1); }
}

@keyframes gacha-shockwave {
  0%   { width: 10px; height: 10px; opacity: 1; }
  100% { width: min(100vw, 100vh); height: min(100vw, 100vh); opacity: 0; }
}

@keyframes gacha-aurora {
  0%   { background-position: 0% 50%; opacity: 0.7; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; opacity: 0; }
}

@keyframes gacha-glow-pulse {
  from { box-shadow: 0 0 10px var(--rarity-color, #ffd700); }
  to   { box-shadow: 0 0 30px var(--rarity-color, #ffd700), 0 0 60px var(--rarity-color, #ffd700); }
}

@keyframes particle-fall {
  to { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ================================================================ */
/* レスポンシブ                                                        */
/* ================================================================ */

/* ── ヘッダー ── */
@media (max-width: 640px) {
  .header-inner {
    height: auto;
    min-height: 52px;
    flex-wrap: wrap;
    padding: 6px 12px;
    gap: 6px;
  }
  .header-nav {
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.82rem;
  }
  .header-user {
    flex-wrap: wrap;
    gap: 6px;
  }
  .header-user .user-name {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.82rem;
  }
  .header-user a {
    font-size: 0.8rem;
  }
  .header-user button {
    font-size: 0.8rem;
    padding: 4px 10px;
  }
  .btn-login {
    font-size: 0.82rem;
    padding: 6px 12px;
  }
}

/* ── 管理サイドバー → モバイル横スクロールナビ ── */
@media (max-width: 768px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }
  .admin-sidebar {
    display: block !important;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .admin-sidebar nav {
    display: inline-flex;
    min-width: 100%;
  }
  .admin-sidebar nav a {
    display: inline-block;
    padding: 10px 14px;
    font-size: 0.82rem;
  }
  .admin-content {
    padding: 14px;
  }
}

/* ── テーブル横スクロール ── */
@media (max-width: 768px) {
  .admin-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  th, td {
    padding: 8px 10px;
    font-size: 0.82rem;
    white-space: nowrap;
  }
}

/* ── コンテナ余白縮小 ── */
@media (max-width: 480px) {
  .container {
    padding: 16px 12px;
  }
}

/* ── ガチャ結果カード ── */
@media (max-width: 480px) {
  .gacha-result-card {
    padding: 20px 14px;
    margin: 16px auto;
  }
  .gacha-result-img {
    width: 140px;
    height: 140px;
  }
  .gacha-result-name {
    font-size: 1.1rem;
  }
  .gacha-draw-btn {
    padding: 12px 16px;
    min-width: 100px;
    font-size: 0.95rem;
  }
}

/* ── モーダル ── */
@media (max-width: 480px) {
  .modal {
    padding: 16px;
    max-height: 90vh;
  }
}
