@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* ★修正: ダークモード対応のゲーミング色彩 */
  --primary: #4c1d95;          
  --primary-hover: #3730a3;
  --secondary: #7c3aed;        
  --accent: #c026d3;           
  --success: #10b981;          
  --danger: #ef4444;           
  --warning: #f59e0b;          
  --dark: #000000;             /* ★修正: 真っ黒 */
  --dark-light: #0a0a0a;       /* ★修正: 限りなく黒に近い */
  --dark-lighter: #1a1a1a;     /* ★修正: 極濃グレー */
  --text: #ffffff;             /* ★修正: 純白 */
  --text-muted: #888888;       /* ★修正: より濃いグレー */
  --border: #333333;           /* ★修正: 濃いボーダー */
  --glass: rgba(0, 0, 0, 0.85);          /* ★修正: 濃い黒ガラス */
  --glass-border: rgba(124, 58, 237, 0.4); /* ★修正: より鮮やかな紫ボーダー */
  --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
  --glow-primary: 0 0 25px rgba(124, 58, 237, 0.7);    /* ★修正: 強いグロー */
  --glow-secondary: 0 0 35px rgba(192, 38, 211, 0.6);  /* ★修正: 強いグロー */
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--dark); /* ★修正: 純黒背景 */
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* ★修正: より強いゲーミング背景エフェクト */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: 
    radial-gradient(circle at 20% 80%, rgba(124, 58, 237, 0.3) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(192, 38, 211, 0.3) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(16, 185, 129, 0.2) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

/* 画面管理 */
.screen {
  display: none;
  height: 100vh;
  width: 100vw;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
}

/* ========== スタート画面（1ページ目） ========== */
#start-screen {
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.start-container {
  max-width: 900px;
  width: 100%;
  text-align: center;
  padding-bottom: 40px;
}

.title-section {
  margin-bottom: 40px;
  padding-top: 20px;
}

.title-section h1 {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 700;
  background: linear-gradient(135deg, var(--secondary) 0%, var(--accent) 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 15px;
  filter: drop-shadow(var(--glow-primary));
}

.subtitle {
  font-size: clamp(1.1rem, 2.5vw, 1.3rem);
  color: var(--text-muted);
  line-height: 1.5;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 25px;
  margin-bottom: 40px;
}

.rule-card {
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 25px;
  box-shadow: var(--shadow);
}

.rule-card h3 {
  color: var(--secondary);
  font-size: 1.2rem;
  margin-bottom: 20px;
  font-weight: 600;
  text-shadow: var(--glow-primary);
}

.controls-compact {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.control-desc {
  font-size: 0.95rem;
  color: var(--text);
}

.control-keys {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.key {
  background: var(--dark-lighter);
  border: 1px solid var(--secondary);
  border-radius: 6px;
  padding: 4px 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--warning);
  box-shadow: var(--glow-primary);
}

.score-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.score-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.95rem;
}

.score-item span {
  font-family: 'JetBrains Mono', monospace;
  color: var(--warning);
  font-weight: 500;
  text-shadow: 0 0 12px rgba(245, 158, 11, 0.5);
}

.mobile-only {
  display: none;
}

.start-btn {
  background: linear-gradient(135deg, var(--secondary), var(--accent));
  color: var(--text);
  border: none;
  padding: 18px 40px;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: var(--glow-secondary);
  text-transform: none;
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--glow-secondary), 0 12px 30px rgba(192, 38, 211, 0.8);
}

/* ========== ゲーム画面（2ページ目） ========== */
#game-screen {
  align-items: stretch;
  justify-content: center;
}

/* PC版レイアウト */
.game-layout-pc {
  display: grid;
  grid-template-columns: 200px 1fr 160px;
  gap: 20px;
  width: 100%;
  max-width: 800px;
  height: 100vh;
  padding: 20px;
  align-items: center;
}

.left-panel, .right-panel {
  display: flex;
  flex-direction: column;
  height: fit-content;
}

.score-panel {
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.score-item {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}

.score-item:last-child {
  margin-bottom: 0;
}

.score-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.score-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--warning);
  text-shadow: 0 0 15px rgba(245, 158, 11, 0.7);
}

.center-game {
  display: flex;
  justify-content: center;
  align-items: center;
}

.game-area {
  position: relative;
}

#game, #mobile-game {
  border: 3px solid var(--secondary);
  border-radius: 8px;
  box-shadow: var(--glow-primary), 0 0 50px rgba(124, 58, 237, 0.5);
  background: #000;
}

.next-panel {
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.next-panel h4 {
  color: var(--secondary);
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-shadow: var(--glow-primary);
}

.next-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.next-list canvas {
  border: 1px solid var(--secondary);
  border-radius: 4px;
  background: #000;
  box-shadow: 0 0 12px rgba(124, 58, 237, 0.4);
}

/* タップゾーン */
.tap-zones {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  display: none;
}

.tap-zone {
  position: absolute;
  touch-action: manipulation;
}

.tap-rotate {
  top: 0;
  left: 0;
  width: 100%;
  height: 20%;
}

.tap-left {
  top: 20%;
  left: 0;
  width: 30%;
  height: 60%;
}

.tap-right {
  top: 20%;
  right: 0;
  width: 30%;
  height: 60%;
}

.tap-down {
  bottom: 0;
  left: 0;
  width: 100%;
  height: 20%;
}

/* ★修正: スマホ版レイアウト - 画面いっぱい使用 */
.game-layout-mobile {
  display: none;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
}

.mobile-header {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: var(--glass);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
  padding: 8px 15px; /* ★修正: さらにコンパクト */
  flex-shrink: 0;
  min-height: 65px; /* ★修正: さらに縮小 */
}

.mobile-score, .mobile-level, .mobile-next {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px; /* ★修正: gap縮小 */
}

.mobile-score span, .mobile-level span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem; /* ★修正: さらに縮小 */
  font-weight: 700;
  color: var(--warning);
  text-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}

