    :root {
        --bg-color: #02040a;
        --accent-blue: #00f2ff;
        --accent-green: #39ff14;
        --panel-bg: rgba(255, 255, 255, 0.08);
        --text-color: #ffffff;
        --radius: 18px;
    }

/* --- 1. 一番下の土台（最背面）を真っ黒に固定 --- */
html {
    background-color: #000 !important;
}

body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    color: #ffffff;
    
    /* --- 2. 土台の色を黒に（画像が切れた場所はこの色になります） --- */
    background-color: #000 !important; 
    
    /* 画像の設定（JSから流し込まれます） */
    background-repeat: no-repeat;
    background-position: center; /* 中央に置くことで、上下左右の余った場所が黒くなる */
    background-size: contain;    /* 画面内に収まるように配置（隙間は黒になる） */
    background-attachment: fixed;
}

/* --- 3. コンテンツレイヤー：背景を透かして画像を見せる --- */
#app, #remote-view, #control-content, #visual-content {
    background: transparent !important;
}

/* 既存の body を以下のように書き換え、または追記 */
body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden; /* 全体のスクロールを禁止 */
    /* 背景設定はそのまま */
    background-image: url('background/back.jpg');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

/* リモート表示全体を透明にして、bodyの背景が見えるようにする */
#remote-view, 
.content-area, 
#control-content, 
#visual-content {
    background: transparent !important;
}

/* 画面が暗すぎて背景が見えない場合は、ほんのり黒を乗せる程度にする */
body::before {
    content: "";
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4); /* 0.4を調節して暗さを変えられます */
    z-index: -1;
}

    /* アプリ全体の高さをスマホのブラウザ枠に合わせる */
    #app {
    height: 100dvh; 
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

    .hidden { display: none !important; }

    /* --- 設定画面：スクロールを有効に --- */
    #setup-view {
        flex: 1; 
        display: flex; 
        flex-direction: column; 
        padding: 20px;
        box-sizing: border-box; 
        overflow-y: auto; /* 縦スクロールを許可 */
        -webkit-overflow-scrolling: touch; /* iOSのスクロールを滑らかに */
    }

    /* 以下、ボタン等のスタイルはそのまま維持 */
    .btn-edit-row {
        display: flex; align-items: center;
        background: rgba(255,255,255,0.05);
        margin-bottom: 8px; padding: 10px;
        border-radius: 10px; gap: 10px;
    }
    .btn-num { color: var(--accent-blue); font-weight: bold; width: 25px; text-align: center;}
    
    .btn-preview-mini {
        width: 40px; height: 40px; border-radius: 8px;
        background-size: cover; background-position: center;
        background-color: #000; border: 1px solid #333;
    }

    .btn-info { flex: 1; font-size: 0.9rem; }
    .btn-info small { color: #888; display: block; }
    
    .edit-action-btn {
        background: #333; color: white; border: 1px solid #555;
        padding: 5px 10px; border-radius: 5px; font-size: 12px;
        cursor: pointer;
    }
    .delete-btn { color: #ff4d4d; border-color: #ff4d4d; }

    /* --- モーダル：中身をスクロール可能に --- */
    #edit-modal {
        position: fixed; top:0; left:0; width:100%; height:100%;
        background: rgba(0,0,0,0.85); z-index: 1000;
        display: flex; align-items: flex-start; /* 上揃えに変更 */
        justify-content: center;
        overflow-y: auto; /* モーダルが長い場合にスクロール */
        padding: 20px 0;
    }
    .modal-content {
        background: #1a1c23; padding: 25px; border-radius: var(--radius);
        width: 85%; max-width: 400px; border: 1px solid var(--accent-blue);
        margin: auto; /* 中央配置 */
    }
    .modal-content label { display: block; margin-top: 15px; font-weight: bold; color: #ccc;}
    .modal-content input[type="text"],
    .modal-content select {
        width: 100%; padding: 12px; margin: 5px 0 10px 0;
        background: #000; border: 1px solid #444; color: white; border-radius: 8px;
        box-sizing: border-box;
    }

    #icon-preview-container {
    width: 100px; height: 100px; border: 2px dashed #444;
    border-radius: 10px; margin: 10px auto;
    display: flex; align-items: center; justify-content: center;
    /* ★ここを追加：画像が枠に収まるようにする */
    background-color: #000;
    background-size: contain; /* coverより全体が見やすい */
    background-repeat: no-repeat;
    background-position: center;
    overflow: hidden; color: #666; font-size: 0.8rem;
}

/* --- リモート画面：ここが「黒い幕」の正体です --- */
#remote-view {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important; 
    overflow: hidden !important;
    display: flex;
    flex-direction: column;

    /* ★ここを調整！ 0.85(濃い) から 0.2〜0.4(薄い) に変更します */
    /* 完全に透明にしたい場合は transparent にしてください */
    background: rgba(0, 0, 0, 0.3) !important; 
}
    .tab-bar { display: flex; background: rgba(0,0,0,0.9); border-bottom: 1px solid #222; flex-shrink: 0; z-index: 10;}
    .tab-btn { flex: 1; padding: 20px; background: none; border: none; color: #666; font-weight: bold; font-size: 1rem; cursor: pointer;}
    .tab-btn.active { color: var(--accent-blue); border-bottom: 3px solid var(--accent-blue); }
    
    /* ボタンが表示されるエリアを確実にスクロール可能にする */
    .content-area {
    width: 100%;
    height: calc(100vh - 120px);
    overflow-y: auto; /* ボタンが多い時にスクロール可能にする */
    -webkit-overflow-scrolling: touch;
}
    .grid-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 20px; max-width: 1200px; margin: 0 auto; }
    
    .deck-btn {
    /* --- サイズと形状 --- */
    width: 100%;                /* グリッドの1マスいっぱいに広がる */
    aspect-ratio: 1 / 1;        /* 常に正方形を維持 */
    border-radius: var(--radius);
    
    /* --- レイアウト --- */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;         /* ラベル(span)の配置基準 */
    overflow: hidden;
    
    /* --- 見た目 --- */
    background-color: var(--panel-bg);
    border: 2px solid var(--accent-blue);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5), 0 0 10px rgba(0, 242, 255, 0.2);
    
    /* --- 背景画像の設定 --- */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    
    /* --- テキスト設定 --- */
    color: white;
    font-size: 0.9rem;          /* JSで動的に変わるまでの初期値 */
    font-weight: 500;
    text-align: center;
    
    /* --- 操作感 (スマホ最適化) --- */
    transition: all 0.1s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    cursor: pointer;
}

