:root {
  --bg-color: #0a0a0c;
  --card-bg: rgba(255, 255, 255, 0.05);
  --glass-bg: rgba(255, 255, 255, 0.1);
  --glass-border: rgba(255, 255, 255, 0.2);
  
  --p1-color: #4cd964; /* 緑 */
  --p2-color: #ffcc00; /* 黄 */
  --p3-color: #00d2ff; /* 青 */
  --p4-color: #ff2d55; /* 赤 */
  
  --text-main: #ffffff;
  --text-dim: #a0a0a0;
  
  --shadow-glow: 0 0 15px rgba(255, 255, 255, 0.3);
}

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

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: 'Outfit', 'Inter', 'Roboto', sans-serif;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  width: 100vw;
}

/* Title Screen */
#title-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, #2a2a35 0%, #0a0a0c 100%);
  z-index: 4000; /* ヘッダー(2500)よりもさらに前 */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

#title-screen h1 {
  font-size: 38px;
  line-height: 1.15;
  margin-bottom: 10px;
  letter-spacing: 2px;
  text-align: center;
  text-shadow: 0 0 20px rgba(0, 210, 255, 0.5);
}

.title-options {
  display: flex;
  flex-direction: column;
  gap: 15px;
  width: 300px;
  margin-top: 20px;
}

#join-timer-display {
  font-size: 32px;
  font-weight: bold;
  color: var(--ff-color);
  text-shadow: 0 0 15px var(--ff-color);
  margin-bottom: 20px;
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0.8; transform: scale(1.05); }
}

/* Join Area - Force full game width (720px) */
#join-container {
  width: 720px !important;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center !important; /* 引き伸ばしを解除し中央へ */
  text-align: center;            /* 文字を中央揃えに */
  padding: 0 !important;
  margin: 0 !important;
}

/* Join Screen Grid - True 4-Equal Parts across the WHOLE screen */
.join-grid {
  display: flex !important;
  width: 100% !important; /* グリッド自体は画面の両端まで */
  height: 320px;
  gap: 0 !important;
  margin: 20px 0 !important;
  padding: 0 !important;
}

.join-panel {
  flex: 1 0 25% !important; /* 確実に横幅の25%を占有させる */
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
}

.join-panel .panel-num {
  font-size: 54px; /* 横並びに合わせて少し調整 */
  font-weight: bold;
  opacity: 0.2;
  transition: opacity 0.3s;
}

.join-panel .panel-status {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 5px;
}

/* Lit States */
.join-panel.active[data-player="1"] { border-color: var(--p1-color); box-shadow: 0 0 20px var(--p1-color); background: rgba(76, 217, 100, 0.1); }
.join-panel.active[data-player="2"] { border-color: var(--p2-color); box-shadow: 0 0 20px var(--p2-color); background: rgba(255, 204, 0, 0.1); }
.join-panel.active[data-player="3"] { border-color: var(--p3-color); box-shadow: 0 0 20px var(--p3-color); background: rgba(0, 210, 255, 0.1); }
.join-panel.active[data-player="4"] { border-color: var(--p4-color); box-shadow: 0 0 20px var(--p4-color); background: rgba(255, 45, 85, 0.1); }

.join-panel.active .panel-num { opacity: 1; text-shadow: 0 0 20px currentColor; }
.join-panel.active .panel-status { color: white; opacity: 1; }

/* Category Selection (Phase 3) */
#category-container {
  width: 720px !important;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center !important;
  text-align: center;
  padding: 0 !important;
  margin: 0 !important;
}

#category-timer-display {
  font-size: 32px;
  font-weight: bold;
  color: var(--p3-color);
  text-shadow: 0 0 15px var(--p3-color);
  margin-bottom: 10px;
  animation: pulse 1s infinite alternate;
}

.category-grid {
  display: flex !important;
  width: 100% !important;
  height: 260px;
  gap: 0 !important;
  margin: 16px 0 !important;
  padding: 0 !important;
}

.cat-panel {
  flex: 1 0 25% !important;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, border-color 0.2s;
  position: relative;
}

/* 左から順に P1〜P4 の色を割り当て（参加画面と揃える） */
.cat-panel[data-value="大人"]    { --cat-color: var(--p1-color); }
.cat-panel[data-value="こども"]  { --cat-color: var(--p2-color); }
.cat-panel[data-value="ローカル"]{ --cat-color: var(--p3-color); }
.cat-panel[data-value="全国"]    { --cat-color: var(--p4-color); }

.cat-panel[data-value="ローカル"] {
  border-left: 3px dashed rgba(255, 255, 255, 0.25);
}

.cat-panel .cat-key {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 14px;
  font-weight: bold;
  color: var(--cat-color);
  opacity: 0.75;
  letter-spacing: 1px;
}

.cat-panel.active .cat-key {
  opacity: 1;
  text-shadow: 0 0 8px currentColor;
}

.cat-panel .cat-label {
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 4px;
  margin-bottom: 12px;
}

