/* ================================== */
/* === 基本スタイルと初期のスタイル === */
/* ================================== */
/* ... (body, #character-selectorなどのスタイルは変更なし) ... */
body {
    font-family: sans-serif; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; text-align: center; margin: 0; padding: env(safe-area-inset-top, 10px) env(safe-area-inset-right, 10px) env(safe-area-inset-bottom, 10px) env(safe-area-inset-left, 10px); box-sizing: border-box; min-height: 100vh;
    background-color: #f5fafd; /* 背景色を追加 */
}
#character-selector {
    font-size: 1.1em; margin-bottom: 15px; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; padding: 0 10px; box-sizing: border-box;
}
#character-selector label { cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.checkbox-label { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.9em; }

.canvas-container {
    display: flex;
    justify-content: space-around; /* 狭い画面での均等配置 */
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap; /* 折り返し必須 */
    max-width: 100%;
    box-sizing: border-box;
    padding: 0 5px;
    width: 100%;
    max-width: 600px; /* スマホ画面での最大幅目安 */
    margin-left: auto;
    margin-right: auto;
}

canvas {
    border: 1px solid #ffffff; /* 枠線の色を白に変更 */
    margin: 0;
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 10px; /* 角丸を追加 */
    box-shadow: 0px 0px 7px rgba(0, 0, 0, 0.1); /* 影を追加 */
}

/* ▼▼▼ canvas-item の基本スタイル ▼▼▼ */
.canvas-item {
    box-sizing: border-box;
    /* デフォルト(狭い画面)で2列になるように設定 */
    flex-basis: calc(50% - 5px); /* gap 10px の半分を引く */
    max-width: calc(50% - 5px);
    margin-bottom: 10px; /* 下の行との隙間 */
    position: relative; /* 必要に応じて relative を維持 */
    display: flex; /* 中の canvas 配置用 */
    justify-content: center;
    align-items: center;
}
/* ▲▲▲ canvas-item の基本スタイル ▲▲▲ */