/* 画像がある場合のラベル（下部に固定） */
    .deck-btn.has-icon span {
    position: absolute;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 0;
    font-size: 0.7rem; /* アイコン時は少し小さく */
}

    /* 押した瞬間の色を派手にする */
    .deck-btn:active {
    background-color: var(--accent-blue) !important;
    color: #000 !important;
    transform: scale(0.92) !important;
    box-shadow: 0 0 20px var(--accent-blue) !important;
    filter: brightness(1.5);
    transition: 0s; /* 反応を速くするためにアクティブ時は0秒に */
}

/* リモート画面のメインエリア（コントロール） */
#control-content {
    display: flex;
    /* ★ 縦並び(column)から、横並びの折り返し(row wrap)に変更 */
    flex-direction: row;
    flex-wrap: wrap; 
    
    /* ボタンを中央寄せにする */
    justify-content: center; 
    align-content: flex-start;
    
    /* 余白の設定 */
    padding: 20px 10px !important; 
    gap: 15px; /* ボタン同士の隙間 */
    
    /* 幅の設定 */
    width: 100%;
    max-width: 1000px; /* 広がりすぎ防止 */
    margin: 0 auto;
    
    /* はみ出した時にスクロールできるようにする */
    overflow-y: auto;
    height: calc(100vh - 120px); /* タブバーの分を引いた高さ */
    box-sizing: border-box;
}

/* グループコンテナ：横幅に合わせてボタンを自動配置 */
.group-container {
    display: grid;
    /* ↓ 変数を使って、ボタンの最小幅をグリッドに教える */
    grid-template-columns: repeat(auto-fill, minmax(var(--min-btn-size, 80px), 1fr));
    gap: 12px;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
}

/* 上部のグループ切り替えタブ（ALL, STREAM等） */
.group-tabs {
    display: flex;
    gap: 4px;            /* ボタン同士の間隔を狭く */
    padding: 2px 5px;    /* 上下のパディングを最小限に */
    margin: 0;           /* マージンをゼロに */
    overflow-x: auto;
    white-space: nowrap;
    background: rgba(0,0,0,0.5);
    position: sticky;
    top: 0;
    z-index: 100;
}

