/* モダンなタイピングゲームのスタイル */
:root {
  --primary-color: #6366f1;
  --primary-dark: #4f46e5;
  --secondary-color: #f59e0b;
  --accent-color: #ec4899;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --warning-color: #f59e0b;
  --dark-bg: #0f172a;
  --card-bg: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --border-color: #334155;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  text-align: center;
  background: linear-gradient(135deg, var(--dark-bg) 0%, #1e1b4b 100%);
  margin: 0;
  min-height: 100vh;
  color: var(--text-primary);
  line-height: 1.6;
}

/* スクロールバーのカスタマイズ */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--card-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
}

#start-message {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-primary);
  text-shadow: 0 0 20px rgba(99, 102, 241, 0.5);
  animation: pulse-glow 2s ease-in-out infinite;
  margin: 2rem 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

#start-message i {
  color: var(--primary-color);
  font-size: 1.5rem;
  animation: bounce 2s infinite;
}

#start-message .start-text {
  background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-10px);
  }
  60% {
    transform: translateY(-5px);
  }
}

@keyframes pulse-glow {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.05);
  }
}

header {
  background-color: #2c3e50;
  color: white;
  text-align: center;
  position: relative;
  padding: 1rem;
}

header h1 {
  margin: 0;
  font-size: 1.8rem;
}

/* --- ホームボタン --- */
.home-button {
  position: absolute;
  top: 50%;
  right: 15px;
  transform: translateY(-50%); /* 上下中央揃え */
  background-color: #3498db;
  color: white;
  padding: 10px 15px;
  border-radius: 5px;
  text-decoration: none;
  font-weight: bold;
  font-size: 1rem;
  transition: background-color 0.2s ease-in-out;
}

.home-button:hover {
  background-color: #2980b9;
}
@media (max-width: 768px) {
  .home-button {
    padding: 10px;
    font-size: 1.2rem;
  }
  
  .home-button .button-text {
    display: none; /* テキストを非表示に */
  }
}
@media (max-width: 768px) {
  header {
    padding: 0.75rem; /* 1remから0.75remに削減 */
  }
  
  header h1 {
    font-size: 1.5rem; /* 1.75remから1.5remに削減 */
  }
}

@media (max-height: 800px) {
  header {
    padding: 0.5rem; /* 1remから0.5remに削減 */
  }
  
  header h1 {
    font-size: 1.5rem; /* 2remから1.5remに削減 */
  }
}

#game-container {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem; /* 2remから1remに削減 */
}

#formula-display {
  margin: 1rem auto; /* 2remから1remに削減 */
  padding: 1.5rem; /* 2remから1.5remに削減 */
  border: 2px solid var(--border-color);
  border-radius: 20px;
  background: linear-gradient(135deg, var(--card-bg) 0%, #1e293b 100%);
  height: 120px; /* 80pxから120pxに戻す */
  font-size: 2rem; /* 2.5remから2remに削減 */
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-y: hidden;
  overflow-x: auto;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  /* はみ出し防止のための追加設定 */
  min-height: 120px;
  box-sizing: border-box;
}

#timer {
  font-size: 1.5rem; /* 2remから1.5remに削減 */
  font-weight: 700;
  color: var(--danger-color);
  text-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
  margin: 0.5rem 0; /* 1remから0.5remに削減 */
}

#score {
  font-size: 1.5rem; /* 1.75remから1.5remに削減 */
  font-weight: 600;
  color: var(--text-primary);
  margin: 0.25rem 0; /* 0.5remから0.25remに削減 */
  text-shadow: 0 0 10px rgba(16, 185, 129, 0.3);
}

#hp-bar-container {
  width: 100%;
  max-width: 600px;
  height: 20px; /* 24pxから20pxに削減 */
  background: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  margin: 1rem auto; /* 1.5remから1remに削減 */
  overflow: hidden;
  box-shadow: var(--shadow-md);
  position: relative;
}

#hp-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--success-color), #34d399);
  border-radius: 10px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

#hp-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* タイピングエリアの内部要素の配置を調整 */
#text-container {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  font-size: 1.5rem; /* 1.75remから1.5remに削減 */
  margin: 1.5rem auto; /* 3remから1.5remに削減 */
  min-height: 2rem;
  letter-spacing: 0.15em;
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  background: var(--card-bg);
  padding: 1.5rem; /* 2remから1.5remに削減 */
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  width: 100%;
  max-width: 800px;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE and Edge */
  white-space: nowrap;
  /* 中央表示のための最適化 */
  scroll-behavior: smooth;
}

#text-container::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Opera */
}

#text-container p {
  white-space: nowrap;
  margin: 0;
  transition: transform 0.3s ease;
  flex-shrink: 0;
  display: inline-block;
  position: relative;
}

#typed-text {
  color: var(--text-secondary);
  transform: translateX(0);
  transition: transform 0.3s ease;
  position: relative;
}

