/* 基本的なリセット */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ★ ダークモード基本設定 */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    line-height: 1.6;
    background-color: #121212; /* 暗い背景 */
    color: #e0e0e0; /* 明るいテキスト */
    min-height: 100vh;
}

/* 全体をラップするコンテナ */
.container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}


/* ★ ヘッダー調整 */
.app-header {
    background-color: #1e1e1e; /* 少し明るい暗色 */
    color: #eee; /* 明るいテキスト */
    padding: 0.8rem 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    border-bottom: 3px solid #333; /* 暗いボーダー */
}

.app-header h1 {
    font-size: 1.4rem;
    margin: 0;
    font-weight: 600;
}

.controls-top {
    display: flex;
    gap: 0.75rem;
}

/* ★ ボタン調整 */
.button {
    padding: 0.4rem 0.9rem;
    background-color: #444; /* 暗めのグレー */
    color: #eee;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    display: inline-block;
    font-size: 0.9rem;
    transition: background-color 0.2s;
}

.button:hover {
    background-color: #555; /* 少し明るく */
}

.app-main {
    flex: 1;
    padding: 1.5rem 0;
    display: grid;
    gap: 1.5rem;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
        "preview"
        "adjustment"
        "selection"
        "info";
}

/* ★ 各セクションの基本的なスタイル調整 */
.image-preview-section,
.controls-adjustment-section,
.lens-selection-section,
.lens-info-section {
    background-color: #1e1e1e; /* 少し明るい暗色 */
    padding: 1.25rem;
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3); /* 影を少し濃く */
    min-width: 0;
    border: 1px solid #333; /* 境界線 */
}

.image-preview-section { grid-area: preview; }
.controls-adjustment-section { grid-area: adjustment; }
.lens-selection-section { grid-area: selection; }
.lens-info-section { grid-area: info; }

/* ★ 見出し調整 */
h2 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: #ccc; /* 明るいグレー */
    border-bottom: 1px solid #444; /* 暗いボーダー */
    padding-bottom: 0.6rem;
}

/* ★ 画像プレビュー調整 */
.image-preview-container {
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: #2d2d2d; /* さらに少し明るい暗色 */
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
    border: 1px solid #444; /* 暗いボーダー */
    border-radius: 4px;
    cursor: default;
}
.image-preview-container:not(.loupe-disabled) {
    cursor: crosshair;
}


#preview-image { /* ★ これはもう使わないが念のため残す */
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    will-change: filter;
}
#preview-canvas { /* ★ Canvas 用のスタイル */
    display: none; /* 初期非表示 */
    max-width: 100%;
    max-height: 100%;
    /* object-fit は Canvas には効かない */
}


#placeholder-text {
    position: absolute;
    color: #aaa; /* 明るいグレー */
    font-size: 0.9rem;
}

/* ルーペのスタイル */
#loupe {
    position: absolute;
    border: 4px solid rgba(200, 200, 200, 0.7); /* ボーダーを明るく */
    border-radius: 50%;
    background-repeat: no-repeat;
    display: none;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5); /* 影を濃く */
    background-origin: content-box;
}

/* ★ ルーペ調整コントロールのスタイル調整 */
.loupe-controls {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #444; /* 暗いボーダー */
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.5rem; /* トグル間のスペースを広げる */
    font-size: 0.9rem;
}

/* ★ トグルラッパー共通スタイル */
.toggle-wrapper, /* 一般的なクラス名に変更 */
.loupe-toggle-wrapper,
.original-image-toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: fit-content;
}


/* ドロワーコンテンツ (デフォルト非表示) */
.loupe-drawer-content {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.8rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    width: 100%; /* ドロワーは幅いっぱいに */
    margin-top: 0.8rem; /* 上のトグルとのスペース */
}

/* ルーペON時にドロワーを開く */
.loupe-controls.open .loupe-drawer-content {
    max-height: 200px;
}


.loupe-controls .control-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.2rem;
}

.loupe-controls label { /* ルーペ内のラベル */
    white-space: nowrap;
    color: #bbb; /* 明るいグレー */
    margin-bottom: 0;
}

/* ★ スライダー調整 */
.loupe-controls input[type="range"] {
    max-width: none;
    cursor: pointer;
    height: 6px;
    background: #444; /* 暗い背景 */
    border-radius: 3px;
    appearance: none;
    outline: none;
}
.loupe-controls input[type=range]::-webkit-slider-thumb {
  appearance: none; width: 16px; height: 16px; background: #bbb; border-radius: 50%; cursor: pointer; /* 明るいつまみ */
}
.loupe-controls input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; background: #bbb; border-radius: 50%; cursor: pointer; border: none; /* 明るいつまみ */
}


.loupe-controls .value-display {
    min-width: auto;
    text-align: left;
    font-family: monospace;
    color: #ccc; /* 明るいグレー */
    margin-top: 0;
}