.cat-panel .cat-name {
  font-size: 40px;
  font-weight: bold;
  color: var(--cat-color);
  opacity: 0.35;
  transition: opacity 0.3s, color 0.3s, text-shadow 0.3s;
}

.cat-panel .cat-count {
  margin-top: 4px;
  font-size: 12px;
  opacity: 0.55;
  color: var(--text-dim, #aaa);
  letter-spacing: 1px;
}

.cat-panel.active .cat-count {
  opacity: 0.9;
  color: white;
}

.cat-panel.active {
  border-color: var(--cat-color);
  box-shadow: 0 0 20px var(--cat-color);
  background: rgba(255, 255, 255, 0.08);
}

.cat-panel.active .cat-name {
  opacity: 1;
  text-shadow: 0 0 20px currentColor;
}

.cat-panel.active .cat-label {
  color: white;
}

.cat-panel.disabled {
  cursor: not-allowed;
  opacity: 0.35;
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: none;
  filter: grayscale(1);
}

.cat-panel.disabled .cat-name,
.cat-panel.disabled .cat-label,
.cat-panel.disabled .cat-key {
  color: var(--text-dim);
  text-shadow: none;
}

.ext-link {
  margin-top: 30px;
  font-size: 14px;
  color: var(--text-dim);
  text-decoration: underline;
  cursor: pointer;
}

.promo-message {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  max-width: 600px;
  line-height: 1.45;
  opacity: 0.8;
  padding: 6px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

#game-wrapper {
  width: 720px;
  height: 480px;
  background: #111;
  border: 2px solid var(--glass-border);
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center center;
  transform: translate(-50%, -50%);
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 20px rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

/* Layout */
header {
  height: 60px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  padding: 0 15px;
  align-items: center;
  background: rgba(0, 0, 0, 0.5);
  border-bottom: 1px solid var(--glass-border);
  position: relative;
  z-index: 2500; /* 正解ズーム(2000)より前に表示 */
}

.player-score {
  text-align: center;
  padding: 5px;
  border-radius: 8px;
  background: var(--glass-bg);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}

.player-score.active {
  transform: translateY(-2px);
}

.player-score[data-player="1"] { border-bottom: 4px solid var(--p1-color); --p-color: var(--p1-color); }
.player-score[data-player="2"] { border-bottom: 4px solid var(--p2-color); --p-color: var(--p2-color); }
.player-score[data-player="3"] { border-bottom: 4px solid var(--p3-color); --p-color: var(--p3-color); }
.player-score[data-player="4"] { border-bottom: 4px solid var(--p4-color); --p-color: var(--p4-color); }

/* 回答者スロット（答え選択画面と同じ choice-btn フォーマットを流用） */
.choices-grid .answerer-slot.empty {
  background: rgba(20, 20, 20, 0.4);
  border: 4px dashed rgba(255, 255, 255, 0.1);
  box-shadow: none;
}
.choices-grid .answerer-slot.empty::before { display: none; }

.choices-grid .answerer-slot.is-answerer {
  animation: pulse-answerer 0.9s ease-in-out infinite alternate;
}

.choices-grid .answerer-slot.is-answerer .choice-text {
  color: var(--choice-color, #fff);
  text-shadow: 0 0 20px currentColor;
}

/* 押し負けプレイヤーの表示（色・装飾なし、秒数のみ） */
.choices-grid .answerer-slot .answerer-time.late {
  color: rgba(255, 255, 255, 0.7);
  text-shadow: none;
  font-size: 24px;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
}

.choices-grid .answerer-slot .answerer-time {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  text-align: center;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.05em;
  color: #fff;
  text-shadow: 0 0 10px var(--choice-color, #fff), 0 0 4px #000;
}

@keyframes pulse-answerer {
  from { filter: brightness(1); }
  to   { filter: brightness(1.35); }
}

.score-val {
  font-size: 24px;
  font-weight: bold;
}

.player-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-dim);
}

main {
  position: relative;
  height: 420px; /* 480px - 60px(Header) */
  display: flex;
  justify-content: center;
  align-items: center;
}

#image-container {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000;
  overflow: hidden;
}

#target-image {
  height: 100%;
  width: auto;
  display: block;
  object-fit: contain; /* 比率を維持して縦いっぱいに */
}

/* Effects Canvas Overlay */
#effect-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Overlays */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75); /* 視認性向上のため暗く設定 */
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 100;
  /* backdrop-filter: blur(5px); 画像を隠さないため削除 */
}

#buzzer-overlay {
  background: #000; /* クイズ画像が透けないよう完全に不透明 */
}

#buzzer-winner {
  font-size: 32px;
  font-weight: bold;
  margin-bottom: 20px;
  text-shadow: 0 0 10px currentColor;
}

.choices-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  padding: 10px 15px;
  width: 100%;
  height: 400px;
}

.choice-btn {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  color: white;
  padding: 20px 10px;
  min-height: 100px;
  font-size: 20px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
  text-align: center;
}

