/* ============================================================
   BASE
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@700;900&family=Noto+Sans+JP:wght@400;700&display=swap');

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

body {
  margin: 0;
  overflow: hidden;
  touch-action: none;
  background: #000;
  font-family: 'Noto Sans JP', sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

canvas { display: block; }

/* ============================================================
   TITLE SCREEN
   ============================================================ */
#titleScreen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.title-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 60%, #1a0a2e 0%, #000 70%);
  animation: titlePulse 4s ease-in-out infinite alternate;
}

.title-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(80,0,180,0.04) 2px,
      rgba(80,0,180,0.04) 4px
    );
}

@keyframes titlePulse {
  from { filter: brightness(0.85); }
  to   { filter: brightness(1.1); }
}

.title-content {
  position: relative;
  text-align: center;
  z-index: 1;
  padding: 20px;
}

.title-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  margin-bottom: 8px;
}

.title-main {
  font-family: 'Cinzel', serif;
  font-size: clamp(36px, 10vw, 72px);
  font-weight: 900;
  color: #fff;
  letter-spacing: 6px;
  text-shadow:
    0 0 20px #a855f7,
    0 0 60px #7c3aed,
    0 0 100px #4c1d95;
  animation: titleGlow 2s ease-in-out infinite alternate;
}

.title-sub {
  font-family: 'Cinzel', serif;
  font-size: clamp(24px, 7vw, 52px);
  font-weight: 700;
  color: #c4b5fd;
  letter-spacing: 12px;
  text-shadow: 0 0 30px #7c3aed;
}

@keyframes titleGlow {
  from { text-shadow: 0 0 20px #a855f7, 0 0 60px #7c3aed; }
  to   { text-shadow: 0 0 40px #c084fc, 0 0 100px #a855f7, 0 0 160px #7c3aed; }
}

.title-deco {
  color: #9f7aea;
  font-size: 14px;
  letter-spacing: 4px;
  margin-bottom: 40px;
  opacity: 0.8;
}

.start-btn {
  position: relative;
  background: linear-gradient(135deg, #7c3aed, #4c1d95);
  border: 1px solid #a855f7;
  color: #fff;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 18px;
  font-weight: 700;
  padding: 16px 48px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 3px;
  box-shadow:
    0 0 20px rgba(168,85,247,0.4),
    inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all 0.2s;
  overflow: hidden;
  margin-bottom: 24px;
}

.start-btn::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  animation: btnShine 2.5s infinite;
}

@keyframes btnShine {
  0%   { left: -100%; }
  40%  { left: 100%; }
  100% { left: 100%; }
}

.start-btn:active {
  transform: scale(0.97);
  box-shadow: 0 0 10px rgba(168,85,247,0.3);
}

.continue-btn {
  position: relative;
  background: linear-gradient(135deg, #065f46, #047857);
  border: 1px solid #34d399;
  color: #d1fae5;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 16px;
  font-weight: 700;
  padding: 14px 48px 10px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 2px;
  box-shadow: 0 0 20px rgba(52,211,153,0.3);
  transition: all 0.2s;
  margin-bottom: 20px;
  display: block;
  width: 100%;
}
.continue-btn:active { transform: scale(0.97); }

.save-info {
  font-size: 11px;
  color: #6ee7b7;
  letter-spacing: 1px;
  margin-top: 4px;
  font-weight: 400;
}

.title-hint {
  color: rgba(196,181,253,0.6);
  font-size: 12px;
  line-height: 1.8;
  letter-spacing: 1px;
}

/* ============================================================
   GAME OVER / CLEAR SCREENS
   ============================================================ */
#gameoverScreen, #clearScreen {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gameover-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, #2d0000 0%, #000 70%);
  animation: fadeInBg 0.8s ease;
}

.clear-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, #1a2d00 0%, #000 70%);
  animation: fadeInBg 0.8s ease;
}

@keyframes fadeInBg {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.gameover-content, .clear-content {
  position: relative;
  text-align: center;
  z-index: 1;
  animation: slideUp 0.6s ease 0.3s both;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}

.gameover-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(40px, 12vw, 80px);
  font-weight: 900;
  color: #ef4444;
  letter-spacing: 4px;
  text-shadow: 0 0 40px #dc2626, 0 0 80px #991b1b;
  margin-bottom: 20px;
}

.clear-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(40px, 12vw, 80px);
  font-weight: 900;
  color: #fbbf24;
  letter-spacing: 4px;
  text-shadow: 0 0 40px #f59e0b, 0 0 80px #d97706;
  margin-bottom: 20px;
}

.gameover-stats, .clear-stats {
  color: #d1d5db;
  font-size: 16px;
  line-height: 2;
  margin-bottom: 32px;
  letter-spacing: 2px;
}

.retry-btn {
  background: linear-gradient(135deg, #374151, #1f2937);
  border: 1px solid #6b7280;
  color: #f9fafb;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 16px;
  font-weight: 700;
  padding: 14px 40px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 2px;
  transition: all 0.2s;
}

.retry-btn:active { transform: scale(0.97); }

/* ============================================================
   GAME UI
   ============================================================ */
#gameUI {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

/* ---------- 左上ステータス ---------- */
#ui {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 10px 14px;
  border-radius: 10px;
  color: #fff;
  min-width: 180px;
  pointer-events: none;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #9ca3af;
  width: 24px;
  flex-shrink: 0;
}

.bar-outer {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 5px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.3s ease;
}