/* ================================== */
/* === コントロールUIスタイル === */
/* ================================== */
/* ... (controls, single-line-sliders, slider-subgroup basic styles) ... */
.controls { display: flex; flex-direction: column; align-items: stretch; gap: 15px; width: 90%; max-width: 700px; margin: 20px auto; padding: 0; border: none; background-color: transparent; box-shadow: none; }
.control-group.single-line-sliders { display: flex; flex-wrap: nowrap; align-items: center; justify-content: center; gap: 15px; background-color: #f9f9f9; padding: 15px; border: 1px solid #e0e0e0; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); } /* Base */
.slider-subgroup { display: flex; flex-direction: row; align-items: center; gap: 8px; flex-grow: 1; flex-basis: 0; min-width: 0; } /* Base */
.slider-subgroup label { font-size: 0.9em; color: #555; white-space: nowrap; margin-right: auto; flex-shrink: 0;} /* Base, added shrink */
.slider-subgroup .slider-value { font-size: 0.9em; font-weight: bold; color: #333; min-width: 40px; text-align: right; white-space: nowrap; margin-left: 5px; flex-shrink: 0;} /* Base, added shrink */
.slider-subgroup input[type="range"] { order: 3; width: 100%; max-width: 150px; height: 10px; margin: 0; appearance: none; -webkit-appearance: none; background: #e9e9e9; border-radius: 5px; outline: none; cursor: pointer; } /* Base */
.slider-subgroup input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; background: #169eae; border-radius: 50%; cursor: pointer; border: none; box-shadow: 0 0 2px rgba(0, 0, 0, 0.3); }
.slider-subgroup input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; background: #169eae; border-radius: 50%; cursor: pointer; border: none; box-shadow: 0 0 2px rgba(0, 0, 0, 0.3); }
/* ▼▼▼ Action Button Styles ▼▼▼ */
.action-button {
    flex-grow: 1; padding: 10px 15px; font-size: 0.9em; min-width: auto;
    background-color: #169eae; color: #ffffff; border: none; border-radius: 12px;
    font-weight: bold; cursor: pointer; font-family: 'Segoe UI', sans-serif;
    display: inline-flex; align-items: center; justify-content: center; height: auto;
    transition: background-color 0.2s ease, transform 0.1s ease; /* Added transition */
}
.action-button:hover:not(:disabled) { background-color: #1cd4ea; transform: scale(1.03); }
.action-button:disabled { background-color: #aaaaaa !important; cursor: not-allowed; transform: none; }
.action-button.button-drawing:disabled { background-color: #cccccc !important; }
.action-button:disabled:hover { background-color: #aaaaaa !important; transform: none !important; }
.action-button.button-drawing:disabled:hover { background-color: #cccccc !important; transform: none !important; }

/* ▼▼▼ Icon Styles ▼▼▼ */
.button-icon {
    height: 1.2em; /* Adjust size relative to font */
    width: auto;
    margin-right: 6px; /* Space between icon and text */
    vertical-align: middle; /* Align vertically */
}
/* ▲▲▲ Icon Styles ▲▲▲ */
/* ▼▼▼ Icon Styles ▼▼▼ */
.button-icon {
    height: 1.2em; /* Adjust size relative to font */
    width: auto;
    margin-right: 6px; /* Space between icon and text */
    vertical-align: middle; /* Align vertically */
}
/* ▲▲▲ Icon Styles ▲▲▲ */

/* ▲▲▲ Action Button Styles ▲▲▲ */


/* ================================== */
/* === メディアクエリ (画面幅での調整) === */
/* ================================== */

/* ------------------------------------ */
/* 中間サイズ以上 (601px~) - 2段レイアウト */
/* ------------------------------------ */
@media (min-width: 601px) {
    .canvas-container {
        justify-content: center; /* 広い画面では中央揃え */
        gap: 15px;
        padding: 0 10px;
        width: auto;
        max-width: none;
    }
    /* ▼▼▼ canvas-item のスタイル - 中間画面以上 (4列表示) ▼▼▼ */
    .canvas-item {
        flex-basis: calc(25% - 12px); /* 隙間 15px を考慮 */
        max-width: calc(25% - 12px);
        margin-bottom: 15px;
    }
    /* ▲▲▲ canvas-item のスタイル - 中間画面以上 ▲▲▲ */

    .controls { align-items: center; }

    /* ▼▼▼ コントロールグループ: 縦積み設定 ▼▼▼ */
    .control-group.single-line-sliders {
        flex-direction: column; /* 縦積みに変更 */
        align-items: stretch; /* 幅を親に合わせる */
        width: auto;
        max-width: 500px; /* 最大幅を調整 */
        padding: 15px; /* パディング調整 */
        gap: 15px; /* 縦方向のgap */
    }
    /* ▲▲▲ コントロールグループ: 縦積み設定 ▲▲▲ */

    /* ▼▼▼ スライダーサブグループ: 内部は横並び、grow/basis削除 ▼▼▼ */
    .slider-subgroup {
        display: flex; /* 内部は横並び */
        flex-direction: row;
        align-items: center;
        gap: 15px; /* 内部のgap */
        flex-grow: 0; /* Grow削除 */
        flex-basis: auto; /* Basis削除 */
        min-width: auto; /* min-width削除 */
    }
     /* ▲▲▲ スライダーサブグループ: 内部は横並び、grow/basis削除 ▲▲▲ */

    /* ▼▼▼ ラベル: autoマージン削除 ▼▼▼ */
    .slider-subgroup label {
        font-size: 1em;
        margin-right: 0; /* autoマージン削除 */
        flex-shrink: 0; /* 縮まないように */
    }
    /* ▲▲▲ ラベル: autoマージン削除 ▲▲▲ */

    /* ▼▼▼ 値: 左マージン削除、最小幅指定 ▼▼▼ */
    .slider-subgroup .slider-value {
        font-size: 1em;
        min-width: 50px; /* 最小幅 */
        text-align: right;
        margin-left: 0; /* 左マージン削除 */
        flex-shrink: 0; /* 縮まないように */
    }
    /* ▲▲▲ 値: 左マージン削除、最小幅指定 ▲▲▲ */

    /* ▼▼▼ スライダー: 残りのスペースを埋める ▼▼▼ */
    .slider-subgroup input[type="range"] {
        height: 16px;
        max-width: none; /* max-width削除 (flex-growで制御) */
        width: auto; /* width リセット */
        flex-grow: 1; /* 残りのスペースを埋める */
    }
     /* ▲▲▲ スライダー: 残りのスペースを埋める ▲▲▲ */

    .slider-subgroup input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; border: 2px solid #fff; }
    .slider-subgroup input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; border: 2px solid #fff; }
}

/* ------------------------------------ */
/* さらに広い画面 (1200px~) */
/* ------------------------------------ */
@media (min-width: 1200px) {
     .canvas-container { gap: 20px; }
     /* ▼▼▼ canvas-item のスタイル - 大画面 (最大幅指定) ▼▼▼ */
     .canvas-item {
         flex-basis: 275px;
         max-width: 275px;
         margin-bottom: 0;
     }
    /* ▲▲▲ canvas-item のスタイル - 大画面 ▲▲▲ */

     /* 1200px以上でもコントロールは縦2段のままにする */
     .control-group.single-line-sliders {
         max-width: 600px; /* 必要ならさらに広げる */
     }
}

/* ------------------------------------ */
/* 特に小さい画面 (500px 以下) の再調整 */
/* ------------------------------------ */
@media (max-width: 500px) {
    #character-selector { font-size: 1em; gap: 8px;}
    .action-button { padding: 8px 12px; font-size: 0.8em; }
    .controls { width: 95%; }

    /* ▼▼▼ Canvasコンテナとアイテムの調整 ▼▼▼ */
    .canvas-container {
        padding: 0 2px;
        gap: 5px; /* 隙間を詰める */
    }
    .canvas-item {
        flex-basis: calc(50% - 3px); /* 隙間 5px を考慮 */
        max-width: calc(50% - 3px);
        margin-bottom: 5px;
    }
    /* ▲▲▲ Canvasコンテナとアイテムの調整 ▲▲▲ */

    /* ▼▼▼ 500px以下も縦積み ▼▼▼ */
    .control-group.single-line-sliders {
        flex-direction: column; /* 縦積み */
        align-items: stretch;
        gap: 15px;
        padding: 10px;
        max-width: none; /* 最大幅制限なし */
    }
    .slider-subgroup {
        display: flex;
        flex-direction: row; /* ラベル・値・スライダーは横 */
        flex-wrap: wrap; /* 必要なら折り返し */
        align-items: center;
        gap: 5px 10px; /* 縦横のgap */
        flex-grow: 0; /* Growなし */
        flex-basis: auto; /* Basisなし */
        justify-content: space-between; /* 必要なら調整 */
    }
    .slider-subgroup label {
        margin-right: 0;
        order: 1;
        font-size: 0.9em;
        flex-shrink: 0;
     }
    .slider-subgroup .slider-value {
        order: 2;
        font-size: 0.9em;
        min-width: 40px;
        margin-left: 0;
        flex-shrink: 0;
    }
    .slider-subgroup input[type="range"] {
        order: 3;
        /* flex-grow: 1; */ /* 削除して wrap に任せる */
        width: 100%; /* 必要なら幅100%で改行 */
        max-width: none;
        min-width: 120px; /* 最小幅は維持 */
        flex-basis: 100%; /* 必要なら幅100%で改行 */
        margin-top: 5px; /* 上にスペース */
        height: 10px; /* 高さを戻す */
    }
     .slider-subgroup input[type="range"]::-webkit-slider-thumb { width: 20px; height: 20px; border: none; }
     .slider-subgroup input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border: none; }
    /* ▲▲▲ 500px以下のスタイル調整 ▲▲▲ */
}