:root {
  --bg-dark: #1a0b2e;
  --ui-bg: #2d1b4e;
  --text-main: #f8fafc;
  --brand: #a855f7;
  --brand-shadow: #7e22ce;
  --error: #e11d48;
  --error-shadow: #9f1239;
  --btn-bg: #4c2882;
  --btn-shadow: #261047;
}

* { 
  box-sizing: border-box; 
  touch-action: manipulation; 
  user-select: none; 
  -webkit-user-select: none; 
}

body { 
  margin: 0; 
  padding: 0; 
  background: #000; 
  font-family: 'M PLUS Rounded 1c', sans-serif; 
  height: 100dvh; 
  width: 100vw; 
  overflow: hidden; 
  display: flex; 
}

/* 確実な非表示（絶対鉄則） */
.hidden { 
  opacity: 0; 
  pointer-events: none; 
  visibility: hidden; 
  z-index: -1 !important; 
  position: absolute; 
}

/* アイコン用クラス */
.ui-icon {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

/* === グローバルボタン（ホーム＆言語） === */
.global-btn {
  position: absolute;
  z-index: 9998;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid #4c2882;
  color: #4c2882;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.2);
  transition: transform 0.1s;
}
.global-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 3px rgba(0,0,0,0.2);
}
.home-btn {
  top: 15px; left: 15px;
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 20px;
  display: flex; justify-content: center; align-items: center;
}
.lang-btn {
  top: 15px; right: 15px;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
}

#app { 
  display: flex; 
  flex-direction: row; /* plushotに合わせる */
  width: 100%; 
  height: 100%; 
  background: var(--bg-dark); 
  position: relative; 
}

/* 左右分割UI */
#stage { 
  position: relative; 
  flex: 1 1 auto; /* plushotに合わせる */
  overflow: hidden; 
}

/* 🌟 コックピットをplushotのレイアウトに統合（高さやFlex割合を固定化） */
#cockpit { 
  flex: 0 0 35%; min-width: 300px; max-width: 450px;
  background: radial-gradient(120% 80% at 50% 0%, rgba(107, 33, 168, 0.55), rgba(45, 27, 78, 0.95) 70%),
              linear-gradient(180deg, #2d1b4e, #1a0b2e 80%);
  border-left: 3px solid var(--brand); 
  box-shadow: inset 2px 0 0 rgba(216, 180, 254, 0.35);
  display: flex; flex-direction: column; justify-content: center; padding: 20px;
  z-index: 10; 
}

canvas { 
  display: block; 
  position: absolute; inset: 0;
  width: 100%; 
  height: 100%; 
  touch-action: none; 
  background: #1a0b2e; 
}

#hud-top { 
  position: absolute; top: 10px; left: 70px; right: 120px; 
  display: flex; justify-content: space-between; z-index: 5; 
}
#life-area, #score-area {
  background: rgba(26, 11, 46, 0.7); border: 2px solid rgba(168, 85, 247, 0.6); border-radius: 12px;
  padding: 6px 12px; font-size: 18px; display: flex; align-items: baseline; gap: 4px; color: #fff;
}
#life-area { color: #ff5d6e; font-size: 24px; }
#score, #kill-count { font-size: 24px; color: #d8b4fe; margin: 0 2px; }
.score-label, .score-suffix { font-size: 14px; opacity: 0.85; }

#loading { position: absolute; inset: 0; display: flex; justify-content: center; align-items: center; background: var(--bg-dark); color: #fff; font-size: 24px; font-weight: bold; z-index: 100; text-align: center; line-height: 1.5; }

/* 🌟 Expression Barの高さを固定 */
#expression-bar { 
  position: relative; height: 80px; margin-bottom: 20px; background: #1a0b2e;
  border: 2px solid var(--brand); border-radius: 12px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  box-shadow: inset 0 0 15px rgba(0,0,0,0.8);
}
#expression { font-family: 'Klee One', sans-serif; font-size: 48px; color: #fff; letter-spacing: 4px; transition: color 0.2s; }
#expression.error { color: var(--error); animation: shake 0.3s; }
#target-hint { position: absolute; top: 4px; right: 10px; font-size: 11px; color: #d8b4fe; }

