/* === 共通・ベース設定 === */
:root {
    --brand-color: #4A90E2;
    --bg-ui: #fdfbf7;
    --btn-color: #fff;
    --btn-active: #e3f2fd;
    --text-dark: #333;
}

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

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

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

#app-container { position: relative; width: 100vw; height: 100dvh; overflow: hidden; }
.screen { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; transition: opacity 0.3s; }

.home-btn, .back-btn {
    position: absolute; top: 15px; left: 15px; z-index: 9998;
    background: rgba(255, 255, 255, 0.9); border: 2px solid #ddd; border-radius: 20px;
    padding: 8px 16px; font-size: 1.2rem; font-weight: bold; color: #555;
    display: flex; align-items: center; gap: 5px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); cursor: pointer;
}
.home-btn:active, .back-btn:active { transform: translateY(4px); box-shadow: 0 0 2px rgba(0,0,0,0.1); }

.ui-btn {
    background-color: var(--btn-color); color: var(--text-dark); border: 3px solid var(--brand-color); border-radius: 12px;
    font-size: 1.5rem; font-family: 'M PLUS Rounded 1c', sans-serif; font-weight: bold;
    padding: 10px 20px; box-shadow: 0 6px 0 #2a5d96, 0 8px 6px rgba(0,0,0,0.2);
    transition: transform 0.05s, box-shadow 0.05s; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.ui-btn:active { transform: translateY(6px); box-shadow: 0 0px 0 #2a5d96, 0 2px 3px rgba(0,0,0,0.2); background-color: var(--btn-active); }
.disabled { opacity: 0.5; pointer-events: none; }

.btn-group { display: flex; flex-direction: column; gap: 1.5vh; margin-bottom: 2vh; }

/* ホーム画面 */
#home-screen { flex-direction: column; align-items: center; justify-content: center; }
.bg-image { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.title-box {
    position: relative; z-index: 2; margin-bottom: 5vh; background: rgba(255, 255, 255, 0.85);
    padding: 20px 40px; border-radius: 20px; border: 4px solid var(--brand-color); text-align: center;
}
.title-box h1 { margin: 0; font-size: clamp(2rem, 5vw, 3.5rem); color: var(--brand-color); }
.mode-container { position: relative; z-index: 2; display: flex; gap: 3vw; }
.mode-card {
    background: #fff; border: 4px solid #f39c12; border-radius: 20px; padding: 30px; text-align: center;
    cursor: pointer; box-shadow: 0 8px 15px rgba(0,0,0,0.2); transition: transform 0.2s; width: clamp(250px, 25vw, 350px);
}
.mode-card:hover { transform: translateY(-5px); }
.mode-card h2 { margin: 0 0 10px 0; font-size: 1.8rem; color: #d35400; }
.mode-card p { margin: 0; font-family: 'Klee One', cursive; font-size: 1.2rem; font-weight: bold; }

/* ゲームエリア */
.game-area { position: relative; width: 70%; height: 100%; }
.game-area .bg-image { opacity: 0.35; }
.main-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 2; touch-action: none; }

/* モード1・2用のUIエリア（従来のまま） */
.ui-area-mode12 {
    position: relative; width: 30%; height: 100%; background-color: var(--bg-ui);
    border-left: 4px solid #ccc; box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    display: flex; flex-direction: column; padding: 2vh; z-index: 5;
    overflow-y: auto; justify-content: flex-start;
}

/* モード3専用のUIエリア（ジェムナビ被り防止の padding-bottom: 90px 追加） */
.ui-area {
    position: relative; width: 30%; height: 100%; background-color: var(--bg-ui);
    border-left: 4px solid #ccc; box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    display: flex; flex-direction: column; 
    padding: 2vh 2vh 90px 2vh; 
    z-index: 5;
    overflow-y: auto; justify-content: flex-start;
}
.panel-title { text-align: center; font-size: 1.5rem; color: var(--brand-color); margin-bottom: 1vh; margin-top: 0; }

/* モード1 */
.score-board { background: #fff; border: 2px solid #ccc; border-radius: 10px; padding: 10px; margin-bottom: 2vh; font-size: 1.2rem; font-weight: bold; }
.count-yellow { color: #f1c40f; font-size: 1.5rem; }
.count-blue { color: #3498db; font-size: 1.5rem; }
#m1-square-overlay { position: absolute; border: 4px solid #e74c3c; z-index: 3; pointer-events: none; background: rgba(231, 76, 60, 0.2); }

/* モード2 */
.label-text {
    position: absolute; font-family: 'Klee One', cursive; font-size: 2rem; font-weight: bold; color: #e74c3c;
    background: rgba(255,255,255,0.9); padding: 5px 15px; border-radius: 10px; border: 3px solid #e74c3c; z-index: 10; transition: opacity 0.5s;
}
#m2-label-radius-hidden, #m2-label-radius-ans { top: 50%; left: 10%; transform: translateY(-50%); }
#m2-label-circum-hidden, #m2-label-circum-ans { bottom: 15%; left: 50%; transform: translateX(-50%); }
.placeholder-box { display: inline-block; min-width: 80px; border-bottom: 2px dashed #e74c3c; text-align: center; }

/* モード3 */
.shape-form { background: #fff; border: 2px solid #ccc; border-radius: 10px; display: flex; flex-direction: column; gap: 5px; }
.ui-select { font-family: 'M PLUS Rounded 1c', sans-serif; font-size: 1.2rem; padding: 5px; border-radius: 5px; border: 1px solid #ccc; background: #fff; }
.layer-btn-group { display: flex; justify-content: space-between; gap: 8px; }
.layer-btn { flex: 1; padding: 5px 0 !important; font-size: 1.1rem !important; border-color: #3498db; color: #3498db; }

/* ジェムナビ */
.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;
}
.gem-navi-handle { padding: 0 15px; background: #E6E9ED; color: #AAB2BD; cursor: grab; font-size: 1.2rem; display: flex; align-items: center; justify-content: center; }
.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;
}
.gem-navi-icon { width: 24px !important; height: 24px !important; border-radius: 50% !important; margin-right: 4px !important; }