/* ============================================
   リテイクつぶせ！ - Master Stylesheet
   ============================================ */

:root {
  --color-primary: #FF4757;
  --color-accent: #FFA502;
  --color-accent2: #2ED573;
  --color-dark: #1a1a2e;
  --color-darker: #0f0f23;
  --color-text: #2f3542;
  --color-text-light: #ffffff;
  --color-glass: rgba(255, 255, 255, 0.5);
  --color-glass-dark: rgba(0, 0, 0, 0.5);
  --font-main: 'M PLUS Rounded 1c', 'Zen Maru Gothic', sans-serif;
}

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

body {
  background: #0a0a1a;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: var(--font-main);
  overflow: hidden;
}

/* ---- Game Container (16:9 fixed) ---- */
#game-container {
  position: relative;
  width: 100vw;
  max-width: calc(100vh * 16 / 9);
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 80px rgba(255, 71, 87, 0.15);
  container-type: size;
}

/* ---- Sound Toggle Button ---- */
.sound-toggle {
  position: absolute;
  top: 2%;
  right: 1.5%;
  z-index: 500;
  width: clamp(36px, 4vw, 52px);
  height: clamp(36px, 4vw, 52px);
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(6px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
  padding: 0;
}
.sound-toggle:hover {
  background: rgba(0,0,0,0.7);
  border-color: rgba(255,255,255,0.4);
}
.sound-toggle-icon {
  font-size: clamp(16px, 2vw, 24px);
  line-height: 1;
  pointer-events: none;
}

/* ---- Background Layers ---- */
.bg-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transition: opacity 1s ease;
  opacity: 0;
  z-index: 1;
}
.bg-layer.active {
  opacity: 1;
}

/* ---- Splash Screen ---- */
.splash-screen {
  position: absolute;
  inset: 0;
  z-index: 999;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.5s ease;
}
.splash-screen.hidden {
  opacity: 0;
  pointer-events: none;
}
.splash-image {
  max-width: 100%;
  max-height: 85%;
  object-fit: contain;
}
.splash-hint {
  position: absolute;
  bottom: 5%;
  font-size: clamp(0.8rem, 1.8vw, 1.3rem);
  font-weight: 700;
  color: rgba(255,255,255,0.6);
  letter-spacing: 0.1em;
  transition: opacity 0.3s ease;
}
.splash-hint[style*="opacity: 1"], .splash-hint[style*="opacity:1"] {
  animation: splashBlink 1.5s ease-in-out infinite;
}
@keyframes splashBlink {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* Splash Progress Bar */
.splash-progress {
  position: absolute;
  bottom: 12%;
  left: 50%;
  transform: translateX(-50%);
  width: clamp(200px, 50%, 400px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.splash-progress-text {
  font-size: clamp(0.7rem, 1.4vw, 1rem);
  font-weight: 700;
  color: rgba(255,255,255,0.7);
  letter-spacing: 0.05em;
}
.splash-progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  overflow: hidden;
}
.splash-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #FF4757, #ffa502);
  border-radius: 3px;
  transition: width 0.2s ease;
}

/* ---- Screens ---- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
/* Game screen: no z-index so its children layer independently with chara */
#screen-game {
  z-index: auto;
}
.screen.active {
  display: flex;
}

/* ============ MENU SCREEN ============ */
.menu-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5%;
  z-index: 10;
  position: relative;
}

.title-block {
  text-align: center;
  animation: titleFloat 3s ease-in-out infinite;
}

@keyframes titleFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.game-title {
  font-size: clamp(2rem, 6vw, 5rem);
  font-weight: 900;
  color: #fff;
  text-shadow:
    0 0 10px rgba(255,71,87,0.8),
    0 0 30px rgba(255,71,87,0.5),
    0 4px 0 #c0392b,
    0 5px 0 #a93226,
    0 6px 10px rgba(0,0,0,0.5);
  letter-spacing: 0.05em;
}

.game-subtitle {
  font-size: clamp(0.8rem, 2vw, 1.5rem);
  color: #ffeaa7;
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  margin-top: 0.3em;
  font-weight: 700;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.5vw, 18px);
  align-items: center;
  margin-top: clamp(16px, 3vw, 40px);
}

