/* ===== Google Fonts ===== */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@700;900&family=Noto+Serif+JP:wght@400;600;700&display=swap');

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Forest Academy カラーパレット */
  --bg:           #0e160a;
  --surface:      rgba(38, 24, 8, 0.92);
  --surface2:     rgba(52, 34, 12, 0.80);
  --border:       rgba(185, 140, 55, 0.45);
  --border-hover: rgba(210, 170, 80, 0.75);

  --accent:       #5a8a35;
  --accent-light: #7ab845;
  --accent-warm:  #c17f24;
  --accent-gold:  #d4a83a;
  --accent-glow:  rgba(90, 138, 53, 0.35);
  --gold-glow:    rgba(193, 127, 36, 0.35);

  --correct:      #5a9e3a;
  --correct-bg:   rgba(90, 158, 58, 0.15);
  --wrong:        #c0392b;
  --wrong-bg:     rgba(192, 57, 43, 0.14);

  --text:         #f0e6c4;
  --text-muted:   #b89a60;
  --text-dim:     #8a7040;

  --radius:       14px;
  --radius-sm:    8px;
  --transition:   0.22s ease;
}

body {
  min-height: 100vh;
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 30%, rgba(50, 80, 20, 0.25) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 70%, rgba(80, 50, 10, 0.20) 0%, transparent 60%);
  color: var(--text);
  font-family: 'Noto Serif JP', 'Georgia', serif;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

/* ===== Screen Transitions ===== */
.screen { display: none; width: 100%; max-width: 580px; }
.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: fadeUp 0.45s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(22px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== START SCREEN ===== */
#start-screen.active {
  position: fixed;
  inset: 0;
  max-width: none;
  justify-content: center;
  background-image: url('images/top.jpeg');
  background-size: cover;
  background-position: center top;
  z-index: 10;
}

.start-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    160deg,
    rgba(8, 18, 4, 0.55) 0%,
    rgba(18, 10, 2, 0.62) 60%,
    rgba(10, 20, 5, 0.50) 100%
  );
  backdrop-filter: blur(1.5px);
}

.start-card {
  position: relative;
  z-index: 1;
  max-width: 460px;
  width: calc(100% - 32px);
  text-align: center;
  background: linear-gradient(150deg, rgba(30,18,5,0.90) 0%, rgba(20,30,8,0.88) 100%);
  border: 1.5px solid var(--border);
  box-shadow:
    0 0 0 1px rgba(210,170,80,0.10),
    0 8px 50px rgba(0,0,0,0.65),
    inset 0 1px 0 rgba(220,185,85,0.12);
}

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%;
  box-shadow:
    0 6px 36px rgba(0,0,0,0.55),
    inset 0 1px 0 rgba(220,185,85,0.10);
}

/* ===== Start Card Content ===== */
.school-label {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  color: var(--accent-gold);
  text-transform: uppercase;
  margin-bottom: 10px;
  opacity: 0.9;
}

.app-title {
  font-family: 'Noto Serif JP', serif;
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.08em;
  margin-bottom: 18px;
  background: linear-gradient(135deg, #f0d080 10%, #c17f24 55%, #e8c060 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  filter: drop-shadow(0 2px 8px rgba(180,130,30,0.35));
}

.app-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.85;
  margin-bottom: 30px;
}

/* ===== Decorative divider ===== */
.card::before {
  content: '✦ ── ✦ ── ✦';
  display: block;
  text-align: center;
  font-size: 0.65rem;
  letter-spacing: 0.25em;
  color: var(--text-dim);
  margin-bottom: 22px;
  opacity: 0.7;
}
.start-card::before { content: '🌿 ── Forest Academy ── 🌿'; font-size: 0.68rem; color: var(--accent-gold); opacity: 0.65; }

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  width: 100%;
  padding: 13px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Noto Serif JP', serif;
  font-size: 0.97rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
  letter-spacing: 0.06em;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, #3d6b1e 0%, #5a9030 55%, #4a7a26 100%);
  color: #e8f0d0;
  border: 1px solid rgba(120, 180, 60, 0.4);
  box-shadow: 0 3px 18px rgba(60, 110, 20, 0.4), inset 0 1px 0 rgba(180, 240, 100, 0.15);
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.btn-primary:hover {
  filter: brightness(1.15);
  box-shadow: 0 5px 24px rgba(60, 110, 20, 0.55);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  margin-top: 18px;
}
.btn-secondary:hover {
  border-color: var(--border-hover);
  color: var(--text);
  background: rgba(185,140,55,0.10);
}

/* ===== Quiz Header ===== */
.quiz-header { width: 100%; margin-bottom: 14px; }

.progress-wrap {
  height: 7px;
  background: rgba(255,255,255,0.06);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 9px;
  border: 1px solid rgba(185,140,55,0.15);
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-warm) 100%);
  border-radius: 99px;
  transition: width 0.45s cubic-bezier(0.4,0,0.2,1);
  width: 0%;
  box-shadow: 0 0 8px var(--accent-glow);
}

.meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}
/* バッジは左端に配置、スコアと問題数は右側へ */
#diff-badge { margin-right: auto; }

/* 音声トグルボタン */
.sound-btn {
  background: none;
  border: 1px solid rgba(185,140,55,0.25);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.9rem;
  width: 28px;
  height: 28px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.sound-btn:hover { border-color: var(--border-hover); background: rgba(185,140,55,0.10); }
.sound-btn.muted { opacity: 0.4; }

/* ===== Quiz Card ===== */
.quiz-card { display: flex; flex-direction: column; }

.question-text {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.75;
  margin-bottom: 24px;
  min-height: 56px;
  color: var(--text);
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(185,140,55,0.18);
}

/* ===== Choices ===== */
.choices { display: flex; flex-direction: column; gap: 10px; }

.choice-btn {
  background: var(--surface2);
  border: 1.5px solid rgba(185,140,55,0.20);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: 'Noto Serif JP', serif;
  font-size: 0.92rem;
  padding: 13px 16px;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition),
              color var(--transition), transform var(--transition);
  position: relative;
  overflow: hidden;
}
.choice-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(90,138,53,0.15), rgba(193,127,36,0.08));
  opacity: 0;
  transition: opacity var(--transition);
}
.choice-btn span { position: relative; z-index: 1; }

.choice-btn:not(:disabled):hover {
  border-color: var(--border-hover);
  color: var(--text);
  transform: translateX(5px);
}
.choice-btn:not(:disabled):hover::before { opacity: 1; }

.choice-btn.correct {
  border-color: var(--correct);
  background: var(--correct-bg);
  color: #90d870;
  animation: pulse-correct 0.5s ease;
}
.choice-btn.wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
  color: #e07060;
  animation: shake 0.4s ease;
}
.choice-btn.reveal-correct {
  border-color: var(--correct);
  background: var(--correct-bg);
  color: #90d870;
}

@keyframes pulse-correct {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.025); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-7px); }
  40%     { transform: translateX(7px); }
  60%     { transform: translateX(-4px); }
  80%     { transform: translateX(4px); }
}

/* ===== Feedback ===== */
.feedback {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.92rem;
  animation: fadeUp 0.3s ease;
  border: 1px solid transparent;
}
.feedback.hidden { display: none !important; }
.feedback.correct {
  background: var(--correct-bg);
  color: #90d870;
  border-color: rgba(90,158,58,0.3);
}
.feedback.wrong {
  background: var(--wrong-bg);
  color: #e07060;
  border-color: rgba(192,57,43,0.3);
}
#feedback-icon { font-size: 1.15rem; }

/* ===== Result Screen ===== */
.result-card { text-align: center; }

.result-title {
  font-family: 'Cinzel', 'Noto Serif JP', serif;
  font-size: 1.55rem;
  font-weight: 700;
  margin-bottom: 22px;
  letter-spacing: 0.15em;
  background: linear-gradient(135deg, #f0d080, #c17f24, #e8c060);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 8px rgba(180,130,30,0.3));
}

/* Result Image */
.result-img-wrap {
  width: 100%;
  max-width: 480px;
  margin: 0 auto 22px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--border);
  box-shadow: 0 4px 24px rgba(0,0,0,0.45), 0 0 0 1px rgba(210,170,80,0.10);
  background: rgba(20,14,4,0.5);
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.result-img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
  transition: opacity 0.4s ease;
}
.result-img[src=''] { display: none; }

/* Score Circle */
.score-circle {
  position: relative;
  width: 148px;
  height: 148px;
  margin: 0 auto 20px;
}
.score-circle svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}
.score-circle .track {
  fill: none;
  stroke: rgba(255,255,255,0.05);
  stroke-width: 9;
}
.score-circle .ring {
  fill: none;
  stroke: url(#grad);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 314;
  stroke-dashoffset: 314;
  transition: stroke-dashoffset 1.1s cubic-bezier(0.4,0,0.2,1);
  filter: drop-shadow(0 0 6px rgba(193,127,36,0.5));
}

.score-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#result-score {
  font-family: 'Cinzel', serif;
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent-gold);
  text-shadow: 0 0 16px rgba(193,127,36,0.5);
}
.score-denom { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

.result-rate {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--accent-gold);
  letter-spacing: 0.06em;
}
.result-comment {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 28px;
  line-height: 1.75;
}

/* ===== Difficulty Selection ===== */
.diff-label {
  font-size: 0.78rem;
  letter-spacing: 0.15em;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 14px;
}

.diff-btns {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.diff-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  padding: 16px 20px;
  border-radius: 12px;
  border: 1.5px solid rgba(185,140,55,0.25);
  background: var(--surface2);
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition),
              box-shadow var(--transition), background var(--transition);
  width: 100%;
}
.diff-btn:hover {
  transform: translateX(6px);
  border-color: var(--border-hover);
}

