/* ===============================
   基本設定（全要素に適用）
   =============================== */
* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation; /*タブレット連打時の拡大防止 */
}

html {
  margin: 0;
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  font-family:
      -apple-system,
      BlinkMacSystemFont,
      "Hiragino Sans",
      "Yu Gothic",
      "Meiryo",
      sans-serif;
  background: #f2f2f2;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  margin: 0 auto;
  border: 2px solid #333;
  width: 100%;
  max-width: 1196px;
  height: 540px;
  display: flex;
  flex-direction: column;
}

.game-main {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: grid;
  place-items: center;
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: linear-gradient(160deg, #fffbe8 0%, #fff0d0 100%);
  }

  /* ===== 背景装飾 ===== */
  .bg-deco {
    position: absolute;
    border-radius: 50%;
    opacity: 0.18;
    pointer-events: none;
  }
  .bg-deco.d1 { width:320px;height:320px; background:#ffb347; top:-80px;left:-80px; }
  .bg-deco.d2 { width:200px;height:200px; background:#7ec8e3; bottom:-60px;right:80px; }
  .bg-deco.d3 { width:140px;height:140px; background:#ff6b9d; top:40px;right:-30px; }
  .bg-deco.d4 { width:100px;height:100px; background:#a8e063; bottom:40px;left:60px; }

  /* ===== 共通 ===== */
  .screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.35s ease, transform 0.35s ease;
  }
  .screen.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.96);
  }

  /* ===== タイトル画面 ===== */
  #title-screen {
    gap: 0;
  }

  .title-bug {
    font-size: 64px;
    line-height: 1;
    margin-bottom: 4px;
    animation: bounce 1.6s ease-in-out infinite;
  }
  @keyframes bounce {
    0%,100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
  }

  .title-text {
    font-size: 54px;
    font-weight: 900;
    color: #3a2a0a;
    letter-spacing: 4px;
    text-shadow: 3px 3px 0 #ffb347, 5px 5px 0 rgba(0,0,0,0.08);
    margin-bottom: 6px;
  }

  .title-sub {
    font-size: 18px;
    color: #7a5c2a;
    margin-bottom: 36px;
    letter-spacing: 2px;
  }

  .level-label {
    font-size: 20px;
    font-weight: 700;
    color: #5a3e1b;
    margin-bottom: 14px;
    letter-spacing: 2px;
  }

  .level-buttons {
    display: flex;
    gap: 18px;
  }

  .level-btn {
    padding: 14px 32px;
    border: none;
    border-radius: 50px;
    font-size: 20px;
    font-weight: 900;
    cursor: pointer;
    letter-spacing: 2px;
    transition: transform 0.12s, box-shadow 0.12s;
    box-shadow: 0 5px 0 rgba(0,0,0,0.18);
  }
  .level-btn:hover { transform: translateY(-3px); box-shadow: 0 8px 0 rgba(0,0,0,0.18); }
  .level-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.18); }

  .level-btn.easy  { background: #6ecb63; color: #1a5a14; }
  .level-btn.mid   { background: #f9a825; color: #6b3a00; }
  .level-btn.hard  { background: #e05a5a; color: #fff; }

  /* ===== ゲーム画面 ===== */
  #game-screen {
    gap: 0;
    justify-content: flex-start;
    padding: 22px 40px 12px;
  }

  .play-header {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-rows: auto auto;
    align-items: center;
    row-gap: 14px;
    margin-bottom: 24px;
  }

  .progress-wrap {
    display: flex;
    gap: 10px;
    align-items: center;
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: center;
  }

  .play-title {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
    font-size: 28px;
    font-weight: 900;
    color: #3a2a0a;
    letter-spacing: 3px;
    white-space: nowrap;
  }

  .progress-dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ddd;
    transition: background 0.3s;
  }
  .progress-dot.done { background: #6ecb63; }
  .progress-dot.current { background: #f9a825; border: 3px solid #c77c00; }

  .score-badge {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
    background: #fff;
    border-radius: 50px;
    padding: 9px 24px;
    font-size: 20px;
    font-weight: 700;
    color: #e05a5a;
    border: 3px solid #f9a825;
    box-shadow: 0 3px 0 #e8a000;
  }

  .header-actions {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .quit-btn,
  .sound-btn {
    background: #fff;
    border: 3px solid #ddd;
    border-radius: 50px;
    padding: 9px 22px;
    font-size: 18px;
    font-weight: 700;
    color: #888;
    cursor: pointer;
    letter-spacing: 1px;
    transition: border-color 0.15s, color 0.15s;
  }
  .quit-btn:hover { border-color: #e05a5a; color: #e05a5a; }
  .sound-btn {
    background: #fff0ad;
    border-color: #f2b321;
    color: #694100;
    box-shadow: 0 3px 0 #d89500;
    min-width: 104px;
  }
  .sound-btn:hover {
    background: #ffe680;
    border-color: #dc9700;
    color: #5a3500;
  }
  .sound-btn.sound-off {
    background: #e9edf1;
    border-color: #aeb7c0;
    color: #66717b;
    box-shadow: 0 3px 0 #929ba4;
  }

  /* ===== 問題エリア ===== */
  .question-area {
    background: #fff;
    border-radius: 28px;
    border: 4px solid #f9e4a0;
    box-shadow: 0 6px 24px rgba(0,0,0,0.08);
    padding: 30px 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    width: 100%;
    max-width: 760px;
    margin-bottom: 24px;
    min-height: 180px;
  }

  .bug-label {
    font-size: 16px;
    color: #b07c2a;
    letter-spacing: 2px;
    font-weight: 700;
  }

  .equation {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 58px;
    font-weight: 900;
    color: #3a2a0a;
    letter-spacing: 4px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .eq-num {
    min-width: 60px;
    text-align: center;
  }

  .eq-op {
    color: #f9a825;
  }

  .eq-eq {
    color: #888;
  }

  .blank-box {
    min-width: 80px;
    height: 80px;
    background: #fff9e6;
    border: 4px dashed #ffb347;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 54px;
    font-weight: 900;
    color: #e05a5a;
    position: relative;
    transition: background 0.2s;
  }

  .bug-sprite {
    position: absolute;
    font-size: 28px;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    animation: bugwiggle 0.9s ease-in-out infinite;
  }
  @keyframes bugwiggle {
    0%,100% { transform: translateX(-50%) rotate(-8deg); }
    50% { transform: translateX(-50%) rotate(8deg); }
  }

  /* ===== 選択肢 ===== */
  .choices {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    max-width: 760px;
  }

  .choice-btn {
    min-width: 98px;
    padding: 16px 22px;
    border: 4px solid #ddd;
    border-radius: 20px;
    background: #fff;
    font-size: 38px;
    font-weight: 900;
    cursor: pointer;
    color: #3a2a0a;
    transition: transform 0.1s, box-shadow 0.1s, border-color 0.15s, background 0.15s;
    box-shadow: 0 5px 0 #ccc;
  }
  .choice-btn:hover:not(:disabled) {
    transform: translateY(-4px);
    box-shadow: 0 9px 0 #bbb;
    border-color: #f9a825;
    background: #fffbe8;
  }
  .choice-btn:active:not(:disabled) {
    transform: translateY(4px);
    box-shadow: 0 1px 0 #ccc;
  }
  .choice-btn.correct {
    background: #e8fbe0;
    border-color: #6ecb63;
    color: #1a5a14;
    box-shadow: 0 5px 0 #4aaa3a;
    animation: pop 0.3s ease;
  }
  .choice-btn.wrong {
    background: #fde8e8;
    border-color: #e05a5a;
    color: #a00;
    animation: shake 0.4s ease;
  }
  .choice-btn:disabled { cursor: default; }

  @keyframes pop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.18); }
    100% { transform: scale(1); }
  }
  @keyframes shake {
    0%,100% { transform: translateX(0); }
    25%  { transform: translateX(-6px); }
    75%  { transform: translateX(6px); }
  }

  /* ===== フィードバック ===== */
  .feedback {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 2px;
    min-height: 32px;
    margin-top: 20px;
    transition: opacity 0.2s;
  }
  .feedback.ok   { color: #3a9a28; }
  .feedback.ng   { color: #c0392b; }
  .feedback.hidden { opacity: 0; }

  /* ===== 結果画面 ===== */
  #result-screen {
    gap: 10px;
  }

  .result-star-row {
    display: flex;
    gap: 12px;
    margin-bottom: 4px;
  }

  .result-star {
    font-size: 54px;
    opacity: 0.25;
    transition: opacity 0.4s, transform 0.4s;
    transform: scale(0.7);
  }
  .result-star.lit {
    opacity: 1;
    transform: scale(1.1);
  }

  .result-title {
    font-size: 38px;
    font-weight: 900;
    color: #3a2a0a;
    letter-spacing: 4px;
  }

  .result-score {
    font-size: 56px;
    font-weight: 900;
    color: #e05a5a;
  }

  .result-score span {
    font-size: 28px;
    color: #888;
  }

  .result-msg {
    font-size: 20px;
    color: #7a5c2a;
    letter-spacing: 2px;
  }

  .result-btns {
    display: flex;
    gap: 18px;
    margin-top: 24px;
  }

  .result-btn {
    padding: 14px 36px;
    border: none;
    border-radius: 50px;
    font-size: 20px;
    font-weight: 900;
    cursor: pointer;
    letter-spacing: 2px;
    transition: transform 0.12s, box-shadow 0.12s;
    box-shadow: 0 5px 0 rgba(0,0,0,0.18);
  }
  .result-btn:hover { transform: translateY(-3px); box-shadow: 0 8px 0 rgba(0,0,0,0.18); }
  .result-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.18); }
  .result-btn.retry { background: #f9a825; color: #5a3000; }
  .result-btn.home  { background: #7ec8e3; color: #0a3a5a; }

  /* ===== 浮遊してる虫 ===== */
  .float-bug {
    position: absolute;
    font-size: 36px;
    pointer-events: none;
    opacity: 0.6;
    animation: floatbug 6s ease-in-out infinite;
  }
  @keyframes floatbug {
    0%   { transform: translate(0,0) rotate(-5deg); }
    33%  { transform: translate(12px,-18px) rotate(5deg); }
    66%  { transform: translate(-8px,10px) rotate(-3deg); }
    100% { transform: translate(0,0) rotate(-5deg); }
  }

.float-bug.bug-1 { top: 30px; left: 200px; animation-delay: -1s; }
.float-bug.bug-2 { top: 80px; right: 260px; animation-delay: -3s; font-size: 28px; }
.float-bug.bug-3 { bottom: 60px; left: 300px; animation-delay: -4.5s; font-size: 32px; }
.float-bug.bug-4 { bottom: 40px; right: 200px; animation-delay: -2s; font-size: 26px; }

@media (max-width: 640px) {
  #game-screen {
    padding: 10px 16px 14px;
  }

  .play-title {
    font-size: 20px;
    letter-spacing: 1px;
  }

  .score-badge,
  .quit-btn,
  .sound-btn {
    padding: 7px 12px;
    font-size: 16px;
  }
}