/* Primary start button */
.menu-btn {
  font-family: var(--font-main);
  font-size: clamp(0.9rem, 2vw, 1.5rem);
  font-weight: 800;
  padding: 0.6em 2.5em;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.05em;
  position: relative;
  overflow: hidden;
  min-width: 260px;
}

/* Secondary buttons (smaller, subdued) */
.menu-btn-sub {
  font-size: clamp(0.65rem, 1.3vw, 1rem);
  padding: 0.45em 1.8em;
  min-width: 180px;
  font-weight: 700;
  opacity: 0.85;
}

.menu-btn:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}
.menu-btn:active {
  transform: translateY(0) scale(0.98);
}

.btn-start {
  background: linear-gradient(135deg, #FF4757, #ff6b81);
  color: #fff;
  box-shadow: 0 4px 15px rgba(255,71,87,0.4);
}
.btn-highscore {
  background: linear-gradient(135deg, #FFA502, #ffc048);
  color: #fff;
  box-shadow: 0 4px 15px rgba(255,165,2,0.4);
}
.btn-leaderboard {
  background: linear-gradient(135deg, #0984e3, #74b9ff);
  color: #fff;
  box-shadow: 0 4px 15px rgba(9,132,227,0.4);
}
.btn-credit {
  background: linear-gradient(135deg, #57606f, #747d8c);
  color: #fff;
  box-shadow: 0 4px 15px rgba(87,96,111,0.4);
}
.btn-retry {
  background: linear-gradient(135deg, #2ed573, #7bed9f);
  color: #fff;
  box-shadow: 0 4px 15px rgba(46,213,115,0.4);
}

.btn-icon {
  margin-right: 0.3em;
}

/* Version Info */
.version-info {
  position: absolute;
  bottom: 3%;
  right: 3%;
  font-size: clamp(0.6rem, 1.2vw, 0.9rem);
  font-weight: 700;
  color: rgba(255,255,255,0.35);
  letter-spacing: 0.1em;
}

/* ============ TIPS AREA ============ */
.tips-area {
  position: absolute;
  bottom: 2.5%;
  left: 3%;
  z-index: 50;
  max-width: 50%;
  pointer-events: none;
}
.tips-label {
  font-size: clamp(0.6rem, 1.2vw, 0.85rem);
  font-weight: 700;
  color: rgba(255,255,255,0.5);
  margin-bottom: 0.2em;
}
.tips-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.tips-list li {
  font-size: clamp(0.5rem, 1vw, 0.72rem);
  color: rgba(255,255,255,0.4);
  line-height: 1.5;
}
.tips-list li::before {
  content: '・';
}

/* ============ GAME SCREEN ============ */

/* HUD: 共通ボックススタイル */
.hud {
  position: absolute;
  top: 2%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: clamp(12px, 2vw, 32px);
  z-index: 30;
  align-items: stretch;
}

.hud-box {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border-radius: 16px;
  padding: 0.4em 1em;
  text-align: center;
  border: 2px solid rgba(255,255,255,0.15);
  min-width: clamp(80px, 10vw, 140px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.hud-label {
  font-size: clamp(0.5rem, 1.2vw, 0.8rem);
  color: rgba(255,255,255,0.7);
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 2px;
}

.hud-value {
  font-size: clamp(1.2rem, 3.5vw, 2.5rem);
  font-weight: 900;
  color: #fff;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* TYPE/MISS用のスタイル */
.hud-stats-box {
  min-width: clamp(120px, 15vw, 200px);
}

.hud-stats-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.hud-stat-item {
  display: flex;
  flex-direction: column;
}

.hud-stat-label {
  font-size: clamp(0.4rem, 1vw, 0.7rem);
  color: rgba(255,255,255,0.5);
  font-weight: 700;
}

.hud-stat-value {
  font-size: clamp(1rem, 2.5vw, 1.8rem);
  font-weight: 900;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.hud-miss-value {
  color: #ff6b6b;
}

/* Timer Specifics */
.timer-value.timer-warning {
  color: var(--color-primary);
  animation: timerPulse 0.5s ease infinite;
}

.timer-value.timer-critical {
  color: #FF4757;
  animation: timerPulse 0.25s ease infinite;
  text-shadow: 0 0 15px rgba(255,71,87,0.8);
}

@keyframes timerPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.score-value {
  color: var(--color-accent2);
}

/* Phase indicator */
.phase-indicator {
  position: absolute;
  top: 2%;
  right: 3%;
  font-size: clamp(0.6rem, 1.2vw, 1rem);
  font-weight: 800;
  padding: 0.3em 1em;
  border-radius: 20px;
  z-index: 30;
  background: rgba(46,213,115,0.3);
  color: #2ed573;
  border: 1px solid rgba(46,213,115,0.5);
  transition: all 0.5s ease;
}

.phase-indicator.phase-Rush {
  background: rgba(255,165,2,0.3);
  color: #ffa502;
  border-color: rgba(255,165,2,0.5);
  animation: rushPulse 1s ease infinite;
}
.phase-indicator.phase-Climax {
  background: rgba(255,71,87,0.4);
  color: #ff4757;
  border-color: rgba(255,71,87,0.6);
  animation: climaxPulse 0.4s ease infinite;
}

@keyframes rushPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(255,165,2,0.3); }
  50% { box-shadow: 0 0 25px rgba(255,165,2,0.6); }
}
@keyframes climaxPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(255,71,87,0.4); }
  50% { box-shadow: 0 0 35px rgba(255,71,87,0.8); }
}

/* Question background panel (behind character z:25) */
.question-bg-panel {
  position: absolute;
  top: 55%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  max-width: 900px;
  height: auto;
  min-height: 200px;
  background: var(--color-glass);
  backdrop-filter: blur(6px);
  border-radius: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  z-index: 10;
  padding: clamp(16px, 3vw, 40px);
  pointer-events: none;
}

/* Question text layer (above character z:25) */
.question-box {
  position: absolute;
  top: 55%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 70%;
  max-width: 900px;
  padding: clamp(16px, 3vw, 40px);
  text-align: center;
  z-index: 35;
}

.question-desc-spacer {
  height: clamp(8px, 1.5cqh, 20px);
  border-top: 1px solid rgba(0,0,0,0.08);
  margin-top: clamp(4px, 0.8cqh, 12px);
  width: 60%;
  align-self: center;
}

.question-description {
  font-size: clamp(0.55rem, 1.1cqw, 0.85rem);
  color: #636e72;
  font-weight: 600;
  line-height: 1.6;
  min-height: 1.2em;
  opacity: 0.75;
}

.question-text {
  font-size: clamp(1.5rem, 4vw, 3.5rem);
  font-weight: 900;
  color: var(--color-text);
  text-shadow: 0 1px 2px rgba(255,255,255,0.5);
  margin-bottom: 0.15em;
  white-space: nowrap;
  overflow: visible;
  max-width: 100%;
  line-height: 1.3;
}

.question-kana {
  font-size: clamp(0.7rem, 1.5vw, 1.2rem);
  color: #636e72;
  font-weight: 700;
  margin-bottom: 0.5em;
  letter-spacing: 0.15em;
}

.question-romaji {
  font-size: clamp(1rem, 2.5vw, 2rem);
  font-weight: 700;
  margin-bottom: 0.5em;
  letter-spacing: 0.08em;
  font-family: 'Courier New', monospace;
  word-break: break-all;
  overflow-wrap: break-word;
  max-width: 100%;
  line-height: 1.4;
}

.romaji-done {
  color: var(--color-accent2);
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.romaji-remain {
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5), 0 0 8px rgba(0,0,0,0.2);
}

.input-display {
  font-size: clamp(1.2rem, 3vw, 2.4rem);
  font-weight: 700;
  color: var(--color-primary);
  min-height: 1.5em;
  font-family: 'Caveat', cursive;
  letter-spacing: 0.05em;
  /* 入力が長くなったときのスクロール対応 */
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  display: flex;
  justify-content: center;
  align-items: center;
  /* スクロールバーを非表示（見た目をスッキリ） */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}
.input-display::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.input-cursor {
  animation: cursorBlink 0.6s ease-in-out infinite;
  color: var(--color-primary);
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Reward Area */
.reward-area {
  position: absolute;
  bottom: 3%;
  left: 3%;
  z-index: 20;
  opacity: 0;
  transition: none;
}

.reward-image {
  max-height: 50cqh;
  width: auto;
  border-radius: 48px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  /* 白色の境界線を追加 */
  border: 4px solid #ffffff;
}

/* ============ CHARACTER ============ */
.chara-container {
  position: absolute;
  bottom: 0;
  right: 0;
  z-index: 25;
  display: none;
  pointer-events: none;
  /* 余白ゼロにするため */
  line-height: 0; 
  padding: 0;
  margin: 0;
}

.chara-image {
  height: 80cqh;
  width: auto;
  image-rendering: auto;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
  /* 画像下の隙間を消す */
  display: block; 
}

/* Character Animations */
/* idle揺れのみ（まばたき無し：panic, scream等で使用） */
.chara-idle {
  animation: charaIdle 4s ease-in-out infinite;
}
/* idle揺れ＋まばたき（normal, shyのみで使用） */
.chara-idle-blink {
  animation: charaIdle 4s ease-in-out infinite;
}
@keyframes charaIdle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.chara-bounce {
  animation: charaBounce 0.4s ease infinite;
}
@keyframes charaBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.chara-sway {
  animation: charaSway 2s ease-in-out infinite;
}
@keyframes charaSway {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(6px); }
  75% { transform: translateX(-6px); }
}

/* ============ RESULT SCREEN (RESPONSIVE) ============ */
.result-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* gapは最小限にし、配置(justify-content)で調整する */
  gap: 1cqh; 
  z-index: 10;
  position: relative;
  
  /* 横幅・高さをコンテナいっぱいに */
  width: 100%;
  height: 100%;
  
  /* パディングも高さに応じて変動させる */
  padding: 2cqh 2cqw;
  
  /* はみ出し防止（スクロールバーを出さない） */
  overflow: hidden;
  
  /* 縦方向に「均等配置」を行う */
  justify-content: space-evenly; 
}

.result-title {
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 10px rgba(0,0,0,0.5);
  flex-shrink: 0; /* タイトル文字は潰さない */
}

/* Result Title (称号) Image */
.result-title-image {
  /* 幅はなりゆき、高さは制限 */
  width: auto;
  height: auto;
  
  /* 画面高さの20%を決して超えないように制限 */
  max-height: 20cqh; 
  max-width: 60%; /* 横幅も少し制限してバランスを取る */
  
  object-fit: contain;
  border-radius: 16px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.4);
  
  /* 画面が狭いときは、この画像が優先的に縮むようにする */
  flex-shrink: 1; 
  min-height: 0; /* Flexboxの子要素として縮小を許可するために必要 */
}

/* Result Title Label */
.result-title-label {
  font-size: clamp(0.9rem, 2.5vw, 1.6rem);
  font-weight: 800;
  color: #ffeaa7;
  text-shadow: 0 2px 10px rgba(0,0,0,0.5);
  text-align: center;
  flex-shrink: 0;
}

.result-title-name {
  color: #fff;
  font-size: clamp(1.1rem, 3vw, 2rem);
  background: linear-gradient(135deg, #ffa502, #ff6b81);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 900;
}

.result-box {
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  /* パディングを高さ依存(cqh)にして、縦が狭い時は詰める */
  padding: 2cqh 4cqw;
  min-width: clamp(240px, 35cqw, 500px);
  border: 2px solid rgba(255,255,255,0.15);
  flex-shrink: 0;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0.4em 0;
  gap: 1em;
}

.result-label {
  font-size: clamp(0.7rem, 1.5vw, 1.1rem);
  color: rgba(255,255,255,0.7);
  font-weight: 700;
}

.result-number {
  font-size: clamp(1.5rem, 4vw, 3rem);
  font-weight: 900;
  color: #fff;
}

.result-divider {
  height: 1px;
  background: rgba(255,255,255,0.15);
  margin: 0.3em 0;
}

.highscore-number {
  color: var(--color-accent);
}

.new-record {
  text-align: center;
  font-size: clamp(1rem, 2.5vw, 1.8rem);
  font-weight: 900;
  color: var(--color-accent);
  margin-top: 0.5em;
  animation: recordPop 0.6s ease infinite alternate;
}

@keyframes recordPop {
  0% { transform: scale(1); }
  100% { transform: scale(1.08); }
}

.result-stats {
  text-align: center;
  font-size: clamp(0.65rem, 1.2vw, 0.9rem);
  color: rgba(255,255,255,0.55);
  margin-top: 0.4em;
  font-weight: 600;
  letter-spacing: 0.03em;
}

/* ---- Result Speech Bubble (リザルト画面フキダシ) ---- */
.result-speech-bubble {
  position: absolute;
  top: 8%;
  right: 3%;
  z-index: 40;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  padding: clamp(12px, 2cqh, 28px) clamp(16px, 3cqw, 36px);
  border-radius: 20px;
  border: 3px solid #ffffff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  max-width: min(320px, 25cqw);
  min-width: min(200px, 18cqw);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.5s ease 0.8s, transform 0.5s ease 0.8s;
  pointer-events: none;
}
.result-speech-bubble.visible {
  opacity: 1;
  transform: translateY(0);
}
.result-speech-text {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: clamp(0.7rem, 1.6cqw, 1.1rem);
  font-weight: 700;
  color: #2f3542;
  line-height: 1.6;
  text-align: center;
}
/* フキダシのしっぽ（左下→キャラクター方向） */
.result-speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 30px;
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 12px solid #ffffff;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.15));
}

/* Submit Area */
.submit-area {
  width: clamp(240px, 35cqw, 500px);
  flex-shrink: 0; /* 入力欄も潰さない */
}

.submit-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.player-name-input {
  flex: 1;
  font-family: var(--font-main);
  font-size: clamp(0.8rem, 1.8vw, 1.2rem);
  font-weight: 700;
  padding: 0.5em 1em;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 50px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  outline: none;
  transition: border-color 0.2s;
}
.player-name-input:focus {
  border-color: var(--color-accent);
}
.player-name-input::placeholder {
  color: rgba(255,255,255,0.35);
}

.btn-submit {
  background: linear-gradient(135deg, #0984e3, #74b9ff);
  color: #fff;
  box-shadow: 0 4px 15px rgba(9,132,227,0.4);
  padding: 0.5em 1.5em;
  min-width: auto;
  font-size: clamp(0.7rem, 1.5vw, 1rem);
  white-space: nowrap;
}

.submit-status {
  text-align: center;
  font-size: clamp(0.7rem, 1.3vw, 0.95rem);
  font-weight: 700;
  margin-top: 0.3em;
  min-height: 1.5em;
  color: rgba(255,255,255,0.7);
}
.submit-status.success { color: var(--color-accent2); }
.submit-status.error { color: var(--color-primary); }

/* Result Buttons Row */
.result-buttons {
  display: flex;
  gap: clamp(8px, 1.5vw, 16px);
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  /* ボタンエリアは絶対に潰さない */
  flex-shrink: 0; 
  padding-bottom: 1cqh;
}

/* Tweet Button */
.btn-tweet {
  background: linear-gradient(135deg, #1a1a2e, #2d3436);
  color: #fff;
  box-shadow: 0 4px 15px rgba(0,0,0,0.4);
  border: 2px solid rgba(255,255,255,0.15);
}
.btn-tweet:hover {
  background: linear-gradient(135deg, #2d3436, #636e72);
}

/* Time Penalty Popup */
.time-penalty {
  color: var(--color-primary) !important;
}

/* ============ LEADERBOARD SCREEN ============ */
.leaderboard-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(12px, 2.5vw, 28px);
  z-index: 10;
  position: relative;
  max-height: 95%;
}

.leaderboard-title {
  font-size: clamp(1.5rem, 3.5vw, 2.5rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 10px rgba(0,0,0,0.5);
}

.leaderboard-box {
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: clamp(14px, 3vw, 36px);
  min-width: clamp(300px, 50vw, 700px);
  max-height: 55vh;
  overflow-y: auto;
  border: 2px solid rgba(255,255,255,0.15);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
}

.leaderboard-table th {
  font-size: clamp(0.6rem, 1.2vw, 0.9rem);
  color: rgba(255,255,255,0.5);
  font-weight: 700;
  text-align: left;
  padding: 0.5em 0.8em;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.leaderboard-table td {
  font-size: clamp(0.7rem, 1.4vw, 1.05rem);
  color: rgba(255,255,255,0.85);
  font-weight: 700;
  padding: 0.55em 0.8em;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.leaderboard-table tr:hover td {
  background: rgba(255,255,255,0.04);
}

/* Top 3 highlight */
.leaderboard-table tr.lb-gold td { color: #ffd700; }
.leaderboard-table tr.lb-silver td { color: #c0c0c0; }
.leaderboard-table tr.lb-bronze td { color: #cd7f32; }

.lb-rank { width: 10%; text-align: center !important; }
.lb-name { width: 25%; }
.lb-score { width: 18%; text-align: right !important; }
.lb-title-col { width: 25%; }
.lb-date { width: 22%; font-size: 0.85em; opacity: 0.7; white-space: nowrap; }

.leaderboard-loading,
.leaderboard-empty,
.leaderboard-error {
  text-align: center;
  color: rgba(255,255,255,0.6);
  font-size: clamp(0.8rem, 1.5vw, 1.1rem);
  font-weight: 700;
  padding: 2em 1em;
  line-height: 1.8;
}
.leaderboard-error { color: rgba(255,100,100,0.8); }
.leaderboard-error small { font-weight: 400; opacity: 0.6; }

/* ============ CREDIT SCREEN ============ */
#screen-credit {
  cursor: pointer;
}
.credit-content {
  cursor: default;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(16px, 3vw, 32px);
  z-index: 10;
  position: relative;
}

.credit-title {
  font-size: clamp(1.5rem, 3.5vw, 2.5rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 10px rgba(0,0,0,0.5);
}

.credit-box {
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: clamp(20px, 4vw, 50px);
  min-width: clamp(280px, 40vw, 550px);
  text-align: center;
  color: rgba(255,255,255,0.85);
  font-size: clamp(0.7rem, 1.5vw, 1.1rem);
  line-height: 1.8;
  border: 2px solid rgba(255,255,255,0.15);
}

.credit-note {
  color: rgba(255,255,255,0.5);
  font-size: 0.85em;
}

.credit-box a {
  color: #74b9ff;
  text-decoration: none;
  transition: color 0.2s;
}
.credit-box a:hover {
  color: #a29bfe;
  text-decoration: underline;
}

/* ============ SCREEN SHAKE ============ */
.shake {
  animation: screenShake 0.15s ease;
}
@keyframes screenShake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
  100% { transform: translateX(0); }
}

/* ============ FADE TRANSITIONS ============ */
.fade-in {
  animation: fadeIn 0.5s ease forwards;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============ COUNTDOWN OVERLAY ============ */
.countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
}

.countdown-number {
  font-size: clamp(5rem, 15vw, 12rem);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px rgba(255,71,87,0.8);
  animation: countdownPop 0.8s ease forwards;
}

@keyframes countdownPop {
  0% { transform: scale(2); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { transform: scale(0.8); opacity: 0; }
}

/* ============ TIME BONUS POPUP ============ */
.time-bonus {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(1rem, 2.5vw, 2rem);
  font-weight: 900;
  color: var(--color-accent2);
  z-index: 35;
  pointer-events: none;
  animation: bonusFloat 1s ease forwards;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

@keyframes bonusFloat {
  0% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-30px); }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .question-box {
    width: 85%;
    padding: 12px;
  }
  .hud {
    gap: 8px;
  }
  .result-buttons {
    flex-direction: column;
  }
}
/* ============ SPEECH BUBBLE (セリフフキダシ) ============ */
.speech-bubble {
  position: absolute;
  top: 17%;
  right: 17%;
  z-index: 40;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  padding: clamp(16px, 3cqh, 40px) clamp(20px, 4cqw, 56px);
  border-radius: 20px;
  border: 3px solid #ffffff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  max-width: min(640px, 45cqw);
  min-width: min(360px, 30cqw);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

.speech-bubble.visible {
  opacity: 1;
  transform: translateY(0);
}

.speech-bubble-text {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: clamp(1rem, 2.5cqw, 2.2rem);
  font-weight: 700;
  color: #2f3542;
  line-height: 1.6;
  text-align: center;
}

/* 文字数に応じたフォントサイズ調整 */
.speech-bubble.text-medium .speech-bubble-text {
  font-size: clamp(0.9rem, 2.2cqw, 1.9rem);
}

.speech-bubble.text-small .speech-bubble-text {
  font-size: clamp(0.8rem, 1.9cqw, 1.6rem);
}

.speech-bubble.text-tiny .speech-bubble-text {
  font-size: clamp(0.7rem, 1.6cqw, 1.3rem);
}

/* 吹き出しのしっぽ（三角形） */
.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -12px;
  right: 40px;
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 12px solid #ffffff;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.15));
}

/* フェードアウト用のクラス */
.speech-bubble.fade-out {
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

/* レスポンシブ対応：小さい画面では更に縮小 */
@media (max-height: 600px) {
  .speech-bubble {
    top: 12%;
    right: 12%;
    padding: clamp(8px, 2cqh, 20px) clamp(12px, 2cqw, 28px);
    max-width: min(400px, 35cqw);
    min-width: min(240px, 25cqw);
  }
  
  .speech-bubble-text {
    font-size: clamp(0.8rem, 2cqw, 1.4rem);
  }
  
  .speech-bubble.text-medium .speech-bubble-text {
    font-size: clamp(0.7rem, 1.8cqw, 1.2rem);
  }
  
  .speech-bubble.text-small .speech-bubble-text {
    font-size: clamp(0.6rem, 1.6cqw, 1.0rem);
  }
  
  .speech-bubble.text-tiny .speech-bubble-text {
    font-size: clamp(0.55rem, 1.4cqw, 0.9rem);
  }
}

/* ==== RETAKE STAMP (®) ==== */
.retake-stamp {
  position: absolute;
  top: 12%;
  left: 11%;
  font-family: 'Caveat', cursive;
  font-size: clamp(7.5rem, 20.4vw, 15.3rem);
  color: #e8301e;
  font-weight: 700;
  z-index: 60;
  opacity: 0;
  transform: scale(2.5);
  pointer-events: none;
  filter: drop-shadow(0 0 8px rgba(255,255,255,0.9)) drop-shadow(0 0 20px rgba(255,255,255,0.5)) drop-shadow(2px 4px 6px rgba(0,0,0,0.25));
  transition: none;
}
.retake-stamp.stamp-appear {
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.3s ease-out, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.retake-stamp.stamp-fadeout {
  opacity: 0;
  transition: opacity 1s ease-out;
}

/* ==== TYPING PROGRESS BAR ==== */
.typing-progress-container {
  width: 80%;
  max-width: 600px;
  height: 6px;
  background: rgba(0,0,0,0.15);
  border-radius: 3px;
  margin: 0.3em auto;
  overflow: hidden;
  position: relative;
}
.typing-progress-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  /* バー自体は常に100%幅でグラデーション、clip-pathで進捗分だけ表示 */
  width: 100%;
  background: linear-gradient(90deg, var(--color-accent2), var(--color-primary));
  border-radius: 3px;
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.08s ease-out;
}

/* ============ PARTICLE EFFECTS ============ */
.particle {
  position: absolute;
  pointer-events: none;
  z-index: 45;
  border-radius: 50%;
  box-shadow: 0 0 var(--glow-size, 4px) var(--glow-color, rgba(180,220,255,0.8));
  animation: particleBurst var(--particle-duration, 0.8s) ease-out forwards;
}

@keyframes particleBurst {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }
  40% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: translate(var(--px, 0px), var(--py, -60px)) scale(0.1);
  }
}

/* コンボマイルストーン用の大きなパーティクル */
.particle-combo {
  animation: particleCombo var(--particle-duration, 1.2s) ease-out forwards;
}

@keyframes particleCombo {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1) rotate(0deg);
  }
  50% {
    opacity: 0.9;
  }
  100% {
    opacity: 0;
    transform: translate(var(--px, 0px), var(--py, -100px)) scale(0.1) rotate(var(--pr, 360deg));
  }
}

/* ============ CONFETTI (紙吹雪) ============ */
.confetti-piece {
  position: absolute;
  top: 0;
  z-index: 900;
  pointer-events: none;
  opacity: 0;
  animation:
    confettiFall var(--confetti-duration, 3s) cubic-bezier(0.25, 0, 0.6, 1) forwards,
    confettiSway var(--sway-period, 1.8s) ease-in-out infinite;
  animation-delay: var(--confetti-delay, 0s);
}

@keyframes confettiFall {
  0% {
    opacity: 1;
    transform: translateY(-10px) rotate(0deg) scale(1);
  }
  70% {
    opacity: 0.7;
  }
  100% {
    opacity: 0;
    transform: translateY(var(--fall-distance, 500px)) rotate(var(--confetti-rotate, 720deg)) scale(0.4);
  }
}
@keyframes confettiSway {
  0%, 100% { margin-left: 0; }
  50% { margin-left: var(--sway, 15px); }
}

@media (max-width: 600px) {
  .retake-stamp {
    top: 8%;
    left: 6%;
    font-size: clamp(5.1rem, 25.5vw, 10.2rem);
  }
  .typing-progress-container {
    width: 90%;
    height: 5px;
  }
}