/* 解答エリア内のボタンのみを縦書き巨大化 */
.choices-grid .choice-btn {
  flex: 1;
  background: rgba(40, 40, 40, 0.9);
  border: 4px solid var(--choice-color, #555); /* ボタンごとの色 */
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  cursor: pointer;
  writing-mode: vertical-rl;
  text-orientation: upright;
  transition: all 0.2s ease;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.5), inset 0 0 20px var(--choice-color, transparent);
  overflow: hidden;
}

.choice-btn::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(to top, var(--choice-color, transparent) 0%, transparent 40%);
  opacity: 0.3;
  pointer-events: none;
}

.choices-grid .choice-text {
  /* 固定サイズを削除し、親要素(btn)の計算値を継承させる */
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.05em;
  white-space: nowrap; /* 絶対に2列にさせない */
}

.choice-key-hint {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 14px;
  opacity: 0.6;
  writing-mode: horizontal-tb;
}

/* Footer Bars */
/* Footer removed */

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

.timer-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 4px;
  background: #00d2ff;
  width: 100%;
  box-shadow: 0 0 10px #00d2ff;
}

/* Message & States */

.wrong-mark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 200px;
  color: #ff2d55;
  font-weight: bold;
  pointer-events: none;
  z-index: 600;
  text-shadow: 0 0 30px rgba(0,0,0,0.5);
  animation: popMark 0.5s forwards ease-out;
}

@keyframes popMark {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

#game-message {
  position: absolute;
  bottom: 80px;
  width: 100%;
  text-align: center;
  font-size: 32px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 15px rgba(0,0,0,1), 0 0 10px rgba(0,0,0,1);
  line-height: 1.3;
  z-index: 3000;
  pointer-events: none;
}

/* 答えワードのみ白カードで強調（画像を遮らないよう最小面積） */
.answer-card {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 22px;
  background: rgba(255, 255, 255, 0.96);
  color: #111;
  border-radius: 12px;
  border: 2px solid #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.55), 0 0 0 2px rgba(0,0,0,0.3);
  text-shadow: none;
  font-size: 0.95em;
  line-height: 1.3;
}

/* Inactive Player State */
.inactive-player {
  opacity: 0.15 !important;
  filter: grayscale(1) !important;
  pointer-events: none !important;
}

/* Responsive Touch Zones */
.touch-zones {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: 1fr;
  pointer-events: auto;
  z-index: 50;
}

.touch-zone {
  /* background: rgba(255, 255, 255, 0.05); */
  border: 1px solid rgba(255, 255, 255, 0.02);
}

/* Hidden Edit Button */
#secret-admin-trigger {
  position: absolute;
  top: 0;
  right: 0;
  width: 40px;
  height: 40px;
  cursor: pointer;
  z-index: 200;
}

/* Correct State Zoom */
.correct-zoom {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000; /* 文字よりも後ろ、でも他のUIより前 */
  animation: fadeIn 0.5s forwards;
}

/* Result ranking reveal transition - much slower and gentler */
.ranking-item {
  display: flex;
  justify-content: space-between;
  padding: 15px;
  margin-bottom: 8px;
  background: var(--glass-bg);
  border-radius: 8px;
  animation: rankingReveal 0.8s ease-out both;
  font-size: 24px;
}

.correct-zoom img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  box-shadow: 0 0 50px rgba(255,255,255,0.6);
  filter: none !important;
  transform: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
#result-container h1 {
  font-size: 48px;
  margin-bottom: 30px;
  background: linear-gradient(to bottom, #fff, #888);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.ranking-list {
  width: 300px;
}

.ranking-item {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  margin-bottom: 5px;
  background: var(--glass-bg);
  border-radius: 5px;
  /* Add reveal animation */
  animation: rankingReveal 0.5s ease-out both;
}

@keyframes rankingReveal {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Final Quiz Special: Hide Scores */
.final-quiz-header-hidden header {
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.5s;
}

/* System Message Styles */
#system-msg-content {
  animation: messagePop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes messagePop {
  0% { transform: scale(0.5); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.floating-score {
  position: absolute;
  font-weight: bold;
  color: #ffd700;
  pointer-events: none;
  z-index: 3100; /* メッセージ(3000)よりもさらに前 */
  text-shadow: 0 0 20px rgba(0,0,0,0.8), 0 0 40px rgba(255, 215, 0, 0.5);
  transition: all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform: translate(-50%, -50%) scale(0);
}
.btn {
  padding: 10px 20px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 16px;
  transition: all 0.2s;
}

.btn:hover {
  background: rgba(255,255,255,0.2);
  transform: translateY(-2px);
}

.btn:active {
  transform: translateY(0);
}

.btn-back {
  background: rgba(255, 255, 255, 0.05);
  font-size: 14px;
}

#global-ranking-list {
  scrollbar-width: thin;
  scrollbar-color: var(--glass-border) transparent;
}

#global-ranking-list::-webkit-scrollbar {
  width: 6px;
}

#global-ranking-list::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 3px;
}

.ranking-item span:first-child {
  font-weight: bold;
}
