:root {
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #4f7cff;
  --accent-dark: #3a5fd9;
  --correct: #2faf6a;
  --wrong: #e2574c;
  --border: #e3e6ec;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans",
    "Noto Sans JP", "Yu Gothic", sans-serif;
  background-color: #0c0a09;
  color: var(--text);
  line-height: 1.6;
}

/* ===== ホラー背景（title1 を暗くぼかして使用 + 暗幕 + ビネット） ===== */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0.25) 35%, rgba(0, 0, 0, 0.9) 100%),
    linear-gradient(rgba(12, 8, 5, 0.7), rgba(8, 5, 3, 0.82)),
    url("images/title1.png");
  background-size: cover, cover, cover;
  background-position: center, center, center;
  background-repeat: no-repeat;
  filter: blur(7px) brightness(0.55) sepia(0.25) contrast(1.05);
  transform: scale(1.08); /* ぼかしによる端の隙間を隠す */
}

/* ===== ヘッダー ===== */
.site-header {
  text-align: center;
  padding: 32px 16px 8px;
}
.site-header h1 {
  margin: 0 0 4px;
  font-size: 1.8rem;
}
.subtitle {
  margin: 0 0 12px;
  color: #d8c7ad;
  font-size: 0.95rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}
.title-images {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 16px;
  max-width: 720px;
  margin: 16px auto;
}
.title-images img {
  width: 100%;
  max-width: 340px;
  height: auto;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.story {
  max-width: 640px;
  margin: 8px auto 4px;
  padding: 20px 22px;
  text-align: left;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  line-height: 1.9;
}
.story-title {
  margin: 0 0 12px;
  text-align: center;
  letter-spacing: 0.3em;
  font-size: 1.15rem;
  color: var(--accent-dark);
}
.story p {
  margin: 0 0 1em;
  font-size: 0.95rem;
}
.story p:last-child {
  margin-bottom: 0;
}

.progress {
  display: inline-block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 18px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ===== グリッド ===== */
main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px;
}
.quiz-grid {
  display: grid;
  gap: 20px;
  /* スマホ: 1列 */
  grid-template-columns: 1fr;
}
/* PC / タブレット横: 2列 */
@media (min-width: 700px) {
  .quiz-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ===== 問題カード ===== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s;
}
.card.solved {
  border-color: var(--correct);
}
.card-label {
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-label .check {
  color: var(--correct);
  font-size: 1.1rem;
}

.card-image {
  width: 100%;
  border-radius: 8px;
  background: #fafbfc;
  border: 1px dashed var(--border);
  aspect-ratio: 4 / 3;
  object-fit: contain;
  margin-bottom: 14px;
}

/* 入力エリア */
.answer-row {
  display: flex;
  gap: 8px;
}
.answer-input {
  flex: 1;
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
}
.answer-input:focus {
  border-color: var(--accent);
}
.check-btn {
  padding: 10px 18px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.check-btn:hover {
  background: var(--accent-dark);
}
.card.solved .check-btn {
  background: var(--correct);
  cursor: default;
}

/* 判定フィードバック */
.feedback {
  min-height: 1.4em;
  margin-top: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}
.feedback.correct {
  color: var(--correct);
}
.feedback.wrong {
  color: var(--wrong);
}

/* ===== 全問正解バナー ===== */
.clear-banner {
  text-align: center;
  margin: 28px auto 0;
  padding: 18px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--correct);
  background: #eaf7ef;
  border: 1px solid #bfe6cd;
  border-radius: var(--radius);
}

/* ===== ポップアップ ===== */
.popup-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at center, rgba(60, 0, 0, 0.35) 0%, rgba(0, 0, 0, 0.92) 75%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  animation: fade 0.25s ease;
}
.popup {
  position: relative;
  background: #120a0a;
  border: 1px solid #6e1414;
  border-radius: 8px;
  padding: 34px 28px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 0 60px rgba(120, 0, 0, 0.45),
    inset 0 0 40px rgba(0, 0, 0, 0.7);
  animation: pop 0.3s ease, popupFlicker 3.5s linear 0.3s infinite;
}
.popup-emoji {
  font-size: 2.8rem;
  line-height: 1;
  filter: grayscale(0.4) brightness(0.95);
  animation: flickerSlow 2.2s steps(1) infinite;
}
.popup-title {
  margin: 14px 0 8px;
  color: #c81d1d;
  font-size: 1.7rem;
  letter-spacing: 0.12em;
  text-shadow: 0 0 8px rgba(200, 0, 0, 0.8), 0 0 2px rgba(255, 80, 80, 0.6);
  animation: flickerSlow 3s steps(1) infinite;
}
.popup-message {
  margin: 0 0 22px;
  color: #b9a99a;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  white-space: pre-line;
  line-height: 1.8;
}

/* 文字を四角で囲み、上に番号を付ける注記 */
.annot {
  display: inline-block;
  text-align: center;
  vertical-align: bottom;
  line-height: 1;
}
.annot-num {
  display: block;
  font-size: 1.5em;
  font-weight: 700;
  margin-bottom: 2px;
  color: #c81d1d;
}
.annot-box {
  display: inline-block;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  padding: 0 3px;
  line-height: 1.25;
}
.popup-close {
  padding: 10px 30px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: #e8d9c8;
  background: #3a0d0d;
  border: 1px solid #7a1717;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}
.popup-close:hover {
  background: #5e1414;
  box-shadow: 0 0 14px rgba(160, 0, 0, 0.6);
}

/* 隠しカード出現時の演出 */
.card.reveal {
  animation: cardReveal 1.1s ease;
}
@keyframes cardReveal {
  0% { opacity: 0; transform: translateY(14px) scale(0.96); box-shadow: 0 0 0 rgba(200,0,0,0); }
  30% { opacity: 1; }
  45% { box-shadow: 0 0 40px 6px rgba(200, 0, 0, 0.7); }
  55% { box-shadow: 0 0 8px 1px rgba(200, 0, 0, 0.2); }
  70% { box-shadow: 0 0 30px 4px rgba(200, 0, 0, 0.55); }
  100% { opacity: 1; transform: translateY(0) scale(1); box-shadow: 0 0 0 rgba(200,0,0,0); }
}

/* 不正解時：カードを揺らして赤くフラッシュ */
.card.wrong-shake {
  animation: hShake 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
.card.wrong-shake .card-image {
  animation: redFlash 0.45s ease;
}

/* ===== 共通 ===== */
.hidden {
  display: none !important;
}
.site-footer {
  text-align: center;
  color: #9a8a72;
  padding: 24px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}
.site-footer .disclaimer {
  display: block;
  margin-top: 6px;
  font-size: 0.8rem;
  color: #7c6f5d;
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ホラー演出 */
@keyframes popupFlicker {
  0%, 100% { box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 60px rgba(120,0,0,0.45), inset 0 0 40px rgba(0,0,0,0.7); }
  47% { box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 60px rgba(120,0,0,0.45), inset 0 0 40px rgba(0,0,0,0.7); }
  48% { box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 18px rgba(120,0,0,0.2), inset 0 0 40px rgba(0,0,0,0.85); }
  49% { box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 70px rgba(150,0,0,0.55), inset 0 0 40px rgba(0,0,0,0.6); }
  50% { box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 10px rgba(80,0,0,0.15), inset 0 0 40px rgba(0,0,0,0.9); }
  51% { box-shadow: 0 0 0 1px rgba(0,0,0,0.6), 0 0 60px rgba(120,0,0,0.45), inset 0 0 40px rgba(0,0,0,0.7); }
}
@keyframes flickerSlow {
  0%, 100% { opacity: 1; }
  46% { opacity: 1; }
  47% { opacity: 0.35; }
  48% { opacity: 1; }
  72% { opacity: 1; }
  73% { opacity: 0.5; }
  74% { opacity: 1; }
}
@keyframes hShake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}
@keyframes redFlash {
  0% { box-shadow: 0 0 0 rgba(200, 0, 0, 0); filter: none; }
  30% { box-shadow: 0 0 30px 6px rgba(200, 0, 0, 0.75); filter: brightness(0.6) sepia(0.5) hue-rotate(-30deg) saturate(3); }
  100% { box-shadow: 0 0 0 rgba(200, 0, 0, 0); filter: none; }
}