#current-char {
  color: var(--text-primary);
  border-bottom: 4px solid var(--primary-color);
  min-width: 0.6em;
  position: relative;
  animation: cursor-blink 1s infinite;
  background: rgba(99, 102, 241, 0.1);
  padding: 0 2px;
  border-radius: 4px;
  text-align: center;
  position: relative;
  /* 中央表示のための特別なスタイル */
  z-index: 10;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
  /* スペース文字を確実に表示するためのスタイル */
  white-space: pre;
  word-break: keep-all;
}

#question {
  color: var(--text-secondary);
  opacity: 0.7;
  position: relative;
  /* スペース文字を確実に表示するためのスタイル */
  white-space: pre;
  word-break: keep-all;
}

/* 長いコードがはみ出ないようにするためのスタイル */
#text-container::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 50px;
  background: linear-gradient(90deg, var(--card-bg) 0%, transparent 100%);
  z-index: 1;
  pointer-events: none;
}

#text-container::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 50px;
  background: linear-gradient(90deg, transparent 0%, var(--card-bg) 100%);
  z-index: 1;
  pointer-events: none;
}

@keyframes cursor-blink {
  0%, 50% { border-bottom-color: var(--primary-color); }
  51%, 100% { border-bottom-color: transparent; }
}

#action-area {
  width: 100%;
  max-width: 800px;
  height: 150px; /* 200pxから150pxに削減 */
  background: linear-gradient(135deg, var(--card-bg) 0%, #1e293b 100%);
  border: 2px solid var(--border-color);
  border-radius: 20px;
  margin: 1rem auto 0; /* 2remから1remに削減 */
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(10px);
}

#cannon {
  width: 70px;
  height: 35px;
  background: linear-gradient(135deg, #64748b, #475569);
  border-radius: 0 17px 17px 0;
  border-left: 10px solid #334155;
  position: absolute;
  bottom: 30px;
  left: 30px;
  z-index: 2;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
}

#cannon.cannon-destroyed {
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  transform: rotate(-45deg) scale(0.7) translateY(30px);
  opacity: 0;
  filter: grayscale(100%);
}

.bullet {
  width: 18px;
  height: 18px;
  background: radial-gradient(circle, var(--danger-color), #dc2626);
  border-radius: 50%;
  position: absolute;
  left: 100px;
  bottom: 35px;
  animation: fire-bullet 0.8s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  box-shadow: 0 0 20px var(--danger-color);
}

@keyframes fire-bullet {
  from {
    transform: scale(1);
    opacity: 1;
  }
  to {
    left: 100%;
    transform: scale(0.3);
    opacity: 0;
  }
}

#enemy-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.enemy {
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, var(--danger-color), #dc2626);
  border: 3px solid #991b1b;
  border-radius: 16px;
  position: absolute;
  bottom: 20px;
  box-shadow: var(--shadow-lg);
  transition: all 0.3s ease;
}

.enemy-hp-bar-container {
  width: 60px;
  height: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  border-radius: 5px;
  overflow: hidden;
}

.enemy-hp-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--warning-color), #fbbf24);
  transition: width 0.3s ease;
}

.enemy.defeated {
  animation: defeat-enemy 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes move-enemy {
  from {
    left: 100%;
  }
  to {
    left: -100%;
  }
}

@keyframes defeat-enemy {
  to {
    transform: scale(1.3) rotate(45deg);
    opacity: 0;
    filter: brightness(1.5) saturate(2);
  }
}

.enemy-hp-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 28px;
  font-weight: 700;
  color: white;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
}

.explosion {
  position: absolute;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, var(--warning-color), #f59e0b, #d97706);
  border-radius: 50%;
  transform: scale(0);
  animation: explode 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  z-index: 10;
  box-shadow: 0 0 40px var(--warning-color);
}

@keyframes explode {
  from {
    transform: scale(0);
    opacity: 1;
  }
  to {
    transform: scale(1.8);
    opacity: 0;
  }
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: linear-gradient(135deg, var(--card-bg) 0%, #1e293b 100%);
  padding: 2rem 3rem; /* 3rem 4remから2rem 3remに削減 */
  border-radius: 24px;
  box-shadow: var(--shadow-xl);
  text-align: center;
  border: 1px solid var(--border-color);
  max-width: 450px; /* 500pxから450pxに削減 */
  width: 90%;
}

.modal-content h2 {
  margin-top: 0;
  color: var(--danger-color);
  font-size: 2rem; /* 2.5remから2remに削減 */
  font-weight: 700;
  margin-bottom: 0.75rem; /* 1remから0.75remに削減 */
}

#restart-button {
  padding: 12px 30px; /* 15px 35pxから12px 30pxに削減 */
  font-size: 1.2rem; /* 1.3remから1.2remに削減 */
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-md);
  margin-top: 0.75rem; /* 1remから0.75remに削減 */
}

#restart-button:hover {
  transform: scale(1.05);
  box-shadow: var(--shadow-xl);
  background: linear-gradient(135deg, var(--primary-dark), var(--primary-color));
}

#final-score {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 2rem 0;
  text-shadow: 0 0 20px rgba(99, 102, 241, 0.5);
}

.hidden {
  display: none;
}

