:root {
    /* JavaScriptで設定されるビューポートの高さ */
    --vh: 1vh;
}

body {
    margin: 0;
    padding: 0;
    font-family: sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh; /* fallback for browsers that don't support Custom Properties */
    min-height: calc(var(--vh, 1vh) * 100); /* Use --vh for accurate viewport height */
    /* ★修正: 背景画像の設定 */
    background-image: url('images/background.jpg');
    background-size: cover; /* 縦幅に合わせてアスペクト比固定、見切れOK */
    background-position: center center;
    background-repeat: no-repeat;
    background-color: #ffffff; /* 画像がない場合のフォールバック */
    overflow: hidden; /* スクロール防止 */

    /* 画面の向きを縦向きに固定 (一部ブラウザ/OSに依存) */
    /* iOSではユーザーの回転操作を完全に無効化できない場合があります */
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
    -webkit-transform-origin: 50% 50%;
    -moz-transform-origin: 50% 50%;
    -ms-transform-origin: 50% 50%;
    -o-transform-origin: 50% 50%;
    transform-origin: 50% 50%;
    width: 100vw;
    height: calc(var(--vh, 1vh) * 100); /* Use --vh for accurate viewport height */
    max-width: 100vw;
    max-height: calc(var(--vh, 1vh) * 100); /* Use --vh for accurate viewport height */
}

/* 画面が横向きになった場合の対処（保険的な対応、今回は縦向き固定を優先） */
@media screen and (orientation: landscape) {
    /* 縦向き固定を優先するため、特別な処理は行わない */
    /* 必要であれば、横向き時の警告などを表示するCSSを追加 */
}

/* ★追加: 撮影時のブラックアウト用アニメーション */
body.flash {
    animation: flash-animation 0.1s ease-out;
}

@keyframes flash-animation {
    0% { background-color: rgba(0, 0, 0, 0); }
    50% { background-color: rgba(0, 0, 0, 1); }
    100% { background-color: rgba(0, 0, 0, 0); }
}

#app {
    width: 100vw;
    height: calc(var(--vh, 1vh) * 100); /* Use --vh for accurate viewport height */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    box-sizing: border-box;
    overflow: hidden; /* アプリ全体のスクロール防止 */
}

/* 画面共通のスタイルとアニメーション */
.screen {
    width: 100%;
    height: calc(var(--vh, 1vh) * 100);
    position: absolute; /* 各画面を重ねる */
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out; /* フェードアニメーション */
    opacity: 1;
    visibility: visible;
    /* ★修正: 画面の背景を透明にするか、または半透明にする */
    background-color: rgba(255, 255, 255, 0); /* 各画面の背景を透明に */
}

.screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none; /* クリックイベントを無効化 */
}


/* キャラクター選択画面 */
#character-selection-screen {
    text-align: center;
    padding: 20px;
    /* background-color: #e0ffff; この背景色はbodyで設定したため不要 */
    overflow-y: auto; /* コンテンツがはみ出た場合にスクロール */
    justify-content: flex-start; /* コンテンツを上部に寄せる */
    padding-top: calc(var(--vh, 1vh) * 5); /* 上部に余白を追加 */
}

/* ★修正: アプリケーションタイトル */
.app-title {
    font-size: 2.2em; /* 大きめのフォントサイズ */
    color: #333; /* 暗めの色 */
    margin-bottom: 5px; /* ★修正: 下のメッセージとの隙間を調整 */
    font-weight: bold; /* ★修正: 太字に */
    text-shadow: 
       2px  2px 1px #ffffff,
      -2px  2px 1px #ffffff,
       2px -2px 1px #ffffff,
      -2px -2px 1px #ffffff,
       2px  0px 1px #ffffff,
       0px  2px 1px #ffffff,
      -2px  0px 1px #ffffff,
       0px -2px 1px #ffffff;
}

/* ★追加: キャラクター選択の指示文 (pタグ用) */
.character-selection-prompt {
    font-size: 1.5em; /* 元のh1のサイズを維持 */
    color: #333; /* テキスト色を調整 */
    margin-top: 0; /* app-titleとの隙間を調整 */
    margin-bottom: 20px;
    text-shadow: 
       2px  2px 1px #ffffff,
      -2px  2px 1px #ffffff,
       2px -2px 1px #ffffff,
      -2px -2px 1px #ffffff,
       2px  0px 1px #ffffff,
       0px  2px 1px #ffffff,
      -2px  0px 1px #ffffff,
       0px -2px 1px #ffffff;
}