.diff-icon  { font-size: 1.6rem; flex-shrink: 0; }
.diff-name  { display: block; font-size: 1.05rem; font-weight: 700; color: var(--text); letter-spacing: 0.05em; }
.diff-desc  { display: block; font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

/* かんたん：緑 */
.diff-easy  { border-color: rgba(90,158,58,0.35); }
.diff-easy:hover  { background: rgba(90,158,58,0.12); box-shadow: 0 4px 18px rgba(90,158,58,0.2); }
.diff-easy  .diff-name { color: #7ab845; }

/* ふつう：琥珀 */
.diff-normal { border-color: rgba(193,127,36,0.35); }
.diff-normal:hover { background: rgba(193,127,36,0.12); box-shadow: 0 4px 18px rgba(193,127,36,0.2); }
.diff-normal .diff-name { color: var(--accent-gold); }

/* むずかしい：赤紫 */
.diff-hard  { border-color: rgba(160,60,60,0.35); }
.diff-hard:hover  { background: rgba(160,60,60,0.12); box-shadow: 0 4px 18px rgba(160,60,60,0.25); }
.diff-hard  .diff-name { color: #e07878; }

/* クイズ画面の難易度バッジ */
.diff-badge {
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 99px;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.diff-badge.lv1 { background: rgba(90,158,58,0.18);  color: #7ab845; border: 1px solid rgba(90,158,58,0.4); }
.diff-badge.lv2 { background: rgba(193,127,36,0.18); color: var(--accent-gold); border: 1px solid rgba(193,127,36,0.4); }
.diff-badge.lv3 { background: rgba(160,60,60,0.18);  color: #e07878; border: 1px solid rgba(160,60,60,0.4); }

/* リザルト画面の難易度表示 */
.result-diff {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}

/* ===== Owl Character ===== */
.owl-wrap {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  padding-right: 18px;
  margin-bottom: -30px; /* カードに少し被せる */
  z-index: 2;
  pointer-events: none;
}

.owl {
  width: 100px;
  height: auto;
  filter: drop-shadow(0 6px 14px rgba(0,0,0,0.55));
  transform-origin: bottom center;
  will-change: transform;
}

/* 吹き出し */
.owl-balloon {
  position: absolute;
  right: 112px;
  bottom: 10px;
  background: rgba(38, 24, 8, 0.93);
  border: 1.5px solid var(--border);
  border-radius: 10px 10px 4px 10px;
  padding: 7px 12px;
  font-size: 0.78rem;
  font-family: 'Noto Serif JP', serif;
  color: var(--text);
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: balloon-pop 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
.owl-balloon::after {
  content: '';
  position: absolute;
  right: -9px;
  bottom: 6px;
  border: 5px solid transparent;
  border-left-color: var(--border);
}
.owl-balloon.hidden { display: none; }

/* ── アニメーション定義 ── */

/* 出題中：ゆったりホバリング */
@keyframes owl-float {
  0%, 100% { transform: translateY(0px) rotate(0deg); }
  30%       { transform: translateY(-9px) rotate(1.5deg); }
  70%       { transform: translateY(-5px) rotate(-1deg); }
}

/* 正解：跳び上がってドヤ顔着地 */
@keyframes owl-correct {
  0%   { transform: translateY(0)   scale(1)    rotate(0deg); }
  20%  { transform: translateY(-28px) scale(1.12) rotate(-6deg); }
  40%  { transform: translateY(-38px) scale(1.15) rotate(6deg); }
  60%  { transform: translateY(-18px) scale(1.05) rotate(-3deg); }
  75%  { transform: translateY(-6px) scale(0.97) rotate(1deg); }
  88%  { transform: translateY(-12px) scale(1.03) rotate(0deg); }
  100% { transform: translateY(0)   scale(1)    rotate(0deg); }
}

/* 不正解：左右に頭を振る */
@keyframes owl-wrong {
  0%,100% { transform: rotate(0deg) translateX(0); }
  15%     { transform: rotate(-12deg) translateX(-5px); }
  30%     { transform: rotate(10deg)  translateX(5px); }
  45%     { transform: rotate(-9deg)  translateX(-4px); }
  60%     { transform: rotate(7deg)   translateX(4px); }
  75%     { transform: rotate(-4deg)  translateX(-2px); }
  88%     { transform: rotate(3deg)   translateX(2px); }
}

/* 吹き出しポップイン */
@keyframes balloon-pop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ── クラス切り替え ── */
.owl-idle    { animation: owl-float   2.8s ease-in-out infinite; }
.owl-correct { animation: owl-correct 0.75s cubic-bezier(0.36,0.07,0.19,0.97) forwards; }
.owl-wrong   { animation: owl-wrong   0.65s ease forwards; }

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .card { padding: 26px 18px; }
  .app-title { font-size: 2.1rem; }
  .question-text { font-size: 0.97rem; }
}