.mobile-next canvas {
  border: 1px solid var(--secondary);
  border-radius: 4px;
  background: #000;
  box-shadow: 0 0 8px rgba(124, 58, 237, 0.4);
}

.mobile-header small {
  font-size: 0.65rem; /* ★修正: さらに縮小 */
  color: var(--text-muted);
}

/* ★修正: モバイルゲームエリア - 余白最小化 */
.mobile-game-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px; /* ★修正: 余白最小化 */
  overflow: hidden;
  min-height: 0;
}

/* ★修正: iPhone14向け画面いっぱいサイズ */
#mobile-game {
  width: min(350px, calc(100vw - 10px)) !important; /* ★修正: 画面幅ほぼ全体 */
  height: min(550px, calc(100vh - 75px)) !important; /* ★修正: 画面高さほぼ全体 */
  border: 2px solid var(--secondary);
  border-radius: 8px;
  box-shadow: var(--glow-primary), 0 0 30px rgba(124, 58, 237, 0.5);
  background: #000;
  display: block;
  margin: 0 auto;
}

/* モーダル */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.95); /* ★修正: より濃い背景 */
  backdrop-filter: blur(20px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 40px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 400px;
  width: 90%;
  position: relative;
}

.modal-content h2 {
  font-size: 1.6rem;
  margin-bottom: 24px;
  background: linear-gradient(135deg, var(--secondary), var(--accent));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: var(--glow-primary);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.menu-buttons button {
  background: linear-gradient(135deg, var(--secondary), var(--accent));
  color: var(--text);
  border: none;
  padding: 14px 20px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 0 15px rgba(124, 58, 237, 0.5);
}

.menu-buttons button:hover {
  transform: translateY(-1px);
  box-shadow: var(--glow-primary);
}

.restart-btn {
  background: linear-gradient(135deg, var(--success), #047857) !important;
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.5) !important;
}

.menu-btn {
  background: linear-gradient(135deg, var(--danger), #dc2626) !important;
  box-shadow: 0 0 15px rgba(239, 68, 68, 0.5) !important;
}

.menu-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.result-stats {
  display: flex;
  justify-content: space-around;
  margin-bottom: 24px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stat-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--warning);
  text-shadow: 0 0 12px rgba(245, 158, 11, 0.5);
}

/* ★修正: レスポンシブ - iPhone14最適化 */
@media (max-width: 768px) {
  body {
    overflow: auto;
    position: static;
  }

  #start-screen {
    height: auto;
    min-height: 100vh;
    overflow-y: visible;
    position: relative;
  }

  #game-screen {
    height: 100vh !important;
    overflow: hidden !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
  }

  body.game-active {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
  }

  .mobile-only {
    display: block;
  }

  .tap-area-demo {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 8px;
    height: 120px;
    border: 2px solid var(--secondary);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 12px rgba(124, 58, 237, 0.4);
  }

  .demo-area {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
  }

  .demo-rotate {
    background: rgba(124, 58, 237, 0.3);
    grid-column: 1 / -1;
  }

  .demo-left {
    background: rgba(59, 130, 246, 0.3);
  }

  .demo-right {
    background: rgba(59, 130, 246, 0.3);
  }

  .demo-down {
    background: rgba(16, 185, 129, 0.3);
    grid-column: 1 / -1;
  }

  .game-layout-pc {
    display: none;
  }

  .game-layout-mobile {
    display: flex !important;
  }

  .tap-zones {
    display: block;
  }

  .rules-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .start-btn {
    width: 100%;
    max-width: 300px;
  }
}

/* ★修正: iPhone14 Pro Max対応 */
@media (max-width: 430px) and (min-height: 900px) {
  .mobile-header {
    padding: 6px 12px;
    min-height: 60px;
  }

  .mobile-game-area {
    padding: 3px;
  }

  #mobile-game {
    width: min(380px, calc(100vw - 6px)) !important;  /* ★修正: iPhone14向けさらに拡大 */
    height: min(580px, calc(100vh - 65px)) !important; /* ★修正: 縦もフル活用 */
  }
}

/* ★修正: 小画面対応 */
@media (max-width: 480px) {
  .rule-card {
    padding: 20px;
  }
  
  .mobile-game-area {
    padding: 4px; /* ★修正: さらに余白縮小 */
  }

  .mobile-header {
    padding: 6px 12px; /* ★修正: さらにコンパクト */
    min-height: 60px;  /* ★修正: さらに縮小 */
  }

  #mobile-game {
    width: min(320px, calc(100vw - 8px)) !important;  /* ★修正: 画面ほぼフル活用 */
    height: min(520px, calc(100vh - 70px)) !important;
  }

  .title-section h1 {
    font-size: 2.5rem;
  }
}

/* ★修正: 横画面対応 - 画面フル活用 */
@media (max-width: 768px) and (orientation: landscape) {
  .mobile-header {
    padding: 4px 15px;  /* ★修正: 横画面でさらにコンパクト */
    min-height: 50px;   /* ★修正: 横画面で極小 */
  }

  .mobile-game-area {
    padding: 3px;
  }

  #mobile-game {
    width: min(450px, calc(100vh - 55px)) !important; /* ★修正: 横画面フル活用 */
    height: min(350px, calc(100vh - 55px)) !important;
  }
}
