/* ============ 基本設定（ダークモードがデフォルト） ============ */

:root {
    --color-bg: #000000;
    --color-text: #ffffff;
    --color-placeholder: #8f8f8f;
    --color-accent: #1da1f2;
    --color-border: #ffffff;
}

/* ライトモード用の色定義 */
body.light-mode {
    --color-bg: #ffffff;
    --color-text: #000000;
    --color-placeholder: #8f8f8f;
    --color-accent: #1da1f2;
    --color-border: #000000;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: "Hiragino Mincho ProN", "Times New Roman", serif;
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* ============ ヘッダー ============ */

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

.app-title {
    font-size: 28px;
    letter-spacing: 2px;
    margin: 0;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.output-count-select {
    background-color: var(--color-bg);
    /* 追加 */
    color: var(--color-text);
    border: 1px solid var(--color-border);
    padding: 4px 8px;
    font-size: 14px;
}

.icon-button {
    background: none;
    border: none;
    color: var(--color-text);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
}

/* ============ トグルスイッチ（ダーク/ライト切替） ============ */

.theme-toggle {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.theme-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: transparent;
    border: 1.5px solid var(--color-border);
    border-radius: 20px;
    transition: 0.2s;
}

.theme-toggle-slider::before {
    content: "";
    position: absolute;
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: var(--color-border);
    border-radius: 50%;
    transition: 0.2s;
}

/* チェック時（ONの時）はスライダーの丸を右へ移動 */
.theme-toggle input:checked+.theme-toggle-slider::before {
    transform: translateX(16px);
}

/* ============ メインエリア ============ */

.tweet-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* 追加：上から順に並べる */
    gap: 16px;
    padding: 40px 12px 140px;
}

.placeholder-text {
    color: var(--color-placeholder);
    font-size: 18px;
    letter-spacing: 1px;
}

/* ============ 左下の固定ボタン群 ============ */

.floating-buttons {
    position: fixed;
    left: 24px;
    bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.btn {
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    font-weight: bold;
    color: #ffffff;
    background-color: var(--color-accent);
    cursor: pointer;
}

.btn:hover {
    opacity: 0.85;
}

.btn-top {
    font-size: 13px;
    padding: 6px 16px;
}

/* ============ 設定モーダル ============ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    position: relative;
    background-color: var(--color-bg);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 32px;
    min-width: 300px;
}

.modal-close-button {
    position: absolute;
    top: 8px;
    right: 12px;
    background: none;
    border: none;
    font-size: 20px;
    color: var(--color-text);
    cursor: pointer;
}

/* ============ 投稿カード（既存分。テーマに合わせて色を変数化） ============ */

.tweet-card,
.error-card {
    width: 100%;
    margin: 0 auto;
    /* 追加：横方向を確実に中央寄せ */
    background-color: var(--color-bg);
    border-radius: 12px;
    padding: 16px;
    color: var(--color-text);
}

/* ============ モーダル：外側クリックで閉じる/スムーズな開閉 ============ */

.modal-overlay {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.modal-overlay.show {
    opacity: 1;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    transform: scale(0.95);
    transition: transform 0.2s ease;
    max-height: 80vh;
    overflow-y: auto;
    /* スクロール可能 */
    width: 90%;
    max-width: 560px;
}

.modal-overlay.show .modal-content {
    transform: scale(1);
}

.modal-hint {
    font-size: 13px;
    color: var(--color-text);
    margin-bottom: 12px;
}

/* ============ プレビュー枠（ドラッグ&ドロップ用） ============ */

.button-preview-frame {
    position: relative;
    width: 100%;
    height: 260px;
    background-color: #000000;
    color: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
}

.preview-header {
    padding: 10px 14px;
    border-bottom: 1px solid #ffffff;
    font-size: 15px;
}

.preview-draggable-button {
    position: absolute;
    cursor: grab;
    transform-origin: top left;
}

.preview-draggable-button:active {
    cursor: grabbing;
}

/* ============ サイズ変更スライダー ============ */

.slider-group {
    margin-bottom: 14px;
}

.slider-group label {
    font-size: 12px;
    display: block;
    margin-bottom: 4px;
}

.slider-group input[type="range"] {
    width: 100%;
}

.slider-scale {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--color-placeholder);
}

/* ============ トグル行 ============ */

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
}

/* ============ 実ページの浮動ボタン（絶対配置に変更） ============ */

.floating-buttons {
    position: static;
    /* 個々のボタンがfixedで自身の位置を持つため無効化 */
}

.floating-buttons .btn {
    position: fixed;
    left: 24px;
    transform-origin: top left;
}

#top-button {
    bottom: 84px;
}

