/* ============================================================
   QUANTUM RACE - サイバーパンク / 近未来UI (v2 完成版)
   ============================================================ */

/* ---------- リセット & ベース ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --neon-cyan:    #00f0ff;
  --neon-pink:    #ff2d95;
  --neon-purple:  #b44dff;
  --neon-green:   #39ff14;
  --neon-yellow:  #ffe600;
  --neon-orange:  #ff6f00;
  --bg-dark:      #0a0a14;
  --bg-card:      #12122a;
  --bg-card-alt:  #1a1a3e;
  --text-main:    #e0e0f0;
  --text-dim:     #7a7a9a;
  --text-bright:  #ffffff;
  --border-glow:  rgba(0, 240, 255, 0.3);
  --font-jp:  'Noto Sans JP', sans-serif;
  --font-en:  'Orbitron', sans-serif;
}

html, body {
  width: 100%; height: 100%;
  overflow-x: hidden;
  font-family: var(--font-jp);
  background: var(--bg-dark);
  color: var(--text-main);
  line-height: 1.6;
}

#bgCanvas {
  position: fixed; top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
}

.hidden { display: none !important; }

.neon-text {
  color: var(--neon-cyan);
  text-shadow: 0 0 8px var(--neon-cyan), 0 0 20px rgba(0,240,255,.4);
}

/* ---------- モーダル ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: none; align-items: center; justify-content: center;
  background: rgba(5,5,15,.85);
  backdrop-filter: blur(8px);
  padding: 1rem;
  overflow-y: auto;
}
.modal-overlay.active { display: flex; }

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-glow);
  border-radius: 16px;
  padding: 2rem;
  max-width: 540px; width: 100%;
  position: relative;
  box-shadow: 0 0 40px rgba(0,240,255,.1), inset 0 0 40px rgba(0,240,255,.03);
  animation: modalIn .4s cubic-bezier(.16,1,.3,1);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.92) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ---------- タイトル画面 ---------- */
.title-box { max-width: 560px; }
.title-icon { text-align: center; font-size: 3rem; margin-bottom: .5rem; }
.title-heading {
  font-family: var(--font-en); font-weight: 900;
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  text-align: center;
  background: linear-gradient(90deg, var(--neon-cyan), var(--neon-pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; letter-spacing: .15em;
}
.title-subtitle {
  text-align: center; color: var(--text-dim);
  margin-bottom: 1.2rem; font-size: .9rem;
}

/* タブ */
.intro-tabs { display: flex; gap: .5rem; margin-bottom: .8rem; justify-content: center; }
.tab-btn {
  font-family: var(--font-jp); font-weight: 700; font-size: .82rem;
  padding: .4rem 1rem;
  border: 1px solid var(--border-glow); border-radius: 8px;
  background: transparent; color: var(--text-dim);
  cursor: pointer; transition: all .2s;
}
.tab-btn.active {
  background: rgba(0,240,255,.1); color: var(--neon-cyan);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 12px rgba(0,240,255,.2);
}
.tab-content {
  display: none; font-size: .85rem; line-height: 1.7;
  max-height: 200px; overflow-y: auto; padding: .3rem 0;
}
.tab-content.active { display: block; }
.tab-content blockquote {
  border-left: 3px solid var(--neon-pink);
  padding: .5rem 1rem; margin: .6rem 0;
  background: rgba(255,45,149,.05);
  color: var(--neon-pink); font-style: italic;
}
.rules-list { list-style: none; }
.rules-list li { padding: .3rem 0; display: flex; align-items: flex-start; gap: .5rem; }
.rule-icon { font-size: 1rem; flex-shrink: 0; }

/* モード選択ボタン */
.mode-buttons {
  display: flex; gap: .8rem; margin-top: 1.2rem;
  flex-wrap: wrap; justify-content: center;
}
.btn-mode {
  flex: 1; min-width: 200px; max-width: 260px;
  flex-direction: column; gap: .3rem;
  padding: 1rem 1.2rem;
  text-align: center;
}
.mode-icon { font-size: 1.8rem; display: block; }
.mode-label { font-size: .95rem; font-weight: 900; display: block; }
.mode-desc { font-size: .7rem; color: var(--text-dim); display: block; font-weight: 400; }

/* ---------- ネオンボタン ---------- */
.btn-neon {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-jp); font-weight: 700; font-size: .95rem;
  padding: .7rem 2rem;
  border: 2px solid var(--neon-cyan); border-radius: 12px;
  background: transparent; color: var(--neon-cyan);
  cursor: pointer; transition: all .25s;
  letter-spacing: .08em; position: relative; overflow: hidden;
}
.btn-neon::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(0,240,255,.15), rgba(180,77,255,.15));
  opacity: 0; transition: opacity .25s;
}
.btn-neon:hover::before { opacity: 1; }
.btn-neon:hover {
  box-shadow: 0 0 20px rgba(0,240,255,.4), 0 0 40px rgba(0,240,255,.15);
  transform: translateY(-2px);
}
.btn-neon:active { transform: translateY(0); }
.btn-pink  { border-color: var(--neon-pink);  color: var(--neon-pink); }
.btn-pink:hover  { box-shadow: 0 0 20px rgba(255,45,149,.4); }
.btn-green { border-color: var(--neon-green); color: var(--neon-green); }
.btn-green:hover { box-shadow: 0 0 20px rgba(57,255,20,.4); }
.btn-small { font-size: .8rem; padding: .5rem 1.2rem; }

