/* ピンパズル ステージエディタ - スタイル */

:root {
    --bg-dark: #1a1b26;
    --bg-panel: #24283b;
    --bg-hover: #414868;
    --accent: #7aa2f7;
    --accent-hover: #89b4fa;
    --danger: #f7768e;
    --success: #9ece6a;
    --text: #e0e8f0;
    --text-muted: #a8b8d4;
    --text-strong: #ffffff;
    --page-text: #e0e8f0;
    --page-text-muted: #b8c5dc;
    --page-text-strong: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

body {
    font-family: 'Segoe UI', 'Yu Gothic UI', sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    overflow: auto;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ヘッダー */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--text-muted);
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.toolbar {
    display: flex;
    gap: 12px;
}

/* ステージエディタ: ログイン中表示（モバイルでは非表示） */
.editor-header-user {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
    min-width: 0;
}

/* ステージエディタ: トップ（index）へ。モバイル幅では非表示 */
.editor-home-link {
    font-size: 0.9rem;
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: 500;
}

.editor-home-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--text-muted);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #ff6b8a;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #b9f27c;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* メインエリア */
.main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* サイドバー */
.sidebar {
    width: 220px;
    padding: 16px;
    background: var(--bg-panel);
    border-right: 1px solid var(--text-muted);
    overflow-y: auto;
}

.sidebar h3 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.module-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.module-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-dark);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.module-item:hover {
    background: var(--bg-hover);
}

.module-item.selected {
    border: 2px solid var(--accent);
    background: rgba(122, 162, 247, 0.1);
}

.module-preview {
    width: 32px;
    height: 32px;
    border-radius: 4px;
}

.person-preview {
    background: linear-gradient(135deg, #a6e3a1 0%, #94e2d5 100%);
}

.pin-preview {
    background: linear-gradient(135deg, #f7768e 0%, #ff9e64 100%);
}

.obstacle-preview {
    background: linear-gradient(135deg, #565f89 0%, #414868 100%);
}

.objects-list {
    margin-top: 8px;
}

.object-preview {
    width: 32px;
    height: 32px;
    border-radius: 4px;
}

.object-preview.circle {
    border-radius: 50%;
}

.props-panel {
    margin-bottom: 24px;
    padding: 12px;
    background: var(--bg-dark);
    border-radius: 8px;
    border: 1px solid var(--text-muted);
}

.props-panel.hidden {
    display: none;
}


.tool-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 24px;
}

.tool-btn {
    padding: 10px;
    background: var(--bg-dark);
    border: 1px solid var(--text-muted);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.tool-btn:hover {
    background: var(--bg-hover);
}

.tool-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.stage-props label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.stage-props input {
    width: 80px;
    padding: 4px 8px;
    margin-left: 8px;
    background: var(--bg-dark);
    border: 1px solid var(--text-muted);
    border-radius: 4px;
    color: var(--text);
}

/* エディタエリア */
.editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    overflow: auto;
    min-width: 0;
}

.canvas-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-dark);
    border-radius: 8px;
    min-height: 400px;
    position: relative;
}

.stage-wrap {
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
}

#stage-canvas {
    display: block;
    margin: auto;
    cursor: crosshair;
    touch-action: none;
}

#stage-canvas.place-mode {
    cursor: crosshair;
}

#stage-canvas.select-mode {
    cursor: move;
}

#stage-canvas.delete-mode {
    cursor: crosshair;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    padding: 8px 16px;
    margin-top: 8px;
    background: var(--bg-panel);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* エディタのクリア条件セレクト */
.stage-props select {
    width: 100%;
    padding: 5px 8px;
    margin-top: 4px;
    background: var(--bg-dark);
    border: 1px solid var(--text-muted);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.85rem;
}

/* ===== ボトムシート: デスクトップでは非表示 ===== */
.mobile-bottom-sheet {
    display: none;
}

.btn-short-text {
    display: none;
}