#rand-button {
    bottom: 24px;
}

#unified-button {
    bottom: 24px;
}

.hidden {
    display: none !important;
}

.tweet-images {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* 画像を左寄せにし、余白があっても中央に伸びないようにする */
    gap: 8px;
}

.tweet-images img {
    display: block;
    /* inlineの横並び挙動を断ち切る */
    width: auto;
    /* 本来のサイズを維持する */
    height: auto;
    max-width: 100%;
    /* 画面幅を超えないよう上限だけ設定 */
    border-radius: 8px;
}

/* ============ スマホ用レイアウト（画面幅600px以下） ============ */

@media (max-width: 600px) {

    .app-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 16px;
    }

    .app-title {
        font-size: 20px;
        /* PCでは28px */
    }

    .header-controls {
        width: 100%;
        justify-content: space-between;
    }

    .tweet-container {
        padding: 20px 8px 160px;
        /* 下部の固定ボタンと被らないよう広めに確保 */
        gap: 12px;
    }

    .tweet-card,
    .error-card {
        padding: 12px;
        /* PCでは16px */
    }

    .tweet-icon {
        width: 36px;
        /* PCでは48px */
        height: 36px;
    }

    .tweet-username {
        font-size: 14px;
    }

    .tweet-date {
        font-size: 11px;
    }

    /* モーダルも画面幅いっぱいに近い形で表示 */
    .modal-content {
        width: 95%;
        padding: 20px;
        max-height: 85vh;
    }

    .button-preview-frame {
        height: 200px;
        /* PCでは260px、スマホでは操作領域を圧縮 */
    }
}

/* ============ 動画プレイヤー ============ */

.video-player {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.video-player video {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    border-radius: 8px;
}

.video-custom-controls {
    display: flex;
    gap: 8px;
}

.video-control-button {
    background-color: var(--color-accent);
    color: #ffffff;
    border: none;
    border-radius: 16px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
}

.video-control-button:hover {
    opacity: 0.85;
}

/* ============ インフィード広告プレースホルダー ============ */

.content-slot {
    width: 100%;
    max-width: 500px;
    min-height: 100px;
    margin: 0 auto;
    background-color: rgba(128, 128, 128, 0.15);
    border: 1px dashed var(--color-placeholder);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-placeholder);
    font-size: 13px;
    letter-spacing: 2px;
}

.content-slot-sidebar {
    display: none;
}

@media (min-width: 601px) {
    .content-slot-sidebar {
        display: flex;
        position: fixed;
        right: 24px;
        bottom: 24px;
        width: 160px;
        height: 300px;
    }
}

/* ============ 設定モーダルのプレビュー枠内に、広告除外エリアを視覚化する ============ */

.button-preview-frame::after {
    content: "広告エリア（配置不可）";
    position: absolute;
    right: 0;
    bottom: 0;
    width: 22%;
    height: 25%;
    background-color: rgba(255, 0, 0, 0.15);
    border: 1px dashed rgba(255, 0, 0, 0.5);
    font-size: 9px;
    color: #ff8080;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: none;
}

/* ============ フッター：広告までのカウントダウン ============ */

.app-footer {
    position: fixed;
    bottom: 4px;
    left: 0;
    width: 100%;
    text-align: center;
    pointer-events: none;
    /* ボタン操作の邪魔をしないようクリックを透過させる */
    z-index: 5;
}

.interstitial-countdown {
    font-size: 11px;
    color: var(--color-placeholder);
}

/* ============ インタースティシャル広告（全画面） ============ */

.interstitial-content {
    width: 90%;
    max-width: 400px;
    padding: 0;
    position: relative;
    /* 追加：閉じるボタンの基準位置を明確にする */
}

.interstitial-close-button {
    z-index: 10;
    /* 追加：広告プレースホルダーより手前に表示する */
    background-color: rgba(0, 0, 0, 0.5);
    /* 追加：どんな背景色の広告が来ても視認できるようにする */
    border-radius: 50%;
    width: 28px;
    height: 28px;
}

.ad-slot-fullscreen {
    min-height: 500px;
    max-width: none;
    border-radius: 12px;
}