* { 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;
}
/* 左側：ゲーム画面 */
#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;
}
/* 右側：コックピット */
#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;
}
/* HUD（スコア・ライフ） */
#hud-top {
  position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; z-index: 5;
}
#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);
}
.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: 24px; }

/* オーバーレイ・メダル */
.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; }
.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: 14px 28px; width: 80%; border-radius: 14px; border: 3px solid transparent; cursor: pointer;
}
.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-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; }
* { 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; }
#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; }
#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;
}
#hud-top { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; z-index: 5; }
#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);
}
.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: 24px; }

/* 🌟 追加：サブコントロール（速度・やめる） */
#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;
}
.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: 13px;
  padding: 6px 12px; border-radius: 8px; border: 2px solid #9fb8d2;
  background: #2a3744; color: #eaf6ff; cursor: pointer; line-height: 1;
}

.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; }
.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: 14px 28px; width: 80%; border-radius: 14px; border: 3px solid transparent; cursor: pointer;
}
.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-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; }