.hp-bar {
  width: 100%;
  background: linear-gradient(90deg, #ef4444, #f87171);
  box-shadow: 0 0 6px rgba(239,68,68,0.6);
}

.mp-bar {
  width: 100%;
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
  box-shadow: 0 0 6px rgba(59,130,246,0.6);
}

.exp-bar {
  width: 0%;
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  box-shadow: 0 0 6px rgba(245,158,11,0.6);
}

.stat-num {
  font-size: 11px;
  font-weight: 700;
  color: #e5e7eb;
  width: 28px;
  text-align: right;
  flex-shrink: 0;
}

.info-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  color: #d1d5db;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.equip-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #c4b5fd;
  margin-top: 3px;
}
.equip-icon { font-size: 12px; }

.gold-row {
  font-size: 12px;
  font-weight: 700;
  color: #fbbf24;
  margin-top: 3px;
}

.stat-detail {
  font-size: 10px;
  color: #9ca3af;
  margin-top: 2px;
  letter-spacing: 1px;
}

/* ============================================================
   SHOP SCREEN
   ============================================================ */
#shopScreen {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
}

.shop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.82);
  backdrop-filter: blur(4px);
}

.shop-content {
  position: relative;
  z-index: 1;
  background: linear-gradient(160deg, #1e1a2e, #0f0d1a);
  border: 1px solid rgba(168,85,247,0.3);
  border-radius: 16px;
  padding: 20px;
  width: min(92vw, 380px);
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 0 40px rgba(124,58,237,0.3);
}

.shop-header {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  font-weight: 700;
  color: #e9d5ff;
  text-align: center;
  letter-spacing: 3px;
  margin-bottom: 6px;
}

.shop-gold {
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: #fbbf24;
  margin-bottom: 14px;
}

.shop-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.shop-tab {
  flex: 1;
  padding: 8px 0;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #9ca3af;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.shop-tab.active {
  background: rgba(124,58,237,0.4);
  border-color: #7c3aed;
  color: #e9d5ff;
}

.shop-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.shop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 10px 14px;
  gap: 10px;
}

.shop-item-info { flex: 1; }

.shop-item-name {
  font-size: 14px;
  font-weight: 700;
  color: #f3f4f6;
}

.shop-item-desc {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}

.shop-item-equipped {
  font-size: 10px;
  color: #34d399;
  margin-top: 2px;
}

.shop-buy-btn {
  background: linear-gradient(135deg, #7c3aed, #5b21b6);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.shop-buy-btn:disabled {
  background: rgba(255,255,255,0.08);
  color: #6b7280;
  cursor: not-allowed;
}

.shop-buy-btn:not(:disabled):active { transform: scale(0.96); }

.shop-save-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.shop-save-btn, .shop-load-btn {
  flex: 1;
  padding: 11px 0;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  transition: all 0.15s;
}

.shop-save-btn {
  background: linear-gradient(135deg, #065f46, #047857);
  border: 1px solid #34d399;
  color: #d1fae5;
}

.shop-load-btn {
  background: linear-gradient(135deg, #1e3a5f, #1d4ed8);
  border: 1px solid #60a5fa;
  color: #dbeafe;
}

.shop-save-btn:active, .shop-load-btn:active { transform: scale(0.97); }

.shop-close-btn {
  width: 100%;
  padding: 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  color: #d1d5db;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 2px;
}

.shop-close-btn:active { transform: scale(0.98); }

/* ---------- ミニマップ ---------- */
#minimap {
  position: absolute;
  top: 12px;
  right: 12px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
}

/* ---------- メッセージ ---------- */
#message {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.1);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

#message.visible { opacity: 1; }

/* ---------- レベルアップ ---------- */
#levelupMsg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Cinzel', serif;
  font-size: clamp(28px, 8vw, 48px);
  font-weight: 900;
  color: #fbbf24;
  text-shadow: 0 0 30px #f59e0b, 0 0 60px #d97706;
  letter-spacing: 4px;
  pointer-events: none;
  animation: levelupAnim 2s ease forwards;
}

@keyframes levelupAnim {
  0%   { opacity: 0; transform: translate(-50%, -40%) scale(0.8); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  70%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -60%) scale(0.9); }
}

/* ---------- ステータスボタン ---------- */
.status-open-btn {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 7px 0;
  background: rgba(124,58,237,0.25);
  border: 1px solid rgba(168,85,247,0.4);
  border-radius: 8px;
  color: #e9d5ff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 1px;
  pointer-events: all;
  transition: all 0.15s;
}
.status-open-btn:active { transform: scale(0.97); }

/* ---------- 回復ボタン（右下） ---------- */
#itemButtons {
  position: absolute;
  bottom: 80px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: all;
}

.item-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: all 0.15s;
  min-width: 120px;
}

.hp-btn {
  background: rgba(34,197,94,0.25);
  border-color: rgba(34,197,94,0.5);
}

.mp-btn {
  background: rgba(59,130,246,0.25);
  border-color: rgba(59,130,246,0.5);
}

.item-btn:active { transform: scale(0.95); }

.item-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.item-btn-icon  { font-size: 20px; }
.item-btn-label { font-size: 12px; font-weight: 700; color: #f3f4f6; flex: 1; }
.item-btn-count { font-size: 13px; font-weight: 700; color: #fbbf24; }
#chargeIndicator {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  color: #60a5fa;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  text-shadow: 0 0 10px #3b82f6;
}

#chargeIndicator.visible { opacity: 1; }