/* カメラアクセス注意書き */
.camera-access-note {
    font-size: 0.9em;
    color: #555;
    margin-top: -10px; /* 必要に応じて調整 */
    margin-bottom: 20px;
    text-shadow: 
       2px  2px 1px #ffffff,
      -2px  2px 1px #ffffff,
       2px -2px 1px #ffffff,
      -2px -2px 1px #ffffff,
       2px  0px 1px #ffffff,
       0px  2px 1px #ffffff,
      -2px  0px 1px #ffffff,
       0px -2px 1px #ffffff; 
}

/* ★追加: 最新OSへのアップデートを促す注意書き */
.os-update-note {
    font-size: 0.8em;
    color: #555;
    text-align: center;
    margin-top: 20px;
    margin-bottom: 20px;
    text-shadow: 
       2px  2px 1px #ffffff,
      -2px  2px 1px #ffffff,
       2px -2px 1px #ffffff,
      -2px -2px 1px #ffffff,
       2px  0px 1px #ffffff,
       0px  2px 1px #ffffff,
      -2px  0px 1px #ffffff,
       0px -2px 1px #ffffff; 
}

.character-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    align-items: center; /* ボタンを中央寄せ */
}

.character-options button {
    padding: 15px 30px;
    font-size: 1.2em;
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    background-color: #ffffff;
    color: #333;
    transition: all 0.2s;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    width: 80%; /* 幅を調整 */
    max-width: 300px;
}

.character-options button:hover {
    border-color: #007bff;
    background-color: #e6f2ff;
}

.character-options button.selected {
    border-color: #007bff;
    background-color: #007bff;
    color: white;
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.5);
}

/* キャラクター選択時のアニメーション */
.character-options button.character-selected-animate {
    animation: pulse 0.3s ease-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}


/* カメラ画面 */
#camera-screen {
    /* background-color: #e0ffff; この背景色はbodyで設定したため不要 */
    position: relative; /* ローディングスピナーのために */
    display: flex; /* Flexboxコンテナとして設定 */
    flex-direction: column; /* 子要素を縦に並べる */
    align-items: center; /* 子要素を水平方向に中央寄せ */
    justify-content: space-between; /* camera-viewportとcontrolsを上下に配置 */
}

/* 修正: カメラプレビューとオーバーレイを囲むコンテナのスタイル */
#camera-viewport {
    position: relative;
    width: 100%; /* 親要素の幅いっぱいに広げる */
    /* アスペクト比4:3 (height / width = 4 / 3) を維持 */
    /* padding-bottomハックを利用してアスペクト比を固定 */
    padding-bottom: calc(100% * (4 / 3)); /* 4/3 = 1.333... */
    overflow: hidden; /* コンテナからはみ出る内容を非表示 */
    flex-grow: 1; /* 残りのスペースを埋める */
    display: flex; /* 子要素を中央に配置するためにFlexboxを使用 */
    justify-content: center;
    align-items: center;
    background-color: black; /* コンテナの背景色 */
}

#camera-preview,
#overlay-image {
    position: absolute; /* camera-viewport内で絶対配置 */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain; /* アスペクト比を維持し、コンテナに収まるように */
    z-index: 1;
}

#overlay-image {
    opacity: 0.6; /* オーバーレイ画像の透明度 */
    pointer-events: none; /* クリックイベントを無効化 */
    z-index: 2;
}

.camera-controls {
    position: absolute; /* camera-viewportの下に配置される */
    bottom: 0;
	z-index: 3;
    width: 100%;
    padding: 15px 10px; /* パディングを調整 */
    box-sizing: border-box;
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, rgba(0,0,0,0) 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px; /* コントロール間の隙間を調整 */
    padding-bottom: env(safe-area-inset-bottom, 15px); /* セーフエリアを考慮 */
    flex-shrink: 0; /* 縮小させない */
}

.zoom-controls {
    width: 90%; /* 幅を広げる */
    max-width: 450px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 5px; /* ボタンとの間にスペース */
    background-color: rgba(0, 0, 0, 0.4); /* 背景を追加して視認性向上 */
    border-radius: 10px;
    padding: 8px 15px; /* パディングを追加 */
}

#zoom-slider {
    width: 100%;
    -webkit-appearance: none;
    height: 10px; /* 少し太く */
    border-radius: 5px;
    background: linear-gradient(to right, #007bff, #5cb85c); /* グラデーションで視認性向上 */
    outline: none;
    opacity: 0.9; /* デフォルトの不透明度を上げる */
    transition: opacity .2s;
}

#zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 28px; /* 少し大きく */
    height: 28px; /* 少し大きく */
    border-radius: 50%;
    background: #ffffff; /* 白に変更 */
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0,0,0,0.5); /* 影を強調 */
    border: 2px solid #007bff; /* ボーダーを追加 */
}

#zoom-slider:hover {
    opacity: 1;
}

.bottom-buttons {
    display: flex;
    /* 修正: ボタンの配置を調整 */
    justify-content: space-between; /* 両端に寄せて、中央のボタンにスペースを確保 */
    align-items: center;
    flex-wrap: nowrap;
    gap: 10px; /* 必要に応じて調整 */
    width: 100%;
    padding: 0 5px;
    box-sizing: border-box;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0;
}

/* 修正: ボタンのスタイルを画像に合わせる */
#camera-screen .camera-controls button,
#photo-confirm-screen .controls button {
    background-color: transparent; /* 背景色を透明に */
    border: none; /* ボーダーをなくす */
    box-shadow: none; /* 影をなくす */
    padding: 0; /* パディングをなくす */
    cursor: pointer;
    display: flex; /* 画像を中央配置するため */
    justify-content: center;
    align-items: center;
    min-width: unset; /* 最小幅をリセット */
    flex-shrink: 0;
    /* ★追加: 押下時のフィードバック用 transition */
    transition: transform 0.1s ease-out;
}

/* ★追加: ボタン押下時のフィードバック */
#camera-screen .camera-controls button:active,
#photo-confirm-screen .controls button:active {
    transform: scale(0.9);
}


/* 撮影画面のボタン画像 */
#camera-screen .camera-controls button img {
    width: 60px; /* ボタン画像のサイズ調整 */
    height: 60px;
    object-fit: contain;
}

/* ★修正: 撮影ボタンのみ1.2倍に拡大 */
#camera-screen .camera-controls button#capture-button img {
    width: 72px; /* 60px * 1.2 = 72px */
    height: 72px; /* 60px * 1.2 = 72px */
}


/* 撮影画面の個別のボタン配置（orderプロパティはCSSで維持） */
#camera-screen .camera-controls button#capture-button {
    order: 2; /* 2番目に表示されるようにする */
}

#camera-screen .camera-controls button#toggle-camera-button {
    order: 1; /* 1番目に表示されるようにする */
}

#camera-screen .camera-controls button#change-character-button {
    order: 3; /* 3番目に表示されるようにする */
}

/* ローディングスピナー */
#loading-spinner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    color: white;
    font-size: 1.2em;
    transition: opacity 0.3s ease-in-out;
}

#loading-spinner.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #007bff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* 撮影確認画面 */
#photo-confirm-screen {
    /* background-color: #e0ffff; この背景色はbodyで設定したため不要 */
    justify-content: flex-start; /* コンテンツを上部に寄せる */
    /* ★修正: 上部の余白を調整 */
}

/* ★修正: 撮影確認画面のメッセージ */
.confirm-message {
    font-size: 1.1em;
    color: #333;
    text-align: center;
    font-weight: bold;
    text-shadow: 
       2px  2px 1px #ffffff,
      -2px  2px 1px #ffffff,
       2px -2px 1px #ffffff,
      -2px -2px 1px #ffffff,
       2px  0px 1px #ffffff,
       0px  2px 1px #ffffff,
      -2px  0px 1px #ffffff,
       0px -2px 1px #ffffff;
}

#captured-photo {
	position: absolute;
    width: 100%; /* ブラウザの横幅と合わせる */
    max-width: 100%;
    display: block;
    object-fit: contain;
}

#photo-confirm-screen .controls {
    display: flex;
    flex-wrap: nowrap; /* ボタンを横一列に強制 */
    gap: 10px; /* 隙間を調整 */
    /* ★修正: ボタンを等間隔に配置 */
    justify-content: space-around; /* ブラウザに対する等間隔 */
    width: 100%;
    max-width: unset;
    padding: 0 5px; /* 左右パディングを調整 */
    box-sizing: border-box;
    position: absolute;
    bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom, 20px); /* セーフエリアを考慮 */
}

/* 撮影確認画面のボタン画像 */
#photo-confirm-screen .controls button img {
    width: 60px; /* ボタン画像のサイズ調整 */
    height: 60px;
    object-fit: contain;
}