/* ★ トグルスイッチ共通スタイル */
.switch { position: relative; display: inline-block; width: 40px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #555; transition: .4s; } /* 暗い背景 */
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: #ccc; transition: .4s; } /* 明るいつまみ */
input:checked + .slider { background-color: #0d6efd; } /* ONの色はそのまま */
/* ★ translateX を元に戻す */
input:checked + .slider:before { transform: translateX(20px); background-color: white; } /* ONのつまみ色 */
.slider.round { border-radius: 20px; }
.slider.round:before { border-radius: 50%; }
.toggle-label { min-width: 30px; text-align: left; color: #bbb; font-weight: 500; } /* 明るいグレー */


/* パラメータ調整 */
.adjustment-controls {
    display: grid;
    gap: 0.8rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: nowrap;
}

/* ★ ラベル調整 */
.control-group label {
    min-width: 85px;
    font-size: 0.9rem;
    color: #bbb; /* 明るいグレー */
    text-align: right;
    flex-shrink: 0;
}

/* ★ スライダー・セレクト調整 */
.control-group input[type="range"],
.control-group select {
    flex-grow: 1;
    cursor: pointer;
    min-width: 80px;
    padding: 0.3rem 0.5rem;
    border: 1px solid #555; /* 暗いボーダー */
    border-radius: 4px;
    background-color: #333; /* 暗い背景 */
    color: #eee; /* 明るいテキスト */
    font-size: 0.9rem;
}
.control-group input[type="range"] {
    height: 6px; background: #444; border-radius: 3px; appearance: none; outline: none; padding: 0; /* 暗い背景 */
}
.control-group input[type=range]::-webkit-slider-thumb {
  appearance: none; width: 16px; height: 16px; background: #bbb; border-radius: 50%; cursor: pointer; /* 明るいつまみ */
}
.control-group input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; background: #bbb; border-radius: 50%; cursor: pointer; border: none; /* 明るいつまみ */
}


/* ★ 値表示調整 */
.value-display {
    min-width: 55px;
    text-align: right;
    font-family: monospace;
    font-size: 0.9rem;
    color: #ccc; /* 明るいグレー */
    flex-shrink: 0;
}

/* ★ レンズ選択調整 */
.lens-categories {
    margin-bottom: 1rem;
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.category-button {
    padding: 0.3rem 0.7rem;
    border: 1px solid #555; /* 暗いボーダー */
    background-color: #333; /* 暗い背景 */
    color: #ccc; /* 明るいグレー */
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.category-button:hover {
    background-color: #444;
}
.category-button.active {
    background-color: #0d6efd;
    color: #fff;
    border-color: #0d6efd;
}
.lens-list-container {
    overflow-x: auto;
    overflow-y: hidden;
    width: 100%;
    border: 1px solid #444; /* 暗いボーダー */
    border-radius: 4px;
    background-color: #222; /* 暗い背景 */
    padding: 0.5rem 0;
}
.lens-list {
    display: flex;
    gap: 1rem;
    padding: 0 1rem;
    min-width: max-content;
}
.lens-item {
    border: 2px solid transparent;
    padding: 0.5rem;
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
    max-width: 120px;
    flex-shrink: 0;
}
.lens-item:hover {
    background-color: #333; /* 暗いホバー背景 */
}
.lens-item.selected {
    border-color: #0d6efd;
    background-color: #2a2a4a; /* 暗い選択背景 */
}
.lens-item img {
    max-width: 80px;
    height: auto;
    display: block;
    margin-left: auto;
    margin-right: auto;
    filter: brightness(0.9) contrast(1.1); /* 画像が暗い背景で沈まないように調整 */
}
.lens-item p {
    font-size: 0.8rem;
    color: #bbb; /* 明るいグレー */
    margin: 0;
    line-height: 1.3;
    white-space: normal;
    word-break: break-word;
    margin-top: 0.5rem;
}

/* ★ レンズ情報調整 */
#lens-details {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #444; /* 暗いボーダー */
}
#lens-details h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: #eee; /* 明るいテキスト */
}
#lens-details p {
    font-size: 0.9rem;
    color: #bbb; /* 明るいグレー */
    margin: 0;
}


/* レスポンシブデザイン: 横幅が広い場合 (例: 992px以上) */
@media (min-width: 992px) {
    .app-main {
        grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
        grid-template-rows: auto auto 1fr;
        grid-template-areas:
            "preview adjustment"
            "selection adjustment"
            "info info";
        align-items: start;
    }

    .controls-adjustment-section {
        position: sticky;
        top: 1rem;
        overflow-y: auto;
        max-height: calc(100vh - 2rem);
    }

    .image-preview-container {
         max-height: calc(85vh);
         aspect-ratio: auto;
    }
    #preview-canvas {
        max-height: calc(85vh);
    }
    .loupe-controls {
        gap: 1.5rem;
    }
    .loupe-drawer-content {
        gap: 1.5rem;
        max-height: 100px;
        width: auto;
    }

    .loupe-controls .control-group {
        width: auto;
    }
    .loupe-controls input[type="range"] {
        width: 100px;
    }
     .loupe-controls .value-display {
        text-align: right;
        min-width: 45px;
    }

    .control-group {
        flex-direction: row;
        align-items: center;
        width: auto;
    }
    .control-group input[type="range"], .control-group select {
        width: auto;
        flex-grow: 1;
    }
    .value-display {
        text-align: right;
        min-width: 55px;
    }

}

/* さらに小さい画面用の調整 (オプション) */
@media (max-width: 991px) {
    .control-group label { text-align: left; }
    .value-display { text-align: left; }
    .loupe-controls .value-display { text-align: left; }
}