#ranking-container {
  width: 95%;
  max-width: 600px;
  margin: 1.5rem auto; /* 3remから1.5remに削減 */
  padding: 1.5rem; /* 2remから1.5remに削減 */
  background: linear-gradient(135deg, var(--card-bg) 0%, #1e293b 100%);
  border: 2px solid var(--border-color);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  /* ランキングを非表示にする */
  display: none;
}

/* ランキング表示ボタンのスタイル */
#ranking-toggle-container {
  text-align: center;
  margin: 1rem auto;
  /* 常に表示 */
  display: block;
}

.ranking-button {
  background: linear-gradient(135deg, var(--secondary-color), #f59e0b);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 auto;
}

.ranking-button:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  background: linear-gradient(135deg, #f59e0b, var(--secondary-color));
}

.ranking-button i {
  font-size: 1rem;
}

/* ランキングが表示されている時のボタン */
.ranking-button.showing-ranking {
  background: linear-gradient(135deg, var(--danger-color), #dc2626);
}

.ranking-button.showing-ranking:hover {
  background: linear-gradient(135deg, #dc2626, var(--danger-color));
}

#ranking-list {
  list-style-type: none;
  padding: 0;
  margin: 0;
}

#ranking-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border-color);
  transition: all 0.3s ease;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

#ranking-list li:hover {
  background: rgba(99, 102, 241, 0.1);
  transform: translateX(5px);
}

#ranking-list li:last-child {
  border-bottom: none;
}

#ranking-list .name {
  font-weight: 600;
  color: var(--text-primary);
}

#ranking-list .score {
  color: var(--secondary-color);
  font-weight: 700;
  font-size: 1.2rem;
}

.pc-only {
  display: none;
}

@media (min-width: 769px) {
  .pc-only {
    display: block;
  }
}

.mobile-only {
  display: block;
}

@media (min-width: 769px) {
  .mobile-only {
    display: none;
  }
  .pcde {
    display: none;
  }
}

.highlight-red {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 1.1rem;
}

.pcde {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

/* 追加のモダンなアニメーション */
@keyframes fade-in-up {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#game-container > * {
  animation: fade-in-up 0.6s ease-out;
}

/* レスポンシブデザインの改善 */
@media (max-width: 768px) {
  #game-container {
    padding: 0.5rem; /* 1remから0.5remに削減 */
  }
  
  #formula-display {
    font-size: 1.5rem; /* 2remから1.5remに削減 */
    padding: 1rem; /* 1.5remから1remに削減 */
    height: 60px; /* 80pxから60pxに削減 */
    margin: 0.5rem auto; /* 1remから0.5remに削減 */
  }
  
  #text-container {
    font-size: 1.25rem; /* 1.5remから1.25remに削減 */
    padding: 1rem; /* 1.5remから1remに削減 */
    margin: 1rem auto; /* 1.5remから1remに削減 */
  }
  
  #action-area {
    height: 120px; /* 150pxから120pxに削減 */
    margin: 0.5rem auto 0; /* 1remから0.5remに削減 */
  }
  
  #timer {
    font-size: 1.25rem; /* 1.5remから1.25remに削減 */
    margin: 0.25rem 0; /* 0.5remから0.25remに削減 */
  }
  
  #score {
    font-size: 1.25rem; /* 1.5remから1.25remに削減 */
    margin: 0.125rem 0; /* 0.25remから0.125remに削減 */
  }
  
  #start-message {
    font-size: 1.25rem; /* 1.5remから1.25remに削減 */
    margin: 0.5rem 0; /* 1remから0.5remに削減 */
  }
  
  header h1 {
    font-size: 1.75rem; /* 2remから1.75remに削減 */
  }
  
  .modal-content {
    padding: 1.5rem 2rem; /* 2rem 3remから1.5rem 2remに削減 */
    max-width: 400px; /* 450pxから400pxに削減 */
  }
  
  .modal-content h2 {
    font-size: 1.75rem; /* 2remから1.75remに削減 */
    margin-bottom: 0.5rem; /* 0.75remから0.5remに削減 */
  }
  
  #restart-button {
    padding: 10px 25px; /* 12px 30pxから10px 25pxに削減 */
    font-size: 1.1rem; /* 1.2remから1.1remに削減 */
    margin-top: 0.5rem; /* 0.75remから0.5remに削減 */
  }
}

@media (max-height: 800px) {
  .modal-content {
    padding: 1.5rem 2rem;
    max-width: 400px;
  }
  
  .modal-content h2 {
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
  }
  
  #restart-button {
    padding: 10px 25px;
    font-size: 1.1rem;
    margin-top: 0.5rem;
  }
}

/* さらに小さい画面用の最適化 */
@media (max-height: 800px) {
  #game-container {
    padding: 0.5rem;
  }
  
  #formula-display {
    margin: 0.5rem auto;
    height: 60px;
    padding: 1rem;
  }
  
  #text-container {
    margin: 1rem auto;
    padding: 1rem;
  }
  
  #action-area {
    height: 100px;
    margin: 0.5rem auto 0;
  }
  
  #start-message {
    margin: 0.5rem 0;
  }
  
  #ranking-container {
    margin: 1rem auto;
    padding: 1rem;
  }
}