:root {
    --button-size: 60px; /* 初期キーサイズ */
    --gap-size: 10px;    /* keypad-content の gap と一致 */
    --font-size: 1.4em;  /* キーの初期フォントサイズ */
--button-size-min: 40px; /* PC/タブレットの最小基準 */
}


/* --- キーパッドのコンテナ（可動部分） --- */
#movableKeypad {
/* 💡 修正 4: 内部要素を縦に配置し、keypad-contentが残りの高さを埋める設定 */
    display: flex;
    flex-direction: column; 
    height: 400px; /* 初期値を設定し、JSで上書きされる */

    /* 可動式（画面に固定）に設定 */
    position: fixed; 
    top: 100px;
    right: 50px;
    width: 280px; /* 全体の幅 */
    background-color: #fff;
    border: 1px solid #aaa;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    z-index: 1000; /* 他の要素の上に表示 */

min-width: 200px; /* 最小幅 */
    min-height: 250px; /* 最小高 */
    resize: none; /* ブラウザ標準のリサイズ機能を無効化 */
    
    /* タッチ時のハイライト防止 */
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ドラッグハンドル部分 */
.keypad-header {

    background-color: #3f51b5; /* 青系統 */
    color: white;
    padding: 8px 15px;
    text-align: center;
    font-size: 0.9em;
    cursor: move; /* 移動可能であることを示すカーソル */
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    flex-shrink: 0;
}

/* --- ボタンのコンテナ（.keypad-content）の修正 --- */
.keypad-content {
display: grid;
    gap: var(--gap-size);
    padding: var(--gap-size);
    
    flex-grow: 1;
    
    justify-content: center;
    align-content: center;
    
    /* 💡 修正 1: grid-template-rows を 4 から 5 に変更 */
    grid-template-columns: repeat(4, var(--button-size));
    grid-template-rows: repeat(5, var(--button-size)); /* ★★★ 修正 ★★★ */
}

/* 文字キー (a, b, x, y) の基本スタイル */
.key.character {
    /* ★★★ 修正: 背景色を少し濃い緑 (#C8E6C9) に変更 ★★★ */
    background-color: #C8E6C9; /* Medium Light Green */
    color: #333; /* 文字色は濃いまま */
    
    font-weight: bold;
    border: none;
    border-radius: 8px;
    
    /* 影の色もベースの緑に合わせて #A5D6A7 に変更 */
    box-shadow: 0 3px #A5D6A7; 
    cursor: pointer;
    transition: background-color 0.1s, transform 0.1s;
    font-size: var(--font-size);
}

.key.character:hover {
    /* ホバー時はさらに濃い緑に */
    background-color: #A5D6A7; 
}

.key.character:active {
    /* クリック時は最も濃い緑にして、押下感を出す */
    background-color: #81C784; 
    box-shadow: 0 1px #A5D6A7;
    transform: translateY(2px);
}

/* <i>タグの斜体スタイルは変更なし */
.key.character i {
    font-style: italic;
    font-size: 1.1em;
    line-height: 1;
    display: block;
    text-align: center;
}

#char-a {
    /* 5行目 (row 5) の 1列目 (column 1) から開始するように強制 */
    grid-column-start: 1 !important;
    grid-row-start: 5 !important;
}

#char-b {
    /* 5行目 (row 5) の 1列目 (column 1) から開始するように強制 */
    grid-column-start: 2 !important;
    grid-row-start: 5 !important;
}

#char-x {
    /* 5行目 (row 5) の 1列目 (column 1) から開始するように強制 */
    grid-column-start: 3 !important;
    grid-row-start: 5 !important;
}

#char-y {
    /* 5行目 (row 5) の 1列目 (column 1) から開始するように強制 */
    grid-column-start: 4 !important;
    grid-row-start: 5 !important;
}

/* 文字 a, b, x, y を斜体にするための <i> タグのスタイル */
.key.character i {
    font-style: italic; /* 斜体を強制 */
    /* 変数らしく、ボタンサイズに対して少し大きめに調整 */
    font-size: 1.1em; /* ボタンのfont-sizeの1.1倍 */
    line-height: 1;
    display: block;
    text-align: center;
}

/* --- ボタンのスタイル（.key）の修正 --- */
.key {
    /* 💡 修正 3: 固定のパディングは削除 */
    /* padding: 20px 0; */
    
    /* キーの高さと幅をCSS変数に完全に依存させる */
    width: var(--button-size);
    height: var(--button-size); 
    
    /* font-size も変数化を推奨 */
    font-size: var(--font-size, 1.4em); 

    cursor: pointer;
    border: none;
    border-radius: 8px;
    background-color: #e0e0e0;
    transition: background-color 0.1s, transform 0.1s;
}

/* マウスホバー時 */
.key:hover {
    background-color: #d0d0d0;
}

/* クリック/タップ時（フィードバック） */
.key:active {
    background-color: #c0c0c0;
    transform: scale(0.98); /* わずかに縮小 */
}




/* 演算子ボタン (+, -, ×, ÷) のスタイル */
.key.operator,
.key.equals {
    background-color: #ff9800; /* オレンジ系統 */
    color: white;
}

.key.operator:active,
.key.equals:active {
    background-color: #e68900;
}

/* クリアボタン (C) の色 */
.key.clear {
    background-color: #ff5252;
    color: white;
}
.key.clear:active {
    background-color: #e04b4b;
}

/* リサイズハンドル */
#resizeHandle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 15px;
    height: 15px;
    background: rgba(255, 255, 255, 0.2); /* 目立たない背景 */
    border-bottom-right-radius: 10px;
    cursor: nwse-resize; /* サイズ変更を示すカーソル */
    z-index: 1001; /* ヘッダーより上に配置 */
}

@media (max-width: 1050px) {
    #movableKeypad {
        /* キーパッド全体を小さくする */
        width: 220px; /* 幅を280pxから220pxに縮小 */
        height: 330px; /* 高さを350pxから300pxに縮小 */
        
        /* 画面右側からの距離も少し近づけるなど、配置を調整できます */
        right: 20px; 
        
        /* フォントやボタンサイズはCSS変数で調整します (次を参照) */
    }

:root { 
        /* 例: PCでのサイズが60pxだった場合、45pxに縮小 */
        --button-size: 45px !important; 
        
        /* フォントサイズも連動して小さくする */
        --font-size: 18px !important; 
    }

}

@media (orientation: landscape) and (max-width: 1050px){
  /* .lessonのwidthを100%に指定してください */

/* 1. キーパッド全体のサイズ設定 (最小要件に近づける) */
    #movableKeypad {
    width: 184px !important;
    height: 275px !important;
    top: 100px;
    right: 6rem;
    min-width: 150px;
    min-height: 275px;
}

    /* 2. ボタンの最小基準サイズを36pxに上書き */
    :root { 
        --button-size: 36px !important; 
    }

.keypad-header {
    background-color: #3f51b5;
    color: white;
    padding: 8px 15px;
    text-align: center;
    font-size: 0.7em;
    cursor: move;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    flex-shrink: 0;
}




}



@media (max-width: 430px) {
/* 1. キーパッド全体のサイズ設定 (最小要件に近づける) */
    #movableKeypad {
    width: 184px !important;
    height: 280px !important;
    top: 22rem;
    left: 17vw;
    min-width: 150px;
    min-height: 280px;
}

    /* 2. ボタンの最小基準サイズを36pxに上書き */
    :root { 
        --button-size: 36px !important; 
    }
}