/* ===== CSS変数定義 ===== */
:root {
    --primary: #2D5BFF;
    --primary-dark: #1E3FA0;
    --secondary: #FF6B35;
    --bg-main: #0F1419;
    --bg-secondary: #1A1F29;
    --bg-tertiary: #242B38;
    --text-primary: #E8E9ED;
    --text-secondary: #A0A5B8;
    --border: #2D3748;
    --success: #10B981;
    --warning: #F59E0B;
    --error: #EF4444;
    --code-bg: #0D1117;
    --shadow: rgba(0, 0, 0, 0.3);
}

/* ===== 基本リセット ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Hiragino Sans', 'Yu Gothic UI', sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* ===== ヘッダー ===== */
.header {
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 4px 12px var(--shadow);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* ===== ボタン ===== */
.btn {
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(45, 91, 255, 0.3);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

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

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

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

.btn-warning:hover {
    background: #D97706;
}

/* ===== メインコンテナ ===== */
.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
}

/* ===== ドロップゾーン ===== */
.drop-zone {
    border: 3px dashed var(--border);
    border-radius: 12px;
    padding: 4rem 2rem;
    text-align: center;
    background: var(--bg-secondary);
    margin-bottom: 2rem;
    transition: all 0.3s ease;
}

.drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(45, 91, 255, 0.05);
    transform: scale(1.02);
}

.drop-zone.loaded {
    display: none;
}

.drop-zone-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.drop-zone h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.drop-zone p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ===== エディタエリア ===== */
.editor-area {
    display: none;
    animation: fadeIn 0.3s ease;
}

.editor-area.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== モード切替 ===== */
.mode-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    background: var(--bg-secondary);
    padding: 0.5rem;
    border-radius: 8px;
}

.mode-btn {
    flex: 1;
    padding: 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    font-weight: 600;
    transition: all 0.2s ease;
}

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

/* ===== セクション ===== */
.section {
    background: var(--bg-secondary);
    border-radius: 12px;
    margin-bottom: 1.5rem;
    overflow: hidden;
    border: 1px solid var(--border);
}

.section-header {
    padding: 1rem 1.5rem;
    background: var(--bg-tertiary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.section-header:hover {
    background: #2a3340;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-toggle {
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}

.section-toggle.collapsed {
    transform: rotate(-180deg);
}

.section-content {
    padding: 1.5rem;
    max-height: 600px;
    overflow-y: auto;
    overflow-x: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
}

.section-content.collapsed {
    max-height: 0;
    padding: 0 1.5rem;
    overflow: hidden;
}

/* カスタムスクロールバー */
.section-content::-webkit-scrollbar {
    width: 8px;
}

.section-content::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.section-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.section-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* ===== フォームグループ ===== */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45, 91, 255, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
    font-family: 'Consolas', 'Monaco', monospace;
}

/* ===== エディタブルリスト ===== */
.editable-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.editable-item {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

.editable-item:hover {
    border-color: var(--primary);
}

.editable-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.editable-item-tag {
    font-family: 'Consolas', 'Monaco', monospace;
    color: var(--secondary);
    font-weight: 600;
    font-size: 0.9rem;
}

.item-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    padding: 0.4rem 0.6rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: var(--border);
    color: var(--text-primary);
}

.btn-delete:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.btn-edit-code:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* ===== コードエディタ ===== */
.code-editor {
    background: var(--code-bg);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.code-editor-header {
    background: #161b22;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.code-editor-title {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'Consolas', 'Monaco', monospace;
}

.code-editor-textarea {
    width: 100%;
    min-height: 400px;
    padding: 1.5rem;
    background: var(--code-bg);
    border: none;
    color: #c9d1d9;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    resize: vertical;
    tab-size: 2;
}

.code-editor-textarea:focus {
    outline: none;
}

/* ===== カスタムタグ ===== */
.custom-tag-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.custom-tag-card {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s ease;
}

.custom-tag-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.custom-tag-card-title {
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.custom-tag-card-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: 'Consolas', 'Monaco', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== モーダル ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-title {
    font-size: 1.3rem;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ===== 通知 ===== */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 8px;
    border-left: 4px solid var(--success);
    box-shadow: 0 4px 16px var(--shadow);
    z-index: 3000;
    animation: slideIn 0.3s ease;
    display: none;
}

.notification.active {
    display: block;
}

.notification.error {
    border-left-color: var(--error);
}

.notification.warning {
    border-left-color: var(--warning);
}

.ninjabox {
    transform: scale(1);
    margin-left: 0;
}
.ninjaleft {
    transform: scale(1);
    margin-left: 0;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ===== レスポンシブ ===== */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }

    .header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .custom-tag-list {
        grid-template-columns: 1fr;
    }

    .ninjabox {
    transform: scale(0.75);
    margin-left: -10px;
    }
    .ninjaleft {
        transform: scale(0.7);
        margin-left: -2rem;
    }
}

/* ===== 追加要素用のスタイル ===== */
.add-element-popup {
    position: absolute;
    background: var(--bg-secondary);
    border: 2px solid var(--primary);
    border-radius: 8px;
    padding: 1rem;
    z-index: 1000;
    box-shadow: 0 8px 24px var(--shadow);
    display: none;
    min-width: 300px;
}

.add-element-popup h4 {
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.element-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.btn-add-element {
    padding: 0.5rem 1rem;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.btn-add-element:hover {
    background: var(--primary);
    border-color: var(--primary);
}

.insert-position {
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.btn-position {
    flex: 1;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.btn-position:hover,
.btn-position.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ===== リサイザー ===== */
.resizer {
    height: 4px;
    background: var(--border);
    cursor: ns-resize;
    position: relative;
    margin: 0.5rem 0;
    border-radius: 2px;
    transition: background 0.2s ease;
}

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

.resizer::after {
    content: '⋮';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-secondary);
    font-size: 1rem;
}