/* 🌟 Keypadのボタンスタイルをplushotの立体感（紫ベース）に統合 */
#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: #f3e8ff; background: linear-gradient(180deg, #7e22ce, #4c2882);
  border: 2px solid #c084fc; 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; justify-content: center; align-items: center; gap: 4px;
}
.key:active, .key.pressed { transform: translateY(2px); box-shadow: inset 0 2px 6px rgba(0,0,0,0.4); }
.key.op { color: #fff; background: linear-gradient(180deg, #a855f7, #7e22ce); border-color: #d8b4fe; }
.key.del { color: #ffe1e1; background: linear-gradient(180deg, #e11d48, #9f1239); border-color: #fb7185; font-size: 24px; }

.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: 8px 10px; border-radius: 8px; border: 2px solid rgba(168, 85, 247, 0.6);
  background: rgba(26, 11, 46, 0.55); color: #d8b4fe; cursor: pointer; line-height: 1;
}
.speed-btn.active { background: var(--brand); color: #fff; border-color: #d8b4fe; }
.ghost-btn {
  font-family: 'M PLUS Rounded 1c', sans-serif; font-weight: 700; font-size: 13px;
  padding: 8px 12px; border-radius: 8px; border: 2px solid #a855f7;
  background: #2d1b4e; color: #f3e8ff; cursor: pointer; line-height: 1;
  transition: all 0.2s;
}
.ghost-btn:hover { background: #4c2882; }

/* 以下、既存のオーバーレイ等のスタイル */
.overlay { position: absolute; inset: 0; background: rgba(26, 11, 46, 0.85); display: flex; justify-content: center; align-items: center; z-index: 50; backdrop-filter: blur(4px); }
.modal-box { background: #fff; padding: 32px; border-radius: 24px; text-align: center; width: 90%; max-width: 550px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.3); border: 4px solid var(--brand); }
.modal-box h1 { margin: 0 0 8px 0; color: #2d1b4e; font-size: 32px; }
.modal-box p { margin: 0 0 20px 0; color: #6b21a8; font-weight: bold; }

.mode-select-container { display: flex; gap: 16px; margin-bottom: 24px; text-align: left; justify-content: center; }
.mode-select-box { background: #f3e8ff; border: 2px solid var(--brand); border-radius: 12px; padding: 12px 20px; display: flex; flex-direction: column; gap: 8px; flex: 1; transition: opacity 0.3s; }
.mode-title { font-size: 14px; font-weight: bold; color: var(--brand); margin: 0 0 4px 0; border-bottom: 2px solid #d8b4fe; padding-bottom: 4px; }
.mode-radio { font-size: 18px; color: #4c2882; cursor: pointer; display: flex; align-items: center; gap: 8px; font-weight: bold; }

.mode-radio input {
  accent-color: var(--brand);
  transform: scale(1.3);
  margin-right: 4px;
}

.medal-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.medal-btn {
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-size: 18px; font-weight: bold; padding: 12px 24px; border-radius: 12px; cursor: pointer; width: 80%;
  margin: 0 auto; border: none; box-shadow: 0 4px 0 rgba(0,0,0,0.2); transition: transform 0.1s;
}
.medal-btn:active { transform: translateY(4px); box-shadow: none; }
.medal-btn.primary { background: linear-gradient(180deg, #a855f7, #7e22ce); color: #fff; border-color: #e9d5ff; box-shadow: 0 4px 0 #581c87; }
.medal-btn.ghost { background: transparent; color: #a855f7; border: 2px solid #a855f7; box-shadow: none; }
/* 認定証ボタン用カラー追加 */
.medal-btn.cert-color { background: linear-gradient(180deg, #f1c40f, #d35400); color: #fff; border-color: #f39c12; box-shadow: 0 4px 0 #b9770e; }

.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;}

/* === ジェムナビボタン完全版（要塞化スタイル） === */
.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-float-quit-btn {
  background: #ff5d6e;
  color: #fff;
  border: none;
  padding: 0 16px;
  font-weight: bold;
  font-family: "M PLUS Rounded 1c", sans-serif;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 2px solid #78C2C4;
  transition: background-color 0.1s;
}
.gem-float-quit-btn:active {
  background: #e11d48;
}

.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-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;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-5px); }
}