/* Settings Modal Responsive & Scroll Support */
#settings-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--theme-uiOverlayBg);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    touch-action: auto !important;
}

.settings-modal, .control-select-modal {
    background: var(--theme-uiPanelBg);
    width: 95%;
    height: auto;
    max-width: 500px;
    max-height: 90vh !important; /* 画面高の90%に抑える */
    border: 2px solid var(--theme-uiPanelBorder);
    border-radius: 20px;
    padding: 30px 20px 0px 20px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    touch-action: auto !important;
    position: relative;
}

.settings-modal h2, .control-select-modal h2 {
    color: var(--theme-uiTextMain);
    text-shadow: var(--theme-uiTitleShadow);
    margin: 0 0 10px 0;
    font-family: 'Outfit';
    font-size: 2rem;
    letter-spacing: 2px;
    flex-shrink: 0;
}

.settings-content {
    flex: 1;
    min-height: 0; /* 【超重要】中身が親の高さを超えた場合に強制的に縮ませてスクロールさせる */
    overflow-y: auto !important;
    overflow-x: hidden;
    padding-bottom: 30px;
    touch-action: pan-y !important; /* スマホの縦スクロールをブラウザレベルで強制許可 */
    -webkit-overflow-scrolling: touch;
    padding: 15px 25px 0 25px;
    text-align: left;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch; /* Stretch to fill width */
}

/* Scrollbar Customization */
.settings-content::-webkit-scrollbar {
    width: 6px;
}
.settings-content::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.05);
    border-radius: 10px;
}
.settings-content::-webkit-scrollbar-thumb {
    background: var(--color-accent-primary);
    border-radius: 10px;
}

.settings-item {
    margin-bottom: 20px;
}

.settings-item label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: bold;
    font-family: 'Outfit';
    font-size: 0.95rem;
    width: 100%;
}

/* Version Info Block */
.version-container {
    margin-top: auto !important;
    padding-top: 10px;
    padding-bottom: 20px !important;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    text-align: center;
    font-family: "Outfit";
}
.brand-label {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-text-brand);
    margin-bottom: 2px;
}
.version-label {
    font-size: 11px;
    font-weight: 400;
    color: var(--color-text-version);
    letter-spacing: 1px;
}


/* Theme Lock: Only show if all cleared */
#theme-selection-container {
    display: none;
}
body.all-cleared #theme-selection-container {
    display: block;
  font-family: var(--font-family);
}

/* BGM Gallery Overlay */
#bgm-gallery-overlay {
    background: var(--theme-uiOverlayBg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.gallery-modal {
    background: var(--theme-uiPanelBg);
    width: 90%;
    height: 85%;
    border-radius: 30px;
    border: 3px solid var(--theme-uiPanelBorder);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.gallery-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--theme-uiPanelBorder);
}

.gallery-header h2 {
    font-family: 'Outfit';
    color: var(--theme-uiTextMain);
    font-size: 1.5rem;
    margin: 0;
    letter-spacing: 1px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--theme-uiTextMuted);
    cursor: pointer;
}

.gallery-tabs {
    display: flex;
    padding: 15px;
    gap: 10px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border-radius: 15px;
    border: 2px solid var(--theme-uiPanelBorder);
    background: transparent;
    color: var(--theme-uiTextMain);
    font-family: 'Outfit';
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--theme-uiStatBoxBorder);
    color: white;
}

#bgm-gallery-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

/* Composer Grid */
.composer-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.composer-card {
    background: var(--theme-uiPanelBg);
    border: 2px solid var(--theme-uiPanelBorder);
    border-radius: 15px;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.composer-card:hover {
    transform: translateY(-5px);
    background: var(--theme-uiBg);
}

.composer-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 10px;
    margin-bottom: 8px;
    background: rgba(0,0,0,0.2);
}

.composer-card .composer-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--theme-uiTextMain);
}

