/* --- ベース設定 --- */
:root {
    --brand-color: #4A90E2;
    --bg-color: #eef2f5;
    --bg-ui: #F8F9FA;
    --text-dark: #2c3e50;
    --text-main: #333;
    --danger: #E53935;
    --success: #2ecc71;
    --win-color: #3498db;
    --grayout: #bdc3c7;
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    font-family: 'M PLUS Rounded 1c', sans-serif;
}

body {
    margin: 0; padding: 0; width: 100vw; height: 100dvh; overflow: hidden; background-color: #000;
}

.hidden {
    opacity: 0; pointer-events: none; visibility: hidden; z-index: -1 !important; position: absolute;
}

#app-container {
    position: relative; width: 100%; height: 100%; background-color: var(--bg-color); display: flex; overflow: hidden;
}

.screen {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex;
}

/* --- 汎用ボタン --- */
.ui-btn {
    font-size: clamp(1.2rem, 2vw, 1.5rem); font-weight: bold; padding: 10px 20px; color: white; border: none; border-radius: 10px;
    cursor: pointer; transition: transform 0.1s, box-shadow 0.1s; box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}
.ui-btn:active:not(.disabled) { transform: translateY(4px); box-shadow: none; }
.ui-btn.disabled { background-color: var(--grayout); box-shadow: 0 4px 0 #AAB2BD; pointer-events: none; color: #7f8c8d; }
.blue-btn { background-color: var(--brand-color); }
.red-btn { background-color: var(--danger); box-shadow: 0 4px 0 #B71C1C; }
.gray-btn { background-color: #AAB2BD; color: #fff; box-shadow: 0 4px 0 #656D78; }
.btn-large { font-size: 1.5rem; padding: 15px 30px; border-radius: 15px; width: 100%; margin-bottom: 15px; }

/* ヘッダー周りのボタン群 */
.global-home-btn {
    position: absolute; top: 15px; left: 15px; z-index: 9998; background: #fff; border: 2px solid var(--brand-color); border-radius: 20px;
    padding: 8px 15px; font-weight: bold; color: var(--brand-color); cursor: pointer; box-shadow: 0 4px 0 #2a5d96; display: flex; align-items: center; gap: 5px;
}
.global-home-btn:active { transform: translateY(4px); box-shadow: none; }

.global-lang-btn {
    position: absolute; top: 15px; right: 15px; z-index: 9998; background: #fff; border: 2px solid #2ecc71; border-radius: 20px; 
    padding: 8px 15px; font-weight: bold; color: #2ecc71; cursor: pointer; box-shadow: 0 4px 0 #27ae60; transition: transform 0.1s, box-shadow 0.1s;
}
.global-lang-btn:active { transform: translateY(4px); box-shadow: none; }

/* タイトル画面 */
#title-screen { flex-direction: column; align-items: center; justify-content: center; background: radial-gradient(circle, #fff, #e0f0ff); z-index: 10; }
.title-content { text-align: center; width: 80%; max-width: 600px; }
.title-logo { width: 100%; max-width: 400px; margin-bottom: 30px; border-radius: 20px; filter: drop-shadow(0 10px 15px rgba(0,0,0,0.2)); }
.title-buttons { display: flex; flex-direction: column; gap: 10px; }

/* モンスターメイク画面 */
#create-mode { display: flex; width: 100%; height: 100%; background: #E2E8F0; }
#game-area { width: 70%; height: 100%; position: relative; display: flex; justify-content: center; align-items: center; padding: 20px; }
#ui-area { width: 30%; height: 100%; background-color: #F8F9FA; border-left: 4px solid var(--brand-color); display: flex; flex-direction: column; box-shadow: -5px 0 15px rgba(0,0,0,0.05); z-index: 30; }

.canvas-wrapper {
    position: relative; width: 100%; height: 100%; max-width: 800px; max-height: 800px; display: flex; justify-content: center; align-items: center;
    background-image: radial-gradient(circle, #fff 10%, transparent 10%), radial-gradient(circle, #fff 10%, transparent 10%);
    background-size: 20px 20px; background-position: 0 0, 10px 10px; background-color: #d1d8e0; border-radius: 20px; box-shadow: inset 0 0 20px rgba(0,0,0,0.1);
}
#app-canvas { border-radius: 20px; touch-action: none; }

#slot-container {
    position: absolute; left: 15px; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, 0.9); padding: 15px 10px; border-radius: 20px;
    border: 3px solid var(--brand-color); box-shadow: 0 4px 10px rgba(0,0,0,0.1); display: flex; flex-direction: column; align-items: center; z-index: 10;
}
.slot-title { font-size: 12px; font-weight: bold; color: var(--brand-color); margin-bottom: 10px; text-align: center; line-height: 1.2; }
.slots { display: flex; flex-direction: column; gap: 10px; }
.slot { width: 60px; height: 60px; border: 3px dashed #AAB2BD; border-radius: 10px; background: #F5F7FA; display: flex; justify-content: center; align-items: center; }
.slot img { width: 80%; height: 80%; object-fit: contain; }
.slot.filled { border: 3px solid var(--brand-color); background: #fff; }

.ui-step { display: flex; flex-direction: column; width: 100%; height: 100%; }
.panel-header { background-color: var(--brand-color); color: white; padding: 15px; text-align: center; font-weight: 700; font-size: 1.5rem; }
.instruction { padding: 15px; text-align: center; font-size: 1.1rem; color: var(--text-main); font-weight: bold; line-height: 1.4; }

.tab-nav { display: flex; flex-wrap: wrap; background-color: #E6E9ED; }
.tab-btn { flex: 1 1 25%; padding: 8px 2px; text-align: center; font-weight: 700; font-size: 14px; color: #656D78; cursor: pointer; border-bottom: 4px solid transparent; transition: all 0.2s; line-height: 1.2; }
.tab-btn.active { color: var(--brand-color); border-bottom-color: var(--brand-color); background-color: #FFFFFF; }
.tab-sub { font-size: 10px; }

.tab-content-wrapper { flex: 1; overflow-y: auto; padding: 15px; background-color: #FFFFFF; }
.parts-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; align-content: start; max-width: 100%; }
@media (min-width: 1024px) { .parts-grid { grid-template-columns: repeat(3, 1fr); } }

.part-btn { background-color: #F5F7FA; border: 3px solid #CCD1D9; border-radius: 15px; aspect-ratio: 1/1; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: transform 0.1s, border-color 0.1s; }
.part-btn:active { transform: scale(0.95); }
.part-btn:hover, .part-btn.selected { border-color: var(--brand-color); }
.part-btn.selected { background-color: #e0f0ff; }
.part-btn.disabled { opacity: 0.4; pointer-events: none; filter: grayscale(100%); }
.part-btn img { width: 85%; height: 85%; object-fit: contain; pointer-events: none; }

.layer-control-area { padding: 10px 20px; background-color: #F8F9FA; border-top: 2px solid #E6E9ED; }
.layer-title { font-size: 12px; font-weight: bold; color: #656D78; margin-bottom: 10px; }
.layer-buttons { display: flex; gap: 10px; justify-content: space-between; }
.layer-btn { flex: 1; padding: 8px; background-color: #FFFFFF; border: 2px solid #CCD1D9; border-radius: 8px; cursor: pointer; font-size: 16px; color: var(--brand-color); transition: all 0.1s; box-shadow: 0 2px 0 #E6E9ED; }
.layer-btn:active { transform: translateY(2px); box-shadow: none; background-color: #E6E9ED; }

.action-area { padding: 20px; display: flex; flex-direction: column; background-color: #FAFAFA; }
.sub-btn { background-color: #AAB2BD; box-shadow: 0 4px 0 #656D78; font-size: 1rem; padding: 10px; }
.battle-btn { background-color: var(--danger); box-shadow: 0 4px 0 #B71C1C; }

.skill-list { flex: 1; padding: 15px; display: flex; flex-direction: column; gap: 15px; overflow-y: auto; }
.skill-item { display: flex; align-items: center; background: #fff; border: 3px solid var(--brand-color); border-radius: 15px; padding: 10px; gap: 15px; }
.skill-icon { width: 60px; height: 60px; background: #F5F7FA; border-radius: 10px; display: flex; justify-content: center; align-items: center; }
.skill-icon img { width: 80%; height: 80%; object-fit: contain; }
.skill-text { font-family: 'Klee One', cursive; font-size: 1.5rem; font-weight: bold; color: var(--text-main); }


/* バトルモード */
#battle-mode { display: flex; }
#battle-left {
    width: 70%; height: 100%; position: relative; display: flex; flex-direction: column; align-items: center;
    background-image: radial-gradient(circle, #fff 10%, transparent 10%), radial-gradient(circle, #fff 10%, transparent 10%);
    background-size: 20px 20px; background-position: 0 0, 10px 10px;
}
#battle-right {
    width: 30%; height: 100%; background-color: var(--bg-ui); border-left: 4px solid var(--brand-color);
    display: flex; flex-direction: column; padding: 10px 15px; box-shadow: -5px 0 15px rgba(0,0,0,0.1); z-index: 10;
}

#monster-stage { flex-grow: 1; display: flex; align-items: center; justify-content: center; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-15px); } }
#monster-battle-canvas { animation: float 3s ease-in-out infinite; filter: drop-shadow(0 10px 10px rgba(0,0,0,0.2)); border-radius: 20px; }
@keyframes attackDash { 0% { transform: scale(1) translateY(0); } 50% { transform: scale(1.1) translateY(-30px); filter: drop-shadow(0 20px 20px rgba(0,0,0,0.3)); } 100% { transform: scale(1) translateY(0); } }
.anim-attack { animation: attackDash 0.5s ease !important; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-10px); } 50% { transform: translateX(10px); } 75% { transform: translateX(-10px); } }
.anim-damage { animation: shake 0.3s ease !important; }

#attack-area { width: 95%; margin-bottom: 5vh; background: rgba(255,255,255,0.8); border-radius: 15px; border: 2px solid #ccc; padding: 15px; }
.attack-title { text-align: center; margin: 0 0 10px 0; border: none; font-size: 1.2rem; color: var(--brand-color); border-bottom: 2px dashed var(--brand-color); padding-bottom: 5px; }
#attack-commands { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.attack-btn { width: calc(25% - 10px); min-width: 80px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #fff; border: 2px solid var(--brand-color); border-radius: 10px; padding: 5px; cursor: pointer; transition: transform 0.1s; box-shadow: 0 4px 0 rgba(0,0,0,0.1); }
.attack-btn:active:not(.disabled):not(.used) { transform: translateY(4px); box-shadow: none; background: #e0f0ff; }
.attack-btn img { width: 45px; height: 45px; object-fit: contain; margin-bottom: 5px; }
.attack-btn span { font-size: 0.9rem; font-weight: bold; color: var(--text-dark); text-align: center; }

/* 厳格なグレーアウト（コマンド用） */
.attack-btn.disabled, .defense-btn.disabled {
    opacity: 0.4 !important; pointer-events: none !important; filter: grayscale(100%) !important; box-shadow: none !important; transform: translateY(4px);
}
/* 使用済みアタックコマンド */
.attack-btn.used {
    opacity: 0.4 !important; pointer-events: none !important; filter: grayscale(100%) !important; box-shadow: none !important; transform: translateY(4px);
}

#defense-commands { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.defense-btn { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: clamp(0.9rem, 1.5vw, 1.1rem); font-weight: bold; border-radius: 8px; border: none; cursor: pointer; box-shadow: 0 4px 0 rgba(0,0,0,0.1); transition: transform 0.1s; white-space: nowrap; }
.defense-btn:active:not(.disabled) { transform: translateY(4px); box-shadow: none; }
.can-btn { background-color: #fff; border: 2px solid var(--brand-color); color: var(--brand-color); }
.cant-btn { background-color: var(--danger); color: white; border: 2px solid #c0392b; justify-content: center; margin-top: 2px; }
.def-icon { width: 30px; height: 30px; background: #f1f2f6; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.def-icon img { width: 20px; height: 20px; object-fit: contain; }

/* バトル右側レイアウト整理 */
#score-display { text-align: center; margin-bottom: 10px; background: #fff; padding: 5px; border-radius: 10px; border: 2px solid var(--brand-color); }
#score-text { font-size: 1.4rem; font-weight: bold; color: var(--brand-color); }

#battle-controls { 
    background: #fdf2e9; padding: 10px; border-radius: 10px; margin-bottom: 10px; border: 2px solid #e67e22; 
    display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 8px; min-height: 100px;
}
#current-opponent-name { font-weight: bold; font-size: 1.1rem; color: #d35400; text-align: center; }
#life-display { font-size: 1.6rem; letter-spacing: 5px; text-align: center; }
.result-btns { display: flex; gap: 10px; justify-content: center; width: 100%; }
.result-btns button { flex: 1; padding: 8px; font-size: 1rem; }

.result-text { font-size: 2.2rem; font-weight: bold; text-align: center; line-height: 1.2; font-family: 'Klee One', cursive; }
.text-blue { color: var(--win-color); }
.text-red { color: var(--danger); }

.battle-history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item { padding: 10px; border-radius: 8px; font-weight: bold; text-align: center; font-size: 1.1rem; border: 2px solid #dcdde1; }
.history-item.win { background-color: var(--win-color); color: white; border-color: #2980b9; }
.history-item.lose { background-color: var(--danger); color: white; border-color: #c0392b; }

/* 新規：アタック結果選択モーダル専用CSS */
#attack-result-modal { background: rgba(0,0,0,0.7); z-index: 65; align-items: center; justify-content: center; }
.attack-result-container { background: #fff; width: 90%; max-width: 400px; padding: 30px; border-radius: 15px; text-align: center; border: 5px solid var(--brand-color); box-shadow: 0 10px 20px rgba(0,0,0,0.3); }

/* キーボードモーダル */
#keyboard-modal { background: rgba(0,0,0,0.6); z-index: 50; align-items: center; justify-content: center; }
.keyboard-container { background: #fff; width: 90%; max-width: 800px; padding: 20px; border-radius: 15px; border: 5px solid var(--brand-color); }
.keyboard-title { text-align: center; margin: 0 0 15px 0; color: var(--text-dark); }
.keyboard-display-box { background: #f1f2f6; height: 60px; border-radius: 10px; margin-bottom: 20px; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-family: 'Klee One', cursive; border: 2px inset #ccc; }
.keyboard-grid { display: grid; grid-template-rows: repeat(5, 1fr); grid-auto-flow: column; direction: rtl; gap: 8px; margin-bottom: 15px; }
.kb-key { direction: ltr; background: #fff; border: 2px solid #ccc; border-radius: 8px; font-size: 1.5rem; font-weight: bold; height: 50px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.kb-key:active:not(.empty-key) { background: #e0f0ff; border-color: var(--brand-color); }
.empty-key { border: none; background: transparent; cursor: default; }
.keyboard-actions { display: flex; gap: 15px; justify-content: center; }
.keyboard-actions button { width: 120px; }

/* ターン表示用バトルトースト */
#battle-toast {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.8); color: #fff; padding: 20px 40px; border-radius: 20px;
    font-size: 2.2rem; font-weight: bold; text-align: center; z-index: 100;
    font-family: 'Klee One', cursive; pointer-events: none; border: 3px solid #ffeb3b;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5); line-height: 1.3;
}
@keyframes pulseToast {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    20% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}


/* === 💎 ジェムナビボタン（開閉式改修） === */
.gem-navi-wrapper { 
    position: fixed; bottom: 20px; right: 0; z-index: 9999; display: flex; align-items: stretch; background: #fff; 
    border-radius: 30px 0 0 30px; box-shadow: -2px 4px 6px rgba(0,0,0,0.2); border: 3px solid #78C2C4; border-right: none;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform: translateX(calc(100% - 35px)); /* 取っ手だけ見せる */
}
.gem-navi-wrapper.is-open {
    transform: translateX(0);
}
.gem-navi-handle { 
    width: 35px; background: #E6E9ED; color: #AAB2BD; cursor: pointer; font-size: 1.2rem; user-select: none; 
    display: flex; align-items: center; justify-content: center; border-radius: 27px 0 0 27px;
}
.gem-navi-handle:active { 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-icon { width: 24px !important; height: 24px !important; object-fit: cover !important; border-radius: 50% !important; flex-shrink: 0 !important; margin-right: 4px !important; }


/* スマホレスポンシブ */
@media (max-width: 768px) {
    #app-container, #create-mode, #battle-mode { flex-direction: column; }
    #game-area, #battle-left { width: 100%; height: 50%; padding: 10px; }
    #ui-area, #battle-right { width: 100%; height: 50%; border-left: none; border-top: 4px solid var(--brand-color); overflow-y: auto; }
    #slot-container { left: 5px; top: 10px; transform: none; padding: 5px; flex-direction: row; }
    .slots { flex-direction: row; }
    .slot { width: 40px; height: 40px; }
    #attack-area { margin-bottom: 2vh; padding: 10px; }
    .attack-btn img { width: 30px; height: 30px; }
    .attack-btn span { font-size: 0.7rem; }
}