.group-tab {
    padding: 4px 10px;   /* タブ自体の上下も詰める */
    font-size: 0.75rem;
    border-radius: 4px;  /* 少し角を立てると詰めやすい */
    background: #333;
    color: #888;
    border: 1px solid #444;
}

/* ボタン内の文字配置を中央に完全固定 */
.deck-btn span {
    display: block;
    width: 100%;
    text-align: center;
    line-height: 1.2;
    word-break: break-all;
    padding: 0 4px;
    box-sizing: border-box;
    z-index: 2; /* 画像より前面に */
}

.group-tab.active {
    background: var(--accent-blue);
    color: #000;
    border-color: var(--accent-blue);
}

/* グループの見出しも少し大きくして読みやすく */
.group-header {
    width: 100%;
    text-align: left;
    font-size: 1.2rem;
    font-weight: bold;
    padding: 10px 0;
    border-bottom: 2px solid var(--accent-blue);
    margin-bottom: 15px;
    color: var(--accent-blue);
    letter-spacing: 2px; /* 基本は広め */
}
    #launch-btn { background: linear-gradient(45deg, var(--accent-blue), var(--accent-green)); color: black; border: none; padding: 25px; font-weight: bold; font-size: 1.2rem; border-radius: var(--radius); width: 100%; margin-top: 20px; cursor: pointer;}
    .back-to-setup { position: fixed; top: 15px; right: 15px; z-index: 100; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: white; padding: 8px 15px; border-radius: 8px; font-size: 12px; cursor: pointer;}
    .std-btn { padding: 10px; border: none; border-radius: 8px; cursor: pointer; font-weight: bold;}

/* ダッシュボード全体（親要素）の設定 */
#main-dashboard { /* もし親のIDが違えば書き換えてください */
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    height: 100vh;
}

/* カレンダーの枠のデザイン */
#calendar-container {
    width: 40% !important;
    height: 50% !important;
    overflow: hidden !important;
    background: transparent !important;
    border: 1px solid rgba(0, 242, 255, 0.3); /* ネオンブルーの枠 */
    border-radius: 15px;
}

#calendar-container iframe {
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    
    /* 【魔法の一行】白背景を黒に反転させ、その黒を透明化する */
    filter: invert(90%) hue-rotate(180deg) brightness(0.8) contrast(0.8) !important;    
    /* 2. 不透明度を 0.5〜0.7 くらいに設定（数値が小さいほど透けます） */
    opacity: 0.6;
    mix-blend-mode: screen !important; 
}

/* ラジオボタンで切り替わる位置の定義 */
.pos-left   { order: 1; }
.pos-center { order: 2; }
.pos-right  { order: 3; }

/* 時計の箱の設定をリセットしてFlexboxに従わせる */
/* アナログ時計のキャンバスを箱の中に閉じ込める */
#analog-clock-canvas {
    position: relative !important; /* absolute（絶対配置）を解除 */
    top: auto !important;
    left: auto !important;
    transform: none !important;
    margin-bottom: 40px; /* デジタル時計との隙間 */
}

#clock-container {
    /* 以前の absolute や transform を強制解除 */
    position: relative !important; 
    top: auto !important;
    left: auto !important;
    transform: none !important;
    
    /* 横幅を確保して中央寄せ */
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    width: 45%; /* カレンダーとのバランス */
    z-index: 10;
    margin: 0 !important;
}

/* Canvas：親要素の枠内にぴったり合わせる */
#vu-canvas {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 2;
    pointer-events: none;
    /* 縦伸び防止：アスペクト比を維持させない（JS側で制御するため） */
    object-fit: none; 
}

/* カレンダーと時計を横に並べるための親要素 */
#vu-meter-container {
    flex: 1; /* 残りの画面スペースをすべて使う */
    width: 100%;
    height: 100%;
    background: transparent !important;
    position: relative;
    z-index: 10 !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 以前の「真ん中固定」の設定を解除する */
#clock-container, #calendar-container {
    position: relative !important;
    top: auto !important;
    left: auto !important;
    transform: none !important;
    margin: 0 !important;
}