/* ---------- レベル選択 ---------- */
.level-select-box { max-width: 560px; text-align: center; }
.level-select-title {
  font-family: var(--font-en); font-weight: 900;
  font-size: 1.4rem; margin-bottom: .3rem;
  color: var(--neon-cyan);
}
.level-select-desc { font-size: .82rem; color: var(--text-dim); margin-bottom: 1rem; }

.level-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: .6rem;
}
.level-card {
  display: flex; flex-direction: column; align-items: center;
  gap: .3rem; padding: .8rem .5rem;
  border: 2px solid rgba(255,255,255,.08);
  border-radius: 12px; background: rgba(255,255,255,.02);
  cursor: pointer; transition: all .25s;
}
.level-card:hover {
  border-color: var(--neon-cyan);
  background: rgba(0,240,255,.06);
  box-shadow: 0 0 16px rgba(0,240,255,.2);
  transform: translateY(-3px);
}
.level-card-emoji { font-size: 2rem; }
.level-card-name { font-weight: 700; font-size: .85rem; }
.level-card-speed { font-size: .65rem; color: var(--text-dim); }

/* ---------- カウントダウン ---------- */
.countdown-text {
  font-family: var(--font-en); font-weight: 900;
  font-size: clamp(6rem, 20vw, 14rem);
  color: var(--neon-cyan);
  text-shadow: 0 0 40px var(--neon-cyan), 0 0 80px rgba(0,240,255,.5);
  animation: countPop .7s cubic-bezier(.16,1,.3,1) forwards;
  user-select: none;
}
.countdown-text.don {
  font-size: clamp(4rem, 14vw, 9rem);
  background: linear-gradient(90deg, var(--neon-pink), var(--neon-yellow));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; text-shadow: none;
  filter: drop-shadow(0 0 30px rgba(255,45,149,.6));
}
@keyframes countPop {
  0%   { opacity: 0; transform: scale(2.5); }
  30%  { opacity: 1; transform: scale(.9); }
  50%  { transform: scale(1.05); }
  100% { opacity: .15; transform: scale(.8); }
}

/* ---------- ゲーム画面 ---------- */
.game-screen {
  position: relative; z-index: 1;
  min-height: 100vh;
  display: flex; flex-direction: column;
  padding: .8rem;
}

.game-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; padding: .5rem 0;
  border-bottom: 1px solid rgba(0,240,255,.15);
  margin-bottom: .6rem; flex-wrap: wrap;
}
.header-left, .header-right { display: flex; align-items: center; gap: .5rem; }