/* ===== モバイル対応 (max-width: 840px) ===== */
@media (max-width: 840px) {
    /* ゲーム TOP・エディタのみ body 固定（お問い合わせ等の単独ページはスクロール可能に） */
    body:has(.app-main),
    body:has(.app) {
        overflow: hidden;
    }

    /* ヘッダー */
    .header {
        padding: 8px 10px;
        gap: 6px;
    }

    .header h1 {
        font-size: 0.82rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100px;
        flex-shrink: 1;
    }

    .toolbar {
        gap: 5px;
        flex-shrink: 0;
    }

    .editor-header-user {
        display: none !important;
    }

    .editor-home-link {
        display: none !important;
    }

    .header-right {
        gap: 5px;
    }

    .toolbar .btn {
        padding: 6px 8px;
        font-size: 0.78rem;
        white-space: nowrap;
    }

    .btn-full-text {
        display: none;
    }

    .btn-short-text {
        display: inline;
    }

    /* メインエリア: 縦並びに変更 */
    .main {
        flex-direction: column;
    }

    /* サイドバーを非表示 */
    .sidebar {
        display: none;
    }

    /* エディタエリア: ピン持ち手が端で切れないよう左右に確保しつつ、詰めすぎない */
    .editor-area {
        padding: 8px 14px;
        overflow: auto;
        min-height: 0;
        flex: 1;
        align-items: flex-start;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* ステータスバー横パディングを詰める */
    .editor-area .status-bar {
        padding: 6px 8px;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* canvas-container: 中央揃えをやめ、左上起点にしてスクロールを自然に */
    .canvas-container {
        min-height: 0;
        flex: 0 0 auto;
        height: auto;
        justify-content: flex-start;
        align-items: flex-start;
        align-self: flex-start;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* margin:auto が横に均等な「余白」に見えるのをやめる（縮尺は editor.js が担当） */
    .editor-area #stage-canvas {
        margin: 0;
        max-width: 100%;
        display: block;
    }

    /* ===== ボトムシート ===== */
    .mobile-bottom-sheet {
        display: flex;
        flex-direction: column;
        height: 190px;
        flex-shrink: 0;
        background: var(--bg-panel);
        border-top: 2px solid var(--text-muted);
    }

    /* タブバー */
    .bs-tab-bar {
        display: flex;
        flex-shrink: 0;
        border-bottom: 1px solid var(--text-muted);
    }

    .bs-tab-btn {
        flex: 1;
        padding: 8px 12px;
        background: transparent;
        border: none;
        border-bottom: 3px solid transparent;
        color: var(--text-muted);
        font-size: 0.85rem;
        cursor: pointer;
        transition: color 0.15s;
    }

    .bs-tab-btn.active {
        color: var(--accent);
        border-bottom-color: var(--accent);
    }

    /* タブコンテンツエリア */
    .bs-content {
        flex: 1;
        overflow-y: auto;
        padding: 10px;
    }

    .bs-panel.bs-hidden {
        display: none;
    }

    /* パーツタブ: ツール選択 */
    .bs-tools {
        display: flex;
        gap: 6px;
        margin-bottom: 10px;
    }

    .bs-tools .tool-btn {
        flex: 1;
        padding: 7px 4px;
        font-size: 0.82rem;
        text-align: center;
    }

    /* パーツタブ: モジュール一覧（横並び） */
    .bs-modules {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }

    .bs-modules .module-item {
        flex-direction: column;
        align-items: center;
        padding: 8px 6px;
        min-width: 60px;
        max-width: 80px;
        font-size: 0.75rem;
        gap: 4px;
        flex: 0 0 auto;
    }

    .bs-modules .module-list {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        margin-bottom: 0;
    }

    /* パーツタブ: セクションラベル */
    .bs-section-label {
        font-size: 0.72rem;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        margin: 10px 0 4px;
    }

    .bs-section-label:first-child {
        margin-top: 0;
    }

    /* 両スロットdivを透過させ、子要素を親flexに直接参加させる */
    #bs-basic-object-slot,
    #bs-optional-object-slot {
        display: contents;
    }

    /* #object-list が親 flex の直接子になるので幅いっぱいに広げ横並びにする */
    #bs-optional-modules #object-list {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        margin-bottom: 0;
        flex: 1 1 100%;
        width: 100%;
    }

    /* 設定タブ */
    #bs-panel-settings .stage-props {
        margin-bottom: 14px;
    }

    #bs-panel-settings > .btn {
        margin-top: 4px;
        width: 100%;
    }
}

/* ===== 単独ページ（マイページ等）の本文 ===== */
.page-content {
    color: var(--page-text);
}
.page-content h1,
.page-content h2 {
    color: var(--page-text-strong);
}
.page-muted {
    color: var(--page-text-muted);
}

/* ===== 暗背景用データテーブル ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.data-table thead tr {
    background: rgba(255, 255, 255, 0.1);
}
.data-table th {
    padding: 8px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--page-text-strong);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}
.data-table td {
    padding: 8px 10px;
    color: var(--page-text);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    vertical-align: middle;
}
.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* ===== 白背景モーダル（暗いページ上） ===== */
.panel-light {
    background: #ffffff;
    color: #1a1d26;
    padding: 20px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.panel-light h1,
.panel-light h2,
.panel-light h3,
.panel-light label,
.panel-light p,
.panel-light span,
.panel-light div {
    color: #1a1d26;
}
.panel-light a {
    color: #0d6efd;
}
.panel-light .panel-notice {
    color: #343a40;
    background: #e9ecef;
    border-left: 3px solid #0d6efd;
    padding: 10px 12px;
    border-radius: 6px;
    line-height: 1.5;
    font-size: 0.875rem;
    margin: 0 0 12px;
}
.panel-light input[type="text"],
.panel-light input[type="email"],
.panel-light input[type="number"],
.panel-light textarea,
.panel-light select {
    color: #1a1d26;
    background: #ffffff;
    border: 1px solid #adb5bd;
}
.panel-light input::placeholder,
.panel-light textarea::placeholder {
    color: #6c757d;
}
.panel-light .btn-secondary {
    background: #f1f3f5;
    color: #212529;
    border: 1px solid #ced4da;
}
.panel-light .btn-secondary:hover {
    background: #e9ecef;
    color: #1a1d26;
}
.panel-light .btn-primary {
    color: #ffffff;
}