/* カレンダーの背景を黒く反転させ、その黒を透明化する */
#calendar-container iframe {
    filter: invert(90%) hue-rotate(180deg) brightness(1.2) contrast(0.8) !important;
    mix-blend-mode: screen !important;
}

/* ビジュアルモードのエリア設定 */
#visual-content {
    flex: 1;
    height: calc(100dvh - 120px); /* タブバー等の分を引く */
    padding: 0;
    margin: 0;
    overflow: hidden;
}

/* --- カレンダーを透明化してネオン風にする魔法 --- */
#box5 {
    /* ...既存の設定... */
    cursor: default; /* 中身がハミ出してもスクロールを出さない */
    -index: 1; /* 通常時は低め */
}
/* 1. コンテナ自体の背景を透明にする */
#embedded-calendar-container {
    position: relative;
    z-index: 10; /* 中身のコンテナをBox5内で最前面に */
    pointer-events: auto !important; /* クリックを強制有効 */
    background-color: rgba(0, 0, 0, 0.2) !important;
}

#embedded-calendar-container iframe {
    /* 前回のフィルタは維持 */
    filter: invert(90%) hue-rotate(180deg) brightness(1.1) contrast(0.9) !important;
    mix-blend-mode: screen !important;
    
    /* 重要：iframe自体がクリックを奪われないようにする */
    position: relative;
    z-index: 20;
    pointer-events: auto !important;
}

/* カレンダーコンテナとiframeのクリックを強制的に有効化 */
#calendar-container, 
#calendar-container iframe {
    pointer-events: auto !important;
}

/* 逆に、背景のキャンバスやビジュアルレイヤーが邪魔しないようにする */
#vu-canvas, #visual-bg-layer {
    pointer-events: none !important;
}


/* --- スマホ・レスポンシブ調整 --- */

/* --- スマホ・レスポンシブ最終調整（重なり・切れ防止） --- */
@media screen and (max-width: 480px) and (orientation: portrait) {
    /* 1. 親コンテナ：高さを100%に固定し、中身を均等に配置 */
    #vu-meter-container {
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important; /* 中央寄せ */
        align-items: center !important;
        height: calc(100dvh - 80px) !important; /* タブバー等を除いた有効な高さ */
        padding: 5px 0 !important;
        gap: 10px !important; /* 要素間の最低限の隙間 */
        overflow: hidden !important;
    }

    /* 2. 時計コンテナ：高さの最大値を制限 */
    #clock-container {
        flex: 0 1 auto !important; /* コンテンツに合わせて縮小を許可 */
        width: 90% !important;
        max-height: 40% !important; /* 画面の4割以上は絶対に使わない */
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        margin: 0 !important; /* マイナスマージンは全て削除 */
    }

    /* アナログ時計：画面の「高さ」に合わせて小さくなるように設定 */
    #analog-clock-canvas {
        width: 35vh !important;  /* 高さ基準(vh)にすることで、縦の重なりを防ぐ */
        height: 35vh !important;
        max-width: 160px !important; 
        max-height: 160px !important;
        margin: 0 auto !important;
    }

    /* デジタル時計：文字が小さすぎる問題の解消 */
    #digital-clock {
        font-size: 2.8rem !important; /* 視認性を上げるために大きく設定 */
        font-weight: bold !important;
        margin-top: 0px !important;
        line-height: 1.0 !important;
        white-space: nowrap !important;
    }

    /* 3. カレンダーコンテナ：残りのスペースを使い、はみ出しをカット */
    #calendar-container {
        flex: 1 1 auto !important;
        width: 95% !important;
        max-height: 45% !important; /* 画面の半分弱に抑える */
        margin: 0 auto !important;
        overflow: hidden !important;
        border-radius: 12px !important;
        min-height: 0; /* flex内の潰れ防止 */
    }

    #calendar-container iframe {
        width: 100% !important;
        height: 100% !important;
        /* スマホで見やすいよう、iframe内のスケールを調整したい場合はここ */
        transform: scale(0.95);
        transform-origin: top center;
    }
}

/* カレンダー非表示時の調整：時計を中央に寄せる（JS側で非表示にした時用） */
#clock-container[style*="display: none"] + #calendar-container,
#calendar-container[style*="display: none"] + #clock-container {
    flex: 1 !important;
    justify-content: center !important;
}