.header-title {
  font-family: var(--font-en); font-weight: 700;
  font-size: clamp(.8rem, 2.5vw, 1.2rem);
  background: linear-gradient(90deg, var(--neon-cyan), var(--neon-pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; cursor: pointer; letter-spacing: .1em;
}

.mode-badge {
  font-size: .65rem; font-weight: 700;
  padding: .2rem .5rem; border-radius: 6px;
  letter-spacing: .05em;
}
.mode-badge.story { background: rgba(255,45,149,.15); color: var(--neon-pink); border: 1px solid var(--neon-pink); }
.mode-badge.level { background: rgba(0,240,255,.15); color: var(--neon-cyan); border: 1px solid var(--neon-cyan); }

.rank-badge {
  font-size: .75rem; font-weight: 700;
  padding: .25rem .7rem; border-radius: 20px;
  border: 1px solid; white-space: nowrap;
}
.puzzle-progress { font-size: .75rem; color: var(--text-dim); white-space: nowrap; }
.score-display { display: flex; gap: .6rem; font-size: .82rem; font-weight: 700; }
.score-win  { color: var(--neon-green); }
.score-lose { color: var(--neon-pink); }

/* QAプログレス */
.qa-progress-container { margin-bottom: .6rem; }
.qa-progress-label {
  display: flex; justify-content: space-between;
  font-size: .7rem; color: var(--text-dim); margin-bottom: .2rem;
}
.qa-progress-bar {
  height: 8px; background: rgba(255,255,255,.06);
  border-radius: 4px; overflow: hidden;
  border: 1px solid rgba(0,240,255,.1);
}
.qa-progress-fill {
  height: 100%; width: 0%; border-radius: 4px;
  background: linear-gradient(90deg, var(--neon-cyan), var(--neon-pink));
  transition: width .4s ease-out;
  box-shadow: 0 0 10px var(--neon-cyan);
}

/* 盤面 */
.boards-container {
  flex: 1; display: flex; align-items: flex-start; justify-content: center;
  gap: 1rem; padding: .5rem 0; flex-wrap: wrap;
}
.board-section { flex: 1; min-width: 170px; max-width: 340px; }
.board-label {
  display: flex; align-items: center; gap: .4rem;
  font-family: var(--font-en); font-weight: 700;
  font-size: clamp(.7rem, 1.8vw, .95rem);
  margin-bottom: .4rem; justify-content: center;
}
.player-section .board-label { color: var(--neon-green); }
.qa-section .board-label { color: var(--neon-pink); }
.label-icon { font-size: 1.2rem; }

.vs-divider {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: .2rem; padding-top: 2rem; flex-shrink: 0;
}
.vs-text {
  font-family: var(--font-en); font-weight: 900; font-size: 1.4rem;
  background: linear-gradient(180deg, var(--neon-cyan), var(--neon-pink));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.vs-lightning { font-size: 1.4rem; animation: vsFlicker 2s infinite; }
@keyframes vsFlicker { 0%,100%{opacity:1} 50%{opacity:.3} }

.sudoku-board {
  display: grid; grid-template-columns: repeat(4,1fr);
  gap: 4px; padding: 8px;
  background: rgba(0,240,255,.04);
  border: 1px solid rgba(0,240,255,.15);
  border-radius: 12px; aspect-ratio: 1;
}
.cell {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-en); font-weight: 700;
  font-size: clamp(1.1rem, 3.5vw, 1.7rem);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  color: var(--text-main);
  transition: all .2s; cursor: default; user-select: none;
}
.cell.initial {
  background: rgba(0,240,255,.08); color: var(--neon-cyan);
  border-color: rgba(0,240,255,.2);
}
.cell.editable { cursor: pointer; background: rgba(255,255,255,.02); }
.cell.editable:hover {
  background: rgba(0,240,255,.1); border-color: var(--neon-cyan);
  box-shadow: 0 0 12px rgba(0,240,255,.2);
}
.cell.filled {
  background: rgba(57,255,20,.08); color: var(--neon-green);
  border-color: rgba(57,255,20,.25);
}
.cell.disabled { opacity: .5; pointer-events: none; }
.qa-board .cell.revealed {
  background: rgba(255,45,149,.1); color: var(--neon-pink);
  border-color: rgba(255,45,149,.3);
  animation: cellReveal .4s ease-out;
}
@keyframes cellReveal {
  0%   { transform: scale(1.3); opacity: 0; box-shadow: 0 0 20px var(--neon-pink); }
  100% { transform: scale(1); opacity: 1; box-shadow: none; }
}

/* ---------- ラウンド結果 ---------- */
.round-box { text-align: center; max-width: 420px; }
.round-icon { font-size: 3.5rem; margin-bottom: .4rem; }
.round-title { font-family: var(--font-en); font-size: 1.4rem; margin-bottom: .4rem; }
.round-msg { font-size: .85rem; color: var(--text-dim); margin-bottom: 1.2rem; }
.round-buttons { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }

/* ---------- ランククリア ---------- */
.rank-clear-box { text-align: center; max-width: 480px; overflow: hidden; }
.rank-clear-title {
  font-family: var(--font-en); font-size: clamp(1.2rem, 4vw, 1.8rem);
  margin-bottom: .8rem; animation: glowPulse 2s infinite;
}
@keyframes glowPulse {
  0%,100% { text-shadow: 0 0 10px var(--neon-cyan); }
  50% { text-shadow: 0 0 30px var(--neon-cyan), 0 0 60px var(--neon-pink); }
}
.rank-clear-badge { margin-bottom: .8rem; }
.rank-clear-msg { font-size: .85rem; color: var(--text-dim); margin-bottom: .8rem; }
.next-rank-preview { margin-bottom: 1.2rem; }
.rank-clear-buttons { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }

/* ---------- 進捗ドット ---------- */
.progress-dots { display: flex; gap: 4px; align-items: center; }
.progress-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15); transition: all .3s;
}
.progress-dot.done { background: var(--neon-green); border-color: var(--neon-green); box-shadow: 0 0 6px var(--neon-green); }
.progress-dot.current { background: var(--neon-cyan); border-color: var(--neon-cyan); box-shadow: 0 0 8px var(--neon-cyan); animation: dotPulse 1s infinite; }
@keyframes dotPulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.3)} }

