* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #07101a; color: #fff;
  font-family: 'M PLUS Rounded 1c', system-ui, sans-serif; font-weight: 700;
  -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
#app { display: flex; flex-direction: row; width: 100%; height: 100dvh; background: #07101a; position: relative; }
#stage { position: relative; flex: 1 1 auto; overflow: hidden; background: #0a1a2a; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; background: #0a1a2a; }

/* === 🏠 グローバルホームボタン === */
.global-home-btn {
  position: fixed; top: 15px; left: 15px; z-index: 9998;
  width: 50px; height: 50px; border-radius: 50%;
  background: #fff; border: 3px solid #78C2C4;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 6px rgba(0,0,0,0.2); cursor: pointer; transition: transform 0.1s;
}
.global-home-btn:active { transform: scale(0.9); }
.global-home-icon { width: 28px; height: 28px; object-fit: contain; }

/* ホームボタンと被らないように left を 80px に変更！ */
#hud-top { position: absolute; top: 10px; left: 80px; right: 10px; display: flex; justify-content: space-between; z-index: 5; }

#cockpit {
  flex: 0 0 35%; min-width: 300px; max-width: 450px;
  background: radial-gradient(120% 80% at 50% 0%, rgba(40, 80, 130, 0.55), rgba(8, 16, 26, 0.95) 70%),
              linear-gradient(180deg, #102030, #050a12 80%);
  border-left: 3px solid #2d8acf; box-shadow: inset 2px 0 0 rgba(120, 200, 255, 0.35);
  display: flex; flex-direction: column; justify-content: center; padding: 20px;
}
#life-area, #score-area {
  background: rgba(7, 16, 26, 0.7); border: 2px solid rgba(120, 200, 255, 0.6); border-radius: 12px;
  padding: 6px 12px; font-size: 18px; display: flex; align-items: baseline; gap: 4px;
}
#life-area { color: #ff5d6e; font-size: 24px; }
#score, #kill-count { font-size: 24px; color: #ffe07a; margin: 0 2px; }
.score-label, .score-suffix { font-size: 14px; opacity: 0.85; }

#expression-bar {
  position: relative; height: 80px; margin-bottom: 20px; background: #020a14;
  border: 2px solid #2d8acf; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
#expression { font-family: 'Klee One', sans-serif; font-size: 48px; color: #b6f1ff; text-shadow: 0 0 12px rgba(120, 220, 255, 0.95); }
#expression.error { color: #ff8a8a; text-shadow: 0 0 12px rgba(255, 90, 90, 0.9); }
#target-hint { position: absolute; top: 4px; right: 10px; font-size: 11px; color: rgba(200, 230, 255, 0.7); }

#keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key {
  font-family: 'M PLUS Rounded 1c', sans-serif; font-weight: 900; font-size: 32px; height: 70px;
  color: #eaf6ff; background: linear-gradient(180deg, #2a5a8a, #163657);
  border: 2px solid #5fb2ee; border-radius: 14px; cursor: pointer; touch-action: manipulation;
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), inset 0 -3px 0 rgba(0,0,0,0.35), 0 3px 0 rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.key:active, .key.pressed { transform: translateY(2px); box-shadow: inset 0 2px 6px rgba(0,0,0,0.4); }
.key.op { color: #fff8c0; background: linear-gradient(180deg, #8a5d1a, #5a3b10); border-color: #ffd25f; }
.key.del { color: #ffe1e1; background: linear-gradient(180deg, #8a2a3c, #4a121e); border-color: #ff7a8a; font-size: 20px; }

.btn-icon { width: 24px; height: 24px; object-fit: contain; }

.disabled { opacity: 0.3; pointer-events: none; }

#sub-controls { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
#speed-controls { display: flex; gap: 4px; }
.speed-btn {
  font-family: 'M PLUS Rounded 1c', sans-serif; font-weight: 700; font-size: 12px;
  padding: 6px 10px; border-radius: 8px; border: 2px solid rgba(120, 200, 255, 0.6);
  background: rgba(7, 16, 26, 0.55); color: #d6f1ff; cursor: pointer; line-height: 1;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.speed-btn .btn-icon { width: 28px; height: 28px; }
.speed-btn.active { background: #2d8acf; color: #fff; border-color: #b6e6ff; }
.ghost-btn {
  font-family: 'M PLUS Rounded 1c', sans-serif; font-weight: 700; font-size: 14px;
  padding: 8px 14px; border-radius: 8px; border: 2px solid #9fb8d2;
  background: #2a3744; color: #eaf6ff; cursor: pointer; line-height: 1;
  display: flex; align-items: center; gap: 6px;
}

.overlay {
  position: absolute; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.85); backdrop-filter: blur(4px);
}
.modal-box { width: 90%; max-width: 500px; text-align: center; }
.modal-box h1 { font-size: 36px; color: #fff; margin-bottom: 10px; }
.modal-box p { font-size: 20px; color: #ffeaa6; margin-bottom: 20px; }

.lang-btn {
  position: absolute; top: 20px; right: 20px;
  font-family: 'M PLUS Rounded 1c', sans-serif; font-weight: 700; font-size: 16px;
  padding: 8px 16px; border-radius: 20px; border: 2px solid #9fb8d2;
  background: #2a3744; color: #eaf6ff; cursor: pointer; z-index: 110;
  box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}
.lang-btn:active { transform: translateY(2px); box-shadow: none; }

.mode-select-box {
  background: rgba(45, 138, 207, 0.2); border: 2px solid #2d8acf; border-radius: 12px;
  padding: 15px 20px; margin-bottom: 20px; display: flex; flex-direction: column; gap: 12px; text-align: left;
}
.setting-group {
  display: flex; flex-direction: column; gap: 12px;
}
.setting-group.horizontal {
  flex-direction: row; justify-content: flex-start; gap: 20px;
}
.mode-divider {
  border: none; border-top: 2px dashed rgba(255,255,255,0.3); margin: 5px 0; width: 100%;
}
.mode-radio {
  font-size: 20px; color: #eaf6ff; cursor: pointer; display: flex; align-items: center; gap: 12px;
}
.mode-radio input[type="radio"] { transform: scale(1.6); margin: 0; cursor: pointer; }

.medal-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.medal-btn {
  font-family: 'M PLUS Rounded 1c', sans-serif; font-weight: 900; font-size: 20px;
  padding: 12px 24px; width: 85%; border-radius: 14px; border: 3px solid transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.medal-btn .btn-icon { width: 28px; height: 28px; }
.medal-btn.primary { background: linear-gradient(180deg, #4fd17a, #1f8b46); color: #fff; border-color: #b6f5cc; }
.medal-btn.ghost { background: linear-gradient(180deg, #4a5868, #2a3744); color: #eaf6ff; border-color: #9fb8d2; }
/* 認定証ボタン用の特別カラー */
.medal-btn.cert-color { background: linear-gradient(180deg, #f1c40f, #d35400); color: #fff; border-color: #f39c12; }

.medal-visual { width: 150px; height: 150px; margin: 0 auto 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 60px; border: 6px solid #fff;}
.medal-visual.bronze { background: radial-gradient(circle, #f6c597, #6b3a16); border-color: #f0d0a8;}
.medal-visual.silver { background: radial-gradient(circle, #ffffff, #6b7480); border-color: #ffffff;}
.medal-visual.gold { background: radial-gradient(circle, #fff5b0, #a4750a); border-color: #fff3a8; box-shadow: 0 0 30px #ffd34d;}

.hidden { opacity: 0; pointer-events: none; visibility: hidden; z-index: -1 !important; position: absolute; }
#loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 24px; background: #07101a; z-index: 200; }

.gem-navi-wrapper {
    position: fixed; bottom: 20px; right: 20px; z-index: 9999;
    display: flex; align-items: stretch; background: #fff;
    border-radius: 30px; box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    border: 3px solid #78C2C4; overflow: hidden; transition: box-shadow 0.2s;
}
.gem-navi-handle {
    padding: 0 15px; background: #E6E9ED; color: #AAB2BD;
    cursor: grab; font-size: 1.2rem; user-select: none; touch-action: none;
    display: flex; align-items: center; justify-content: center;
}
.gem-navi-handle:active { cursor: grabbing; background: #CCD1D9; }
.gem-navi-btn {
    background: linear-gradient(135deg, #A0CECB, #78C2C4);
    color: #fff !important; text-decoration: none; padding: 10px 20px;
    font-weight: bold; font-family: "M PLUS Rounded 1c", sans-serif;
    display: flex; align-items: center; gap: 5px; font-size: 1rem; white-space: nowrap;
}
.gem-navi-btn:hover { opacity: 0.9; }
.gem-navi-icon {
    width: 24px !important; height: 24px !important; object-fit: cover !important;
    border-radius: 50% !important; flex-shrink: 0 !important;
    margin-right: 4px !important; display: inline-block !important;
}