/* Track List */
.track-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.track-item {
    background: var(--theme-uiPanelBg);
    border: 2px solid var(--theme-uiPanelBorder);
    border-radius: 12px;
    padding: 12px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s;
}

.track-item.locked {
    opacity: 0.5;
    cursor: default;
    filter: grayscale(0.5);
}

.track-item.unlocked:hover {
    background: var(--theme-uiBg);
    border-color: var(--theme-uiStatBoxBorder);
}

.track-info-mini {
    display: flex;
    flex-direction: column;
}

.track-name-mini {
    font-weight: 700;
    color: var(--theme-uiTextMain);
    font-size: 0.95rem;
}

.track-composer-mini {
    font-size: 0.8rem;
    color: var(--theme-uiTextMuted);
}

.lock-icon {
    font-size: 1.2rem;
}

/* Preview Modal */
.preview-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    z-index: var(--z-index-settings);
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-modal {
    width: 90%;
    max-width: 450px;
    background: var(--theme-uiBg);
    border: 3px solid var(--theme-uiPanelBorder);
    border-radius: 20px;
    padding: 20px;
    position: relative;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
}

.stage-grid {
    display: grid;
    /* スマホの狭い画面でも確実にはみ出さないよう、最小幅を45pxに下げて自動折り返し（auto-fill）を設定 */
    grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
    gap: 8px;
    padding: 15px 0;
    width: 100%;
    box-sizing: border-box;
}

.stage-btn {
    width: 100%;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

/* タイトル画面用ステージセレクトのスクロール設定 */
#stage-buttons-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 15px;
    touch-action: pan-y !important;
    -webkit-overflow-scrolling: touch;
}

#stage-buttons-container::-webkit-scrollbar {
    width: 6px;
}
#stage-buttons-container::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.05);
    border-radius: 10px;
}
#stage-buttons-container::-webkit-scrollbar-thumb {
    background: var(--color-accent-primary);
    border-radius: 10px;
}

/* 操作方法選択モーダル専用スタイル */
.control-select-modal {
    max-width: 550px !important;
}

.select-desc {
    color: var(--theme-uiTextMuted);
    font-size: 0.9rem;
    margin: 0 0 20px 0;
    line-height: 1.5;
    text-align: center;
}

.control-options-container {
    display: flex;
    gap: 15px;
    margin-bottom: 25px;
    text-align: left;
}

.control-card {
    flex: 1;
    padding: 18px;
    border: 2px solid var(--theme-uiPanelBorder);
    border-radius: 15px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.02);
    transition: transform 0.2s, border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.control-card:hover {
    transform: translateY(-3px);
    border-color: var(--theme-uiStatBoxBorder);
    background: rgba(255, 255, 255, 0.05);
}

.control-card.active {
    border-color: var(--color-accent-primary);
    background: rgba(255, 183, 178, 0.08); /* 淡いテーマカラー */
    box-shadow: 0 0 15px rgba(255, 183, 178, 0.2);
}

.control-card .card-header {
    font-weight: 700;
    font-size: 1.05rem;
    margin-bottom: 8px;
    color: var(--theme-uiTextMain);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-card.active .card-header {
    color: var(--color-accent-primary);
}

.control-card .card-desc {
    font-size: 0.78rem;
    color: var(--theme-uiTextMuted);
    line-height: 1.45;
    margin: 0;
    flex: 1;
}

.control-svg-wrapper {
    margin-top: 15px;
    text-align: center;
    color: var(--theme-uiTextMuted);
}

.control-card.active .control-svg-wrapper {
    color: var(--color-accent-primary);
}

.control-preview-svg {
    width: 80px;
    height: 50px;
    opacity: 0.8;
}

/* スマホ等での縦並びレスポンシブ対応 */
@media (max-width: 480px) {
    .control-options-container {
        flex-direction: column;
        gap: 12px;
    }
    .control-card {
        padding: 14px;
    }
    .control-svg-wrapper {
        display: none; /* 縦幅を抑えるためモバイルではプレビューイラストを非表示 */
    }
}