/* ---------- ゲームオーバー ---------- */
.gameover-box { text-align: center; max-width: 480px; }
.gameover-glitch {
  font-family: var(--font-en); font-weight: 900;
  font-size: clamp(1.8rem, 7vw, 3.2rem);
  color: var(--neon-pink);
  text-shadow: 0 0 10px var(--neon-pink), 0 0 40px rgba(255,45,149,.4);
  letter-spacing: .15em;
  animation: glitchFlicker 3s infinite;
  margin-bottom: .3rem;
}
@keyframes glitchFlicker {
  0%,93%,100% { opacity:1; transform:none; }
  94% { opacity:.8; transform:translateX(-3px) skewX(-2deg); }
  95% { opacity:.6; transform:translateX(3px) skewX(2deg); }
  96% { opacity:1; transform:none; }
  97% { opacity:.7; transform:translateX(-2px); }
  98% { opacity:1; transform:none; }
}
.gameover-sub { color: var(--text-dim); font-size: .85rem; margin-bottom: 1.2rem; }

.scoreboard {
  background: rgba(0,240,255,.03);
  border: 1px solid rgba(0,240,255,.12);
  border-radius: 12px; padding: 1rem; margin-bottom: 1.2rem;
}
.scoreboard-title {
  font-family: var(--font-en); font-weight: 700; font-size: .8rem;
  color: var(--neon-cyan); letter-spacing: .2em; margin-bottom: .8rem;
  text-shadow: 0 0 8px rgba(0,240,255,.3);
}
.scoreboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .8rem; }
.sb-item {
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  padding: .5rem; background: rgba(255,255,255,.02);
  border-radius: 8px; border: 1px solid rgba(255,255,255,.05);
}
.sb-label { font-size: .65rem; color: var(--text-dim); }
.sb-value { font-family: var(--font-en); font-weight: 900; font-size: 1.2rem; color: var(--text-bright); }
.sb-green { color: var(--neon-green); text-shadow: 0 0 8px rgba(57,255,20,.3); }
.sb-cyan  { color: var(--neon-cyan); text-shadow: 0 0 8px rgba(0,240,255,.3); }

.sb-rank-progress { margin-top: .4rem; }
.sb-progress-label { font-size: .65rem; color: var(--text-dim); margin-bottom: .4rem; }
.sb-ranks { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; }
.sb-rank-dot {
  width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; border: 2px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.02); transition: all .3s; position: relative;
}
.sb-rank-dot.cleared {
  border-color: var(--neon-green); background: rgba(57,255,20,.1);
  box-shadow: 0 0 8px rgba(57,255,20,.3);
}
.sb-rank-dot.failed {
  border-color: var(--neon-pink); background: rgba(255,45,149,.1);
  box-shadow: 0 0 8px rgba(255,45,149,.3);
}
.sb-rank-dot.failed::after {
  content: '✕'; position: absolute;
  font-size: .55rem; color: var(--neon-pink);
  bottom: -2px; right: -2px; font-weight: 900;
}
.gameover-buttons { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }

/* ---------- レスポンシブ ---------- */
@media (max-width: 640px) {
  .boards-container { gap: .5rem; }
  .vs-divider { padding-top: .5rem; }
  .vs-text { font-size: 1rem; }
  .sudoku-board { gap: 3px; padding: 6px; }
  .modal-box { padding: 1.2rem; }
  .game-header { font-size: .75rem; }
  .mode-buttons { flex-direction: column; align-items: center; }
  .btn-mode { max-width: 100%; }
}
@media (max-width: 480px) {
  .boards-container { flex-direction: column; align-items: center; }
  .board-section { max-width: 280px; width: 100%; }
  .vs-divider { flex-direction: row; padding-top: 0; gap: .5rem; }
  .level-grid { grid-template-columns: repeat(2, 1fr); }
}
